mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Fixes issues with gen_crt_bundle.py for unicode chars
gen_crt_bundle.py could fail to parse the certificates if it contained a non-ascii character.
This commit is contained in:
parent
58e1100473
commit
c343323863
@ -30,6 +30,7 @@ import struct
|
||||
import argparse
|
||||
import csv
|
||||
import re
|
||||
from io import open
|
||||
|
||||
try:
|
||||
from cryptography import x509
|
||||
@ -80,7 +81,7 @@ class CertificateBundle:
|
||||
try:
|
||||
if file_path.endswith('.pem'):
|
||||
status("Parsing certificates from %s" % file_path)
|
||||
with open(file_path, 'r') as f:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
crt_str = f.read()
|
||||
self.add_from_pem(crt_str)
|
||||
return True
|
||||
@ -153,7 +154,7 @@ class CertificateBundle:
|
||||
def add_with_filter(self, crts_path, filter_path):
|
||||
|
||||
filter_set = set()
|
||||
with open(filter_path, 'r') as f:
|
||||
with open(filter_path, 'r', encoding='utf-8') as f:
|
||||
csv_reader = csv.reader(f, delimiter=',')
|
||||
|
||||
# Skip header
|
||||
@ -163,7 +164,7 @@ class CertificateBundle:
|
||||
|
||||
status("Parsing certificates from %s" % crts_path)
|
||||
crt_str = []
|
||||
with open(crts_path, 'r') as f:
|
||||
with open(crts_path, 'r', encoding='utf-8') as f:
|
||||
crt_str = f.read()
|
||||
|
||||
# Split all certs into a list of (name, certificate string) tuples
|
||||
|
@ -0,0 +1,23 @@
|
||||
NetLock Arany (Class Gold) Főtanúsítvány
|
||||
========================================
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEFTCCAv2gAwIBAgIGSUEs5AAQMA0GCSqGSIb3DQEBCwUAMIGnMQswCQYDVQQGEwJIVTERMA8G
|
||||
A1UEBwwIQnVkYXBlc3QxFTATBgNVBAoMDE5ldExvY2sgS2Z0LjE3MDUGA1UECwwuVGFuw7pzw610
|
||||
dsOhbnlraWFkw7NrIChDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzKTE1MDM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P9KdlpeuY0fsFskZ1FSNqb4VjMIDw1Z4fKRzC
|
||||
bLBQWV2QWzuoDTDPv31/zvGdg73JRm4gpvlhUbohL3u+pRVjodSVh/GeufOJ8z2FuLjbvrW5Kfna
|
||||
NwUASZQDhETnv0Mxz3WLJdH0pmT1kvarBes96aULNmLazAZfNou2XjG4Kvte9nHfRCaexOYNkbQu
|
||||
dZWAUWpLMKawYqGT8ZvYzsRjdT9ZR7E=
|
||||
-----END CERTIFICATE-----
|
@ -22,6 +22,7 @@ pem_test_file = 'entrust.pem'
|
||||
verified_der_bundle = 'baltimore_crt_bundle'
|
||||
verified_pem_bundle = 'entrust_crt_bundle'
|
||||
invalid_test_file = 'invalid_crt.pem'
|
||||
non_ascii_file = 'non_ascii_crt.pem'
|
||||
ca_crts_all_file = 'cacrt_all.pem'
|
||||
|
||||
|
||||
@ -72,6 +73,12 @@ class GenCrtBundleTests(Py23TestCase):
|
||||
with self.assertRaisesRegex(gen_crt_bundle.InputError, "No certificate found"):
|
||||
bundle.add_from_pem("")
|
||||
|
||||
def test_non_ascii_crt_input(self):
|
||||
bundle = gen_crt_bundle.CertificateBundle()
|
||||
|
||||
bundle.add_from_file(test_crts_path + non_ascii_file)
|
||||
self.assertTrue(len(bundle.certificates))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user