Exemplo n.º 1
0
def main():
    keychain_file = get_apsd_configuration().keychain
    fh = open(keychain_file)
    apsd_prefs = get_apsd_preferences()
    password = calculate_apsd_keychain_password(apsd_prefs)
    master_key = getdbkey(fh, password)
    keychain = Keychain(fh)
    # record type 16 - private keys
    # see CSSM_DL_DB_RECORD_PRIVATE_KEY in cssmtype.h (libsecurity_cssm)
    table = keychain.table_by_record_type(16)
    record = table.find_record_by_attribute("PrintName", apsd_prefs["CertificateName"])

    key = decrypt_rsa_key(record.data, master_key)
    key_pem = rsa_key_der_to_pem(key)
    certificate_pem = extract_certificate(keychain_file)

    push_cert_file = join(CERT_PATH, apsd_prefs["CertificateName"] + ".pem")

    cert_fh = sys.stdout
    if len(sys.argv) > 1 and sys.argv[1] == "-f":
        cert_fh = open(push_cert_file, "wb")
        sys.stderr.write("Writing private key and certificate to %s\n" % push_cert_file)

    cert_fh.write(key_pem)
    cert_fh.write(certificate_pem)
Exemplo n.º 2
0
def main():
    keychain_file = get_apsd_configuration().keychain
    fh = open(keychain_file)
    apsd_prefs = get_apsd_preferences()
    password = calculate_apsd_keychain_password(apsd_prefs)
    master_key = getdbkey(fh, password)
    keychain = Keychain(fh)
    # record type 16 - private keys
    # see CSSM_DL_DB_RECORD_PRIVATE_KEY in cssmtype.h (libsecurity_cssm)
    table = keychain.table_by_record_type(16)
    record = table.find_record_by_attribute('PrintName',
                                            apsd_prefs['CertificateName'])

    key = decrypt_rsa_key(record.data, master_key)
    key_pem = rsa_key_der_to_pem(key)
    certificate_pem = extract_certificate(keychain_file)

    push_cert_file = join(CERT_PATH, apsd_prefs['CertificateName'] + '.pem')

    cert_fh = sys.stdout
    if len(sys.argv) > 1 and sys.argv[1] == '-f':
        cert_fh = open(push_cert_file, 'wb')
        sys.stderr.write('Writing private key and certificate to %s\n' %
                         push_cert_file)

    cert_fh.write(key_pem)
    cert_fh.write(certificate_pem)