Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org) |
| 2 | |
| 3 | package org.xbill.DNS; |
| 4 | |
| 5 | import java.io.*; |
| 6 | import org.xbill.DNS.utils.*; |
| 7 | |
| 8 | /** |
| 9 | * 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 | private static final long serialVersionUID = -8104701402654687025L; |
| 17 | |
| 18 | public static class Algorithm { |
| 19 | private Algorithm() {} |
| 20 | |
| 21 | public static final int RSA = 1; |
| 22 | public static final int DSS = 2; |
| 23 | } |
| 24 | |
| 25 | public static class Digest { |
| 26 | private Digest() {} |
| 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 | Record |
| 38 | 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 |
| 49 | SSHFPRecord(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 | |
| 58 | void |
| 59 | rrFromWire(DNSInput in) throws IOException { |
| 60 | alg = in.readU8(); |
| 61 | digestType = in.readU8(); |
| 62 | fingerprint = in.readByteArray(); |
| 63 | } |
| 64 | |
| 65 | void |
| 66 | rdataFromString(Tokenizer st, Name origin) throws IOException { |
| 67 | alg = st.getUInt8(); |
| 68 | digestType = st.getUInt8(); |
| 69 | fingerprint = st.getHex(true); |
| 70 | } |
| 71 | |
| 72 | String |
| 73 | rrToString() { |
| 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. */ |
| 84 | public int |
| 85 | getAlgorithm() { |
| 86 | return alg; |
| 87 | } |
| 88 | |
| 89 | /** Returns the public key's digest type. */ |
| 90 | public int |
| 91 | getDigestType() { |
| 92 | return digestType; |
| 93 | } |
| 94 | |
| 95 | /** Returns the fingerprint */ |
| 96 | public byte [] |
| 97 | getFingerPrint() { |
| 98 | return fingerprint; |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | rrToWire(DNSOutput out, Compression c, boolean canonical) { |
| 103 | out.writeU8(alg); |
| 104 | out.writeU8(digestType); |
| 105 | out.writeByteArray(fingerprint); |
| 106 | } |
| 107 | |
| 108 | } |