1 // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2 
3 package org.xbill.DNS;
4 
5 import java.io.*;
6 import java.security.PublicKey;
7 
8 /**
9  * Key - contains a cryptographic public key for use by DNS.
10  * The data can be converted to objects implementing
11  * java.security.interfaces.PublicKey
12  * @see DNSSEC
13  *
14  * @author Brian Wellington
15  */
16 
17 public class DNSKEYRecord extends KEYBase {
18 
19 public static class Protocol {
Protocol()20 	private Protocol() {}
21 
22 	/** Key will be used for DNSSEC */
23 	public static final int DNSSEC = 3;
24 }
25 
26 public static class Flags {
Flags()27 	private Flags() {}
28 
29 	/** Key is a zone key */
30 	public static final int ZONE_KEY = 0x100;
31 
32 	/** Key is a secure entry point key */
33 	public static final int SEP_KEY = 0x1;
34 
35 	/** Key has been revoked */
36 	public static final int REVOKE = 0x80;
37 }
38 
39 private static final long serialVersionUID = -8679800040426675002L;
40 
DNSKEYRecord()41 DNSKEYRecord() {}
42 
43 Record
getObject()44 getObject() {
45 	return new DNSKEYRecord();
46 }
47 
48 /**
49  * Creates a DNSKEY Record from the given data
50  * @param flags Flags describing the key's properties
51  * @param proto The protocol that the key was created for
52  * @param alg The key's algorithm
53  * @param key Binary representation of the key
54  */
55 protected
DNSKEYRecord(Name name, int type, int dclass, long ttl, int flags, int proto, int alg, byte [] key)56 DNSKEYRecord(Name name, int type, int dclass, long ttl, int flags, int proto,
57 	     int alg, byte [] key)
58 {
59 	super(name, type, dclass, ttl, flags, proto, alg, key);
60 }
61 
62 /**
63  * Creates a DNSKEY Record from the given data
64  * @param flags Flags describing the key's properties
65  * @param proto The protocol that the key was created for
66  * @param alg The key's algorithm
67  * @param key Binary representation of the key
68  */
69 public
DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg, byte [] key)70 DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
71 	     byte [] key)
72 {
73 	this(name, Type.DNSKEY, dclass, ttl, flags, proto, alg, key);
74 }
75 
76 /**
77  * Creates a DNSKEY Record from the given data
78  * @param flags Flags describing the key's properties
79  * @param proto The protocol that the key was created for
80  * @param alg The key's algorithm
81  * @param key The key as a PublicKey
82  * @throws DNSSEC.DNSSECException The PublicKey could not be converted into DNS
83  * format.
84  */
85 public
DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg, PublicKey key)86 DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
87 	     PublicKey key) throws DNSSEC.DNSSECException
88 {
89 	super(name, Type.DNSKEY, dclass, ttl, flags, proto, alg,
90 	      DNSSEC.fromPublicKey(key, alg));
91 	publicKey = key;
92 }
93 
94 void
rdataFromString(Tokenizer st, Name origin)95 rdataFromString(Tokenizer st, Name origin) throws IOException {
96 	flags = st.getUInt16();
97 	proto = st.getUInt8();
98 	String algString = st.getString();
99 	alg = DNSSEC.Algorithm.value(algString);
100 	if (alg < 0)
101 		throw st.exception("Invalid algorithm: " + algString);
102 	key = st.getBase64();
103 }
104 
105 }
106