fbrosson | 3a74571 | 2018-04-04 22:26:56 +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 | 056eab5 | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 3 | # key-exchanges.pl |
| 4 | # |
Bence Szépkúti | 44bfbe3 | 2020-08-19 16:54:51 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 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: |
Bence Szépkúti | 09b4f19 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 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 | # |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 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 | # |
Manuel Pégourié-Gonnard | 056eab5 | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 47 | # Purpose |
| 48 | # |
| 49 | # To test the code dependencies on individual key exchanges in the SSL module. |
| 50 | # is a verification step to ensure we don't ship SSL code that do not work |
| 51 | # for some build options. |
| 52 | # |
| 53 | # The process is: |
| 54 | # for each possible key exchange |
| 55 | # build the library with all but that key exchange disabled |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 56 | # |
| 57 | # Usage: tests/scripts/key-exchanges.pl |
Manuel Pégourié-Gonnard | 056eab5 | 2017-06-06 11:51:34 +0200 | [diff] [blame] | 58 | # |
| 59 | # This script should be executed from the root of the project directory. |
| 60 | # |
| 61 | # For best effect, run either with cmake disabled, or cmake enabled in a mode |
| 62 | # that includes -Werror. |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 63 | |
| 64 | use warnings; |
| 65 | use strict; |
| 66 | |
| 67 | -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n"; |
| 68 | |
| 69 | my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p'; |
| 70 | my $config_h = 'include/mbedtls/config.h'; |
| 71 | my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` ); |
| 72 | |
| 73 | system( "cp $config_h $config_h.bak" ) and die; |
| 74 | sub abort { |
| 75 | system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n"; |
Manuel Pégourié-Gonnard | fa973e0 | 2017-10-26 09:47:36 +0200 | [diff] [blame] | 76 | # use an exit code between 1 and 124 for git bisect (die returns 255) |
Manuel Pégourié-Gonnard | b26b28a | 2017-07-12 12:15:24 +0200 | [diff] [blame] | 77 | warn $_[0]; |
| 78 | exit 1; |
Manuel Pégourié-Gonnard | 5df9216 | 2015-10-22 16:11:39 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | for my $kex (@kexes) { |
| 82 | system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 83 | system( "make clean" ) and die; |
| 84 | |
| 85 | print "\n******************************************\n"; |
| 86 | print "* Testing with key exchange: $kex\n"; |
| 87 | print "******************************************\n"; |
| 88 | |
| 89 | # full config with all key exchanges disabled except one |
| 90 | system( "scripts/config.pl full" ) and abort "Failed config full\n"; |
| 91 | for my $k (@kexes) { |
| 92 | next if $k eq $kex; |
| 93 | system( "scripts/config.pl unset $k" ) |
| 94 | and abort "Failed to disable $k\n"; |
| 95 | } |
| 96 | |
Manuel Pégourié-Gonnard | 50bd260 | 2015-10-23 08:53:34 +0200 | [diff] [blame] | 97 | 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] | 98 | } |
| 99 | |
| 100 | system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; |
| 101 | system( "make clean" ) and die; |
| 102 | exit 0; |