Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@
# Build up trust database.
trust = dict()
for obj in objects:
if obj['CKA_CLASS'] not in ('CKO_NETSCAPE_TRUST', 'CKO_NSS_TRUST'):
if obj['CKA_CLASS'] != 'CKO_NSS_TRUST':
continue
elif obj['CKA_TRUST_SERVER_AUTH'] in ('CKT_NETSCAPE_TRUSTED_DELEGATOR',
'CKT_NSS_TRUSTED_DELEGATOR'):
trust[obj['CKA_LABEL']] = True
elif obj['CKA_TRUST_EMAIL_PROTECTION'] in ('CKT_NETSCAPE_TRUSTED_DELEGATOR',
'CKT_NSS_TRUSTED_DELEGATOR'):
# Only roots trusted for TLS belong in the bundle. Roots Mozilla trusts
# only for S/MIME must not become TLS roots, since OpenSSL, curl and Go
# use the bundle for TLS without any purpose check.
elif obj['CKA_TRUST_SERVER_AUTH'] == 'CKT_NSS_TRUSTED_DELEGATOR':
trust[obj['CKA_LABEL']] = True
else:
print("Ignoring certificate %s. SAUTH=%s, EPROT=%s" % \
Expand All @@ -106,11 +105,12 @@
if obj['CKA_CLASS'] == 'CKO_CERTIFICATE':
if not obj['CKA_LABEL'] in trust or not trust[obj['CKA_LABEL']]:
continue
fname = obj['CKA_LABEL'][1:-1].replace('/', '_')\
bname = obj['CKA_LABEL'][1:-1].replace('/', '_')\
.replace(' ', '_')\
.replace('(', '=')\
.replace(')', '=')\
.replace(',', '_') + '.pem'
.replace(',', '_')
fname = bname + '.pem'
# fname can be either in utf8 form ("NetLock Arany (Class
# Gold) Főtanúsítvány") or in an encoded form ("AC Ra\xC3\xADz
# Certic\xC3\xA1mara S.A.")
Expand All @@ -125,6 +125,14 @@
except (UnicodeEncodeError, UnicodeDecodeError):
pass

# Several CAs can share a label; don't let one overwrite the other.
basename = fname[:-4]
suffix = 2
while os.path.exists(fname):
print("Found duplicate certificate name %s, renaming." % fname)
fname = basename + '_%d.pem' % suffix
suffix += 1
Comment on lines +131 to +134

f = open(fname.encode(encoding=sys.getfilesystemencoding(), errors="ignore"), 'w')
f.write("-----BEGIN CERTIFICATE-----\n")
# obj['CKA_VALUE'] is a string of octals like '\060\311…',
Expand Down
Loading