closes bpo-39953: Update OpenSSL error codes table. (GH-19082)

I updated the error codes using the OpenSSL 1.1.1f source tree.
(cherry picked from commit 3e0dd3730b)

Co-authored-by: Benjamin Peterson <benjamin@python.org>
This commit is contained in:
Miss Islington (bot) 2020-04-11 13:53:00 -07:00 committed by GitHub
parent ceba0648d7
commit 2714c907df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4722 additions and 391 deletions

View File

@ -0,0 +1 @@
Update internal table of OpenSSL error codes in the ``ssl`` module.

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@ It takes two arguments:
"""
import datetime
import glob
import os
import re
import sys
@ -18,7 +19,7 @@ import _ssl
def parse_error_codes(h_file, prefix, libcode):
pat = re.compile(r"#define\W+(%s([\w]+))\W+(\d+)\b" % re.escape(prefix))
pat = re.compile(r"#\s*define\W+(%s([\w]+))\W+(\d+)\b" % re.escape(prefix))
codes = []
with open(h_file, "r", encoding="latin1") as f:
for line in f:
@ -28,6 +29,7 @@ def parse_error_codes(h_file, prefix, libcode):
num = int(num)
# e.g. ("SSL_R_BAD_DATA", ("ERR_LIB_SSL", "BAD_DATA", 390))
codes.append((code, (libcode, name, num)))
assert codes, f"no codes found in {h_file}"
return codes
if __name__ == "__main__":
@ -35,18 +37,23 @@ if __name__ == "__main__":
outfile = sys.argv[2]
use_stdout = outfile == '-'
f = sys.stdout if use_stdout else open(outfile, "w")
error_libraries = {
# mnemonic -> (library code, error prefix, header file)
'PEM': ('ERR_LIB_PEM', 'PEM_R_', 'crypto/pem/pem.h'),
'SSL': ('ERR_LIB_SSL', 'SSL_R_', 'ssl/ssl.h'),
'X509': ('ERR_LIB_X509', 'X509_R_', 'crypto/x509/x509.h'),
}
# mnemonic -> (library code, error prefix, header file)
error_libraries = {}
for error_header in glob.glob(os.path.join(openssl_inc, 'include/openssl/*err.h')):
base = os.path.basename(error_header)
if base in ('buffererr.h', 'objectserr.h', 'storeerr.h'):
# Deprecated in 3.0.
continue
mnemonic = base[:-5].upper()
if mnemonic == "":
# Skip err.h.
continue
error_libraries[mnemonic] = (f'ERR_LIB_{mnemonic}', f'{mnemonic}_R_', error_header)
# Read codes from libraries
new_codes = []
for libcode, prefix, h_file in sorted(error_libraries.values()):
new_codes += parse_error_codes(os.path.join(openssl_inc, h_file),
prefix, libcode)
new_codes += parse_error_codes(h_file, prefix, libcode)
new_code_nums = set((libcode, num)
for (code, (libcode, name, num)) in new_codes)