• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env perl
2
3# depends-pkalgs.pl
4#
5# Copyright The Mbed TLS Contributors
6# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# This file is provided under the Apache License 2.0, or the
9# GNU General Public License v2.0 or later.
10#
11# **********
12# Apache License 2.0:
13#
14# Licensed under the Apache License, Version 2.0 (the "License"); you may
15# not use this file except in compliance with the License.
16# You may obtain a copy of the License at
17#
18# http://www.apache.org/licenses/LICENSE-2.0
19#
20# Unless required by applicable law or agreed to in writing, software
21# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23# See the License for the specific language governing permissions and
24# limitations under the License.
25#
26# **********
27#
28# **********
29# GNU General Public License v2.0 or later:
30#
31# This program is free software; you can redistribute it and/or modify
32# it under the terms of the GNU General Public License as published by
33# the Free Software Foundation; either version 2 of the License, or
34# (at your option) any later version.
35#
36# This program is distributed in the hope that it will be useful,
37# but WITHOUT ANY WARRANTY; without even the implied warranty of
38# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39# GNU General Public License for more details.
40#
41# You should have received a copy of the GNU General Public License along
42# with this program; if not, write to the Free Software Foundation, Inc.,
43# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
44#
45# **********
46#
47# Purpose
48#
49# To test the code dependencies on individual PK algs (those that can be used
50# from the PK layer, so currently signature and encryption but not key
51# exchange) in each test suite. This is a verification step to ensure we don't
52# ship test suites that do not work for some build options.
53#
54# The process is:
55#       for each possible PK alg
56#           build the library and test suites with that alg disabled
57#           execute the test suites
58#
59# And any test suite with the wrong dependencies will fail.
60#
61# Usage: tests/scripts/depends-pkalgs.pl
62#
63# This script should be executed from the root of the project directory.
64#
65# For best effect, run either with cmake disabled, or cmake enabled in a mode
66# that includes -Werror.
67
68use warnings;
69use strict;
70
71-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
72
73my $config_h = 'include/mbedtls/config.h';
74
75# Some algorithms can't be disabled on their own as others depend on them, so
76# we list those reverse-dependencies here to keep check_config.h happy.
77my %algs = (
78    'MBEDTLS_ECDSA_C'   => ['MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
79    'MBEDTLS_ECP_C'     => ['MBEDTLS_ECDSA_C',
80                            'MBEDTLS_ECDH_C',
81                            'MBEDTLS_ECJPAKE_C',
82                            'MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED',
83                            'MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED',
84                            'MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED',
85                            'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
86                            'MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED'],
87    'MBEDTLS_X509_RSASSA_PSS_SUPPORT'   => [],
88    'MBEDTLS_PKCS1_V21' => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT'],
89    'MBEDTLS_PKCS1_V15' => ['MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
90                            'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
91                            'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
92                            'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
93    'MBEDTLS_RSA_C'     => ['MBEDTLS_X509_RSASSA_PSS_SUPPORT',
94                            'MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED',
95                            'MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED',
96                            'MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED',
97                            'MBEDTLS_KEY_EXCHANGE_RSA_ENABLED'],
98);
99
100system( "cp $config_h $config_h.bak" ) and die;
101sub abort {
102    system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
103    # use an exit code between 1 and 124 for git bisect (die returns 255)
104    warn $_[0];
105    exit 1;
106}
107
108while( my ($alg, $extras) = each %algs ) {
109    system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
110    system( "make clean" ) and die;
111
112    print "\n******************************************\n";
113    print "* Testing without alg: $alg\n";
114    print "******************************************\n";
115
116    system( "scripts/config.pl unset $alg" )
117        and abort "Failed to disable $alg\n";
118    for my $opt (@$extras) {
119        system( "scripts/config.pl unset $opt" )
120            and abort "Failed to disable $opt\n";
121    }
122
123    system( "CFLAGS='-Werror -Wall -Wextra' make lib" )
124        and abort "Failed to build lib: $alg\n";
125    system( "cd tests && make" ) and abort "Failed to build tests: $alg\n";
126    system( "make test" ) and abort "Failed test suite: $alg\n";
127}
128
129system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
130system( "make clean" ) and die;
131exit 0;
132