aboutsummaryrefslogtreecommitdiff
path: root/src/org/xbill/DNS/SSHFPRecord.java
blob: 079741e221e12c636c2503f8bb8252d4e560af64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)

package org.xbill.DNS;

import java.io.*;
import org.xbill.DNS.utils.*;

/**
 * SSH Fingerprint - stores the fingerprint of an SSH host key.
 *
 * @author Brian Wellington
 */

public class SSHFPRecord extends Record {

private static final long serialVersionUID = -8104701402654687025L;

public static class Algorithm {
	private Algorithm() {}

	public static final int RSA = 1;
	public static final int DSS = 2;
}

public static class Digest {
	private Digest() {}

	public static final int SHA1 = 1;
}

private int alg;
private int digestType;
private byte [] fingerprint;

SSHFPRecord() {} 

Record
getObject() {
	return new SSHFPRecord();
}

/**
 * Creates an SSHFP Record from the given data.
 * @param alg The public key's algorithm.
 * @param digestType The public key's digest type.
 * @param fingerprint The public key's fingerprint.
 */
public
SSHFPRecord(Name name, int dclass, long ttl, int alg, int digestType,
	    byte [] fingerprint)
{
	super(name, Type.SSHFP, dclass, ttl);
	this.alg = checkU8("alg", alg);
	this.digestType = checkU8("digestType", digestType);
	this.fingerprint = fingerprint;
}

void
rrFromWire(DNSInput in) throws IOException {
	alg = in.readU8();
	digestType = in.readU8();
	fingerprint = in.readByteArray();
}

void
rdataFromString(Tokenizer st, Name origin) throws IOException {
	alg = st.getUInt8();
	digestType = st.getUInt8();
	fingerprint = st.getHex(true);
}

String
rrToString() {
	StringBuffer sb = new StringBuffer();
	sb.append(alg);
	sb.append(" ");
	sb.append(digestType);
	sb.append(" ");
	sb.append(base16.toString(fingerprint));
	return sb.toString();
}

/** Returns the public key's algorithm. */
public int
getAlgorithm() {
	return alg;
}

/** Returns the public key's digest type. */
public int
getDigestType() {
	return digestType;
}

/** Returns the fingerprint */
public byte []
getFingerPrint() {
	return fingerprint;
}

void
rrToWire(DNSOutput out, Compression c, boolean canonical) {
	out.writeU8(alg);
	out.writeU8(digestType);
	out.writeByteArray(fingerprint);
}

}