blob: be9567f52a44e0bc66ad1c0b5d674bfa8836f076 [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#
5# Copyright (c) 2015-2017, ARM Limited, All Rights Reserved
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#
20# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020021#
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é-Gonnard5df92162015-10-22 16:11:39 +020031#
32# Usage: tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020033#
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é-Gonnard5df92162015-10-22 16:11:39 +020038
39use warnings;
40use strict;
41
42-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
43
44my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p';
45my $config_h = 'include/mbedtls/config.h';
46my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
47
48system( "cp $config_h $config_h.bak" ) and die;
49sub abort {
50 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020051 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020052 warn $_[0];
53 exit 1;
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020054}
55
56for 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 Peskinea9478ba2019-09-18 18:45:35 +020063 $ENV{MBEDTLS_TEST_CONFIGURATION} = $kex;
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020064
65 # full config with all key exchanges disabled except one
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020066 system( "scripts/config.py full" ) and abort "Failed config full\n";
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020067 for my $k (@kexes) {
68 next if $k eq $kex;
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020069 system( "scripts/config.py unset $k" )
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020070 and abort "Failed to disable $k\n";
71 }
72
Manuel Pégourié-Gonnard50bd2602015-10-23 08:53:34 +020073 system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n";
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020074}
75
76system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
77system( "make clean" ) and die;
78exit 0;