blob: b20eee9238cbe8be2b98cfe7798b1a1b2e8ecefa [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útif744bd72020-06-05 13:02:18 +02006# 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úti51b41d52020-05-26 01:54:15 +020013#
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útif744bd72020-06-05 13:02:18 +020026# **********
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#
Bence Szépkúti51b41d52020-05-26 01:54:15 +020047# This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020048#
49# Purpose
50#
51# To test the code dependencies on individual key exchanges in the SSL module.
52# is a verification step to ensure we don't ship SSL code that do not work
53# for some build options.
54#
55# The process is:
56# for each possible key exchange
57# build the library with all but that key exchange disabled
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020058#
59# Usage: tests/scripts/key-exchanges.pl
Manuel Pégourié-Gonnard9ba9dfb2017-06-06 11:51:34 +020060#
61# This script should be executed from the root of the project directory.
62#
63# For best effect, run either with cmake disabled, or cmake enabled in a mode
64# that includes -Werror.
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020065
66use warnings;
67use strict;
68
69-d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
70
71my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p';
72my $config_h = 'include/mbedtls/config.h';
73my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
74
75system( "cp $config_h $config_h.bak" ) and die;
76sub abort {
77 system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
Manuel Pégourié-Gonnard254eec82017-10-26 09:47:36 +020078 # use an exit code between 1 and 124 for git bisect (die returns 255)
Manuel Pégourié-Gonnarda7c4c8a2017-07-12 12:15:24 +020079 warn $_[0];
80 exit 1;
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +020081}
82
83for my $kex (@kexes) {
84 system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
85 system( "make clean" ) and die;
86
87 print "\n******************************************\n";
88 print "* Testing with key exchange: $kex\n";
89 print "******************************************\n";
90
91 # full config with all key exchanges disabled except one
92 system( "scripts/config.pl full" ) and abort "Failed config full\n";
93 for my $k (@kexes) {
94 next if $k eq $kex;
95 system( "scripts/config.pl unset $k" )
96 and abort "Failed to disable $k\n";
97 }
98
Manuel Pégourié-Gonnard50bd2602015-10-23 08:53:34 +020099 system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n";
Manuel Pégourié-Gonnard5df92162015-10-22 16:11:39 +0200100}
101
102system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
103system( "make clean" ) and die;
104exit 0;