You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dr...@apache.org on 2015/01/10 14:31:03 UTC
[19/42] directory-kerberos git commit: Initially import Haox codebase
(https://github.com/drankye/haox)
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/BERTaggedObjectParser.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/BERTaggedObjectParser.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/BERTaggedObjectParser.java
new file mode 100644
index 0000000..0f45cdb
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/BERTaggedObjectParser.java
@@ -0,0 +1,118 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class BERTaggedObjectParser
+ implements ASN1TaggedObjectParser {
+ private int _baseTag;
+ private int _tagNumber;
+ private InputStream _contentStream;
+
+ private boolean _indefiniteLength;
+
+ protected BERTaggedObjectParser(
+ int baseTag,
+ int tagNumber,
+ InputStream contentStream) {
+ _baseTag = baseTag;
+ _tagNumber = tagNumber;
+ _contentStream = contentStream;
+ _indefiniteLength = contentStream instanceof IndefiniteLengthInputStream;
+ }
+
+ public boolean isConstructed() {
+ return (_baseTag & DERTags.CONSTRUCTED) != 0;
+ }
+
+ public int getTagNo() {
+ return _tagNumber;
+ }
+
+ public DEREncodable getObjectParser(
+ int tag,
+ boolean isExplicit)
+ throws IOException {
+ if (isExplicit) {
+ return new ASN1StreamParser(_contentStream).readObject();
+ } else {
+ switch (tag) {
+ case DERTags.SET:
+ if (_indefiniteLength) {
+ return new BERSetParser(new ASN1ObjectParser(_baseTag, _tagNumber, _contentStream));
+ } else {
+ return new DERSet(loadVector(_contentStream)).parser();
+ }
+ case DERTags.SEQUENCE:
+ if (_indefiniteLength) {
+ return new BERSequenceParser(new ASN1ObjectParser(_baseTag, _tagNumber, _contentStream));
+ } else {
+ return new DERSequence(loadVector(_contentStream)).parser();
+ }
+ case DERTags.OCTET_STRING:
+ if (_indefiniteLength || this.isConstructed()) {
+ return new BEROctetStringParser(new ASN1ObjectParser(_baseTag, _tagNumber, _contentStream));
+ } else {
+ return new DEROctetString(((DefiniteLengthInputStream) _contentStream).toByteArray()).parser();
+ }
+ }
+ }
+
+ throw new RuntimeException("implicit tagging not implemented");
+ }
+
+ private ASN1EncodableVector loadVector(InputStream in)
+ throws IOException {
+ ASN1StreamParser aIn = new ASN1StreamParser(in);
+ ASN1EncodableVector v = new ASN1EncodableVector();
+ DEREncodable obj = aIn.readObject();
+
+ while (obj != null) {
+ v.add(obj.getDERObject());
+ obj = aIn.readObject();
+ }
+
+ return v;
+ }
+
+ private ASN1EncodableVector rLoadVector(InputStream in) {
+ try {
+ return loadVector(in);
+ }
+ catch (IOException e) {
+ throw new IllegalStateException(e.getMessage());
+ }
+ }
+
+ public DERObject getDERObject() {
+ if (_indefiniteLength) {
+ ASN1EncodableVector v = rLoadVector(_contentStream);
+
+ if (v.size() > 1) {
+ return new BERTaggedObject(false, _tagNumber, new BERSequence(v));
+ } else if (v.size() == 1) {
+ return new BERTaggedObject(true, _tagNumber, v.get(0));
+ } else {
+ return new BERTaggedObject(false, _tagNumber, new BERSequence());
+ }
+ } else {
+ if (this.isConstructed()) {
+ ASN1EncodableVector v = rLoadVector(_contentStream);
+
+ if (v.size() == 1) {
+ return new DERTaggedObject(true, _tagNumber, v.get(0));
+ }
+
+ return new DERTaggedObject(false, _tagNumber, new DERSequence(v));
+ }
+
+ try {
+ return new DERTaggedObject(false, _tagNumber, new DEROctetString(((DefiniteLengthInputStream) _contentStream).toByteArray()));
+ }
+ catch (IOException e) {
+ throw new IllegalStateException(e.getMessage());
+ }
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/ConstructedOctetStream.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/ConstructedOctetStream.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/ConstructedOctetStream.java
new file mode 100644
index 0000000..18565bb
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/ConstructedOctetStream.java
@@ -0,0 +1,92 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+class ConstructedOctetStream
+ extends InputStream {
+ private final ASN1ObjectParser _parser;
+
+ private boolean _first = true;
+ private InputStream _currentStream;
+
+ ConstructedOctetStream(
+ ASN1ObjectParser parser) {
+ _parser = parser;
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (_currentStream == null) {
+ if (!_first) {
+ return -1;
+ }
+
+ ASN1OctetStringParser s = (ASN1OctetStringParser) _parser.readObject();
+
+ if (s == null) {
+ return -1;
+ }
+
+ _first = false;
+ _currentStream = s.getOctetStream();
+ }
+
+ int totalRead = 0;
+
+ for (; ;) {
+ int numRead = _currentStream.read(b, off + totalRead, len - totalRead);
+
+ if (numRead >= 0) {
+ totalRead += numRead;
+
+ if (totalRead == len) {
+ return totalRead;
+ }
+ } else {
+ ASN1OctetStringParser aos = (ASN1OctetStringParser) _parser.readObject();
+
+ if (aos == null) {
+ _currentStream = null;
+ return totalRead < 1 ? -1 : totalRead;
+ }
+
+ _currentStream = aos.getOctetStream();
+ }
+ }
+ }
+
+ public int read()
+ throws IOException {
+ if (_currentStream == null) {
+ if (!_first) {
+ return -1;
+ }
+
+ ASN1OctetStringParser s = (ASN1OctetStringParser) _parser.readObject();
+
+ if (s == null) {
+ return -1;
+ }
+
+ _first = false;
+ _currentStream = s.getOctetStream();
+ }
+
+ for (; ;) {
+ int b = _currentStream.read();
+
+ if (b >= 0) {
+ return b;
+ }
+
+ ASN1OctetStringParser s = (ASN1OctetStringParser) _parser.readObject();
+
+ if (s == null) {
+ _currentStream = null;
+ return -1;
+ }
+
+ _currentStream = s.getOctetStream();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERApplicationSpecific.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERApplicationSpecific.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERApplicationSpecific.java
new file mode 100644
index 0000000..1396f91
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERApplicationSpecific.java
@@ -0,0 +1,143 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/** Base class for an application specific object */
+public class DERApplicationSpecific
+ extends ASN1Object {
+ private int tag;
+ private byte[] octets;
+
+ public DERApplicationSpecific(
+ int tag,
+ byte[] octets) {
+ this.tag = tag;
+ this.octets = octets;
+ }
+
+ public DERApplicationSpecific(
+ int tag,
+ DEREncodable object)
+ throws IOException {
+ this(true, tag, object);
+ }
+
+ public DERApplicationSpecific(
+ boolean explicit,
+ int tag,
+ DEREncodable object)
+ throws IOException {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ DEROutputStream dos = new DEROutputStream(bOut);
+
+ dos.writeObject(object);
+
+ byte[] data = bOut.toByteArray();
+
+ if (tag >= 0x1f) {
+ throw new IOException("unsupported tag number");
+ }
+
+ if (explicit) {
+ this.tag = tag | DERTags.CONSTRUCTED;
+ this.octets = data;
+ } else {
+ this.tag = tag;
+ int lenBytes = getLengthOfLength(data);
+ byte[] tmp = new byte[data.length - lenBytes];
+ System.arraycopy(data, lenBytes, tmp, 0, tmp.length);
+ this.octets = tmp;
+ }
+ }
+
+ private int getLengthOfLength(byte[] data) {
+ int count = 2; // TODO: assumes only a 1 byte tag number
+
+ while ((data[count - 1] & 0x80) != 0) {
+ count++;
+ }
+
+ return count;
+ }
+
+ public boolean isConstructed() {
+ return (tag & DERTags.CONSTRUCTED) != 0;
+ }
+
+ public byte[] getContents() {
+ return octets;
+ }
+
+ public int getApplicationTag() {
+ return tag;
+ }
+
+ public DERObject getObject()
+ throws IOException {
+ return new ASN1InputStream(getContents()).readObject();
+ }
+
+ /**
+ * Return the enclosed object assuming implicit tagging.
+ *
+ * @param derTagNo the type tag that should be applied to the object's contents.
+ * @return the resulting object
+ * @throws java.io.IOException if reconstruction fails.
+ */
+ public DERObject getObject(int derTagNo)
+ throws IOException {
+ if (tag >= 0x1f) {
+ throw new IOException("unsupported tag number");
+ }
+
+ byte[] tmp = this.getEncoded();
+
+ tmp[0] = (byte) derTagNo;
+
+ return new ASN1InputStream(tmp).readObject();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.ssl.asn1.DERObject#encode(org.apache.commons.ssl.asn1.DEROutputStream)
+ */
+ void encode(DEROutputStream out) throws IOException {
+ out.writeEncoded(DERTags.APPLICATION | tag, octets);
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERApplicationSpecific)) {
+ return false;
+ }
+
+ DERApplicationSpecific other = (DERApplicationSpecific) o;
+
+ if (tag != other.tag) {
+ return false;
+ }
+
+ if (octets.length != other.octets.length) {
+ return false;
+ }
+
+ for (int i = 0; i < octets.length; i++) {
+ if (octets[i] != other.octets[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ byte[] b = this.getContents();
+ int value = 0;
+
+ for (int i = 0; i != b.length; i++) {
+ value ^= (b[i] & 0xff) << (i % 4);
+ }
+
+ return value ^ this.getApplicationTag();
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBMPString.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBMPString.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBMPString.java
new file mode 100644
index 0000000..e093582
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBMPString.java
@@ -0,0 +1,104 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+/** DER BMPString object. */
+public class DERBMPString
+ extends ASN1Object
+ implements DERString {
+ String string;
+
+ /**
+ * return a BMP String from the given object.
+ *
+ * @param obj the object we want converted.
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERBMPString getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERBMPString) {
+ return (DERBMPString) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERBMPString(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return a BMP String from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERBMPString getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+
+ /** basic constructor - byte encoded string. */
+ public DERBMPString(
+ byte[] string) {
+ char[] cs = new char[string.length / 2];
+
+ for (int i = 0; i != cs.length; i++) {
+ cs[i] = (char) ((string[2 * i] << 8) | (string[2 * i + 1] & 0xff));
+ }
+
+ this.string = new String(cs);
+ }
+
+ /** basic constructor */
+ public DERBMPString(
+ String string) {
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public String toString() {
+ return string;
+ }
+
+ public int hashCode() {
+ return this.getString().hashCode();
+ }
+
+ protected boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERBMPString)) {
+ return false;
+ }
+
+ DERBMPString s = (DERBMPString) o;
+
+ return this.getString().equals(s.getString());
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ char[] c = string.toCharArray();
+ byte[] b = new byte[c.length * 2];
+
+ for (int i = 0; i != c.length; i++) {
+ b[2 * i] = (byte) (c[i] >> 8);
+ b[2 * i + 1] = (byte) c[i];
+ }
+
+ out.writeEncoded(BMP_STRING, b);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBitString.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBitString.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBitString.java
new file mode 100644
index 0000000..2cb649c
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBitString.java
@@ -0,0 +1,245 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class DERBitString
+ extends ASN1Object
+ implements DERString {
+ private static final char[] table = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+
+ protected byte[] data;
+ protected int padBits;
+
+ /**
+ * return the correct number of pad bits for a bit string defined in
+ * a 32 bit constant
+ */
+ static protected int getPadBits(
+ int bitString) {
+ int val = 0;
+ for (int i = 3; i >= 0; i--) {
+ //
+ // this may look a little odd, but if it isn't done like this pre jdk1.2
+ // JVM's break!
+ //
+ if (i != 0) {
+ if ((bitString >> (i * 8)) != 0) {
+ val = (bitString >> (i * 8)) & 0xFF;
+ break;
+ }
+ } else {
+ if (bitString != 0) {
+ val = bitString & 0xFF;
+ break;
+ }
+ }
+ }
+
+ if (val == 0) {
+ return 7;
+ }
+
+
+ int bits = 1;
+
+ while (((val <<= 1) & 0xFF) != 0) {
+ bits++;
+ }
+
+ return 8 - bits;
+ }
+
+ /**
+ * return the correct number of bytes for a bit string defined in
+ * a 32 bit constant
+ */
+ static protected byte[] getBytes(int bitString) {
+ int bytes = 4;
+ for (int i = 3; i >= 1; i--) {
+ if ((bitString & (0xFF << (i * 8))) != 0) {
+ break;
+ }
+ bytes--;
+ }
+
+ byte[] result = new byte[bytes];
+ for (int i = 0; i < bytes; i++) {
+ result[i] = (byte) ((bitString >> (i * 8)) & 0xFF);
+ }
+
+ return result;
+ }
+
+ /**
+ * return a Bit String from the passed in object
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERBitString getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERBitString) {
+ return (DERBitString) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ byte[] bytes = ((ASN1OctetString) obj).getOctets();
+ int padBits = bytes[0];
+ byte[] data = new byte[bytes.length - 1];
+
+ System.arraycopy(bytes, 1, data, 0, bytes.length - 1);
+
+ return new DERBitString(data, padBits);
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return a Bit String from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERBitString getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ protected DERBitString(
+ byte data,
+ int padBits) {
+ this.data = new byte[1];
+ this.data[0] = data;
+ this.padBits = padBits;
+ }
+
+ /**
+ * @param data the octets making up the bit string.
+ * @param padBits the number of extra bits at the end of the string.
+ */
+ public DERBitString(
+ byte[] data,
+ int padBits) {
+ this.data = data;
+ this.padBits = padBits;
+ }
+
+ public DERBitString(
+ byte[] data) {
+ this(data, 0);
+ }
+
+ public DERBitString(
+ DEREncodable obj) {
+ try {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ DEROutputStream dOut = new DEROutputStream(bOut);
+
+ dOut.writeObject(obj);
+ dOut.close();
+
+ this.data = bOut.toByteArray();
+ this.padBits = 0;
+ }
+ catch (IOException e) {
+ throw new IllegalArgumentException("Error processing object : " + e.toString());
+ }
+ }
+
+ public byte[] getBytes() {
+ return data;
+ }
+
+ public int getPadBits() {
+ return padBits;
+ }
+
+
+ /** @return the value of the bit string as an int (truncating if necessary) */
+ public int intValue() {
+ int value = 0;
+
+ for (int i = 0; i != data.length && i != 4; i++) {
+ value |= (data[i] & 0xff) << (8 * i);
+ }
+
+ return value;
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ byte[] bytes = new byte[getBytes().length + 1];
+
+ bytes[0] = (byte) getPadBits();
+ System.arraycopy(getBytes(), 0, bytes, 1, bytes.length - 1);
+
+ out.writeEncoded(BIT_STRING, bytes);
+ }
+
+ public int hashCode() {
+ int value = 0;
+
+ for (int i = 0; i != data.length; i++) {
+ value ^= (data[i] & 0xff) << (i % 4);
+ }
+
+ return value;
+ }
+
+ protected boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERBitString)) {
+ return false;
+ }
+
+ DERBitString other = (DERBitString) o;
+
+ if (data.length != other.data.length) {
+ return false;
+ }
+
+ for (int i = 0; i != data.length; i++) {
+ if (data[i] != other.data[i]) {
+ return false;
+ }
+ }
+
+ return (padBits == other.padBits);
+ }
+
+ public String getString() {
+ StringBuffer buf = new StringBuffer("#");
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ ASN1OutputStream aOut = new ASN1OutputStream(bOut);
+
+ try {
+ aOut.writeObject(this);
+ }
+ catch (IOException e) {
+ throw new RuntimeException("internal error encoding BitString");
+ }
+
+ byte[] string = bOut.toByteArray();
+
+ for (int i = 0; i != string.length; i++) {
+ buf.append(table[(string[i] >>> 4) & 0xf]);
+ buf.append(table[string[i] & 0xf]);
+ }
+
+ return buf.toString();
+ }
+
+ public String toString() {
+ return getString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBoolean.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBoolean.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBoolean.java
new file mode 100644
index 0000000..e49ec6c
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERBoolean.java
@@ -0,0 +1,96 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+public class DERBoolean
+ extends ASN1Object {
+ byte value;
+
+ public static final DERBoolean FALSE = new DERBoolean(false);
+ public static final DERBoolean TRUE = new DERBoolean(true);
+
+ /**
+ * return a boolean from the passed in object.
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERBoolean getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERBoolean) {
+ return (DERBoolean) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERBoolean(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /** return a DERBoolean from the passed in boolean. */
+ public static DERBoolean getInstance(
+ boolean value) {
+ return (value ? TRUE : FALSE);
+ }
+
+ /**
+ * return a Boolean from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERBoolean getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ public DERBoolean(
+ byte[] value) {
+ this.value = value[0];
+ }
+
+ public DERBoolean(
+ boolean value) {
+ this.value = (value) ? (byte) 0xff : (byte) 0;
+ }
+
+ public boolean isTrue() {
+ return (value != 0);
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ byte[] bytes = new byte[1];
+
+ bytes[0] = value;
+
+ out.writeEncoded(BOOLEAN, bytes);
+ }
+
+ protected boolean asn1Equals(
+ DERObject o) {
+ if ((o == null) || !(o instanceof DERBoolean)) {
+ return false;
+ }
+
+ return (value == ((DERBoolean) o).value);
+ }
+
+ public int hashCode() {
+ return value;
+ }
+
+
+ public String toString() {
+ return (value != 0) ? "TRUE" : "FALSE";
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSequence.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSequence.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSequence.java
new file mode 100644
index 0000000..f7cad53
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSequence.java
@@ -0,0 +1,46 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/** @deprecated use DERSequence. */
+public class DERConstructedSequence
+ extends ASN1Sequence {
+ public void addObject(
+ DEREncodable obj) {
+ super.addObject(obj);
+ }
+
+ public int getSize() {
+ return size();
+ }
+
+ /*
+ * A note on the implementation:
+ * <p>
+ * As DER requires the constructed, definite-length model to
+ * be used for structured types, this varies slightly from the
+ * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
+ * we also have to specify CONSTRUCTED, and the objects length.
+ */
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ DEROutputStream dOut = new DEROutputStream(bOut);
+ Enumeration e = this.getObjects();
+
+ while (e.hasMoreElements()) {
+ Object obj = e.nextElement();
+
+ dOut.writeObject(obj);
+ }
+
+ dOut.close();
+
+ byte[] bytes = bOut.toByteArray();
+
+ out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSet.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSet.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSet.java
new file mode 100644
index 0000000..50adf8e
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERConstructedSet.java
@@ -0,0 +1,63 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/** @deprecated use DERSet */
+public class DERConstructedSet
+ extends ASN1Set {
+ public DERConstructedSet() {
+ }
+
+ /** @param obj - a single object that makes up the set. */
+ public DERConstructedSet(
+ DEREncodable obj) {
+ this.addObject(obj);
+ }
+
+ /** @param v - a vector of objects making up the set. */
+ public DERConstructedSet(
+ DEREncodableVector v) {
+ for (int i = 0; i != v.size(); i++) {
+ this.addObject(v.get(i));
+ }
+ }
+
+ public void addObject(
+ DEREncodable obj) {
+ super.addObject(obj);
+ }
+
+ public int getSize() {
+ return size();
+ }
+
+ /*
+ * A note on the implementation:
+ * <p>
+ * As DER requires the constructed, definite-length model to
+ * be used for structured types, this varies slightly from the
+ * ASN.1 descriptions given. Rather than just outputing SET,
+ * we also have to specify CONSTRUCTED, and the objects length.
+ */
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ DEROutputStream dOut = new DEROutputStream(bOut);
+ Enumeration e = this.getObjects();
+
+ while (e.hasMoreElements()) {
+ Object obj = e.nextElement();
+
+ dOut.writeObject(obj);
+ }
+
+ dOut.close();
+
+ byte[] bytes = bOut.toByteArray();
+
+ out.writeEncoded(SET | CONSTRUCTED, bytes);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodable.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodable.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodable.java
new file mode 100644
index 0000000..cbaebf9
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodable.java
@@ -0,0 +1,5 @@
+package org.apache.commons.ssl.asn1;
+
+public interface DEREncodable {
+ public DERObject getDERObject();
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodableVector.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodableVector.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodableVector.java
new file mode 100644
index 0000000..d441a44
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREncodableVector.java
@@ -0,0 +1,31 @@
+package org.apache.commons.ssl.asn1;
+
+import java.util.Vector;
+
+/**
+ * a general class for building up a vector of DER encodable objects -
+ * this will eventually be superceded by ASN1EncodableVector so you should
+ * use that class in preference.
+ */
+public class DEREncodableVector {
+ private Vector v = new Vector();
+
+ /** @deprecated use ASN1EncodableVector instead. */
+ public DEREncodableVector() {
+
+ }
+
+ public void add(
+ DEREncodable obj) {
+ v.addElement(obj);
+ }
+
+ public DEREncodable get(
+ int i) {
+ return (DEREncodable) v.elementAt(i);
+ }
+
+ public int size() {
+ return v.size();
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREnumerated.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREnumerated.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREnumerated.java
new file mode 100644
index 0000000..faacf13
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEREnumerated.java
@@ -0,0 +1,96 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+import java.math.BigInteger;
+
+public class DEREnumerated
+ extends ASN1Object {
+ byte[] bytes;
+
+ /**
+ * return an integer from the passed in object
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DEREnumerated getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DEREnumerated) {
+ return (DEREnumerated) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DEREnumerated(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return an Enumerated from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DEREnumerated getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ public DEREnumerated(
+ int value) {
+ bytes = BigInteger.valueOf(value).toByteArray();
+ }
+
+ public DEREnumerated(
+ BigInteger value) {
+ bytes = value.toByteArray();
+ }
+
+ public DEREnumerated(
+ byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ public BigInteger getValue() {
+ return new BigInteger(bytes);
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(ENUMERATED, bytes);
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DEREnumerated)) {
+ return false;
+ }
+
+ DEREnumerated other = (DEREnumerated) o;
+
+ if (bytes.length != other.bytes.length) {
+ return false;
+ }
+
+ for (int i = 0; i != bytes.length; i++) {
+ if (bytes[i] != other.bytes[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ return this.getValue().hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralString.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralString.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralString.java
new file mode 100644
index 0000000..d571a1d
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralString.java
@@ -0,0 +1,75 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+public class DERGeneralString
+ extends ASN1Object implements DERString {
+ private String string;
+
+ public static DERGeneralString getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERGeneralString) {
+ return (DERGeneralString) obj;
+ }
+ if (obj instanceof ASN1OctetString) {
+ return new DERGeneralString(((ASN1OctetString) obj).getOctets());
+ }
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+ throw new IllegalArgumentException("illegal object in getInstance: "
+ + obj.getClass().getName());
+ }
+
+ public static DERGeneralString getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ public DERGeneralString(byte[] string) {
+ char[] cs = new char[string.length];
+ for (int i = 0; i != cs.length; i++) {
+ cs[i] = (char) (string[i] & 0xff);
+ }
+ this.string = new String(cs);
+ }
+
+ public DERGeneralString(String string) {
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public String toString() {
+ return string;
+ }
+
+ public byte[] getOctets() {
+ char[] cs = string.toCharArray();
+ byte[] bs = new byte[cs.length];
+ for (int i = 0; i != cs.length; i++) {
+ bs[i] = (byte) cs[i];
+ }
+ return bs;
+ }
+
+ void encode(DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(GENERAL_STRING, this.getOctets());
+ }
+
+ public int hashCode() {
+ return this.getString().hashCode();
+ }
+
+ boolean asn1Equals(DERObject o) {
+ if (!(o instanceof DERGeneralString)) {
+ return false;
+ }
+ DERGeneralString s = (DERGeneralString) o;
+ return this.getString().equals(s.getString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralizedTime.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralizedTime.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralizedTime.java
new file mode 100644
index 0000000..0e2de28
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGeneralizedTime.java
@@ -0,0 +1,242 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+/** Generalized time object. */
+public class DERGeneralizedTime
+ extends ASN1Object {
+ String time;
+
+ /**
+ * return a generalized time from the passed in object
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERGeneralizedTime getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERGeneralizedTime) {
+ return (DERGeneralizedTime) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERGeneralizedTime(((ASN1OctetString) obj).getOctets());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return a Generalized Time object from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERGeneralizedTime getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ /**
+ * The correct format for this is YYYYMMDDHHMMSS[.f]Z, or without the Z
+ * for local time, or Z+-HHMM on the end, for difference between local
+ * time and UTC time. The fractional second amount f must consist of at
+ * least one number with trailing zeroes removed.
+ *
+ * @param time the time string.
+ * @throws IllegalArgumentException if String is an illegal format.
+ */
+ public DERGeneralizedTime(
+ String time) {
+ this.time = time;
+ try {
+ this.getDate();
+ }
+ catch (ParseException e) {
+ throw new IllegalArgumentException("invalid date string: " + e.getMessage());
+ }
+ }
+
+ /** base constructer from a java.util.date object */
+ public DERGeneralizedTime(
+ Date time) {
+ SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
+
+ dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
+
+ this.time = dateF.format(time);
+ }
+
+ DERGeneralizedTime(
+ byte[] bytes) {
+ //
+ // explicitly convert to characters
+ //
+ char[] dateC = new char[bytes.length];
+
+ for (int i = 0; i != dateC.length; i++) {
+ dateC[i] = (char) (bytes[i] & 0xff);
+ }
+
+ this.time = new String(dateC);
+ }
+
+ /**
+ * Return the time.
+ *
+ * @return The time string as it appeared in the encoded object.
+ */
+ public String getTimeString() {
+ return time;
+ }
+
+ /**
+ * return the time - always in the form of
+ * YYYYMMDDhhmmssGMT(+hh:mm|-hh:mm).
+ * <p/>
+ * Normally in a certificate we would expect "Z" rather than "GMT",
+ * however adding the "GMT" means we can just use:
+ * <pre>
+ * dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
+ * </pre>
+ * To read in the time and get a date which is compatible with our local
+ * time zone.
+ */
+ public String getTime() {
+ //
+ // standardise the format.
+ //
+ if (time.charAt(time.length() - 1) == 'Z') {
+ return time.substring(0, time.length() - 1) + "GMT+00:00";
+ } else {
+ int signPos = time.length() - 5;
+ char sign = time.charAt(signPos);
+ if (sign == '-' || sign == '+') {
+ return time.substring(0, signPos)
+ + "GMT"
+ + time.substring(signPos, signPos + 3)
+ + ":"
+ + time.substring(signPos + 3);
+ } else {
+ signPos = time.length() - 3;
+ sign = time.charAt(signPos);
+ if (sign == '-' || sign == '+') {
+ return time.substring(0, signPos)
+ + "GMT"
+ + time.substring(signPos)
+ + ":00";
+ }
+ }
+ }
+ return time + calculateGMTOffset();
+ }
+
+ private String calculateGMTOffset() {
+ String sign = "+";
+ TimeZone timeZone = TimeZone.getDefault();
+ int offset = timeZone.getRawOffset();
+ if (offset < 0) {
+ sign = "-";
+ offset = -offset;
+ }
+ int hours = offset / (60 * 60 * 1000);
+ int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000);
+
+ try {
+ if (timeZone.useDaylightTime() && timeZone.inDaylightTime(this.getDate())) {
+ hours += sign.equals("+") ? 1 : -1;
+ }
+ }
+ catch (ParseException e) {
+ // we'll do our best and ignore daylight savings
+ }
+
+ return "GMT" + sign + convert(hours) + ":" + convert(minutes);
+ }
+
+ private String convert(int time) {
+ if (time < 10) {
+ return "0" + time;
+ }
+
+ return Integer.toString(time);
+ }
+
+ public Date getDate()
+ throws ParseException {
+ SimpleDateFormat dateF;
+ String d = time;
+
+ if (time.endsWith("Z")) {
+ if (hasFractionalSeconds()) {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSS'Z'");
+ } else {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
+ }
+
+ dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
+ } else if (time.indexOf('-') > 0 || time.indexOf('+') > 0) {
+ d = this.getTime();
+ if (hasFractionalSeconds()) {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSSz");
+ } else {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
+ }
+
+ dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
+ } else {
+ if (hasFractionalSeconds()) {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSS");
+ } else {
+ dateF = new SimpleDateFormat("yyyyMMddHHmmss");
+ }
+
+ dateF.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID()));
+ }
+
+ return dateF.parse(d);
+ }
+
+ private boolean hasFractionalSeconds() {
+ return time.indexOf('.') == 14;
+ }
+
+ private byte[] getOctets() {
+ char[] cs = time.toCharArray();
+ byte[] bs = new byte[cs.length];
+
+ for (int i = 0; i != cs.length; i++) {
+ bs[i] = (byte) cs[i];
+ }
+
+ return bs;
+ }
+
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(GENERALIZED_TIME, this.getOctets());
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERGeneralizedTime)) {
+ return false;
+ }
+
+ return time.equals(((DERGeneralizedTime) o).time);
+ }
+
+ public int hashCode() {
+ return time.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGenerator.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGenerator.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGenerator.java
new file mode 100644
index 0000000..359d931
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERGenerator.java
@@ -0,0 +1,108 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public abstract class DERGenerator
+ extends ASN1Generator {
+ private boolean _tagged = false;
+ private boolean _isExplicit;
+ private int _tagNo;
+
+ protected DERGenerator(
+ OutputStream out) {
+ super(out);
+ }
+
+ public DERGenerator(
+ OutputStream out,
+ int tagNo,
+ boolean isExplicit) {
+ super(out);
+
+ _tagged = true;
+ _isExplicit = isExplicit;
+ _tagNo = tagNo;
+ }
+
+ private void writeLength(
+ OutputStream out,
+ int length)
+ throws IOException {
+ if (length > 127) {
+ int size = 1;
+ int val = length;
+
+ while ((val >>>= 8) != 0) {
+ size++;
+ }
+
+ out.write((byte) (size | 0x80));
+
+ for (int i = (size - 1) * 8; i >= 0; i -= 8) {
+ out.write((byte) (length >> i));
+ }
+ } else {
+ out.write((byte) length);
+ }
+ }
+
+ void writeDEREncoded(
+ OutputStream out,
+ int tag,
+ byte[] bytes)
+ throws IOException {
+ out.write(tag);
+ writeLength(out, bytes.length);
+ out.write(bytes);
+ }
+
+ void writeDEREncoded(
+ int tag,
+ byte[] bytes)
+ throws IOException {
+ if (_tagged) {
+ int tagNum = _tagNo | DERTags.TAGGED;
+
+ if (_isExplicit) {
+ int newTag = _tagNo | DERTags.CONSTRUCTED | DERTags.TAGGED;
+
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ writeDEREncoded(bOut, tag, bytes);
+
+ writeDEREncoded(_out, newTag, bOut.toByteArray());
+ } else {
+ if ((tag & DERTags.CONSTRUCTED) != 0) {
+ writeDEREncoded(_out, tagNum | DERTags.CONSTRUCTED, bytes);
+ } else {
+ writeDEREncoded(_out, tagNum, bytes);
+ }
+ }
+ } else {
+ writeDEREncoded(_out, tag, bytes);
+ }
+ }
+
+ void writeDEREncoded(
+ OutputStream out,
+ int tag,
+ InputStream in)
+ throws IOException {
+ out.write(tag);
+
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ int b = 0;
+ while ((b = in.read()) >= 0) {
+ bOut.write(b);
+ }
+
+ byte[] bytes = bOut.toByteArray();
+
+ writeLength(out, bytes.length);
+ out.write(bytes);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERIA5String.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERIA5String.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERIA5String.java
new file mode 100644
index 0000000..53d1abf
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERIA5String.java
@@ -0,0 +1,142 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+/** DER IA5String object - this is an ascii string. */
+public class DERIA5String
+ extends ASN1Object
+ implements DERString {
+ String string;
+
+ /**
+ * return a IA5 string from the passed in object
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERIA5String getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERIA5String) {
+ return (DERIA5String) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERIA5String(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return an IA5 String from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERIA5String getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ /** basic constructor - with bytes. */
+ public DERIA5String(
+ byte[] string) {
+ char[] cs = new char[string.length];
+
+ for (int i = 0; i != cs.length; i++) {
+ cs[i] = (char) (string[i] & 0xff);
+ }
+
+ this.string = new String(cs);
+ }
+
+ /** basic constructor - without validation. */
+ public DERIA5String(
+ String string) {
+ this(string, false);
+ }
+
+ /**
+ * Constructor with optional validation.
+ *
+ * @param string the base string to wrap.
+ * @param validate whether or not to check the string.
+ * @throws IllegalArgumentException if validate is true and the string
+ * contains characters that should not be in an IA5String.
+ */
+ public DERIA5String(
+ String string,
+ boolean validate) {
+ if (validate && !isIA5String(string)) {
+ throw new IllegalArgumentException("string contains illegal characters");
+ }
+
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public String toString() {
+ return string;
+ }
+
+ public byte[] getOctets() {
+ char[] cs = string.toCharArray();
+ byte[] bs = new byte[cs.length];
+
+ for (int i = 0; i != cs.length; i++) {
+ bs[i] = (byte) cs[i];
+ }
+
+ return bs;
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(IA5_STRING, this.getOctets());
+ }
+
+ public int hashCode() {
+ return this.getString().hashCode();
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERIA5String)) {
+ return false;
+ }
+
+ DERIA5String s = (DERIA5String) o;
+
+ return this.getString().equals(s.getString());
+ }
+
+ /**
+ * return true if the passed in String can be represented without
+ * loss as an IA5String, false otherwise.
+ *
+ * @return true if in printable set, false otherwise.
+ */
+ public static boolean isIA5String(
+ String str) {
+ for (int i = str.length() - 1; i >= 0; i--) {
+ char ch = str.charAt(i);
+
+ if (ch > 0x007f) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInputStream.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInputStream.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInputStream.java
new file mode 100644
index 0000000..5d35bd3
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInputStream.java
@@ -0,0 +1,237 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Don't use this class. It will eventually disappear, use ASN1InputStream.
+ * <br>
+ * This class is scheduled for removal.
+ *
+ * @deprecated use ASN1InputStream
+ */
+public class DERInputStream
+ extends FilterInputStream implements DERTags {
+ /** @deprecated use ASN1InputStream */
+ public DERInputStream(
+ InputStream is) {
+ super(is);
+ }
+
+ protected int readLength()
+ throws IOException {
+ int length = read();
+ if (length < 0) {
+ throw new IOException("EOF found when length expected");
+ }
+
+ if (length == 0x80) {
+ return -1; // indefinite-length encoding
+ }
+
+ if (length > 127) {
+ int size = length & 0x7f;
+
+ if (size > 4) {
+ throw new IOException("DER length more than 4 bytes");
+ }
+
+ length = 0;
+ for (int i = 0; i < size; i++) {
+ int next = read();
+
+ if (next < 0) {
+ throw new IOException("EOF found reading length");
+ }
+
+ length = (length << 8) + next;
+ }
+
+ if (length < 0) {
+ throw new IOException("corrupted stream - negative length found");
+ }
+ }
+
+ return length;
+ }
+
+ protected void readFully(
+ byte[] bytes)
+ throws IOException {
+ int left = bytes.length;
+
+ if (left == 0) {
+ return;
+ }
+
+ while (left > 0) {
+ int l = read(bytes, bytes.length - left, left);
+
+ if (l < 0) {
+ throw new EOFException("unexpected end of stream");
+ }
+
+ left -= l;
+ }
+ }
+
+ /**
+ * build an object given its tag and a byte stream to construct it
+ * from.
+ */
+ protected DERObject buildObject(
+ int tag,
+ byte[] bytes)
+ throws IOException {
+ switch (tag) {
+ case NULL:
+ return null;
+ case SEQUENCE | CONSTRUCTED:
+ ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
+ BERInputStream dIn = new BERInputStream(bIn);
+ DERConstructedSequence seq = new DERConstructedSequence();
+
+ try {
+ for (; ;) {
+ DERObject obj = dIn.readObject();
+
+ seq.addObject(obj);
+ }
+ }
+ catch (EOFException ex) {
+ return seq;
+ }
+ case SET | CONSTRUCTED:
+ bIn = new ByteArrayInputStream(bytes);
+ dIn = new BERInputStream(bIn);
+
+ ASN1EncodableVector v = new ASN1EncodableVector();
+
+ try {
+ for (; ;) {
+ DERObject obj = dIn.readObject();
+
+ v.add(obj);
+ }
+ }
+ catch (EOFException ex) {
+ return new DERConstructedSet(v);
+ }
+ case BOOLEAN:
+ return new DERBoolean(bytes);
+ case INTEGER:
+ return new DERInteger(bytes);
+ case ENUMERATED:
+ return new DEREnumerated(bytes);
+ case OBJECT_IDENTIFIER:
+ return new DERObjectIdentifier(bytes);
+ case BIT_STRING:
+ int padBits = bytes[0];
+ byte[] data = new byte[bytes.length - 1];
+
+ System.arraycopy(bytes, 1, data, 0, bytes.length - 1);
+
+ return new DERBitString(data, padBits);
+ case UTF8_STRING:
+ return new DERUTF8String(bytes);
+ case PRINTABLE_STRING:
+ return new DERPrintableString(bytes);
+ case IA5_STRING:
+ return new DERIA5String(bytes);
+ case T61_STRING:
+ return new DERT61String(bytes);
+ case VISIBLE_STRING:
+ return new DERVisibleString(bytes);
+ case UNIVERSAL_STRING:
+ return new DERUniversalString(bytes);
+ case GENERAL_STRING:
+ return new DERGeneralString(bytes);
+ case BMP_STRING:
+ return new DERBMPString(bytes);
+ case OCTET_STRING:
+ return new DEROctetString(bytes);
+ case UTC_TIME:
+ return new DERUTCTime(bytes);
+ case GENERALIZED_TIME:
+ return new DERGeneralizedTime(bytes);
+ default:
+ //
+ // with tagged object tag number is bottom 5 bits
+ //
+ if ((tag & TAGGED) != 0) {
+ if ((tag & 0x1f) == 0x1f) {
+ throw new IOException("unsupported high tag encountered");
+ }
+
+ if (bytes.length == 0) // empty tag!
+ {
+ if ((tag & CONSTRUCTED) == 0) {
+ return new DERTaggedObject(false, tag & 0x1f, new DERNull());
+ } else {
+ return new DERTaggedObject(false, tag & 0x1f, new DERConstructedSequence());
+ }
+ }
+
+ //
+ // simple type - implicit... return an octet string
+ //
+ if ((tag & CONSTRUCTED) == 0) {
+ return new DERTaggedObject(false, tag & 0x1f, new DEROctetString(bytes));
+ }
+
+ bIn = new ByteArrayInputStream(bytes);
+ dIn = new BERInputStream(bIn);
+
+ DEREncodable dObj = dIn.readObject();
+
+ //
+ // explicitly tagged (probably!) - if it isn't we'd have to
+ // tell from the context
+ //
+ if (dIn.available() == 0) {
+ return new DERTaggedObject(tag & 0x1f, dObj);
+ }
+
+ //
+ // another implicit object, we'll create a sequence...
+ //
+ seq = new DERConstructedSequence();
+
+ seq.addObject(dObj);
+
+ try {
+ for (; ;) {
+ dObj = dIn.readObject();
+
+ seq.addObject(dObj);
+ }
+ }
+ catch (EOFException ex) {
+ // ignore --
+ }
+
+ return new DERTaggedObject(false, tag & 0x1f, seq);
+ }
+
+ return new DERUnknownTag(tag, bytes);
+ }
+ }
+
+ public DERObject readObject()
+ throws IOException {
+ int tag = read();
+ if (tag == -1) {
+ throw new EOFException();
+ }
+
+ int length = readLength();
+ byte[] bytes = new byte[length];
+
+ readFully(bytes);
+
+ return buildObject(tag, bytes);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInteger.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInteger.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInteger.java
new file mode 100644
index 0000000..4265efe
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERInteger.java
@@ -0,0 +1,114 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+import java.math.BigInteger;
+
+public class DERInteger
+ extends ASN1Object {
+ byte[] bytes;
+
+ /**
+ * return an integer from the passed in object
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERInteger getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERInteger) {
+ return (DERInteger) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERInteger(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return an Integer from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERInteger getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ public DERInteger(
+ int value) {
+ bytes = BigInteger.valueOf(value).toByteArray();
+ }
+
+ public DERInteger(
+ BigInteger value) {
+ bytes = value.toByteArray();
+ }
+
+ public DERInteger(
+ byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ public BigInteger getValue() {
+ return new BigInteger(bytes);
+ }
+
+ /**
+ * in some cases positive values get crammed into a space,
+ * that's not quite big enough...
+ */
+ public BigInteger getPositiveValue() {
+ return new BigInteger(1, bytes);
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(INTEGER, bytes);
+ }
+
+ public int hashCode() {
+ int value = 0;
+
+ for (int i = 0; i != bytes.length; i++) {
+ value ^= (bytes[i] & 0xff) << (i % 4);
+ }
+
+ return value;
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERInteger)) {
+ return false;
+ }
+
+ DERInteger other = (DERInteger) o;
+
+ if (bytes.length != other.bytes.length) {
+ return false;
+ }
+
+ for (int i = 0; i != bytes.length; i++) {
+ if (bytes[i] != other.bytes[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public String toString() {
+ return getValue().toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNull.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNull.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNull.java
new file mode 100644
index 0000000..774cb6e
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNull.java
@@ -0,0 +1,20 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+/** A NULL object. */
+public class DERNull
+ extends ASN1Null {
+ public static final DERNull INSTANCE = new DERNull();
+
+ byte[] zeroBytes = new byte[0];
+
+ public DERNull() {
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(NULL, zeroBytes);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNumericString.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNumericString.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNumericString.java
new file mode 100644
index 0000000..9b72196
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERNumericString.java
@@ -0,0 +1,148 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+/** DER NumericString object - this is an ascii string of characters {0,1,2,3,4,5,6,7,8,9, }. */
+public class DERNumericString
+ extends ASN1Object
+ implements DERString {
+ String string;
+
+ /**
+ * return a Numeric string from the passed in object
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERNumericString getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERNumericString) {
+ return (DERNumericString) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERNumericString(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return an Numeric String from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERNumericString getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ /** basic constructor - with bytes. */
+ public DERNumericString(
+ byte[] string) {
+ char[] cs = new char[string.length];
+
+ for (int i = 0; i != cs.length; i++) {
+ cs[i] = (char) (string[i] & 0xff);
+ }
+
+ this.string = new String(cs);
+ }
+
+ /** basic constructor - without validation.. */
+ public DERNumericString(
+ String string) {
+ this(string, false);
+ }
+
+ /**
+ * Constructor with optional validation.
+ *
+ * @param string the base string to wrap.
+ * @param validate whether or not to check the string.
+ * @throws IllegalArgumentException if validate is true and the string
+ * contains characters that should not be in a NumericString.
+ */
+ public DERNumericString(
+ String string,
+ boolean validate) {
+ if (validate && !isNumericString(string)) {
+ throw new IllegalArgumentException("string contains illegal characters");
+ }
+
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public String toString() {
+ return string;
+ }
+
+ public byte[] getOctets() {
+ char[] cs = string.toCharArray();
+ byte[] bs = new byte[cs.length];
+
+ for (int i = 0; i != cs.length; i++) {
+ bs[i] = (byte) cs[i];
+ }
+
+ return bs;
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(NUMERIC_STRING, this.getOctets());
+ }
+
+ public int hashCode() {
+ return this.getString().hashCode();
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERNumericString)) {
+ return false;
+ }
+
+ DERNumericString s = (DERNumericString) o;
+
+ return this.getString().equals(s.getString());
+ }
+
+ /**
+ * Return true if the string can be represented as a NumericString ('0'..'9', ' ')
+ *
+ * @param str string to validate.
+ * @return true if numeric, fale otherwise.
+ */
+ public static boolean isNumericString(
+ String str) {
+ for (int i = str.length() - 1; i >= 0; i--) {
+ char ch = str.charAt(i);
+
+ if (ch > 0x007f) {
+ return false;
+ }
+
+ if (('0' <= ch && ch <= '9') || ch == ' ') {
+ continue;
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObject.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObject.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObject.java
new file mode 100644
index 0000000..df6dd86
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObject.java
@@ -0,0 +1,18 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+public abstract class DERObject
+ extends ASN1Encodable
+ implements DERTags {
+ public DERObject toASN1Object() {
+ return this;
+ }
+
+ public abstract int hashCode();
+
+ public abstract boolean equals(Object o);
+
+ abstract void encode(DEROutputStream out)
+ throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObjectIdentifier.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObjectIdentifier.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObjectIdentifier.java
new file mode 100644
index 0000000..f53153f
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERObjectIdentifier.java
@@ -0,0 +1,245 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.math.BigInteger;
+
+public class DERObjectIdentifier
+ extends ASN1Object {
+ String identifier;
+
+ /**
+ * return an OID from the passed in object
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERObjectIdentifier getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERObjectIdentifier) {
+ return (DERObjectIdentifier) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERObjectIdentifier(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return an Object Identifier from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERObjectIdentifier getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+
+ DERObjectIdentifier(
+ byte[] bytes) {
+ StringBuffer objId = new StringBuffer();
+ long value = 0;
+ BigInteger bigValue = null;
+ boolean first = true;
+
+ for (int i = 0; i != bytes.length; i++) {
+ int b = bytes[i] & 0xff;
+
+ if (value < 0x80000000000000L) {
+ value = value * 128 + (b & 0x7f);
+ if ((b & 0x80) == 0) // end of number reached
+ {
+ if (first) {
+ switch ((int) value / 40) {
+ case 0:
+ objId.append('0');
+ break;
+ case 1:
+ objId.append('1');
+ value -= 40;
+ break;
+ default:
+ objId.append('2');
+ value -= 80;
+ }
+ first = false;
+ }
+
+ objId.append('.');
+ objId.append(value);
+ value = 0;
+ }
+ } else {
+ if (bigValue == null) {
+ bigValue = BigInteger.valueOf(value);
+ }
+ bigValue = bigValue.shiftLeft(7);
+ bigValue = bigValue.or(BigInteger.valueOf(b & 0x7f));
+ if ((b & 0x80) == 0) {
+ objId.append('.');
+ objId.append(bigValue);
+ bigValue = null;
+ value = 0;
+ }
+ }
+ }
+
+ this.identifier = objId.toString();
+ }
+
+ public DERObjectIdentifier(
+ String identifier) {
+ if (!isValidIdentifier(identifier)) {
+ throw new IllegalArgumentException("string " + identifier + " not an OID");
+ }
+
+ this.identifier = identifier;
+ }
+
+ public String getId() {
+ return identifier;
+ }
+
+ private void writeField(
+ OutputStream out,
+ long fieldValue)
+ throws IOException {
+ if (fieldValue >= (1L << 7)) {
+ if (fieldValue >= (1L << 14)) {
+ if (fieldValue >= (1L << 21)) {
+ if (fieldValue >= (1L << 28)) {
+ if (fieldValue >= (1L << 35)) {
+ if (fieldValue >= (1L << 42)) {
+ if (fieldValue >= (1L << 49)) {
+ if (fieldValue >= (1L << 56)) {
+ out.write((int) (fieldValue >> 56) | 0x80);
+ }
+ out.write((int) (fieldValue >> 49) | 0x80);
+ }
+ out.write((int) (fieldValue >> 42) | 0x80);
+ }
+ out.write((int) (fieldValue >> 35) | 0x80);
+ }
+ out.write((int) (fieldValue >> 28) | 0x80);
+ }
+ out.write((int) (fieldValue >> 21) | 0x80);
+ }
+ out.write((int) (fieldValue >> 14) | 0x80);
+ }
+ out.write((int) (fieldValue >> 7) | 0x80);
+ }
+ out.write((int) fieldValue & 0x7f);
+ }
+
+ private void writeField(
+ OutputStream out,
+ BigInteger fieldValue)
+ throws IOException {
+ int byteCount = (fieldValue.bitLength() + 6) / 7;
+ if (byteCount == 0) {
+ out.write(0);
+ } else {
+ BigInteger tmpValue = fieldValue;
+ byte[] tmp = new byte[byteCount];
+ for (int i = byteCount - 1; i >= 0; i--) {
+ tmp[i] = (byte) ((tmpValue.intValue() & 0x7f) | 0x80);
+ tmpValue = tmpValue.shiftRight(7);
+ }
+ tmp[byteCount - 1] &= 0x7f;
+ out.write(tmp);
+ }
+
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ OIDTokenizer tok = new OIDTokenizer(identifier);
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ DEROutputStream dOut = new DEROutputStream(bOut);
+
+ writeField(bOut,
+ Integer.parseInt(tok.nextToken()) * 40
+ + Integer.parseInt(tok.nextToken()));
+
+ while (tok.hasMoreTokens()) {
+ String token = tok.nextToken();
+ if (token.length() < 18) {
+ writeField(bOut, Long.parseLong(token));
+ } else {
+ writeField(bOut, new BigInteger(token));
+ }
+ }
+
+ dOut.close();
+
+ byte[] bytes = bOut.toByteArray();
+
+ out.writeEncoded(OBJECT_IDENTIFIER, bytes);
+ }
+
+ public int hashCode() {
+ return identifier.hashCode();
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERObjectIdentifier)) {
+ return false;
+ }
+
+ return identifier.equals(((DERObjectIdentifier) o).identifier);
+ }
+
+ public String toString() {
+ return getId();
+ }
+
+ private static boolean isValidIdentifier(
+ String identifier) {
+ if (identifier.length() < 3
+ || identifier.charAt(1) != '.') {
+ return false;
+ }
+
+ char first = identifier.charAt(0);
+ if (first < '0' || first > '2') {
+ return false;
+ }
+
+ boolean periodAllowed = false;
+ for (int i = identifier.length() - 1; i >= 2; i--) {
+ char ch = identifier.charAt(i);
+
+ if ('0' <= ch && ch <= '9') {
+ periodAllowed = true;
+ continue;
+ }
+
+ if (ch == '.') {
+ if (!periodAllowed) {
+ return false;
+ }
+
+ periodAllowed = false;
+ continue;
+ }
+
+ return false;
+ }
+
+ return periodAllowed;
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROctetString.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROctetString.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROctetString.java
new file mode 100644
index 0000000..113a99c
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROctetString.java
@@ -0,0 +1,23 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+public class DEROctetString
+ extends ASN1OctetString {
+ /** @param string the octets making up the octet string. */
+ public DEROctetString(
+ byte[] string) {
+ super(string);
+ }
+
+ public DEROctetString(
+ DEREncodable obj) {
+ super(obj);
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(OCTET_STRING, string);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROutputStream.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROutputStream.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROutputStream.java
new file mode 100644
index 0000000..4a85500
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DEROutputStream.java
@@ -0,0 +1,73 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class DEROutputStream
+ extends FilterOutputStream implements DERTags {
+ public DEROutputStream(
+ OutputStream os) {
+ super(os);
+ }
+
+ private void writeLength(
+ int length)
+ throws IOException {
+ if (length > 127) {
+ int size = 1;
+ int val = length;
+
+ while ((val >>>= 8) != 0) {
+ size++;
+ }
+
+ write((byte) (size | 0x80));
+
+ for (int i = (size - 1) * 8; i >= 0; i -= 8) {
+ write((byte) (length >> i));
+ }
+ } else {
+ write((byte) length);
+ }
+ }
+
+ void writeEncoded(
+ int tag,
+ byte[] bytes)
+ throws IOException {
+ write(tag);
+ writeLength(bytes.length);
+ write(bytes);
+ }
+
+ protected void writeNull()
+ throws IOException {
+ write(NULL);
+ write(0x00);
+ }
+
+ public void write(byte[] buf)
+ throws IOException {
+ out.write(buf, 0, buf.length);
+ }
+
+ public void write(byte[] buf, int offSet, int len)
+ throws IOException {
+ out.write(buf, offSet, len);
+ }
+
+ public void writeObject(
+ Object obj)
+ throws IOException {
+ if (obj == null) {
+ writeNull();
+ } else if (obj instanceof DERObject) {
+ ((DERObject) obj).encode(this);
+ } else if (obj instanceof DEREncodable) {
+ ((DEREncodable) obj).getDERObject().encode(this);
+ } else {
+ throw new IOException("object not DEREncodable");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/23c1fd12/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERPrintableString.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERPrintableString.java b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERPrintableString.java
new file mode 100644
index 0000000..48bd5c7
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/asn1/DERPrintableString.java
@@ -0,0 +1,172 @@
+package org.apache.commons.ssl.asn1;
+
+import java.io.IOException;
+
+/** DER PrintableString object. */
+public class DERPrintableString
+ extends ASN1Object
+ implements DERString {
+ String string;
+
+ /**
+ * return a printable string from the passed in object.
+ *
+ * @throws IllegalArgumentException if the object cannot be converted.
+ */
+ public static DERPrintableString getInstance(
+ Object obj) {
+ if (obj == null || obj instanceof DERPrintableString) {
+ return (DERPrintableString) obj;
+ }
+
+ if (obj instanceof ASN1OctetString) {
+ return new DERPrintableString(((ASN1OctetString) obj).getOctets());
+ }
+
+ if (obj instanceof ASN1TaggedObject) {
+ return getInstance(((ASN1TaggedObject) obj).getObject());
+ }
+
+ throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
+ }
+
+ /**
+ * return a Printable String from a tagged object.
+ *
+ * @param obj the tagged object holding the object we want
+ * @param explicit true if the object is meant to be explicitly
+ * tagged false otherwise.
+ * @throws IllegalArgumentException if the tagged object cannot
+ * be converted.
+ */
+ public static DERPrintableString getInstance(
+ ASN1TaggedObject obj,
+ boolean explicit) {
+ return getInstance(obj.getObject());
+ }
+
+ /** basic constructor - byte encoded string. */
+ public DERPrintableString(
+ byte[] string) {
+ char[] cs = new char[string.length];
+
+ for (int i = 0; i != cs.length; i++) {
+ cs[i] = (char) (string[i] & 0xff);
+ }
+
+ this.string = new String(cs);
+ }
+
+ /** basic constructor - this does not validate the string */
+ public DERPrintableString(
+ String string) {
+ this(string, false);
+ }
+
+ /**
+ * Constructor with optional validation.
+ *
+ * @param string the base string to wrap.
+ * @param validate whether or not to check the string.
+ * @throws IllegalArgumentException if validate is true and the string
+ * contains characters that should not be in a PrintableString.
+ */
+ public DERPrintableString(
+ String string,
+ boolean validate) {
+ if (validate && !isPrintableString(string)) {
+ throw new IllegalArgumentException("string contains illegal characters");
+ }
+
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public byte[] getOctets() {
+ char[] cs = string.toCharArray();
+ byte[] bs = new byte[cs.length];
+
+ for (int i = 0; i != cs.length; i++) {
+ bs[i] = (byte) cs[i];
+ }
+
+ return bs;
+ }
+
+ void encode(
+ DEROutputStream out)
+ throws IOException {
+ out.writeEncoded(PRINTABLE_STRING, this.getOctets());
+ }
+
+ public int hashCode() {
+ return this.getString().hashCode();
+ }
+
+ boolean asn1Equals(
+ DERObject o) {
+ if (!(o instanceof DERPrintableString)) {
+ return false;
+ }
+
+ DERPrintableString s = (DERPrintableString) o;
+
+ return this.getString().equals(s.getString());
+ }
+
+ public String toString() {
+ return string;
+ }
+
+ /**
+ * return true if the passed in String can be represented without
+ * loss as a PrintableString, false otherwise.
+ *
+ * @return true if in printable set, false otherwise.
+ */
+ public static boolean isPrintableString(
+ String str) {
+ for (int i = str.length() - 1; i >= 0; i--) {
+ char ch = str.charAt(i);
+
+ if (ch > 0x007f) {
+ return false;
+ }
+
+ if ('a' <= ch && ch <= 'z') {
+ continue;
+ }
+
+ if ('A' <= ch && ch <= 'Z') {
+ continue;
+ }
+
+ if ('0' <= ch && ch <= '9') {
+ continue;
+ }
+
+ switch (ch) {
+ case ' ':
+ case '\'':
+ case '(':
+ case ')':
+ case '+':
+ case '-':
+ case '.':
+ case ':':
+ case '=':
+ case '?':
+ case '/':
+ case ',':
+ continue;
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+}