directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject directory-kerberos git commit: Refactoring codes
Date Sat, 24 Jan 2015 22:15:24 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/cleanpki ceacb982d -> f6a5c7fa6


Refactoring codes


Project: http://git-wip-us.apache.org/repos/asf/directory-kerberos/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerberos/commit/f6a5c7fa
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerberos/tree/f6a5c7fa
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerberos/diff/f6a5c7fa

Branch: refs/heads/cleanpki
Commit: f6a5c7fa627e478adad0128a6e0dda23a6286489
Parents: ceacb98
Author: Drankye <drankye@gmail.com>
Authored: Sun Jan 25 06:15:06 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Sun Jan 25 06:15:06 2015 +0800

----------------------------------------------------------------------
 3rdparty/not-yet-commons-ssl/pom.xml            |   5 +
 .../org/apache/commons/ssl/ASN1Structure.java   | 112 ----------
 .../java/org/apache/commons/ssl/ASN1Util.java   | 211 -------------------
 .../apache/commons/ssl/Asn1PkcsStructure.java   | 116 ++++++++++
 .../org/apache/commons/ssl/Asn1PkcsUtil.java    | 185 ++++++++++++++++
 .../org/apache/commons/ssl/KeyStoreBuilder.java |   6 +-
 .../java/org/apache/commons/ssl/PKCS8Key.java   |  12 +-
 .../org/apache/kerby/asn1/type/Asn1Null.java    |   8 +-
 .../org/apache/kerby/asn1/type/Asn1Simple.java  |  12 +-
 9 files changed, 331 insertions(+), 336 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/3rdparty/not-yet-commons-ssl/pom.xml
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/pom.xml b/3rdparty/not-yet-commons-ssl/pom.xml
index 92dcd42..ae3bf0f 100644
--- a/3rdparty/not-yet-commons-ssl/pom.xml
+++ b/3rdparty/not-yet-commons-ssl/pom.xml
@@ -63,6 +63,11 @@
 
   <dependencies>
     <dependency>
+      <groupId>org.apache.kerby</groupId>
+      <artifactId>kerby-asn1</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
       <groupId>org.bouncycastle</groupId>
       <artifactId>bcprov-ext-jdk15on</artifactId>
       <version>1.51</version>

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Structure.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Structure.java
b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Structure.java
deleted file mode 100644
index d9df5b9..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Structure.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/ASN1Structure.java
$
- * $Revision: 121 $
- * $Date: 2007-11-13 21:26:57 -0800 (Tue, 13 Nov 2007) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import org.apache.commons.ssl.util.Hex;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-/**
- * @author Credit Union Central of British Columbia
- * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
- * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
- * @since 16-Nov-2005
- */
-class ASN1Structure {
-    List derIntegers = new LinkedList();
-    Set oids = new TreeSet();
-    String oid1;
-    String oid2;
-    String oid3;
-    byte[] salt;
-    byte[] iv;
-    int iterationCount;
-    int keySize;
-    byte[] bigPayload;
-    byte[] smallPayload;
-
-    public String toString() {
-        StringBuffer buf = new StringBuffer(256);
-        buf.append("------ ASN.1 PKCS Structure ------");
-        buf.append("\noid1:    ");
-        buf.append(oid1);
-        if (oid2 != null) {
-            buf.append("\noid2:    ");
-            buf.append(oid2);
-        }
-        buf.append("\nsalt:   ");
-        if (salt != null) {
-            buf.append(Hex.encode(salt));
-        } else {
-            buf.append("[null]");
-        }
-        buf.append("\nic:      ");
-        buf.append(Integer.toString(iterationCount));
-        if (keySize != 0) {
-            buf.append("\nkeySize: ");
-            buf.append(Integer.toString(keySize * 8));
-        }
-        if (oid2 != null) {
-            buf.append("\noid3:    ");
-            buf.append(oid3);
-        }
-        if (oid2 != null) {
-            buf.append("\niv:      ");
-            if (iv != null) {
-                buf.append(Hex.encode(iv));
-            } else {
-                buf.append("[null]");
-            }
-        }
-        if (bigPayload != null) {
-            buf.append("\nbigPayload-length:   ");
-            buf.append(bigPayload.length);
-        }
-        if (smallPayload != null) {
-            buf.append("\nsmallPayload-length: ");
-            buf.append(smallPayload.length);
-        }
-        if (!oids.isEmpty()) {
-            Iterator it = oids.iterator();
-            buf.append("\nAll oids:");
-            while (it.hasNext()) {
-                buf.append("\n");
-                buf.append((String) it.next());
-            }
-        }
-        return buf.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Util.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Util.java
b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Util.java
deleted file mode 100644
index 1cb7764..0000000
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/ASN1Util.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/ASN1Util.java
$
- * $Revision: 121 $
- * $Date: 2007-11-13 21:26:57 -0800 (Tue, 13 Nov 2007) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.commons.ssl;
-
-import org.apache.commons.ssl.asn1.ASN1InputStream;
-import org.apache.commons.ssl.asn1.DEREncodable;
-import org.apache.commons.ssl.asn1.DERInteger;
-import org.apache.commons.ssl.asn1.DERObjectIdentifier;
-import org.apache.commons.ssl.asn1.DEROctetString;
-import org.apache.commons.ssl.asn1.DERPrintableString;
-import org.apache.commons.ssl.asn1.DERSequence;
-import org.apache.commons.ssl.asn1.DERSet;
-import org.apache.commons.ssl.asn1.DERTaggedObject;
-import org.apache.commons.ssl.util.Hex;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Vector;
-
-/**
- * @author Credit Union Central of British Columbia
- * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
- * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
- * @since 16-Nov-2005
- */
-public class ASN1Util {
-    public static boolean DEBUG = false;
-    public final static BigInteger BIGGEST =
-        new BigInteger(Integer.toString(Integer.MAX_VALUE));
-
-    public static ASN1Structure analyze(byte[] asn1)
-        throws IOException {
-        ASN1InputStream asn = new ASN1InputStream(asn1);
-        DERSequence seq = (DERSequence) asn.readObject();
-        ASN1Structure pkcs8 = new ASN1Structure();
-        ASN1Util.analyze(seq, pkcs8, 0);
-        return pkcs8;
-    }
-
-    public static void main(String[] args) throws Exception {
-        DEBUG = true;
-        FileInputStream in = new FileInputStream(args[0]);
-        byte[] bytes = Util.streamToBytes(in);
-        List list = PEMUtil.decode(bytes);
-        if (!list.isEmpty()) {
-            bytes = ((PEMItem) list.get(0)).getDerBytes();
-        }
-
-        ASN1Structure asn1 = analyze(bytes);
-        while (asn1.bigPayload != null) {
-            System.out.println("------------------------------------------");
-            System.out.println(asn1);
-            System.out.println("------------------------------------------");
-            asn1 = analyze(asn1.bigPayload);
-        }
-    }
-
-
-    public static void analyze(DEREncodable seq, ASN1Structure pkcs8,
-                               int depth) {
-        String tag = null;
-        if (depth >= 2) {
-            pkcs8.derIntegers = null;
-        }
-        Enumeration en;
-        if (seq instanceof DERSequence) {
-            en = ((DERSequence) seq).getObjects();
-        } else if (seq instanceof DERSet) {
-            en = ((DERSet) seq).getObjects();
-        } else if (seq instanceof DERTaggedObject) {
-            DERTaggedObject derTag = (DERTaggedObject) seq;
-            tag = Integer.toString(derTag.getTagNo());
-            Vector v = new Vector();
-            v.add(derTag.getObject());
-            en = v.elements();
-        } else {
-            throw new IllegalArgumentException("DEREncodable must be one of: DERSequence,
DERSet, DERTaggedObject");
-        }
-        while (en != null && en.hasMoreElements()) {
-            DEREncodable obj = (DEREncodable) en.nextElement();
-            if (!(obj instanceof DERSequence) &&
-                !(obj instanceof DERSet) &&
-                !(obj instanceof DERTaggedObject)) {
-                String str = obj.toString();
-                String name = obj.getClass().getName();
-                name = name.substring(name.lastIndexOf('.') + 1);
-                if (tag != null) {
-                    name = " [tag=" + tag + "] " + name;
-                }
-                for (int i = 0; i < depth; i++) {
-                    name = "  " + name;
-                }
-                if (obj instanceof DERInteger) {
-                    DERInteger dInt = (DERInteger) obj;
-                    if (pkcs8.derIntegers != null) {
-                        pkcs8.derIntegers.add(dInt);
-                    }
-                    BigInteger big = dInt.getValue();
-                    int intValue = big.intValue();
-                    if (BIGGEST.compareTo(big) >= 0 && intValue > 0) {
-                        if (pkcs8.iterationCount == 0) {
-                            pkcs8.iterationCount = intValue;
-                        } else if (pkcs8.keySize == 0) {
-                            pkcs8.keySize = intValue;
-                        }
-                    }
-                    str = dInt.getValue().toString();
-                } else if (obj instanceof DERObjectIdentifier) {
-                    DERObjectIdentifier id = (DERObjectIdentifier) obj;
-                    str = id.getId();
-                    pkcs8.oids.add(str);
-                    if (pkcs8.oid1 == null) {
-                        pkcs8.oid1 = str;
-                    } else if (pkcs8.oid2 == null) {
-                        pkcs8.oid2 = str;
-                    } else if (pkcs8.oid3 == null) {
-                        pkcs8.oid3 = str;
-                    }
-                } else {
-                    pkcs8.derIntegers = null;
-                    if (obj instanceof DEROctetString) {
-                        DEROctetString oct = (DEROctetString) obj;
-                        byte[] octets = oct.getOctets();
-                        int len = Math.min(10, octets.length);
-                        boolean probablyBinary = false;
-                        for (int i = 0; i < len; i++) {
-                            byte b = octets[i];
-                            boolean isBinary = b > 128 || b < 0;
-                            if (isBinary) {
-                                probablyBinary = true;
-                                break;
-                            }
-                        }
-                        if (probablyBinary && octets.length > 64) {
-                            if (pkcs8.bigPayload == null) {
-                                pkcs8.bigPayload = octets;
-                            }
-                            str = "probably binary";
-                        } else {
-                            str = Hex.encode(octets);
-                            if (octets.length <= 64) {
-                                if (octets.length % 8 == 0) {
-                                    if (pkcs8.salt == null) {
-                                        pkcs8.salt = octets;
-                                    } else if (pkcs8.iv == null) {
-                                        pkcs8.iv = octets;
-                                    }
-                                } else {
-                                    if (pkcs8.smallPayload == null) {
-                                        pkcs8.smallPayload = octets;
-                                    }
-                                }
-                            }
-                        }
-                        str += " (length=" + octets.length + ")";
-                    } else if (obj instanceof DERPrintableString) {
-                        DERPrintableString dps = (DERPrintableString) obj;
-                        str = dps.getString();
-                    }
-                }
-
-                if (DEBUG) {
-                    System.out.println(name + ": [" + str + "]");
-                }
-            } else {
-                if (tag != null && DEBUG) {
-                    String name = obj.getClass().getName();
-                    name = name.substring(name.lastIndexOf('.') + 1);
-                    name = " [tag=" + tag + "] " + name;
-                    for (int i = 0; i < depth; i++) {
-                        name = "  " + name;
-                    }
-                    System.out.println(name);
-                }
-                analyze(obj, pkcs8, depth + 1);
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsStructure.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsStructure.java
b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsStructure.java
new file mode 100644
index 0000000..f183ae6
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsStructure.java
@@ -0,0 +1,116 @@
+/*
+ * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.16/src/java/org/apache/commons/ssl/ASN1Structure.java
$
+ * $Revision: 121 $
+ * $Date: 2007-11-13 21:26:57 -0800 (Tue, 13 Nov 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.ssl;
+
+import org.apache.commons.ssl.util.Hex;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * @author Credit Union Central of British Columbia
+ * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
+ * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
+ * @since 16-Nov-2005
+ */
+
+/**
+ * Adapted from not-yet-commons-ssl ASN1Structure
+ */
+class Asn1PkcsStructure {
+    List derIntegers = new LinkedList();
+    Set oids = new TreeSet();
+    String oid1;
+    String oid2;
+    String oid3;
+    byte[] salt;
+    byte[] iv;
+    int iterationCount;
+    int keySize;
+    byte[] bigPayload;
+    byte[] smallPayload;
+
+    public String toString() {
+        StringBuffer buf = new StringBuffer(256);
+        buf.append("------ ASN.1 PKCS Structure ------");
+        buf.append("\noid1:    ");
+        buf.append(oid1);
+        if (oid2 != null) {
+            buf.append("\noid2:    ");
+            buf.append(oid2);
+        }
+        buf.append("\nsalt:   ");
+        if (salt != null) {
+            buf.append(Hex.encode(salt));
+        } else {
+            buf.append("[null]");
+        }
+        buf.append("\nic:      ");
+        buf.append(Integer.toString(iterationCount));
+        if (keySize != 0) {
+            buf.append("\nkeySize: ");
+            buf.append(Integer.toString(keySize * 8));
+        }
+        if (oid2 != null) {
+            buf.append("\noid3:    ");
+            buf.append(oid3);
+        }
+        if (oid2 != null) {
+            buf.append("\niv:      ");
+            if (iv != null) {
+                buf.append(Hex.encode(iv));
+            } else {
+                buf.append("[null]");
+            }
+        }
+        if (bigPayload != null) {
+            buf.append("\nbigPayload-length:   ");
+            buf.append(bigPayload.length);
+        }
+        if (smallPayload != null) {
+            buf.append("\nsmallPayload-length: ");
+            buf.append(smallPayload.length);
+        }
+        if (!oids.isEmpty()) {
+            Iterator it = oids.iterator();
+            buf.append("\nAll oids:");
+            while (it.hasNext()) {
+                buf.append("\n");
+                buf.append((String) it.next());
+            }
+        }
+        return buf.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsUtil.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsUtil.java
b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsUtil.java
new file mode 100644
index 0000000..4cfe0ea
--- /dev/null
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/Asn1PkcsUtil.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.ssl;
+
+import org.apache.commons.ssl.util.Hex;
+import org.apache.kerby.asn1.Asn1InputBuffer;
+import org.apache.kerby.asn1.type.*;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.List;
+
+/**
+ * @author Credit Union Central of British Columbia
+ * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
+ * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
+ * @since 16-Nov-2005
+ */
+
+/**
+ * Adapted from ASN1Util in not-yet-commons-ssl
+ */
+public class Asn1PkcsUtil {
+
+    public final static BigInteger BIGGEST =
+            new BigInteger(Integer.toString(Integer.MAX_VALUE));
+
+    public static Asn1PkcsStructure analyze(byte[] asn1)
+            throws IOException {
+        Asn1InputBuffer asn = new Asn1InputBuffer(asn1);
+        Asn1Type asn1Obj = asn.read();
+        Asn1PkcsStructure pkcs8 = new Asn1PkcsStructure();
+        if (asn1Obj instanceof Asn1Collection) {
+            Asn1PkcsUtil.analyze((Asn1Collection) asn1Obj, pkcs8, 0);
+        } else {
+            Asn1PkcsUtil.analyze(asn1Obj, pkcs8, 0);
+        }
+        return pkcs8;
+    }
+
+    public static void analyze(Asn1Collection asn1Coll, Asn1PkcsStructure pkcs8, int depth)
{
+        if (depth >= 2) {
+            pkcs8.derIntegers = null;
+        }
+
+        List<Asn1Item> items = asn1Coll.getValue();
+        for (Asn1Item item : items) {
+            if (! item.isCollection()) {
+                analyze(item.getValue(), pkcs8, depth);
+            } else {
+                try {
+                    item.decodeValueAsCollection();
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+                analyze((Asn1Collection) item.getValue(), pkcs8, depth + 1);
+            }
+        }
+    }
+
+    public static void analyze(Asn1Type obj, Asn1PkcsStructure pkcs8, int depth) {
+        String tag = null;
+        if (depth >= 2) {
+            pkcs8.derIntegers = null;
+        }
+
+        String str = obj.toString();
+        String name = obj.getClass().getName();
+        name = name.substring(name.lastIndexOf('.') + 1);
+        if (tag != null) {
+            name = " [tag=" + tag + "] " + name;
+        }
+        for (int i = 0; i < depth; i++) {
+            name = "  " + name;
+        }
+        if (obj instanceof Asn1Integer) {
+            Asn1Integer dInt = (Asn1Integer) obj;
+            if (pkcs8.derIntegers != null) {
+                pkcs8.derIntegers.add(dInt);
+            }
+        } else if (obj instanceof Asn1BigInteger) {
+            Asn1BigInteger dInt = (Asn1BigInteger) obj;
+            if (pkcs8.derIntegers != null) {
+                pkcs8.derIntegers.add(dInt);
+            }
+            BigInteger big = dInt.getValue();
+            int intValue = big.intValue();
+            if (BIGGEST.compareTo(big) >= 0 && intValue > 0) {
+                if (pkcs8.iterationCount == 0) {
+                    pkcs8.iterationCount = intValue;
+                } else if (pkcs8.keySize == 0) {
+                    pkcs8.keySize = intValue;
+                }
+            }
+        } else if (obj instanceof Asn1ObjectIdentifier) {
+            Asn1ObjectIdentifier id = (Asn1ObjectIdentifier) obj;
+            str = id.getValue();
+            pkcs8.oids.add(str);
+            if (pkcs8.oid1 == null) {
+                pkcs8.oid1 = str;
+            } else if (pkcs8.oid2 == null) {
+                pkcs8.oid2 = str;
+            } else if (pkcs8.oid3 == null) {
+                pkcs8.oid3 = str;
+            }
+        } else {
+            pkcs8.derIntegers = null;
+            if (obj instanceof Asn1OctetString) {
+                Asn1OctetString oct = (Asn1OctetString) obj;
+                byte[] octets = oct.getValue();
+                int len = Math.min(10, octets.length);
+                boolean probablyBinary = false;
+                for (int i = 0; i < len; i++) {
+                    byte b = octets[i];
+                    boolean isBinary = b > 128 || b < 0;
+                    if (isBinary) {
+                        probablyBinary = true;
+                        break;
+                    }
+                }
+                if (probablyBinary && octets.length > 64) {
+                    if (pkcs8.bigPayload == null) {
+                        pkcs8.bigPayload = octets;
+                    }
+                } else {
+                    str = Hex.encode(octets);
+                    if (octets.length <= 64) {
+                        if (octets.length % 8 == 0) {
+                            if (pkcs8.salt == null) {
+                                pkcs8.salt = octets;
+                            } else if (pkcs8.iv == null) {
+                                pkcs8.iv = octets;
+                            }
+                        } else {
+                            if (pkcs8.smallPayload == null) {
+                                pkcs8.smallPayload = octets;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        FileInputStream in = new FileInputStream(args[0]);
+        byte[] bytes = Util.streamToBytes(in);
+        List list = PEMUtil.decode(bytes);
+        if (!list.isEmpty()) {
+            bytes = ((PEMItem) list.get(0)).getDerBytes();
+        }
+
+        Asn1PkcsStructure asn1 = analyze(bytes);
+        while (asn1.bigPayload != null) {
+            System.out.println("------------------------------------------");
+            System.out.println(asn1);
+            System.out.println("------------------------------------------");
+            asn1 = analyze(asn1.bigPayload);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyStoreBuilder.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyStoreBuilder.java
b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyStoreBuilder.java
index 9f635ae..e9619d1 100644
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyStoreBuilder.java
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/KeyStoreBuilder.java
@@ -363,13 +363,13 @@ public class KeyStoreBuilder {
 
         boolean isProbablyPKCS12 = false;
         boolean isASN = false;
-        ASN1Structure asn1 = null;
+        Asn1PkcsStructure asn1 = null;
         try {
-            asn1 = ASN1Util.analyze(stuff);
+            asn1 = Asn1PkcsUtil.analyze(stuff);
             isASN = true;
             isProbablyPKCS12 = asn1.oids.contains(PKCS7_ENCRYPTED);
             if (!isProbablyPKCS12 && asn1.bigPayload != null) {
-                asn1 = ASN1Util.analyze(asn1.bigPayload);
+                asn1 = Asn1PkcsUtil.analyze(asn1.bigPayload);
                 isProbablyPKCS12 = asn1.oids.contains(PKCS7_ENCRYPTED);
             }
         }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/PKCS8Key.java
----------------------------------------------------------------------
diff --git a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/PKCS8Key.java
b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/PKCS8Key.java
index 986edda..9345708 100644
--- a/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/PKCS8Key.java
+++ b/3rdparty/not-yet-commons-ssl/src/main/java/org/apache/commons/ssl/PKCS8Key.java
@@ -182,9 +182,9 @@ public class PKCS8Key {
             }
         }
 
-        ASN1Structure pkcs8;
+        Asn1PkcsStructure pkcs8;
         try {
-            pkcs8 = ASN1Util.analyze(derBytes);
+            pkcs8 = Asn1PkcsUtil.analyze(derBytes);
         }
         catch (Exception e) {
             throw new ProbablyNotPKCS8Exception("asn1 parse failure: " + e);
@@ -239,7 +239,7 @@ public class PKCS8Key {
         }
         if (encrypted) {
             try {
-                pkcs8 = ASN1Util.analyze(decryptedPKCS8);
+                pkcs8 = Asn1PkcsUtil.analyze(decryptedPKCS8);
             }
             catch (Exception e) {
                 throw new ProbablyBadPasswordException("Decrypted stream not ASN.1.  Probably
bad decryption password.");
@@ -438,7 +438,7 @@ public class PKCS8Key {
         return new DecryptResult(transformation, keySize, decryptedBytes);
     }
 
-    private static DecryptResult decryptPKCS8(ASN1Structure pkcs8,
+    private static DecryptResult decryptPKCS8(Asn1PkcsStructure pkcs8,
                                               char[] password)
         throws GeneralSecurityException {
         boolean isVersion1 = true;
@@ -898,7 +898,7 @@ public class PKCS8Key {
     }
 
     public static byte[] formatAsPKCS8(byte[] privateKey, String oid,
-                                       ASN1Structure pkcs8) {
+                                       Asn1PkcsStructure pkcs8) {
         DERInteger derZero = new DERInteger(BigInteger.ZERO);
         ASN1EncodableVector outterVec = new ASN1EncodableVector();
         ASN1EncodableVector innerVec = new ASN1EncodableVector();
@@ -909,7 +909,7 @@ public class PKCS8Key {
             if (DSA_OID.equals(oid)) {
                 if (pkcs8 == null) {
                     try {
-                        pkcs8 = ASN1Util.analyze(privateKey);
+                        pkcs8 = Asn1PkcsUtil.analyze(privateKey);
                     }
                     catch (Exception e) {
                         throw new RuntimeException("asn1 parse failure " + e);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java
index 8cabc04..2f4bb9a 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java
@@ -24,13 +24,15 @@ import org.apache.kerby.asn1.UniversalTag;
 
 import java.io.IOException;
 
-public class Asn1Null extends Asn1Simple<Object>
-{
+/**
+ * The Asn1 Null type
+ */
+public class Asn1Null extends Asn1Simple<Object> {
     public static final Asn1Null NULL = new Asn1Null();
     private static final byte[]  EMPTY_BYTES = new byte[0];
 
     public Asn1Null() {
-        super(null, UniversalTag.NULL);
+        super(UniversalTag.NULL, null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/f6a5c7fa/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
index c25309d..5d752f3 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
@@ -128,6 +128,11 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
         }
     }
 
+    /**
+     * Create a simple ASN1 object given tagNo, using the default constructor with no value
provided
+     * @param tagNo
+     * @return
+     */
     public static Asn1Type createSimple(int tagNo) {
         if (! isSimple(tagNo)) {
             throw new IllegalArgumentException("Not simple type, tag: " + tagNo);
@@ -135,6 +140,11 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
         return createSimple(UniversalTag.fromValue(tagNo));
     }
 
+    /**
+     * Create a simple ASN1 object given tagNo, using the default constructor with no value
provided
+     * @param tagNo
+     * @return
+     */
     public static Asn1Type createSimple(UniversalTag tagNo) {
         if (! isSimple(tagNo)) {
             throw new IllegalArgumentException("Not simple type, tag: " + tagNo);
@@ -158,7 +168,7 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
             case INTEGER:
                 return new Asn1Integer();
             case NULL:
-                return new Asn1Null();
+                return Asn1Null.NULL;
             case NUMERIC_STRING:
                 return new Asn1NumericsString();
             case OBJECT_IDENTIFIER:


Mime
View raw message