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: Fixed some issues
Date Sun, 25 Jan 2015 05:18:41 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/cleanpki 94e3ac5be -> 99f8a3ce5


Fixed some issues


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

Branch: refs/heads/cleanpki
Commit: 99f8a3ce52927de0b99a0b5fcb93088cdd816fcb
Parents: 94e3ac5
Author: Drankye <drankye@gmail.com>
Authored: Sun Jan 25 13:18:19 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Sun Jan 25 13:18:19 2015 +0800

----------------------------------------------------------------------
 .../apache/commons/ssl/Asn1PkcsStructure.java   | 10 ++--
 .../org/apache/commons/ssl/Asn1PkcsUtil.java    | 14 +-----
 .../org/apache/commons/ssl/KeyStoreBuilder.java | 32 ++++++-------
 .../java/org/apache/commons/ssl/PKCS8Key.java   | 12 ++---
 .../apache/kerby/asn1/type/Asn1BigInteger.java  | 48 --------------------
 .../org/apache/kerby/asn1/type/Asn1Choice.java  |  2 +-
 .../kerby/asn1/type/Asn1CollectionType.java     |  4 +-
 .../org/apache/kerby/asn1/type/Asn1Integer.java | 18 +++++---
 .../org/apache/kerby/asn1/type/Asn1Simple.java  |  3 +-
 .../org/apache/kerby/asn1/PersonnelRecord.java  |  4 +-
 .../org/apache/kerby/asn1/TestAsn1Integer.java  |  4 +-
 .../kerby/kerberos/kerb/spec/KrbIntegers.java   |  2 +-
 12 files changed, 48 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/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
index 37f30a9..e00d58d 100644
--- 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
@@ -26,13 +26,9 @@
 package org.apache.commons.ssl;
 
 import org.apache.commons.ssl.util.Hex;
-import org.apache.kerby.asn1.type.Asn1BigInteger;
+import org.apache.kerby.asn1.type.Asn1Integer;
 
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.*;
 
 /**
  * @author Credit Union Central of British Columbia
@@ -45,7 +41,7 @@ import java.util.TreeSet;
  * Adapted from not-yet-commons-ssl ASN1Structure
  */
 class Asn1PkcsStructure {
-    List<Asn1BigInteger> derIntegers = new LinkedList<Asn1BigInteger>();
+    List<Asn1Integer> derIntegers = new LinkedList<Asn1Integer>();
     Set oids = new TreeSet();
     String oid1;
     String oid2;

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/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
index 1e17099..4f6823a 100644
--- 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
@@ -101,22 +101,10 @@ public class Asn1PkcsUtil {
         for (int i = 0; i < depth; i++) {
             name = "  " + name;
         }
+
         if (obj instanceof Asn1Integer) {
             Asn1Integer dInt = (Asn1Integer) obj;
             if (pkcs8.derIntegers != null) {
-                pkcs8.derIntegers.add(new Asn1BigInteger(dInt.getValue()));
-            }
-            int intValue = dInt.getValue();
-            if (intValue > 0) {
-                if (pkcs8.iterationCount == 0) {
-                    pkcs8.iterationCount = intValue;
-                } else if (pkcs8.keySize == 0) {
-                    pkcs8.keySize = intValue;
-                }
-            }
-        } else if (obj instanceof Asn1BigInteger) {
-            Asn1BigInteger dInt = (Asn1BigInteger) obj;
-            if (pkcs8.derIntegers != null) {
                 pkcs8.derIntegers.add(dInt);
             }
             BigInteger big = dInt.getValue();

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/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 7d0828b..398f1a6 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
@@ -31,7 +31,7 @@
 
 package org.apache.commons.ssl;
 
-import org.apache.kerby.asn1.type.Asn1BigInteger;
+import org.apache.kerby.asn1.type.Asn1Integer;
 import org.apache.kerby.asn1.type.Asn1Sequence;
 
 import java.io.*;
@@ -613,15 +613,15 @@ public class KeyStoreBuilder {
             if (key instanceof RSAPrivateCrtKey) {
                 RSAPrivateCrtKey rsa = (RSAPrivateCrtKey) key;
                 Asn1Sequence seq = new Asn1Sequence();
-                seq.addItem(new Asn1BigInteger(BigInteger.ZERO));
-                seq.addItem(new Asn1BigInteger(rsa.getModulus()));
-                seq.addItem(new Asn1BigInteger(rsa.getPublicExponent()));
-                seq.addItem(new Asn1BigInteger(rsa.getPrivateExponent()));
-                seq.addItem(new Asn1BigInteger(rsa.getPrimeP()));
-                seq.addItem(new Asn1BigInteger(rsa.getPrimeQ()));
-                seq.addItem(new Asn1BigInteger(rsa.getPrimeExponentP()));
-                seq.addItem(new Asn1BigInteger(rsa.getPrimeExponentQ()));
-                seq.addItem(new Asn1BigInteger(rsa.getCrtCoefficient()));
+                seq.addItem(new Asn1Integer(BigInteger.ZERO));
+                seq.addItem(new Asn1Integer(rsa.getModulus()));
+                seq.addItem(new Asn1Integer(rsa.getPublicExponent()));
+                seq.addItem(new Asn1Integer(rsa.getPrivateExponent()));
+                seq.addItem(new Asn1Integer(rsa.getPrimeP()));
+                seq.addItem(new Asn1Integer(rsa.getPrimeQ()));
+                seq.addItem(new Asn1Integer(rsa.getPrimeExponentP()));
+                seq.addItem(new Asn1Integer(rsa.getPrimeExponentQ()));
+                seq.addItem(new Asn1Integer(rsa.getCrtCoefficient()));
                 byte[] derBytes = seq.encode();
                 PKCS8Key pkcs8 = new PKCS8Key(derBytes, null);
                 pkcs8DerBytes = pkcs8.getDecryptedBytes();
@@ -635,12 +635,12 @@ public class KeyStoreBuilder {
                 BigInteger y = q.modPow(x, p);
 
                 Asn1Sequence seq = new Asn1Sequence();
-                seq.addItem(new Asn1BigInteger(BigInteger.ZERO));
-                seq.addItem(new Asn1BigInteger(p));
-                seq.addItem(new Asn1BigInteger(q));
-                seq.addItem(new Asn1BigInteger(g));
-                seq.addItem(new Asn1BigInteger(y));
-                seq.addItem(new Asn1BigInteger(x));
+                seq.addItem(new Asn1Integer(BigInteger.ZERO));
+                seq.addItem(new Asn1Integer(p));
+                seq.addItem(new Asn1Integer(q));
+                seq.addItem(new Asn1Integer(g));
+                seq.addItem(new Asn1Integer(y));
+                seq.addItem(new Asn1Integer(x));
                 byte[] derBytes = seq.encode();
                 PKCS8Key pkcs8 = new PKCS8Key(derBytes, null);
                 pkcs8DerBytes = pkcs8.getDecryptedBytes();

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/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 6de244e..f63d4e3 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
@@ -899,7 +899,7 @@ public class PKCS8Key {
 
     public static byte[] formatAsPKCS8(byte[] privateKey, String oid,
                                        Asn1PkcsStructure pkcs8) {
-        Asn1BigInteger derZero = new Asn1BigInteger(BigInteger.ZERO);
+        Asn1Integer derZero = new Asn1Integer(BigInteger.ZERO);
         Asn1Sequence outterSeq = new Asn1Sequence();
         Asn1Sequence innerSeq = new Asn1Sequence();
         Asn1OctetString octetsToAppend;
@@ -918,12 +918,12 @@ public class PKCS8Key {
                 throw new RuntimeException("invalid DSA key - can't find P, Q, G, X");
             }
 
-            Asn1BigInteger[] ints = new Asn1BigInteger[pkcs8.derIntegers.size()];
+            Asn1Integer[] ints = new Asn1Integer[pkcs8.derIntegers.size()];
             pkcs8.derIntegers.toArray(ints);
-            Asn1BigInteger p = ints[1];
-            Asn1BigInteger q = ints[2];
-            Asn1BigInteger g = ints[3];
-            Asn1BigInteger x = ints[5];
+            Asn1Integer p = ints[1];
+            Asn1Integer q = ints[2];
+            Asn1Integer g = ints[3];
+            Asn1Integer x = ints[5];
 
             byte[] encodedX = x.encode();
             octetsToAppend = new Asn1OctetString(encodedX);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BigInteger.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BigInteger.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BigInteger.java
deleted file mode 100644
index f880840..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1BigInteger.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- *  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. 
- *  
- */
-package org.apache.kerby.asn1.type;
-
-import org.apache.kerby.asn1.UniversalTag;
-
-import java.io.IOException;
-import java.math.BigInteger;
-
-public class Asn1BigInteger extends Asn1Simple<BigInteger>
-{
-    public Asn1BigInteger() {
-        this(null);
-    }
-
-    public Asn1BigInteger(long value) {
-        this(BigInteger.valueOf(value));
-    }
-
-    public Asn1BigInteger(BigInteger value) {
-        super(UniversalTag.INTEGER, value);
-    }
-
-    protected void toBytes() {
-        setBytes(getValue().toByteArray());
-    }
-
-    protected void toValue() throws IOException {
-        setValue(new BigInteger(getBytes()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
index 59d4ba5..cb439b2 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Choice.java
@@ -162,7 +162,7 @@ public class Asn1Choice extends AbstractAsn1Type<Asn1Type> {
     protected Integer getFieldAsInteger(int index) {
         Asn1Integer value = getFieldAs(index, Asn1Integer.class);
         if (value != null) {
-            return value.getValue();
+            return value.getValue().intValue();
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
index b506c2f..28d8a15 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1CollectionType.java
@@ -169,8 +169,8 @@ public abstract class Asn1CollectionType extends AbstractAsn1Type<Asn1Collection
 
     protected Integer getFieldAsInteger(int index) {
         Asn1Integer value = getFieldAs(index, Asn1Integer.class);
-        if (value != null) {
-            return value.getValue();
+        if (value != null && value.getValue() != null) {
+            return value.getValue().intValue();
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java
index b0893a0..76b4222 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java
@@ -24,23 +24,29 @@ import org.apache.kerby.asn1.UniversalTag;
 import java.io.IOException;
 import java.math.BigInteger;
 
-public class Asn1Integer extends Asn1Simple<Integer>
+public class Asn1Integer extends Asn1Simple<BigInteger>
 {
     public Asn1Integer() {
-        this(null);
+        this((BigInteger) null);
     }
 
     public Asn1Integer(Integer value) {
+        this(BigInteger.valueOf(value));
+    }
+
+    public Asn1Integer(Long value) {
+        this(BigInteger.valueOf(value));
+    }
+
+    public Asn1Integer(BigInteger value) {
         super(UniversalTag.INTEGER, value);
     }
 
-    @Override
     protected void toBytes() {
-        setBytes(BigInteger.valueOf(getValue()).toByteArray());
+        setBytes(getValue().toByteArray());
     }
 
-    @Override
     protected void toValue() throws IOException {
-        setValue(new BigInteger(getBytes()).intValue());
+        setValue(new BigInteger(getBytes()));
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/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 4464000..11296be 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
@@ -166,8 +166,7 @@ public abstract class Asn1Simple<T> extends AbstractAsn1Type<T>
{
             case IA5_STRING:
                 return new Asn1IA5String();
             case INTEGER:
-                // instead of Asn1Integer, for safe in case large number
-                return new Asn1BigInteger();
+                return new Asn1Integer();
             case NULL:
                 return Asn1Null.INSTANCE;
             case NUMERIC_STRING:

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
index 39e08e6..20e4f5c 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecord.java
@@ -191,8 +191,10 @@ public class PersonnelRecord extends TaggingSet {
             super(2, new Asn1Integer(value), true);
             setEncodingOption(EncodingOption.IMPLICIT);
         }
+
         public EmployeeNumber() {
-            this(null);
+            super(2, new Asn1Integer(), true);
+            setEncodingOption(EncodingOption.IMPLICIT);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
index e330da4..3ef76de 100644
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
@@ -61,10 +61,10 @@ public class TestAsn1Integer {
         testDecodingWith(1234567890, "0x02 04 49 96 02 D2");
     }
 
-    private void testDecodingWith(Integer expectedValue, String content) throws IOException
{
+    private void testDecodingWith(int expectedValue, String content) throws IOException {
         Asn1Integer decoded = new Asn1Integer();
         decoded.setEncodingOption(EncodingOption.DER);
         decoded.decode(Util.hex2bytes(content));
-        Assert.assertEquals(expectedValue, decoded.getValue());
+        Assert.assertEquals(expectedValue, decoded.getValue().intValue());
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/99f8a3ce/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbIntegers.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbIntegers.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbIntegers.java
index 36fa3f2..1eef42e 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbIntegers.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KrbIntegers.java
@@ -47,7 +47,7 @@ public class KrbIntegers extends KrbSequenceOfType<Asn1Integer> {
     public List<Integer> getValues() {
         List<Integer> results = new ArrayList<Integer>();
         for (Asn1Integer value : getElements()) {
-            results.add(value.getValue());
+            results.add(value.getValue().intValue());
         }
         return results;
     }


Mime
View raw message