diff options
author | Christian Heimes <christian@cheimes.de> | 2013-11-17 18:59:14 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2013-11-17 18:59:14 (GMT) |
commit | a6bc95aa0252399c026e749c4a294e2a22912f72 (patch) | |
tree | 077efeeb0ba8ac1dc3cc17d9c71239675de2f1bf /Lib/ssl.py | |
parent | 35e4ad71baae5469ee678718bac0f9caf7fae740 (diff) | |
download | cpython-a6bc95aa0252399c026e749c4a294e2a22912f72.zip cpython-a6bc95aa0252399c026e749c4a294e2a22912f72.tar.gz cpython-a6bc95aa0252399c026e749c4a294e2a22912f72.tar.bz2 |
Issue #19448: Add private API to SSL module to lookup ASN.1 objects by OID, NID, short name and long name.
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r-- | Lib/ssl.py | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -91,7 +91,7 @@ import textwrap import re import sys import os -import collections +from collections import namedtuple import _ssl # if we can't import it, let the error propagate @@ -102,6 +102,7 @@ from _ssl import ( SSLSyscallError, SSLEOFError, ) from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED +from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj from _ssl import RAND_status, RAND_egd, RAND_add, RAND_bytes, RAND_pseudo_bytes def _import_symbols(prefix): @@ -256,7 +257,7 @@ def match_hostname(cert, hostname): "subjectAltName fields were found") -DefaultVerifyPaths = collections.namedtuple("DefaultVerifyPaths", +DefaultVerifyPaths = namedtuple("DefaultVerifyPaths", "cafile capath openssl_cafile_env openssl_cafile openssl_capath_env " "openssl_capath") @@ -274,6 +275,27 @@ def get_default_verify_paths(): *parts) +class _ASN1Object(namedtuple("_ASN1Object", "nid shortname longname oid")): + """ASN.1 object identifier lookup + """ + __slots__ = () + + def __new__(cls, oid): + return super().__new__(cls, *_txt2obj(oid, name=False)) + + @classmethod + def fromnid(cls, nid): + """Create _ASN1Object from OpenSSL numeric ID + """ + return super().__new__(cls, *_nid2obj(nid)) + + @classmethod + def fromname(cls, name): + """Create _ASN1Object from short name, long name or OID + """ + return super().__new__(cls, *_txt2obj(name, name=True)) + + class SSLContext(_SSLContext): """An SSLContext holds various SSL-related configuration options and data, such as certificates and possibly a private key.""" |