1
// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
6
import org.xbill.DNS.utils.*;
9
* The base class for KEY/DNSKEY records, which have identical formats
11
* @author Brian Wellington
14
abstract class KEYBase extends Record {
16
protected int flags, proto, alg;
17
protected byte [] key;
18
protected int footprint = -1;
24
KEYBase(Name name, int type, int dclass, long ttl, int flags, int proto,
27
super(name, type, dclass, ttl);
28
this.flags = checkU16("flags", flags);
29
this.proto = checkU8("proto", proto);
30
this.alg = checkU8("alg", alg);
35
rrFromWire(DNSInput in) throws IOException {
39
if (in.remaining() > 0)
40
key = in.readByteArray();
43
/** Converts the DNSKEY/KEY Record to a String */
46
StringBuffer sb = new StringBuffer();
53
if (Options.check("multiline")) {
55
sb.append(base64.formatString(key, 64, "\t", true));
56
sb.append(" ; key_tag = ");
57
sb.append(getFootprint());
60
sb.append(base64.toString(key));
67
* Returns the flags describing the key's properties
75
* Returns the protocol that the key was created for
83
* Returns the key's algorithm
91
* Returns the binary data representing the key
99
* Returns the key's footprint (after computing it)
108
DNSOutput out = new DNSOutput();
109
rrToWire(out, null, false);
110
byte [] rdata = out.toByteArray();
112
if (alg == DNSSEC.Algorithm.RSAMD5) {
113
int d1 = rdata[rdata.length - 3] & 0xFF;
114
int d2 = rdata[rdata.length - 2] & 0xFF;
115
foot = (d1 << 8) + d2;
119
for (i = 0; i < rdata.length - 1; i += 2) {
120
int d1 = rdata[i] & 0xFF;
121
int d2 = rdata[i + 1] & 0xFF;
122
foot += ((d1 << 8) + d2);
124
if (i < rdata.length) {
125
int d1 = rdata[i] & 0xFF;
128
foot += ((foot >> 16) & 0xFFFF);
130
footprint = (foot & 0xFFFF);
135
rrToWire(DNSOutput out, Compression c, boolean canonical) {
140
out.writeByteArray(key);