diff --git a/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py b/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py index 94f31e433..4f558fb68 100755 --- a/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py +++ b/components/mbedtls/esp_crt_bundle/gen_crt_bundle.py @@ -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 diff --git a/components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/non_ascii_crt.pem b/components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/non_ascii_crt.pem new file mode 100644 index 000000000..10ad8a1ca --- /dev/null +++ b/components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/non_ascii_crt.pem @@ -0,0 +1,23 @@ +NetLock Arany (Class Gold) Főtanúsítvány +======================================== +-----BEGIN CERTIFICATE----- +MIIEFTCCAv2gAwIBAgIGSUEs5AAQMA0GCSqGSIb3DQEBCwUAMIGnMQswCQYDVQQGEwJIVTERMA8G +A1UEBwwIQnVkYXBlc3QxFTATBgNVBAoMDE5ldExvY2sgS2Z0LjE3MDUGA1UECwwuVGFuw7pzw610 +dsOhbnlraWFkw7NrIChDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzKTE1MDMGA1UEAwwsTmV0TG9jayBB +cmFueSAoQ2xh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z2FuLjbvrW5Kfna +NwUASZQDhETnv0Mxz3WLJdH0pmT1kvarBes96aULNmLazAZfNou2XjG4Kvte9nHfRCaexOYNkbQu +dZWAUWpLMKawYqGT8ZvYzsRjdT9ZR7E= +-----END CERTIFICATE----- diff --git a/components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/test_gen_crt_bundle.py b/components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/test_gen_crt_bundle.py index b502cea92..167aa6384 100755 --- a/components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/test_gen_crt_bundle.py +++ b/components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/test_gen_crt_bundle.py @@ -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()