You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Function ssl.create_default_context raises exception on Windows 10 when called with ssl.Purpose.SERVER_AUTH) attribute #79846
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-01-08.09:38:24.479>created_at=<Date2019-01-05.12:24:45.346>labels= ['expert-SSL', 'type-bug', '3.9']
title='Function ssl.create_default_context raises exception on Windows 10 when called with ssl.Purpose.SERVER_AUTH) attribute'updated_at=<Date2021-09-28.21:47:58.903>user='https://github.com/pervlad'
The certs are coming from Windows' trust store. Could you please dump the trust store for me and attach the result to the bug tracker. The following script is untested but should work. I don't have access to a Windows machine at the moment.
Version of ssl lib in pythons on my machine:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.1.0j 20 Nov 2018'
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2q 20 Nov 2018'
Your Windows cert store contains multiple invalid certificates. The first failing certificate is the custom "MUPCA Root", which looks like a certificate from http://ca.mup.gov.rs/sertifikati.html. The serial number seems to be badly formated or padded. There is nothing we can do about erroneous and bad certificates.
However, if the fix isn't backported to 3.10 and 3.11 as well you may keep receiving those bug reports — many popular "AI" repos (such as AUTOMATIC1111 for example) have 3.10 as a requirement. Some of them can work also with 3.11, but many can't upgrade without breaking metric ton of libraries they use.
Yes, I am well aware of that. Too bad, because 3.10 is still widely used in AI community without any indication that it could be replaced soon due to all code dependencies.
Activity
pervlad commentedon Jan 5, 2019
In Python 3.7.1 on Windows 10 ssl library function call ssl.create_default_context(ssl.Purpose.SERVER_AUTH) raises an ssl error:
File "C:\Python37\lib\ssl.py", line 471, in _load_windows_store_certs
self.load_verify_locations(cadata=certs)
ssl.SSLError: nested asn1 error (_ssl.c:3926)
In Python 3.6.4 same function call raises no error.
pervlad commentedon Jan 5, 2019
Same outcome in Python 3.7.2.
See first comment for detailed explanation of issue.
vstinner commentedon Jan 7, 2019
It seems like one of your certificate is invalid.
We frequently update OpenSSL in Python. You can get OpenSSL version using:
vstinner commentedon Jan 7, 2019
Would it be possible to attach the certification to the issue so someone can try to reproduce the issue? (but don't attach any private key ;-))
tiran commentedon Jan 7, 2019
The certs are coming from Windows' trust store. Could you please dump the trust store for me and attach the result to the bug tracker. The following script is untested but should work. I don't have access to a Windows machine at the moment.
pervlad commentedon Jan 7, 2019
Public Certificate file cert.pem is attached.
tiran commentedon Jan 7, 2019
Your Windows cert store contains multiple invalid certificates. The first failing certificate is the custom "MUPCA Root", which looks like a certificate from http://ca.mup.gov.rs/sertifikati.html. The serial number seems to be badly formated or padded. There is nothing we can do about erroneous and bad certificates.
$ openssl x509 -in ca.pem unable to load certificate 140613019477824:error:0D0E20DD:asn1 encoding routines:c2i_ibuf:illegal padding:crypto/asn1/a_int.c:187: 140613019477824:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:627:Field=serialNumber, Type=X509_CINF 140613019477824:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:627:Field=cert_info, Type=X509 140613019477824:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:crypto/pem/pem_oth.c:33: $ openssl asn1parse -in ca.pem 0:d=0 hl=4 l=1300 cons: SEQUENCE 4:d=1 hl=4 l= 764 cons: SEQUENCE 8:d=2 hl=2 l= 3 cons: cont [ 0 ] 10:d=3 hl=2 l= 1 prim: INTEGER :02 13:d=2 hl=2 l= 4 prim: INTEGER :BAD INTEGER:[00000066] 19:d=2 hl=2 l= 13 cons: SEQUENCE 21:d=3 hl=2 l= 9 prim: OBJECT :sha1WithRSAEncryption 32:d=3 hl=2 l= 0 prim: NULL 34:d=2 hl=2 l= 83 cons: SEQUENCE 36:d=3 hl=2 l= 19 cons: SET 38:d=4 hl=2 l= 17 cons: SEQUENCE 40:d=5 hl=2 l= 3 prim: OBJECT :commonName 45:d=5 hl=2 l= 10 prim: UTF8STRING :MUPCA Root 57:d=3 hl=2 l= 29 cons: SET 59:d=4 hl=2 l= 27 cons: SEQUENCE 61:d=5 hl=2 l= 3 prim: OBJECT :organizationName 66:d=5 hl=2 l= 20 prim: UTF8STRING :MUP Republike Srbije 88:d=3 hl=2 l= 16 cons: SET 90:d=4 hl=2 l= 14 cons: SEQUENCE 92:d=5 hl=2 l= 3 prim: OBJECT :localityName 97:d=5 hl=2 l= 7 prim: UTF8STRING :Beograd 106:d=3 hl=2 l= 11 cons: SET 108:d=4 hl=2 l= 9 cons: SEQUENCE 110:d=5 hl=2 l= 3 prim: OBJECT :countryName 115:d=5 hl=2 l= 2 prim: PRINTABLESTRING :RS 119:d=2 hl=2 l= 30 cons: SEQUENCE 121:d=3 hl=2 l= 13 prim: UTCTIME :100227161918Z 136:d=3 hl=2 l= 13 prim: UTCTIME :200227161918Z ... $ wget http://ca.mup.gov.rs/MUPCARoot.crt $ openssl x509 -in MUPCARoot.crt -inform DER unable to load certificate 140699773712192:error:0D0E20DD:asn1 encoding routines:c2i_ibuf:illegal padding:crypto/asn1/a_int.c:187: 140699773712192:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:627:Field=serialNumber, Type=X509_CINF 140699773712192:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:627:Field=cert_info, Type=X509tiran commentedon Jan 7, 2019
OpenSSL 1.1.0 is more strict than OpenSSL 1.0.2. That's why you don't see the issue with Python 3.6 but with 3.7. The problem is explained in https://mta.openssl.org/pipermail/openssl-dev/2016-February/005100.html
The CA has encoded the integer 102 (0x66) as "02 04 00
00 00 66", which violates the DER standard. The correct encoding is "02 01 66".
pervlad commentedon Jan 8, 2019
Thank you all for this expeditive help. Sorry for taking your time.
I will remove bad certificates from my machine.
Thanks again.
I will try to close this one.
tiran commentedon Jan 8, 2019
I also checked how other implementations deal with invalid DER encoding. NSS 3.41, Firefox, and Chromium accept the certifiate.
NSS shows the serial number as "102 (0x66)"
Firefox and Chromium display the serial number as "00:00:00:66".
18 remaining items
gh-79846: Make ssl.create_default_context() ignore invalid certificat…
pythongh-79846: Make ssl.create_default_context() ignore invalid cert…
pythongh-79846: Make ssl.create_default_context() ignore invalid cert…
serhiy-storchaka commentedon Aug 7, 2024
Thank you @levicki for reviving this issue.
levicki commentedon Aug 7, 2024
You're welcome.
However, if the fix isn't backported to 3.10 and 3.11 as well you may keep receiving those bug reports — many popular "AI" repos (such as AUTOMATIC1111 for example) have 3.10 as a requirement. Some of them can work also with 3.11, but many can't upgrade without breaking metric ton of libraries they use.
hugovk commentedon Aug 9, 2024
@levicki Unfortunately 3.10 and 3.11 are only accepting security fixes, see https://devguide.python.org/versions/ and https://devguide.python.org/developer-workflow/development-cycle/#security-branches.
@serhiy-storchaka The 3.12 and 3.13 backports are pending merge, keeping in mind 3.13 is in the RC phase.
[3.12] gh-79846: Make ssl.create_default_context() ignore invalid cer…
levicki commentedon Aug 9, 2024
@hugovk
Yes, I am well aware of that. Too bad, because 3.10 is still widely used in AI community without any indication that it could be replaced soon due to all code dependencies.
pythongh-79846: Make ssl.create_default_context() ignore invalid cert…
[3.13] gh-79846: Make ssl.create_default_context() ignore invalid cer…