key-exchanges.pl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env perl
  2. # key-exchanges.pl
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. # Purpose
  20. #
  21. # To test the code dependencies on individual key exchanges in the SSL module.
  22. # is a verification step to ensure we don't ship SSL code that do not work
  23. # for some build options.
  24. #
  25. # The process is:
  26. # for each possible key exchange
  27. # build the library with all but that key exchange disabled
  28. #
  29. # Usage: tests/scripts/key-exchanges.pl
  30. #
  31. # This script should be executed from the root of the project directory.
  32. #
  33. # For best effect, run either with cmake disabled, or cmake enabled in a mode
  34. # that includes -Werror.
  35. use warnings;
  36. use strict;
  37. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  38. my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p';
  39. my $config_h = 'include/mbedtls/config.h';
  40. my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
  41. system( "cp $config_h $config_h.bak" ) and die;
  42. sub abort {
  43. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  44. # use an exit code between 1 and 124 for git bisect (die returns 255)
  45. warn $_[0];
  46. exit 1;
  47. }
  48. for my $kex (@kexes) {
  49. system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
  50. system( "make clean" ) and die;
  51. print "\n******************************************\n";
  52. print "* Testing with key exchange: $kex\n";
  53. print "******************************************\n";
  54. $ENV{MBEDTLS_TEST_CONFIGURATION} = $kex;
  55. # full config with all key exchanges disabled except one
  56. system( "scripts/config.py full" ) and abort "Failed config full\n";
  57. for my $k (@kexes) {
  58. next if $k eq $kex;
  59. system( "scripts/config.py unset $k" )
  60. and abort "Failed to disable $k\n";
  61. }
  62. system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n";
  63. }
  64. system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
  65. system( "make clean" ) and die;
  66. exit 0;