Commit b99eb1b1 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #23248: Update ssl error codes from latest OpenSSL git master.

parent ff6acb1a
...@@ -15,6 +15,8 @@ Core and Builtins ...@@ -15,6 +15,8 @@ Core and Builtins
Library Library
------- -------
- Issue #23248: Update ssl error codes from latest OpenSSL git master.
- Issue #23098: 64-bit dev_t is now supported in the os module. - Issue #23098: 64-bit dev_t is now supported in the os module.
- Issue #23063: In the disutils' check command, fix parsing of reST with code or - Issue #23063: In the disutils' check command, fix parsing of reST with code or
......
This diff is collapsed.
...@@ -5,8 +5,7 @@ This script should be called *manually* when we want to upgrade SSLError ...@@ -5,8 +5,7 @@ This script should be called *manually* when we want to upgrade SSLError
`library` and `reason` mnemnonics to a more recent OpenSSL version. `library` and `reason` mnemnonics to a more recent OpenSSL version.
It takes two arguments: It takes two arguments:
- the path to the OpenSSL include files' directory - the path to the OpenSSL source tree (e.g. git checkout)
(e.g. openssl-1.0.1-beta3/include/openssl/)
- the path to the C file to be generated - the path to the C file to be generated
(probably Modules/_ssl_data.h) (probably Modules/_ssl_data.h)
""" """
...@@ -15,9 +14,10 @@ import datetime ...@@ -15,9 +14,10 @@ import datetime
import os import os
import re import re
import sys import sys
import _ssl
def parse_error_codes(h_file, prefix): 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"#define\W+(%s([\w]+))\W+(\d+)\b" % re.escape(prefix))
codes = [] codes = []
with open(h_file, "r", encoding="latin1") as f: with open(h_file, "r", encoding="latin1") as f:
...@@ -26,7 +26,8 @@ def parse_error_codes(h_file, prefix): ...@@ -26,7 +26,8 @@ def parse_error_codes(h_file, prefix):
if match: if match:
code, name, num = match.groups() code, name, num = match.groups()
num = int(num) num = int(num)
codes.append((code, name, num)) # e.g. ("SSL_R_BAD_DATA", ("ERR_LIB_SSL", "BAD_DATA", 390))
codes.append((code, (libcode, name, num)))
return codes return codes
if __name__ == "__main__": if __name__ == "__main__":
...@@ -34,12 +35,32 @@ if __name__ == "__main__": ...@@ -34,12 +35,32 @@ if __name__ == "__main__":
outfile = sys.argv[2] outfile = sys.argv[2]
use_stdout = outfile == '-' use_stdout = outfile == '-'
f = sys.stdout if use_stdout else open(outfile, "w") f = sys.stdout if use_stdout else open(outfile, "w")
error_libraries = ( error_libraries = {
# (library code, mnemonic, error prefix, header file) # mnemonic -> (library code, error prefix, header file)
('ERR_LIB_PEM', 'PEM', 'PEM_R_', 'pem.h'), 'PEM': ('ERR_LIB_PEM', 'PEM_R_', 'crypto/pem/pem.h'),
('ERR_LIB_SSL', 'SSL', 'SSL_R_', 'ssl.h'), 'SSL': ('ERR_LIB_SSL', 'SSL_R_', 'ssl/ssl.h'),
('ERR_LIB_X509', 'X509', 'X509_R_', 'x509.h'), 'X509': ('ERR_LIB_X509', 'X509_R_', 'crypto/x509/x509.h'),
) }
# 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_code_nums = set((libcode, num)
for (code, (libcode, name, num)) in new_codes)
# Merge with existing codes (in case some old codes disappeared).
codes = {}
for errname, (libnum, errnum) in _ssl.err_names_to_codes.items():
lib = error_libraries[_ssl.lib_codes_to_names[libnum]]
libcode = lib[0] # e.g. ERR_LIB_PEM
errcode = lib[1] + errname # e.g. SSL_R_BAD_SSL_SESSION_ID_LENGTH
# Only keep it if the numeric codes weren't reused
if (libcode, errnum) not in new_code_nums:
codes[errcode] = libcode, errname, errnum
codes.update(dict(new_codes))
def w(l): def w(l):
f.write(l + "\n") f.write(l + "\n")
w("/* File generated by Tools/ssl/make_ssl_data.py */") w("/* File generated by Tools/ssl/make_ssl_data.py */")
...@@ -47,21 +68,19 @@ if __name__ == "__main__": ...@@ -47,21 +68,19 @@ if __name__ == "__main__":
w("") w("")
w("static struct py_ssl_library_code library_codes[] = {") w("static struct py_ssl_library_code library_codes[] = {")
for libcode, mnemo, _, _ in error_libraries: for mnemo, (libcode, _, _) in sorted(error_libraries.items()):
w(' {"%s", %s},' % (mnemo, libcode)) w(' {"%s", %s},' % (mnemo, libcode))
w(' { NULL }') w(' { NULL }')
w('};') w('};')
w("") w("")
w("static struct py_ssl_error_code error_codes[] = {") w("static struct py_ssl_error_code error_codes[] = {")
for libcode, _, prefix, h_file in error_libraries: for errcode, (libcode, name, num) in sorted(codes.items()):
codes = parse_error_codes(os.path.join(openssl_inc, h_file), prefix) w(' #ifdef %s' % (errcode))
for code, name, num in sorted(codes): w(' {"%s", %s, %s},' % (name, libcode, errcode))
w(' #ifdef %s' % (code)) w(' #else')
w(' {"%s", %s, %s},' % (name, libcode, code)) w(' {"%s", %s, %d},' % (name, libcode, num))
w(' #else') w(' #endif')
w(' {"%s", %s, %d},' % (name, libcode, num))
w(' #endif')
w(' { NULL }') w(' { NULL }')
w('};') w('};')
if not use_stdout: if not use_stdout:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment