mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #19448: Add private API to SSL module to lookup ASN.1 objects by OID, NID, short name and long name.
This commit is contained in:
parent
35e4ad71ba
commit
a6bc95aa02
4 changed files with 156 additions and 2 deletions
|
@ -539,6 +539,44 @@ class BasicSocketTests(unittest.TestCase):
|
|||
self.assertIsInstance(ca[0][0], bytes)
|
||||
self.assertIsInstance(ca[0][1], int)
|
||||
|
||||
def test_asn1object(self):
|
||||
expected = (129, 'serverAuth', 'TLS Web Server Authentication',
|
||||
'1.3.6.1.5.5.7.3.1')
|
||||
|
||||
val = ssl._ASN1Object('1.3.6.1.5.5.7.3.1')
|
||||
self.assertEqual(val, expected)
|
||||
self.assertEqual(val.nid, 129)
|
||||
self.assertEqual(val.shortname, 'serverAuth')
|
||||
self.assertEqual(val.longname, 'TLS Web Server Authentication')
|
||||
self.assertEqual(val.oid, '1.3.6.1.5.5.7.3.1')
|
||||
self.assertIsInstance(val, ssl._ASN1Object)
|
||||
self.assertRaises(ValueError, ssl._ASN1Object, 'serverAuth')
|
||||
|
||||
val = ssl._ASN1Object.fromnid(129)
|
||||
self.assertEqual(val, expected)
|
||||
self.assertIsInstance(val, ssl._ASN1Object)
|
||||
self.assertRaises(ValueError, ssl._ASN1Object.fromnid, -1)
|
||||
self.assertRaises(ValueError, ssl._ASN1Object.fromnid, 100000)
|
||||
for i in range(1000):
|
||||
try:
|
||||
obj = ssl._ASN1Object.fromnid(i)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
self.assertIsInstance(obj.nid, int)
|
||||
self.assertIsInstance(obj.shortname, str)
|
||||
self.assertIsInstance(obj.longname, str)
|
||||
self.assertIsInstance(obj.oid, (str, type(None)))
|
||||
|
||||
val = ssl._ASN1Object.fromname('TLS Web Server Authentication')
|
||||
self.assertEqual(val, expected)
|
||||
self.assertIsInstance(val, ssl._ASN1Object)
|
||||
self.assertEqual(ssl._ASN1Object.fromname('serverAuth'), expected)
|
||||
self.assertEqual(ssl._ASN1Object.fromname('1.3.6.1.5.5.7.3.1'),
|
||||
expected)
|
||||
self.assertRaises(ValueError, ssl._ASN1Object.fromname, 'serverauth')
|
||||
|
||||
|
||||
class ContextTests(unittest.TestCase):
|
||||
|
||||
@skip_if_broken_ubuntu_ssl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue