def get_ds(session, environment, zone): res = "" (hold, key_list) = load_key_list(session, environment, zone) for key in key_list.keys(): if key.flags() == 257: rr = key.key_to_rr() ds = ldns.ldns_key_rr2ds(rr, ldns.LDNS_SHA256) if res: res += '\n' res += str(ds) return res
print key #set owner key.set_pubkey_owner(domain) #create the public from the ldns_key pubkey = key.key_to_rr() #previous command is equivalent to # pubkey = ldns.ldns_key2rr(key) print pubkey #calculate and set the keytag key.set_keytag(ldns.ldns_calc_keytag(pubkey)) #build the DS record ds = ldns.ldns_key_rr2ds(pubkey, ldns.LDNS_SHA1) print ds owner, tag = pubkey.owner(), key.keytag() #write public key to .key file fw = open("key-%s-%d.key" % (owner, tag), "wb") pubkey.print_to_file(fw) #write private key to .priv file fw = open("key-%s-%d.private" % (owner, tag), "wb") key.print_to_file(fw) #write DS to .ds file fw = open("key-%s-%d.ds" % (owner, tag), "wb") ds.print_to_file(fw)
print key #set owner key.set_pubkey_owner(domain) #create the public from the ldns_key pubkey = key.key_to_rr() #previous command is equivalent to # pubkey = ldns.ldns_key2rr(key) print pubkey #calculate and set the keytag key.set_keytag(ldns.ldns_calc_keytag(pubkey)) #build the DS record ds = ldns.ldns_key_rr2ds(pubkey, ldns.LDNS_SHA1) print ds owner, tag = pubkey.owner(), key.keytag() #write public key to .key file fw = open("key-%s-%d.key" % (owner,tag), "wb") pubkey.print_to_file(fw) #write private key to .priv file fw = open("key-%s-%d.private" % (owner,tag), "wb") key.print_to_file(fw) #write DS to .ds file fw = open("key-%s-%d.ds" % (owner,tag), "wb") ds.print_to_file(fw)
Exponent1: {7:s} Exponent2: {8:s} Coefficient: {9:s}""".format(str(algorithm), getAlgorithmName(algorithm), format(n), format(e), format(d), format(p), format(q), format(d % p_factor), format(d % q_factor), format(u) ) fw.write(file) fw.close() #construct DNSKEY and DS record fw = open("key.priv", "r") key = ldns.ldns_key.new_frm_fp(fw) key.set_pubkey_owner(ldns.ldns_dname(domain)) key.set_flags(flags) pubkey = key.key_to_rr() ds = ldns.ldns_key_rr2ds(pubkey, getDigestType(algorithm)) owner, algo, tag = pubkey.owner(), str(algorithm).zfill(3), key.keytag() fw = open(sys.argv[1] + "/K%s+%s+%d.key" % (owner,algo,tag), "wb") pubkey.print_to_file(fw) fw = open(sys.argv[1] + "/K%s+%s+%d.private" % (owner,algo,tag), "wb") key.print_to_file(fw) fw = open(sys.argv[1] + "/K%s+%s+%d.ds" % (owner,algo,tag), "wb") ds.print_to_file(fw) os.remove("key.priv")