Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 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 |
| 6 | # |
| 7 | # Purpose |
| 8 | # |
| 9 | # To test the code dependencies on individual key exchanges in the SSL module. |
| 10 | # is a verification step to ensure we don't ship SSL code that do not work |
| 11 | # for some build options. |
| 12 | # |
| 13 | # The process is: |
| 14 | # for each possible key exchange |
| 15 | # build the library with all but that key exchange disabled |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 16 | # |
| 17 | # Usage: tests/scripts/key-exchanges.pl |
Manuel Pégourié-Gonnard | 9ba9dfb | 2017-06-06 11:51:34 +0200 | [diff] [blame^] | 18 | # |
| 19 | # This script should be executed from the root of the project directory. |
| 20 | # |
| 21 | # For best effect, run either with cmake disabled, or cmake enabled in a mode |
| 22 | # that includes -Werror. |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 23 | |
| 24 | use warnings; |
| 25 | use strict; |
| 26 | |
| 27 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 28 | |
| 29 | my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p'; |
| 30 | my $config_h = 'include/mbedtls/config.h'; |
| 31 | my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` ); |
| 32 | |
| 33 | system( "cp $config_h $config_h.bak" ) and die; |
| 34 | sub abort { |
| 35 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
| 36 | die $_[0]; |
| 37 | } |
| 38 | |
| 39 | for my $kex (@kexes) { |
| 40 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 41 | system( "make clean" ) and die; |
| 42 | |
| 43 | print "\n******************************************\n"; |
| 44 | print "* Testing with key exchange: $kex\n"; |
| 45 | print "******************************************\n"; |
| 46 | |
| 47 | # full config with all key exchanges disabled except one |
| 48 | system( "scripts/config.pl full" ) and abort "Failed config full\n"; |
| 49 | for my $k (@kexes) { |
| 50 | next if $k eq $kex; |
| 51 | system( "scripts/config.pl unset $k" ) |
| 52 | and abort "Failed to disable $k\n"; |
| 53 | } |
| 54 | |
Manuel Pégourié-Gonnard | 50bd260 | 2015-10-23 08:53:34 +0200 | [diff] [blame] | 55 | 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] | 56 | } |
| 57 | |
| 58 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 59 | system( "make clean" ) and die; |
| 60 | exit 0; |