blob: 46f1b975426e01f8c98de5bb92e6ed94e0fb894a [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +02002
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +02003# key-exchanges.pl
4#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020020# Purpose
21#
22# To test the code dependencies on individual key exchanges in the SSL module.
23# is a verification step to ensure we don't ship SSL code that do not work
24# for some build options.
25#
26# The process is:
27# for each possible key exchange
28# build the library with all but that key exchange disabled
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020029#
30# Usage: tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020031#
32# This script should be executed from the root of the project directory.
33#
34# For best effect, run either with cmake disabled, or cmake enabled in a mode
35# that includes -Werror.
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020036
37use warnings;
38use strict;
39
40-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
41
42my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p';
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020043my $config_h = 'include/mbedtls/mbedtls_config.h';
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020044my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
45
46system( "cp $config_h $config_h.bak" ) and die;
47sub abort {
48 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020049 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020050 warn $_[0];
51 exit 1;
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020052}
53
54for my $kex (@kexes) {
55 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
56 system( "make clean" ) and die;
57
58 print "\n******************************************\n";
59 print "* Testing with key exchange: $kex\n";
60 print "******************************************\n";
Gilles Peskinea9478ba2019-09-18 18:45:35 +020061 $ENV{MBEDTLS_TEST_CONFIGURATION} = $kex;
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020062
63 # full config with all key exchanges disabled except one
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020064 system( "scripts/config.py full" ) and abort "Failed config full\n";
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020065 for my $k (@kexes) {
66 next if $k eq $kex;
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020067 system( "scripts/config.py unset $k" )
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020068 and abort "Failed to disable $k\n";
69 }
70
Manuel Pégourié-Gonnard50bd2602015-10-23 08:53:34 +020071 system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n";
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020072}
73
74system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
75system( "make clean" ) and die;
76exit 0;