fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 2 | |
Manuel Pégourié-Gonnard | 9ba9dfb | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 3 | # key-exchanges.pl |
| 4 | # |
| 5 | # Copyright (c) 2015-2017, ARM Limited, All Rights Reserved |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame^] | 6 | # 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 | # |
| 20 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 9ba9dfb | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 21 | # |
| 22 | # Purpose |
| 23 | # |
| 24 | # To test the code dependencies on individual key exchanges in the SSL module. |
| 25 | # is a verification step to ensure we don't ship SSL code that do not work |
| 26 | # for some build options. |
| 27 | # |
| 28 | # The process is: |
| 29 | # for each possible key exchange |
| 30 | # build the library with all but that key exchange disabled |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 31 | # |
| 32 | # Usage: tests/scripts/key-exchanges.pl |
Manuel Pégourié-Gonnard | 9ba9dfb | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 33 | # |
| 34 | # This script should be executed from the root of the project directory. |
| 35 | # |
| 36 | # For best effect, run either with cmake disabled, or cmake enabled in a mode |
| 37 | # that includes -Werror. |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 38 | |
| 39 | use warnings; |
| 40 | use strict; |
| 41 | |
| 42 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 43 | |
| 44 | my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p'; |
| 45 | my $config_h = 'include/mbedtls/config.h'; |
| 46 | my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` ); |
| 47 | |
| 48 | system( "cp $config_h $config_h.bak" ) and die; |
| 49 | sub abort { |
| 50 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
Manuel Pégourié-Gonnard | 254eec8 | 2017-10-26 09:47:36 +0200 | [diff] [blame] | 51 | # use an exit code between 1 and 124 for git bisect (die returns 255) |
Manuel Pégourié-Gonnard | a7c4c8a | 2017-07-12 12:15:24 +0200 | [diff] [blame] | 52 | warn $_[0]; |
| 53 | exit 1; |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | for my $kex (@kexes) { |
| 57 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 58 | system( "make clean" ) and die; |
| 59 | |
| 60 | print "\n******************************************\n"; |
| 61 | print "* Testing with key exchange: $kex\n"; |
| 62 | print "******************************************\n"; |
Gilles Peskine | a9478ba | 2019-09-18 18:45:35 +0200 | [diff] [blame] | 63 | $ENV{MBEDTLS_TEST_CONFIGURATION} = $kex; |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 64 | |
| 65 | # full config with all key exchanges disabled except one |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 66 | system( "scripts/config.py full" ) and abort "Failed config full\n"; |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 67 | for my $k (@kexes) { |
| 68 | next if $k eq $kex; |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 69 | system( "scripts/config.py unset $k" ) |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 70 | and abort "Failed to disable $k\n"; |
| 71 | } |
| 72 | |
Manuel Pégourié-Gonnard | 50bd260 | 2015-10-23 08:53:34 +0200 | [diff] [blame] | 73 | system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n"; |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 77 | system( "make clean" ) and die; |
| 78 | exit 0; |