01: // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
02:
03: package org.xbill.DNS;
04:
05: import java.io.*;
06: import org.xbill.DNS.utils.*;
07:
08: /**
09: * SSH Fingerprint - stores the fingerprint of an SSH host key.
10: *
11: * @author Brian Wellington
12: */
13:
14: public class SSHFPRecord extends Record {
15:
16: public static class Algorithm {
17: private Algorithm() {
18: }
19:
20: public static final int RSA = 1;
21: public static final int DSS = 2;
22: }
23:
24: public static class Digest {
25: private Digest() {
26: }
27:
28: public static final int SHA1 = 1;
29: }
30:
31: private int alg;
32: private int digestType;
33: private byte[] fingerprint;
34:
35: SSHFPRecord() {
36: }
37:
38: Record getObject() {
39: return new SSHFPRecord();
40: }
41:
42: /**
43: * Creates an SSHFP Record from the given data.
44: * @param alg The public key's algorithm.
45: * @param digestType The public key's digest type.
46: * @param fingerprint The public key's fingerprint.
47: */
48: public SSHFPRecord(Name name, int dclass, long ttl, int alg,
49: int digestType, byte[] fingerprint) {
50: super (name, Type.SSHFP, dclass, ttl);
51: this .alg = checkU8("alg", alg);
52: this .digestType = checkU8("digestType", digestType);
53: this .fingerprint = fingerprint;
54: }
55:
56: void rrFromWire(DNSInput in) throws IOException {
57: alg = in.readU8();
58: digestType = in.readU8();
59: fingerprint = in.readByteArray();
60: }
61:
62: void rdataFromString(Tokenizer st, Name origin) throws IOException {
63: alg = st.getUInt8();
64: digestType = st.getUInt8();
65: fingerprint = st.getHex(true);
66: }
67:
68: String rrToString() {
69: StringBuffer sb = new StringBuffer();
70: sb.append(alg);
71: sb.append(" ");
72: sb.append(digestType);
73: sb.append(" ");
74: sb.append(base16.toString(fingerprint));
75: return sb.toString();
76: }
77:
78: /** Returns the public key's algorithm. */
79: public int getAlgorithm() {
80: return alg;
81: }
82:
83: /** Returns the public key's digest type. */
84: public int getDigestType() {
85: return digestType;
86: }
87:
88: /** Returns the fingerprint */
89: public byte[] getFingerPrint() {
90: return fingerprint;
91: }
92:
93: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
94: out.writeU8(alg);
95: out.writeU8(digestType);
96: out.writeByteArray(fingerprint);
97: }
98:
99: }
|