6cf4d9
#!/usr/bin/python
6cf4d9
# vim:set et sw=4:
6cf4d9
#
6cf4d9
# certdata2pem.py - splits certdata.txt into multiple files
6cf4d9
#
6cf4d9
# Copyright (C) 2009 Philipp Kern <pkern@debian.org>
6cf4d9
# Copyright (C) 2013 Kai Engert <kaie@redhat.com>
6cf4d9
#
6cf4d9
# This program is free software; you can redistribute it and/or modify
6cf4d9
# it under the terms of the GNU General Public License as published by
6cf4d9
# the Free Software Foundation; either version 2 of the License, or
6cf4d9
# (at your option) any later version.
6cf4d9
#
6cf4d9
# This program is distributed in the hope that it will be useful,
6cf4d9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
6cf4d9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6cf4d9
# GNU General Public License for more details.
6cf4d9
#
6cf4d9
# You should have received a copy of the GNU General Public License
6cf4d9
# along with this program; if not, write to the Free Software
6cf4d9
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
6cf4d9
# USA.
6cf4d9
6cf4d9
import base64
6cf4d9
import os.path
6cf4d9
import re
6cf4d9
import sys
6cf4d9
import textwrap
6cf4d9
import urllib.request, urllib.parse, urllib.error
6cf4d9
import subprocess
6cf4d9
6cf4d9
objects = []
6cf4d9
6cf4d9
def printable_serial(obj):
6cf4d9
  return ".".join([str(x) for x in obj['CKA_SERIAL_NUMBER']])
6cf4d9
6cf4d9
# Dirty file parser.
6cf4d9
in_data, in_multiline, in_obj = False, False, False
6cf4d9
field, ftype, value, binval, obj = None, None, None, bytearray(), dict()
6cf4d9
for line in open('certdata.txt', 'r'):
6cf4d9
    # Ignore the file header.
6cf4d9
    if not in_data:
6cf4d9
        if line.startswith('BEGINDATA'):
6cf4d9
            in_data = True
6cf4d9
        continue
6cf4d9
    # Ignore comment lines.
6cf4d9
    if line.startswith('#'):
6cf4d9
        continue
6cf4d9
    # Empty lines are significant if we are inside an object.
6cf4d9
    if in_obj and len(line.strip()) == 0:
6cf4d9
        objects.append(obj)
6cf4d9
        obj = dict()
6cf4d9
        in_obj = False
6cf4d9
        continue
6cf4d9
    if len(line.strip()) == 0:
6cf4d9
        continue
6cf4d9
    if in_multiline:
6cf4d9
        if not line.startswith('END'):
6cf4d9
            if ftype == 'MULTILINE_OCTAL':
6cf4d9
                line = line.strip()
6cf4d9
                for i in re.finditer(r'\\([0-3][0-7][0-7])', line):
6cf4d9
                    integ = int(i.group(1), 8)
6cf4d9
                    binval.extend((integ).to_bytes(1, sys.byteorder))
6cf4d9
                obj[field] = binval
6cf4d9
            else:
6cf4d9
                value += line
6cf4d9
                obj[field] = value
6cf4d9
            continue
6cf4d9
        in_multiline = False
6cf4d9
        continue
6cf4d9
    if line.startswith('CKA_CLASS'):
6cf4d9
        in_obj = True
6cf4d9
    line_parts = line.strip().split(' ', 2)
6cf4d9
    if len(line_parts) > 2:
6cf4d9
        field, ftype = line_parts[0:2]
6cf4d9
        value = ' '.join(line_parts[2:])
6cf4d9
    elif len(line_parts) == 2:
6cf4d9
        field, ftype = line_parts
6cf4d9
        value = None
6cf4d9
    else:
6cf4d9
        raise NotImplementedError('line_parts < 2 not supported.\n' + line)
6cf4d9
    if ftype == 'MULTILINE_OCTAL':
6cf4d9
        in_multiline = True
6cf4d9
        value = ""
6cf4d9
        binval = bytearray()
6cf4d9
        continue
6cf4d9
    obj[field] = value
6cf4d9
if len(list(obj.items())) > 0:
6cf4d9
    objects.append(obj)
6cf4d9
6cf4d9
# Build up trust database.
6cf4d9
trustmap = dict()
6cf4d9
for obj in objects:
6cf4d9
    if obj['CKA_CLASS'] != 'CKO_NSS_TRUST':
6cf4d9
        continue
6cf4d9
    key = obj['CKA_LABEL'] + printable_serial(obj)
6cf4d9
    trustmap[key] = obj
6cf4d9
    print(" added trust", key)
6cf4d9
6cf4d9
# Build up cert database.
6cf4d9
certmap = dict()
6cf4d9
for obj in objects:
6cf4d9
    if obj['CKA_CLASS'] != 'CKO_CERTIFICATE':
6cf4d9
        continue
6cf4d9
    key = obj['CKA_LABEL'] + printable_serial(obj)
6cf4d9
    certmap[key] = obj
6cf4d9
    print(" added cert", key)
6cf4d9
6cf4d9
def obj_to_filename(obj):
6cf4d9
    label = obj['CKA_LABEL'][1:-1]
6cf4d9
    label = label.replace('/', '_')\
6cf4d9
        .replace(' ', '_')\
6cf4d9
        .replace('(', '=')\
6cf4d9
        .replace(')', '=')\
6cf4d9
        .replace(',', '_')
6cf4d9
    labelbytes = bytearray()
6cf4d9
    i = 0
6cf4d9
    imax = len(label)
6cf4d9
    while i < imax:
6cf4d9
        if i < imax-3 and label[i] == '\\' and label[i+1] == 'x':
6cf4d9
            labelbytes.extend(bytes.fromhex(label[i+2:i+4]))
6cf4d9
            i += 4
6cf4d9
            continue
6cf4d9
        labelbytes.extend(str.encode(label[i]))
6cf4d9
        i = i+1
6cf4d9
        continue
6cf4d9
    label = labelbytes.decode('utf-8')
6cf4d9
    serial = printable_serial(obj)
6cf4d9
    return label + ":" + serial
6cf4d9
6cf4d9
def write_cert_ext_to_file(f, oid, value, public_key):
6cf4d9
    f.write("[p11-kit-object-v1]\n")
6cf4d9
    f.write("label: ");
6cf4d9
    f.write(tobj['CKA_LABEL'])
6cf4d9
    f.write("\n")
6cf4d9
    f.write("class: x-certificate-extension\n");
6cf4d9
    f.write("object-id: " + oid + "\n")
6cf4d9
    f.write("value: \"" + value + "\"\n")
6cf4d9
    f.write("modifiable: false\n");
6cf4d9
    f.write(public_key)
6cf4d9
6cf4d9
trust_types = {
6cf4d9
  "CKA_TRUST_DIGITAL_SIGNATURE": "digital-signature",
6cf4d9
  "CKA_TRUST_NON_REPUDIATION": "non-repudiation",
6cf4d9
  "CKA_TRUST_KEY_ENCIPHERMENT": "key-encipherment",
6cf4d9
  "CKA_TRUST_DATA_ENCIPHERMENT": "data-encipherment",
6cf4d9
  "CKA_TRUST_KEY_AGREEMENT": "key-agreement",
6cf4d9
  "CKA_TRUST_KEY_CERT_SIGN": "cert-sign",
6cf4d9
  "CKA_TRUST_CRL_SIGN": "crl-sign",
6cf4d9
  "CKA_TRUST_SERVER_AUTH": "server-auth",
6cf4d9
  "CKA_TRUST_CLIENT_AUTH": "client-auth",
6cf4d9
  "CKA_TRUST_CODE_SIGNING": "code-signing",
6cf4d9
  "CKA_TRUST_EMAIL_PROTECTION": "email-protection",
6cf4d9
  "CKA_TRUST_IPSEC_END_SYSTEM": "ipsec-end-system",
6cf4d9
  "CKA_TRUST_IPSEC_TUNNEL": "ipsec-tunnel",
6cf4d9
  "CKA_TRUST_IPSEC_USER": "ipsec-user",
6cf4d9
  "CKA_TRUST_TIME_STAMPING": "time-stamping",
6cf4d9
  "CKA_TRUST_STEP_UP_APPROVED": "step-up-approved",
6cf4d9
}
6cf4d9
6cf4d9
legacy_trust_types = {
6cf4d9
  "LEGACY_CKA_TRUST_SERVER_AUTH": "server-auth",
6cf4d9
  "LEGACY_CKA_TRUST_CODE_SIGNING": "code-signing",
6cf4d9
  "LEGACY_CKA_TRUST_EMAIL_PROTECTION": "email-protection",
6cf4d9
}
6cf4d9
6cf4d9
legacy_to_real_trust_types = {
6cf4d9
  "LEGACY_CKA_TRUST_SERVER_AUTH": "CKA_TRUST_SERVER_AUTH",
6cf4d9
  "LEGACY_CKA_TRUST_CODE_SIGNING": "CKA_TRUST_CODE_SIGNING",
6cf4d9
  "LEGACY_CKA_TRUST_EMAIL_PROTECTION": "CKA_TRUST_EMAIL_PROTECTION",
6cf4d9
}
6cf4d9
6cf4d9
openssl_trust = {
6cf4d9
  "CKA_TRUST_SERVER_AUTH": "serverAuth",
6cf4d9
  "CKA_TRUST_CLIENT_AUTH": "clientAuth",
6cf4d9
  "CKA_TRUST_CODE_SIGNING": "codeSigning",
6cf4d9
  "CKA_TRUST_EMAIL_PROTECTION": "emailProtection",
6cf4d9
}
6cf4d9
6cf4d9
cert_distrust_types = {
6cf4d9
  "CKA_NSS_SERVER_DISTRUST_AFTER": "nss-server-distrust-after",
6cf4d9
  "CKA_NSS_EMAIL_DISTRUST_AFTER": "nss-email-distrust-after",
6cf4d9
}
6cf4d9
6cf4d9
for tobj in objects:
6cf4d9
    if tobj['CKA_CLASS'] == 'CKO_NSS_TRUST':
6cf4d9
        key = tobj['CKA_LABEL'] + printable_serial(tobj)
6cf4d9
        print("producing trust for " + key)
6cf4d9
        trustbits = []
6cf4d9
        distrustbits = []
6cf4d9
        openssl_trustflags = []
6cf4d9
        openssl_distrustflags = []
6cf4d9
        legacy_trustbits = []
6cf4d9
        legacy_openssl_trustflags = []
6cf4d9
        for t in list(trust_types.keys()):
6cf4d9
            if t in tobj and tobj[t] == 'CKT_NSS_TRUSTED_DELEGATOR':
6cf4d9
                trustbits.append(t)
6cf4d9
                if t in openssl_trust:
6cf4d9
                    openssl_trustflags.append(openssl_trust[t])
6cf4d9
            if t in tobj and tobj[t] == 'CKT_NSS_NOT_TRUSTED':
6cf4d9
                distrustbits.append(t)
6cf4d9
                if t in openssl_trust:
6cf4d9
                    openssl_distrustflags.append(openssl_trust[t])
6cf4d9
6cf4d9
        for t in list(legacy_trust_types.keys()):
6cf4d9
            if t in tobj and tobj[t] == 'CKT_NSS_TRUSTED_DELEGATOR':
6cf4d9
                real_t = legacy_to_real_trust_types[t]
6cf4d9
                legacy_trustbits.append(real_t)
6cf4d9
                if real_t in openssl_trust:
6cf4d9
                    legacy_openssl_trustflags.append(openssl_trust[real_t])
6cf4d9
            if t in tobj and tobj[t] == 'CKT_NSS_NOT_TRUSTED':
6cf4d9
                raise NotImplementedError('legacy distrust not supported.\n' + line)
6cf4d9
6cf4d9
        fname = obj_to_filename(tobj)
6cf4d9
        try:
6cf4d9
            obj = certmap[key]
6cf4d9
        except:
6cf4d9
            obj = None
6cf4d9
6cf4d9
        # optional debug code, that dumps the parsed input to files
6cf4d9
        #fulldump = "dump-" + fname
6cf4d9
        #dumpf = open(fulldump, 'w')
6cf4d9
        #dumpf.write(str(obj));
6cf4d9
        #dumpf.write(str(tobj));
6cf4d9
        #dumpf.close();
6cf4d9
6cf4d9
        is_legacy = 0
6cf4d9
        if 'LEGACY_CKA_TRUST_SERVER_AUTH' in tobj or 'LEGACY_CKA_TRUST_EMAIL_PROTECTION' in tobj or 'LEGACY_CKA_TRUST_CODE_SIGNING' in tobj:
6cf4d9
            is_legacy = 1
6cf4d9
            if obj == None:
6cf4d9
                raise NotImplementedError('found legacy trust without certificate.\n' + line)
6cf4d9
6cf4d9
            legacy_fname = "legacy-default/" + fname + ".crt"
6cf4d9
            f = open(legacy_fname, 'w')
6cf4d9
            f.write("# alias=%s\n"%tobj['CKA_LABEL'])
6cf4d9
            f.write("# trust=" + " ".join(legacy_trustbits) + "\n")
6cf4d9
            if legacy_openssl_trustflags:
6cf4d9
                f.write("# openssl-trust=" + " ".join(legacy_openssl_trustflags) + "\n")
6cf4d9
            f.write("-----BEGIN CERTIFICATE-----\n")
6cf4d9
            temp_encoded_b64 = base64.b64encode(obj['CKA_VALUE'])
6cf4d9
            temp_wrapped = textwrap.wrap(temp_encoded_b64.decode(), 64)
6cf4d9
            f.write("\n".join(temp_wrapped))
6cf4d9
            f.write("\n-----END CERTIFICATE-----\n")
6cf4d9
            f.close()
6cf4d9
6cf4d9
            if 'CKA_TRUST_SERVER_AUTH' in tobj or 'CKA_TRUST_EMAIL_PROTECTION' in tobj or 'CKA_TRUST_CODE_SIGNING' in tobj:
6cf4d9
                legacy_fname = "legacy-disable/" + fname + ".crt"
6cf4d9
                f = open(legacy_fname, 'w')
6cf4d9
                f.write("# alias=%s\n"%tobj['CKA_LABEL'])
6cf4d9
                f.write("# trust=" + " ".join(trustbits) + "\n")
6cf4d9
                if openssl_trustflags:
6cf4d9
                    f.write("# openssl-trust=" + " ".join(openssl_trustflags) + "\n")
6cf4d9
                f.write("-----BEGIN CERTIFICATE-----\n")
6cf4d9
                f.write("\n".join(textwrap.wrap(base64.b64encode(obj['CKA_VALUE']), 64)))
6cf4d9
                f.write("\n-----END CERTIFICATE-----\n")
6cf4d9
                f.close()
6cf4d9
6cf4d9
            # don't produce p11-kit output for legacy certificates
6cf4d9
            continue
6cf4d9
6cf4d9
        pk = ''
6cf4d9
        cert_comment = ''
6cf4d9
        if obj != None:
6cf4d9
            # must extract the public key from the cert, let's use openssl
6cf4d9
            cert_fname = "cert-" + fname
6cf4d9
            fc = open(cert_fname, 'w')
6cf4d9
            fc.write("-----BEGIN CERTIFICATE-----\n")
6cf4d9
            temp_encoded_b64 = base64.b64encode(obj['CKA_VALUE'])
6cf4d9
            temp_wrapped = textwrap.wrap(temp_encoded_b64.decode(), 64)
6cf4d9
            fc.write("\n".join(temp_wrapped))
6cf4d9
            fc.write("\n-----END CERTIFICATE-----\n")
6cf4d9
            fc.close();
6cf4d9
            pk_fname = "pubkey-" + fname
6cf4d9
            fpkout = open(pk_fname, "w")
6cf4d9
            dump_pk_command = ["openssl", "x509", "-in", cert_fname, "-noout", "-pubkey"]
6cf4d9
            subprocess.call(dump_pk_command, stdout=fpkout)
6cf4d9
            fpkout.close()
6cf4d9
            with open (pk_fname, "r") as myfile:
6cf4d9
                pk=myfile.read()
6cf4d9
            # obtain certificate information suitable as a comment
6cf4d9
            comment_fname = "comment-" + fname
6cf4d9
            fcout = open(comment_fname, "w")
6cf4d9
            comment_command = ["openssl", "x509", "-in", cert_fname, "-noout", "-text"]
6cf4d9
            subprocess.call(comment_command, stdout=fcout)
6cf4d9
            fcout.close()
6cf4d9
            sed_command = ["sed", "--in-place", "s/^/#/", comment_fname]
6cf4d9
            subprocess.call(sed_command)
6cf4d9
            with open (comment_fname, "r", errors = 'replace') as myfile:
6cf4d9
                cert_comment=myfile.read()
6cf4d9
6cf4d9
        fname += ".tmp-p11-kit"
6cf4d9
        f = open(fname, 'w')
6cf4d9
6cf4d9
        if obj != None:
6cf4d9
            is_distrusted = False
6cf4d9
            has_server_trust = False
6cf4d9
            has_email_trust = False
6cf4d9
            has_code_trust = False
6cf4d9
6cf4d9
            if 'CKA_TRUST_SERVER_AUTH' in tobj:
6cf4d9
                if tobj['CKA_TRUST_SERVER_AUTH'] == 'CKT_NSS_NOT_TRUSTED':
6cf4d9
                    is_distrusted = True
6cf4d9
                elif tobj['CKA_TRUST_SERVER_AUTH'] == 'CKT_NSS_TRUSTED_DELEGATOR':
6cf4d9
                    has_server_trust = True
6cf4d9
6cf4d9
            if 'CKA_TRUST_EMAIL_PROTECTION' in tobj:
6cf4d9
                if tobj['CKA_TRUST_EMAIL_PROTECTION'] == 'CKT_NSS_NOT_TRUSTED':
6cf4d9
                    is_distrusted = True
6cf4d9
                elif tobj['CKA_TRUST_EMAIL_PROTECTION'] == 'CKT_NSS_TRUSTED_DELEGATOR':
6cf4d9
                    has_email_trust = True
6cf4d9
6cf4d9
            if 'CKA_TRUST_CODE_SIGNING' in tobj:
6cf4d9
                if tobj['CKA_TRUST_CODE_SIGNING'] == 'CKT_NSS_NOT_TRUSTED':
6cf4d9
                    is_distrusted = True
6cf4d9
                elif tobj['CKA_TRUST_CODE_SIGNING'] == 'CKT_NSS_TRUSTED_DELEGATOR':
6cf4d9
                    has_code_trust = True
6cf4d9
6cf4d9
            if is_distrusted:
6cf4d9
                trust_ext_oid = "1.3.6.1.4.1.3319.6.10.1"
6cf4d9
                trust_ext_value = "0.%06%0a%2b%06%01%04%01%99w%06%0a%01%04 0%1e%06%08%2b%06%01%05%05%07%03%04%06%08%2b%06%01%05%05%07%03%01%06%08%2b%06%01%05%05%07%03%03"
6cf4d9
                write_cert_ext_to_file(f, trust_ext_oid, trust_ext_value, pk)
6cf4d9
6cf4d9
            trust_ext_oid = "2.5.29.37"
6cf4d9
            if has_server_trust:
6cf4d9
                if has_email_trust:
6cf4d9
                    if has_code_trust:
6cf4d9
                        # server + email + code
6cf4d9
                        trust_ext_value = "0%2a%06%03U%1d%25%01%01%ff%04 0%1e%06%08%2b%06%01%05%05%07%03%04%06%08%2b%06%01%05%05%07%03%01%06%08%2b%06%01%05%05%07%03%03"
6cf4d9
                    else:
6cf4d9
                        # server + email
6cf4d9
                        trust_ext_value = "0 %06%03U%1d%25%01%01%ff%04%160%14%06%08%2b%06%01%05%05%07%03%04%06%08%2b%06%01%05%05%07%03%01"
6cf4d9
                else:
6cf4d9
                    if has_code_trust:
6cf4d9
                        # server + code
6cf4d9
                        trust_ext_value = "0 %06%03U%1d%25%01%01%ff%04%160%14%06%08%2b%06%01%05%05%07%03%01%06%08%2b%06%01%05%05%07%03%03"
6cf4d9
                    else:
6cf4d9
                        # server
6cf4d9
                        trust_ext_value = "0%16%06%03U%1d%25%01%01%ff%04%0c0%0a%06%08%2b%06%01%05%05%07%03%01"
6cf4d9
            else:
6cf4d9
                if has_email_trust:
6cf4d9
                    if has_code_trust:
6cf4d9
                        # email + code
6cf4d9
                        trust_ext_value = "0 %06%03U%1d%25%01%01%ff%04%160%14%06%08%2b%06%01%05%05%07%03%04%06%08%2b%06%01%05%05%07%03%03"
6cf4d9
                    else:
6cf4d9
                        # email
6cf4d9
                        trust_ext_value = "0%16%06%03U%1d%25%01%01%ff%04%0c0%0a%06%08%2b%06%01%05%05%07%03%04"
6cf4d9
                else:
6cf4d9
                    if has_code_trust:
6cf4d9
                        # code
6cf4d9
                        trust_ext_value = "0%16%06%03U%1d%25%01%01%ff%04%0c0%0a%06%08%2b%06%01%05%05%07%03%03"
6cf4d9
                    else:
6cf4d9
                        # none
6cf4d9
                        trust_ext_value = "0%18%06%03U%1d%25%01%01%ff%04%0e0%0c%06%0a%2b%06%01%04%01%99w%06%0a%10"
6cf4d9
6cf4d9
            # no 2.5.29.37 for neutral certificates
6cf4d9
            if (is_distrusted or has_server_trust or has_email_trust or has_code_trust):
6cf4d9
                write_cert_ext_to_file(f, trust_ext_oid, trust_ext_value, pk)
6cf4d9
6cf4d9
            pk = ''
6cf4d9
            f.write("\n")
6cf4d9
6cf4d9
            f.write("[p11-kit-object-v1]\n")
6cf4d9
            f.write("label: ");
6cf4d9
            f.write(tobj['CKA_LABEL'])
6cf4d9
            f.write("\n")
6cf4d9
            if is_distrusted:
6cf4d9
                f.write("x-distrusted: true\n")
6cf4d9
            elif has_server_trust or has_email_trust or has_code_trust:
6cf4d9
                f.write("trusted: true\n")
6cf4d9
            else:
6cf4d9
                f.write("trusted: false\n")
6cf4d9
6cf4d9
            # requires p11-kit >= 0.23.4
6cf4d9
            f.write("nss-mozilla-ca-policy: true\n")
6cf4d9
            f.write("modifiable: false\n");
6cf4d9
6cf4d9
            # requires p11-kit >= 0.23.19
6cf4d9
            for t in list(cert_distrust_types.keys()):
6cf4d9
                if t in obj:
6cf4d9
                    value = obj[t]
6cf4d9
                    if value == 'CK_FALSE':
6cf4d9
                        value = bytearray(1)
6cf4d9
                    f.write(cert_distrust_types[t] + ": \"")
6cf4d9
                    f.write(urllib.parse.quote(value));
6cf4d9
                    f.write("\"\n")
6cf4d9
6cf4d9
            f.write("-----BEGIN CERTIFICATE-----\n")
6cf4d9
            temp_encoded_b64 = base64.b64encode(obj['CKA_VALUE'])
6cf4d9
            temp_wrapped = textwrap.wrap(temp_encoded_b64.decode(), 64)
6cf4d9
            f.write("\n".join(temp_wrapped))
6cf4d9
            f.write("\n-----END CERTIFICATE-----\n")
6cf4d9
            f.write(cert_comment)
6cf4d9
            f.write("\n")
6cf4d9
6cf4d9
        else:
6cf4d9
            f.write("[p11-kit-object-v1]\n")
6cf4d9
            f.write("label: ");
6cf4d9
            f.write(tobj['CKA_LABEL']);
6cf4d9
            f.write("\n")
6cf4d9
            f.write("class: certificate\n")
6cf4d9
            f.write("certificate-type: x-509\n")
6cf4d9
            f.write("modifiable: false\n");
6cf4d9
            f.write("issuer: \"");
6cf4d9
            f.write(urllib.parse.quote(tobj['CKA_ISSUER']));
6cf4d9
            f.write("\"\n")
6cf4d9
            f.write("serial-number: \"");
6cf4d9
            f.write(urllib.parse.quote(tobj['CKA_SERIAL_NUMBER']));
6cf4d9
            f.write("\"\n")
6cf4d9
            if (tobj['CKA_TRUST_SERVER_AUTH'] == 'CKT_NSS_NOT_TRUSTED') or (tobj['CKA_TRUST_EMAIL_PROTECTION'] == 'CKT_NSS_NOT_TRUSTED') or (tobj['CKA_TRUST_CODE_SIGNING'] == 'CKT_NSS_NOT_TRUSTED'):
6cf4d9
              f.write("x-distrusted: true\n")
6cf4d9
            f.write("\n\n")
6cf4d9
        f.close()
6cf4d9
        print(" -> written as '%s', trust = %s, openssl-trust = %s, distrust = %s, openssl-distrust = %s" % (fname, trustbits, openssl_trustflags, distrustbits, openssl_distrustflags))