1#!/usr/bin/env perl 2 3# key-exchanges.pl 4# 5# Copyright The Mbed TLS Contributors 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# 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 29# 30# Usage: tests/scripts/key-exchanges.pl 31# 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. 36 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'; 43my $config_h = 'include/mbedtls/mbedtls_config.h'; 44my @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"; 49 # use an exit code between 1 and 124 for git bisect (die returns 255) 50 warn $_[0]; 51 exit 1; 52} 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"; 61 $ENV{MBEDTLS_TEST_CONFIGURATION} = $kex; 62 63 # full config with all key exchanges disabled except one 64 system( "scripts/config.py full" ) and abort "Failed config full\n"; 65 for my $k (@kexes) { 66 next if $k eq $kex; 67 system( "scripts/config.py unset $k" ) 68 and abort "Failed to disable $k\n"; 69 } 70 71 system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n"; 72} 73 74system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n"; 75system( "make clean" ) and die; 76exit 0; 77