2018-04-05 00:26:56 +02:00
|
|
|
#!/usr/bin/env perl
|
2014-05-09 13:40:14 +02:00
|
|
|
|
|
|
|
# Generate error.c
|
2011-05-09 18:17:09 +02:00
|
|
|
#
|
2014-05-09 13:40:14 +02:00
|
|
|
# Usage: ./generate_errors.pl or scripts/generate_errors.pl without arguments,
|
|
|
|
# or generate_errors.pl include_dir data_dir error_file
|
2020-05-26 00:33:31 +02:00
|
|
|
#
|
2020-08-19 16:54:51 +02:00
|
|
|
# Copyright The Mbed TLS Contributors
|
Update license headers to Apache-2.0 OR GPL-2.0-or-later
This will allow us to ship the LTS branches in a single archive
This commit was generated using the following script:
# ========================
#!/bin/sh
header1='\ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later\
*\
* This file is provided under the Apache License 2.0, or the\
* GNU General Public License v2.0 or later.\
*\
* **********\
* Apache License 2.0:\
*\
* Licensed under the Apache License, Version 2.0 (the "License"); you may\
* not use this file except in compliance with the License.\
* You may obtain a copy of the License at\
*\
* http://www.apache.org/licenses/LICENSE-2.0\
*\
* Unless required by applicable law or agreed to in writing, software\
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\
* See the License for the specific language governing permissions and\
* limitations under the License.\
*\
* **********\
*\
* **********\
* GNU General Public License v2.0 or later:\
*\
* This program is free software; you can redistribute it and/or modify\
* it under the terms of the GNU General Public License as published by\
* the Free Software Foundation; either version 2 of the License, or\
* (at your option) any later version.\
*\
* This program is distributed in the hope that it will be useful,\
* but WITHOUT ANY WARRANTY; without even the implied warranty of\
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
* GNU General Public License for more details.\
*\
* You should have received a copy of the GNU General Public License along\
* with this program; if not, write to the Free Software Foundation, Inc.,\
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\
*\
* **********'
find -path './.git' -prune -o '(' -name '*.c' -o -name '*.cpp' -o -name '*.fmt' -o -name '*.h' ')' -print | xargs sed -i "
# Normalize the first line of the copyright headers (no text on the first line of a block comment)
/^\/\*.*Copyright.*Arm/I s/\/\*/&\n */
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header1
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# Format copyright header for inclusion into scripts
header2=$(echo "$header1" | sed 's/^\\\? \* \?/#/')
find -path './.git' -prune -o '(' -name '*.gdb' -o -name '*.pl' -o -name '*.py' -o -name '*.sh' ')' -print | xargs sed -i "
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header2
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# ========================
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-06-05 13:02:18 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
|
|
|
#
|
|
|
|
# This file is provided under the Apache License 2.0, or the
|
|
|
|
# GNU General Public License v2.0 or later.
|
|
|
|
#
|
|
|
|
# **********
|
|
|
|
# Apache License 2.0:
|
2020-05-26 01:54:15 +02:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2020-05-26 00:33:31 +02:00
|
|
|
#
|
Update license headers to Apache-2.0 OR GPL-2.0-or-later
This will allow us to ship the LTS branches in a single archive
This commit was generated using the following script:
# ========================
#!/bin/sh
header1='\ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later\
*\
* This file is provided under the Apache License 2.0, or the\
* GNU General Public License v2.0 or later.\
*\
* **********\
* Apache License 2.0:\
*\
* Licensed under the Apache License, Version 2.0 (the "License"); you may\
* not use this file except in compliance with the License.\
* You may obtain a copy of the License at\
*\
* http://www.apache.org/licenses/LICENSE-2.0\
*\
* Unless required by applicable law or agreed to in writing, software\
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\
* See the License for the specific language governing permissions and\
* limitations under the License.\
*\
* **********\
*\
* **********\
* GNU General Public License v2.0 or later:\
*\
* This program is free software; you can redistribute it and/or modify\
* it under the terms of the GNU General Public License as published by\
* the Free Software Foundation; either version 2 of the License, or\
* (at your option) any later version.\
*\
* This program is distributed in the hope that it will be useful,\
* but WITHOUT ANY WARRANTY; without even the implied warranty of\
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
* GNU General Public License for more details.\
*\
* You should have received a copy of the GNU General Public License along\
* with this program; if not, write to the Free Software Foundation, Inc.,\
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\
*\
* **********'
find -path './.git' -prune -o '(' -name '*.c' -o -name '*.cpp' -o -name '*.fmt' -o -name '*.h' ')' -print | xargs sed -i "
# Normalize the first line of the copyright headers (no text on the first line of a block comment)
/^\/\*.*Copyright.*Arm/I s/\/\*/&\n */
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header1
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# Format copyright header for inclusion into scripts
header2=$(echo "$header1" | sed 's/^\\\? \* \?/#/')
find -path './.git' -prune -o '(' -name '*.gdb' -o -name '*.pl' -o -name '*.py' -o -name '*.sh' ')' -print | xargs sed -i "
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header2
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# ========================
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-06-05 13:02:18 +02:00
|
|
|
# **********
|
|
|
|
#
|
|
|
|
# **********
|
|
|
|
# GNU General Public License v2.0 or later:
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# **********
|
2011-05-09 18:17:09 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2014-05-09 13:40:14 +02:00
|
|
|
my ($include_dir, $data_dir, $error_file);
|
|
|
|
|
|
|
|
if( @ARGV ) {
|
|
|
|
die "Invalid number of arguments" if scalar @ARGV != 3;
|
|
|
|
($include_dir, $data_dir, $error_file) = @ARGV;
|
|
|
|
|
|
|
|
-d $include_dir or die "No such directory: $include_dir\n";
|
|
|
|
-d $data_dir or die "No such directory: $data_dir\n";
|
|
|
|
} else {
|
2015-03-09 18:05:11 +01:00
|
|
|
$include_dir = 'include/mbedtls';
|
2014-05-09 13:40:14 +02:00
|
|
|
$data_dir = 'scripts/data_files';
|
|
|
|
$error_file = 'library/error.c';
|
|
|
|
|
|
|
|
unless( -d $include_dir && -d $data_dir ) {
|
|
|
|
chdir '..' or die;
|
|
|
|
-d $include_dir && -d $data_dir
|
|
|
|
or die "Without arguments, must be run from root or scripts\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-09 18:17:09 +02:00
|
|
|
my $error_format_file = $data_dir.'/error.fmt';
|
|
|
|
|
2018-01-26 17:56:38 +01:00
|
|
|
my @low_level_modules = qw( AES ARC4 ASN1 BASE64 BIGNUM BLOWFISH
|
|
|
|
CAMELLIA CCM CMAC CTR_DRBG DES
|
|
|
|
ENTROPY GCM HMAC_DRBG MD2 MD4 MD5
|
2018-01-25 23:26:24 +01:00
|
|
|
NET OID PADLOCK PBKDF2 RIPEMD160
|
|
|
|
SHA1 SHA256 SHA512 THREADING XTEA );
|
|
|
|
my @high_level_modules = qw( CIPHER DHM ECP MD
|
|
|
|
PEM PK PKCS12 PKCS5
|
|
|
|
RSA SSL X509 );
|
2011-05-09 18:17:09 +02:00
|
|
|
|
|
|
|
my $line_separator = $/;
|
|
|
|
undef $/;
|
|
|
|
|
|
|
|
open(FORMAT_FILE, "$error_format_file") or die "Opening error format file '$error_format_file': $!";
|
|
|
|
my $error_format = <FORMAT_FILE>;
|
|
|
|
close(FORMAT_FILE);
|
|
|
|
|
|
|
|
$/ = $line_separator;
|
|
|
|
|
2017-10-17 22:23:15 +02:00
|
|
|
my @files = <$include_dir/*.h>;
|
2020-05-25 12:21:22 +02:00
|
|
|
my @necessary_include_files;
|
2017-10-09 18:22:07 +02:00
|
|
|
my @matches;
|
|
|
|
foreach my $file (@files) {
|
|
|
|
open(FILE, "$file");
|
2017-10-17 22:24:56 +02:00
|
|
|
my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, <FILE>);
|
2017-10-09 18:22:07 +02:00
|
|
|
push(@matches, @grep_res);
|
|
|
|
close FILE;
|
2020-05-25 12:21:22 +02:00
|
|
|
my $include_name = $file;
|
|
|
|
$include_name =~ s!.*/!!;
|
|
|
|
push @necessary_include_files, $include_name if @grep_res;
|
2017-10-09 18:22:07 +02:00
|
|
|
}
|
2011-05-09 18:17:09 +02:00
|
|
|
|
|
|
|
my $ll_old_define = "";
|
|
|
|
my $hl_old_define = "";
|
|
|
|
|
|
|
|
my $ll_code_check = "";
|
|
|
|
my $hl_code_check = "";
|
|
|
|
|
|
|
|
my $headers = "";
|
2020-05-25 12:21:22 +02:00
|
|
|
my %included_headers;
|
2011-05-09 18:17:09 +02:00
|
|
|
|
2015-01-22 14:19:20 +01:00
|
|
|
my %error_codes_seen;
|
|
|
|
|
2017-10-09 18:22:07 +02:00
|
|
|
foreach my $line (@matches)
|
2011-05-09 18:17:09 +02:00
|
|
|
{
|
2013-09-17 13:25:29 +02:00
|
|
|
next if ($line =~ /compat-1.2.h/);
|
2015-04-08 12:49:31 +02:00
|
|
|
my ($error_name, $error_code) = $line =~ /(MBEDTLS_ERR_\w+)\s+\-(0x\w+)/;
|
2011-05-09 18:17:09 +02:00
|
|
|
my ($description) = $line =~ /\/\*\*< (.*?)\.? \*\//;
|
2015-01-22 14:19:20 +01:00
|
|
|
|
|
|
|
die "Duplicated error code: $error_code ($error_name)\n"
|
|
|
|
if( $error_codes_seen{$error_code}++ );
|
|
|
|
|
2011-05-09 18:17:09 +02:00
|
|
|
$description =~ s/\\/\\\\/g;
|
2015-01-22 14:19:20 +01:00
|
|
|
if ($description eq "") {
|
|
|
|
$description = "DESCRIPTION MISSING";
|
|
|
|
warn "Missing description for $error_name\n";
|
|
|
|
}
|
2011-05-09 18:17:09 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
my ($module_name) = $error_name =~ /^MBEDTLS_ERR_([^_]+)/;
|
2011-05-09 18:17:09 +02:00
|
|
|
|
|
|
|
# Fix faulty ones
|
|
|
|
$module_name = "BIGNUM" if ($module_name eq "MPI");
|
2011-11-27 15:50:49 +01:00
|
|
|
$module_name = "CTR_DRBG" if ($module_name eq "CTR");
|
2014-02-01 10:22:21 +01:00
|
|
|
$module_name = "HMAC_DRBG" if ($module_name eq "HMAC");
|
2011-05-09 18:17:09 +02:00
|
|
|
|
|
|
|
my $define_name = $module_name;
|
2013-09-17 13:25:29 +02:00
|
|
|
$define_name = "X509_USE,X509_CREATE" if ($define_name eq "X509");
|
2011-11-15 17:38:34 +01:00
|
|
|
$define_name = "ASN1_PARSE" if ($define_name eq "ASN1");
|
2011-05-18 15:27:35 +02:00
|
|
|
$define_name = "SSL_TLS" if ($define_name eq "SSL");
|
2013-09-15 20:43:33 +02:00
|
|
|
$define_name = "PEM_PARSE,PEM_WRITE" if ($define_name eq "PEM");
|
2011-05-09 18:17:09 +02:00
|
|
|
|
|
|
|
my $include_name = $module_name;
|
|
|
|
$include_name =~ tr/A-Z/a-z/;
|
|
|
|
|
2016-09-14 15:32:09 +02:00
|
|
|
# Fix faulty ones
|
|
|
|
$include_name = "net_sockets" if ($module_name eq "NET");
|
|
|
|
|
2020-05-25 12:21:22 +02:00
|
|
|
$included_headers{"${include_name}.h"} = $module_name;
|
|
|
|
|
2011-05-09 18:17:09 +02:00
|
|
|
my $found_ll = grep $_ eq $module_name, @low_level_modules;
|
|
|
|
my $found_hl = grep $_ eq $module_name, @high_level_modules;
|
|
|
|
if (!$found_ll && !$found_hl)
|
|
|
|
{
|
2015-08-06 17:24:56 +02:00
|
|
|
printf("Error: Do not know how to handle: $module_name\n");
|
2011-05-09 18:17:09 +02:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $code_check;
|
|
|
|
my $old_define;
|
|
|
|
my $white_space;
|
2013-09-15 20:43:33 +02:00
|
|
|
my $first;
|
2011-05-09 18:17:09 +02:00
|
|
|
|
|
|
|
if ($found_ll)
|
|
|
|
{
|
|
|
|
$code_check = \$ll_code_check;
|
|
|
|
$old_define = \$ll_old_define;
|
|
|
|
$white_space = ' ';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$code_check = \$hl_code_check;
|
|
|
|
$old_define = \$hl_old_define;
|
|
|
|
$white_space = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($define_name ne ${$old_define})
|
|
|
|
{
|
|
|
|
if (${$old_define} ne "")
|
|
|
|
{
|
2013-09-15 20:43:33 +02:00
|
|
|
${$code_check} .= "#endif /* ";
|
|
|
|
$first = 0;
|
|
|
|
foreach my $dep (split(/,/, ${$old_define}))
|
|
|
|
{
|
|
|
|
${$code_check} .= " || " if ($first++);
|
2015-04-08 12:49:31 +02:00
|
|
|
${$code_check} .= "MBEDTLS_${dep}_C";
|
2013-09-15 20:43:33 +02:00
|
|
|
}
|
|
|
|
${$code_check} .= " */\n\n";
|
2011-05-09 18:17:09 +02:00
|
|
|
}
|
|
|
|
|
2013-09-15 20:43:33 +02:00
|
|
|
${$code_check} .= "#if ";
|
|
|
|
$headers .= "#if " if ($include_name ne "");
|
|
|
|
$first = 0;
|
|
|
|
foreach my $dep (split(/,/, ${define_name}))
|
|
|
|
{
|
|
|
|
${$code_check} .= " || " if ($first);
|
|
|
|
$headers .= " || " if ($first++);
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
${$code_check} .= "defined(MBEDTLS_${dep}_C)";
|
|
|
|
$headers .= "defined(MBEDTLS_${dep}_C)" if
|
2013-09-15 20:43:33 +02:00
|
|
|
($include_name ne "");
|
|
|
|
}
|
|
|
|
${$code_check} .= "\n";
|
2015-03-09 18:05:11 +01:00
|
|
|
$headers .= "\n#include \"mbedtls/${include_name}.h\"\n".
|
2011-05-09 18:17:09 +02:00
|
|
|
"#endif\n\n" if ($include_name ne "");
|
|
|
|
${$old_define} = $define_name;
|
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
if ($error_name eq "MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE")
|
2012-05-08 15:12:27 +02:00
|
|
|
{
|
|
|
|
${$code_check} .= "${white_space}if( use_ret == -($error_name) )\n".
|
|
|
|
"${white_space}\{\n".
|
2015-04-08 12:49:31 +02:00
|
|
|
"${white_space} mbedtls_snprintf( buf, buflen, \"$module_name - $description\" );\n".
|
2012-05-08 15:12:27 +02:00
|
|
|
"${white_space} return;\n".
|
|
|
|
"${white_space}}\n"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
${$code_check} .= "${white_space}if( use_ret == -($error_name) )\n".
|
2015-04-08 12:49:31 +02:00
|
|
|
"${white_space} mbedtls_snprintf( buf, buflen, \"$module_name - $description\" );\n"
|
2012-05-08 15:12:27 +02:00
|
|
|
}
|
2011-05-09 18:17:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if ($ll_old_define ne "")
|
|
|
|
{
|
2015-04-08 20:27:02 +02:00
|
|
|
$ll_code_check .= "#endif /* ";
|
|
|
|
my $first = 0;
|
|
|
|
foreach my $dep (split(/,/, $ll_old_define))
|
|
|
|
{
|
|
|
|
$ll_code_check .= " || " if ($first++);
|
|
|
|
$ll_code_check .= "MBEDTLS_${dep}_C";
|
|
|
|
}
|
|
|
|
$ll_code_check .= " */\n";
|
2011-05-09 18:17:09 +02:00
|
|
|
}
|
|
|
|
if ($hl_old_define ne "")
|
|
|
|
{
|
2015-04-08 20:27:02 +02:00
|
|
|
$hl_code_check .= "#endif /* ";
|
|
|
|
my $first = 0;
|
|
|
|
foreach my $dep (split(/,/, $hl_old_define))
|
|
|
|
{
|
|
|
|
$hl_code_check .= " || " if ($first++);
|
|
|
|
$hl_code_check .= "MBEDTLS_${dep}_C";
|
|
|
|
}
|
|
|
|
$hl_code_check .= " */\n";
|
2011-05-09 18:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$error_format =~ s/HEADER_INCLUDED\n/$headers/g;
|
|
|
|
$error_format =~ s/LOW_LEVEL_CODE_CHECKS\n/$ll_code_check/g;
|
|
|
|
$error_format =~ s/HIGH_LEVEL_CODE_CHECKS\n/$hl_code_check/g;
|
|
|
|
|
|
|
|
open(ERROR_FILE, ">$error_file") or die "Opening destination file '$error_file': $!";
|
|
|
|
print ERROR_FILE $error_format;
|
|
|
|
close(ERROR_FILE);
|
2020-05-25 12:21:22 +02:00
|
|
|
|
|
|
|
my $errors = 0;
|
|
|
|
for my $include_name (@necessary_include_files)
|
|
|
|
{
|
|
|
|
if (not $included_headers{$include_name})
|
|
|
|
{
|
|
|
|
print STDERR "The header file \"$include_name\" defines error codes but has not been included!\n";
|
|
|
|
++$errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit !!$errors;
|