SSHFPRecord.java revision d7955ce24d294fb2014c59d11fca184471056f44
1// Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) 2 3package org.xbill.DNS; 4 5import java.io.*; 6import org.xbill.DNS.utils.*; 7 8/** 9 * SSH Fingerprint - stores the fingerprint of an SSH host key. 10 * 11 * @author Brian Wellington 12 */ 13 14public class SSHFPRecord extends Record { 15 16private static final long serialVersionUID = -8104701402654687025L; 17 18public static class Algorithm { 19 private Algorithm() {} 20 21 public static final int RSA = 1; 22 public static final int DSS = 2; 23} 24 25public static class Digest { 26 private Digest() {} 27 28 public static final int SHA1 = 1; 29} 30 31private int alg; 32private int digestType; 33private byte [] fingerprint; 34 35SSHFPRecord() {} 36 37Record 38getObject() { 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 */ 48public 49SSHFPRecord(Name name, int dclass, long ttl, int alg, int digestType, 50 byte [] fingerprint) 51{ 52 super(name, Type.SSHFP, dclass, ttl); 53 this.alg = checkU8("alg", alg); 54 this.digestType = checkU8("digestType", digestType); 55 this.fingerprint = fingerprint; 56} 57 58void 59rrFromWire(DNSInput in) throws IOException { 60 alg = in.readU8(); 61 digestType = in.readU8(); 62 fingerprint = in.readByteArray(); 63} 64 65void 66rdataFromString(Tokenizer st, Name origin) throws IOException { 67 alg = st.getUInt8(); 68 digestType = st.getUInt8(); 69 fingerprint = st.getHex(true); 70} 71 72String 73rrToString() { 74 StringBuffer sb = new StringBuffer(); 75 sb.append(alg); 76 sb.append(" "); 77 sb.append(digestType); 78 sb.append(" "); 79 sb.append(base16.toString(fingerprint)); 80 return sb.toString(); 81} 82 83/** Returns the public key's algorithm. */ 84public int 85getAlgorithm() { 86 return alg; 87} 88 89/** Returns the public key's digest type. */ 90public int 91getDigestType() { 92 return digestType; 93} 94 95/** Returns the fingerprint */ 96public byte [] 97getFingerPrint() { 98 return fingerprint; 99} 100 101void 102rrToWire(DNSOutput out, Compression c, boolean canonical) { 103 out.writeU8(alg); 104 out.writeU8(digestType); 105 out.writeByteArray(fingerprint); 106} 107 108} 109