1// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
2
3package org.xbill.DNS;
4
5import java.io.*;
6import 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
17public class DNSKEYRecord extends KEYBase {
18
19public static class Protocol {
20	private Protocol() {}
21
22	/** Key will be used for DNSSEC */
23	public static final int DNSSEC = 3;
24}
25
26public static class 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
39private static final long serialVersionUID = -8679800040426675002L;
40
41DNSKEYRecord() {}
42
43Record
44getObject() {
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 */
55public
56DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
57	     byte [] key)
58{
59	super(name, Type.DNSKEY, 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 The key as a PublicKey
68 * @throws DNSSEC.DNSSECException The PublicKey could not be converted into DNS
69 * format.
70 */
71public
72DNSKEYRecord(Name name, int dclass, long ttl, int flags, int proto, int alg,
73	     PublicKey key) throws DNSSEC.DNSSECException
74{
75	super(name, Type.DNSKEY, dclass, ttl, flags, proto, alg,
76	      DNSSEC.fromPublicKey(key, alg));
77	publicKey = key;
78}
79
80void
81rdataFromString(Tokenizer st, Name origin) throws IOException {
82	flags = st.getUInt16();
83	proto = st.getUInt8();
84	String algString = st.getString();
85	alg = DNSSEC.Algorithm.value(algString);
86	if (alg < 0)
87		throw st.exception("Invalid algorithm: " + algString);
88	key = st.getBase64();
89}
90
91}
92