diff options
author | Shuyi Chen <shuyichen@google.com> | 2013-05-22 14:51:55 -0700 |
---|---|---|
committer | Shuyi Chen <shuyichen@google.com> | 2013-05-22 17:19:30 -0700 |
commit | d7955ce24d294fb2014c59d11fca184471056f44 (patch) | |
tree | e260500b0b7639127038495d46a0ad6dcbb6d96c /src/org/xbill/DNS/CERTRecord.java | |
parent | 8f4ce9ea0de51fee918bffe19c434612d6bbb2d7 (diff) | |
download | smack-jb-mr2-release.tar.gz |
Add android smack source.HEADandroid-wear-5.0.0_r1android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-l-preview_r2android-cts-5.1_r9android-cts-5.1_r8android-cts-5.1_r7android-cts-5.1_r6android-cts-5.1_r5android-cts-5.1_r4android-cts-5.1_r3android-cts-5.1_r28android-cts-5.1_r27android-cts-5.1_r26android-cts-5.1_r25android-cts-5.1_r24android-cts-5.1_r23android-cts-5.1_r22android-cts-5.1_r21android-cts-5.1_r20android-cts-5.1_r2android-cts-5.1_r19android-cts-5.1_r18android-cts-5.1_r17android-cts-5.1_r16android-cts-5.1_r15android-cts-5.1_r14android-cts-5.1_r13android-cts-5.1_r10android-cts-5.1_r1android-cts-5.0_r9android-cts-5.0_r8android-cts-5.0_r7android-cts-5.0_r6android-cts-5.0_r5android-cts-5.0_r4android-cts-5.0_r3android-cts-4.4_r4android-cts-4.4_r1android-5.1.1_r9android-5.1.1_r8android-5.1.1_r7android-5.1.1_r6android-5.1.1_r5android-5.1.1_r4android-5.1.1_r38android-5.1.1_r37android-5.1.1_r36android-5.1.1_r35android-5.1.1_r34android-5.1.1_r33android-5.1.1_r30android-5.1.1_r3android-5.1.1_r29android-5.1.1_r28android-5.1.1_r26android-5.1.1_r25android-5.1.1_r24android-5.1.1_r23android-5.1.1_r22android-5.1.1_r20android-5.1.1_r2android-5.1.1_r19android-5.1.1_r18android-5.1.1_r17android-5.1.1_r16android-5.1.1_r15android-5.1.1_r14android-5.1.1_r13android-5.1.1_r12android-5.1.1_r10android-5.1.1_r1android-5.1.0_r5android-5.1.0_r4android-5.1.0_r3android-5.1.0_r1android-5.0.2_r3android-5.0.2_r1android-5.0.1_r1android-5.0.0_r7android-5.0.0_r6android-5.0.0_r5.1android-5.0.0_r5android-5.0.0_r4android-5.0.0_r3android-5.0.0_r2android-5.0.0_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1tools_r22.2mastermainlollipop-wear-releaselollipop-releaselollipop-mr1-wfc-releaselollipop-mr1-releaselollipop-mr1-fi-releaselollipop-mr1-devlollipop-mr1-cts-releaselollipop-devlollipop-cts-releasel-previewkitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devidea133-weekly-releaseidea133
Change-Id: I49ce97136c17173c4ae3965c694af6e7bc49897d
Diffstat (limited to 'src/org/xbill/DNS/CERTRecord.java')
-rw-r--r-- | src/org/xbill/DNS/CERTRecord.java | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/src/org/xbill/DNS/CERTRecord.java b/src/org/xbill/DNS/CERTRecord.java new file mode 100644 index 0000000..39bcef3 --- /dev/null +++ b/src/org/xbill/DNS/CERTRecord.java @@ -0,0 +1,224 @@ +// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) + +package org.xbill.DNS; + +import java.io.*; +import org.xbill.DNS.utils.*; + +/** + * Certificate Record - Stores a certificate associated with a name. The + * certificate might also be associated with a KEYRecord. + * @see KEYRecord + * + * @author Brian Wellington + */ + +public class CERTRecord extends Record { + +public static class CertificateType { + /** Certificate type identifiers. See RFC 4398 for more detail. */ + + private CertificateType() {} + + /** PKIX (X.509v3) */ + public static final int PKIX = 1; + + /** Simple Public Key Infrastructure */ + public static final int SPKI = 2; + + /** Pretty Good Privacy */ + public static final int PGP = 3; + + /** URL of an X.509 data object */ + public static final int IPKIX = 4; + + /** URL of an SPKI certificate */ + public static final int ISPKI = 5; + + /** Fingerprint and URL of an OpenPGP packet */ + public static final int IPGP = 6; + + /** Attribute Certificate */ + public static final int ACPKIX = 7; + + /** URL of an Attribute Certificate */ + public static final int IACPKIX = 8; + + /** Certificate format defined by URI */ + public static final int URI = 253; + + /** Certificate format defined by OID */ + public static final int OID = 254; + + private static Mnemonic types = new Mnemonic("Certificate type", + Mnemonic.CASE_UPPER); + + static { + types.setMaximum(0xFFFF); + types.setNumericAllowed(true); + + types.add(PKIX, "PKIX"); + types.add(SPKI, "SPKI"); + types.add(PGP, "PGP"); + types.add(PKIX, "IPKIX"); + types.add(SPKI, "ISPKI"); + types.add(PGP, "IPGP"); + types.add(PGP, "ACPKIX"); + types.add(PGP, "IACPKIX"); + types.add(URI, "URI"); + types.add(OID, "OID"); + } + + /** + * Converts a certificate type into its textual representation + */ + public static String + string(int type) { + return types.getText(type); + } + + /** + * Converts a textual representation of an certificate type into its + * numeric code. Integers in the range 0..65535 are also accepted. + * @param s The textual representation of the algorithm + * @return The algorithm code, or -1 on error. + */ + public static int + value(String s) { + return types.getValue(s); + } +} + +/** PKIX (X.509v3) */ +public static final int PKIX = CertificateType.PKIX; + +/** Simple Public Key Infrastructure */ +public static final int SPKI = CertificateType.SPKI; + +/** Pretty Good Privacy */ +public static final int PGP = CertificateType.PGP; + +/** Certificate format defined by URI */ +public static final int URI = CertificateType.URI; + +/** Certificate format defined by IOD */ +public static final int OID = CertificateType.OID; + +private static final long serialVersionUID = 4763014646517016835L; + +private int certType, keyTag; +private int alg; +private byte [] cert; + +CERTRecord() {} + +Record +getObject() { + return new CERTRecord(); +} + +/** + * Creates a CERT Record from the given data + * @param certType The type of certificate (see constants) + * @param keyTag The ID of the associated KEYRecord, if present + * @param alg The algorithm of the associated KEYRecord, if present + * @param cert Binary data representing the certificate + */ +public +CERTRecord(Name name, int dclass, long ttl, int certType, int keyTag, + int alg, byte [] cert) +{ + super(name, Type.CERT, dclass, ttl); + this.certType = checkU16("certType", certType); + this.keyTag = checkU16("keyTag", keyTag); + this.alg = checkU8("alg", alg); + this.cert = cert; +} + +void +rrFromWire(DNSInput in) throws IOException { + certType = in.readU16(); + keyTag = in.readU16(); + alg = in.readU8(); + cert = in.readByteArray(); +} + +void +rdataFromString(Tokenizer st, Name origin) throws IOException { + String certTypeString = st.getString(); + certType = CertificateType.value(certTypeString); + if (certType < 0) + throw st.exception("Invalid certificate type: " + + certTypeString); + keyTag = st.getUInt16(); + String algString = st.getString(); + alg = DNSSEC.Algorithm.value(algString); + if (alg < 0) + throw st.exception("Invalid algorithm: " + algString); + cert = st.getBase64(); +} + +/** + * Converts rdata to a String + */ +String +rrToString() { + StringBuffer sb = new StringBuffer(); + sb.append (certType); + sb.append (" "); + sb.append (keyTag); + sb.append (" "); + sb.append (alg); + if (cert != null) { + if (Options.check("multiline")) { + sb.append(" (\n"); + sb.append(base64.formatString(cert, 64, "\t", true)); + } else { + sb.append(" "); + sb.append(base64.toString(cert)); + } + } + return sb.toString(); +} + +/** + * Returns the type of certificate + */ +public int +getCertType() { + return certType; +} + +/** + * Returns the ID of the associated KEYRecord, if present + */ +public int +getKeyTag() { + return keyTag; +} + +/** + * Returns the algorithm of the associated KEYRecord, if present + */ +public int +getAlgorithm() { + return alg; +} + +/** + * Returns the binary representation of the certificate + */ +public byte [] +getCert() { + return cert; +} + +void +rrToWire(DNSOutput out, Compression c, boolean canonical) { + out.writeU16(certType); + out.writeU16(keyTag); + out.writeU8(alg); + out.writeByteArray(cert); +} + +} |