key-exchanges.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env perl
  2. # key-exchanges.pl
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. #
  7. # This file is provided under the Apache License 2.0, or the
  8. # GNU General Public License v2.0 or later.
  9. #
  10. # **********
  11. # Apache License 2.0:
  12. #
  13. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  14. # not use this file except in compliance with the License.
  15. # You may obtain a copy of the License at
  16. #
  17. # http://www.apache.org/licenses/LICENSE-2.0
  18. #
  19. # Unless required by applicable law or agreed to in writing, software
  20. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. # See the License for the specific language governing permissions and
  23. # limitations under the License.
  24. #
  25. # **********
  26. #
  27. # **********
  28. # GNU General Public License v2.0 or later:
  29. #
  30. # This program is free software; you can redistribute it and/or modify
  31. # it under the terms of the GNU General Public License as published by
  32. # the Free Software Foundation; either version 2 of the License, or
  33. # (at your option) any later version.
  34. #
  35. # This program is distributed in the hope that it will be useful,
  36. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. # GNU General Public License for more details.
  39. #
  40. # You should have received a copy of the GNU General Public License along
  41. # with this program; if not, write to the Free Software Foundation, Inc.,
  42. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  43. #
  44. # **********
  45. #
  46. # Purpose
  47. #
  48. # To test the code dependencies on individual key exchanges in the SSL module.
  49. # is a verification step to ensure we don't ship SSL code that do not work
  50. # for some build options.
  51. #
  52. # The process is:
  53. # for each possible key exchange
  54. # build the library with all but that key exchange disabled
  55. #
  56. # Usage: tests/scripts/key-exchanges.pl
  57. #
  58. # This script should be executed from the root of the project directory.
  59. #
  60. # For best effect, run either with cmake disabled, or cmake enabled in a mode
  61. # that includes -Werror.
  62. use warnings;
  63. use strict;
  64. -d 'library' && -d 'include' && -d 'tests' or die "Must be run from root\n";
  65. my $sed_cmd = 's/^#define \(MBEDTLS_KEY_EXCHANGE_.*_ENABLED\)/\1/p';
  66. my $config_h = 'include/mbedtls/config.h';
  67. my @kexes = split( /\s+/, `sed -n -e '$sed_cmd' $config_h` );
  68. system( "cp $config_h $config_h.bak" ) and die;
  69. sub abort {
  70. system( "mv $config_h.bak $config_h" ) and warn "$config_h not restored\n";
  71. # use an exit code between 1 and 124 for git bisect (die returns 255)
  72. warn $_[0];
  73. exit 1;
  74. }
  75. for my $kex (@kexes) {
  76. system( "cp $config_h.bak $config_h" ) and die "$config_h not restored\n";
  77. system( "make clean" ) and die;
  78. print "\n******************************************\n";
  79. print "* Testing with key exchange: $kex\n";
  80. print "******************************************\n";
  81. # full config with all key exchanges disabled except one
  82. system( "scripts/config.pl full" ) and abort "Failed config full\n";
  83. for my $k (@kexes) {
  84. next if $k eq $kex;
  85. system( "scripts/config.pl unset $k" )
  86. and abort "Failed to disable $k\n";
  87. }
  88. system( "make lib CFLAGS='-Os -Werror'" ) and abort "Failed to build lib: $kex\n";
  89. }
  90. system( "mv $config_h.bak $config_h" ) and die "$config_h not restored\n";
  91. system( "make clean" ) and die;
  92. exit 0;