harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r472926 - in /incubator/harmony/enhanced/classlib/trunk/modules/auth/src: main/java/common/javax/security/auth/kerberos/ main/java/common/org/apache/harmony/auth/internal/kerberos/v5/ main/java/common/org/apache/harmony/auth/module/ test/ja...
Date Thu, 09 Nov 2006 14:55:06 GMT
Author: smishura
Date: Thu Nov  9 06:55:05 2006
New Revision: 472926

URL: http://svn.apache.org/viewvc?view=rev&rev=472926
Log:
* Prototyping Kerberos API: add EncryptionKey type
* Add serialization test for javax.security.auth.kerberos.KerberosKey class

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptionKey.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.golden.ser
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCReply.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java?view=diff&rev=472926&r1=472925&r2=472926
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java
Thu Nov  9 06:55:05 2006
@@ -30,6 +30,7 @@
 import javax.security.auth.DestroyFailedException;
 import javax.security.auth.Destroyable;
 
+import org.apache.harmony.auth.internal.kerberos.v5.EncryptionKey;
 import org.apache.harmony.auth.internal.nls.Messages;
 import org.apache.harmony.security.utils.Array;
 
@@ -292,19 +293,27 @@
        }
    }
 
-   // TODO: read a object from a stream
    private void readObject(ObjectInputStream s) throws IOException,
-       ClassNotFoundException {
-       s.defaultReadObject();
-   }
+            ClassNotFoundException {
 
-   // TODO: write a object to a stream
-   private void writeObject(ObjectOutputStream s) throws IOException {
-       
-       if(destroyed){
-           throw new IOException(Messages.getString("auth.48")); //$NON-NLS-1$
-       }
-       s.defaultWriteObject();
-   }
+        s.defaultReadObject();
+
+        EncryptionKey ekey = (EncryptionKey) EncryptionKey.ASN1
+                .decode((byte[]) s.readObject());
 
-}
\ No newline at end of file
+        keyType = ekey.getType();
+        keyBytes = ekey.getValue();
+    }
+
+    private void writeObject(ObjectOutputStream s) throws IOException {
+
+        if (destroyed) {
+            throw new IOException(Messages.getString("auth.48")); //$NON-NLS-1$
+        }
+        s.defaultWriteObject();
+
+        byte[] enc = EncryptionKey.ASN1.encode(new EncryptionKey(keyType,
+                keyBytes));
+        s.writeObject(enc);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptionKey.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptionKey.java?view=auto&rev=472926
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptionKey.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptionKey.java
Thu Nov  9 06:55:05 2006
@@ -0,0 +1,93 @@
+/*
+ *  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.harmony.auth.internal.kerberos.v5;
+
+import java.io.IOException;
+
+import org.apache.harmony.security.asn1.ASN1Explicit;
+import org.apache.harmony.security.asn1.ASN1Integer;
+import org.apache.harmony.security.asn1.ASN1OctetString;
+import org.apache.harmony.security.asn1.ASN1Sequence;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+
+/**
+ * Kerberos EncryptionKey type.
+ * 
+ * @see http://www.ietf.org/rfc/rfc4120.txt
+ */
+public class EncryptionKey {
+
+    private final int type;
+
+    private final byte[] value;
+
+    /**
+     * Creates EncryptionKey
+     * 
+     * @param type -
+     *            encryption type
+     * @param value -
+     *            key value
+     */
+    public EncryptionKey(int type, byte[] value) {
+        this.type = type;
+        this.value = value;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public byte[] getValue() {
+        return value;
+    }
+
+    /**
+     * ASN.1 decoder for EncryptionKey
+     * 
+     * EncryptionKey   ::= SEQUENCE {
+     *     keytype         [0] Int32 -- actually encryption type --,
+     *     keyvalue        [1] OCTET STRING
+     * }
+     */
+    public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] {
+    // TODO should we define Int32 type?
+            new ASN1Explicit(0, ASN1Integer.getInstance()), // keytype
+            new ASN1Explicit(1, ASN1OctetString.getInstance()), // keyvalue
+    }) {
+
+        @Override
+        protected Object getDecodedObject(BerInputStream in) throws IOException {
+
+            Object[] values = (Object[]) in.content;
+
+            return new EncryptionKey(ASN1Integer.toIntValue(values[0]),
+                    (byte[]) values[1]);
+        }
+
+        @Override
+        protected void getValues(Object object, Object[] values) {
+
+            EncryptionKey ekey = (EncryptionKey) object;
+
+            values[0] = ASN1Integer.fromIntValue(ekey.type);
+            values[1] = ekey.value;
+        }
+    };
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptionKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCReply.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCReply.java?view=diff&rev=472926&r1=472925&r2=472926
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCReply.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KDCReply.java
Thu Nov  9 06:55:05 2006
@@ -79,7 +79,7 @@
     private PrincipalName sname;
 
     // session key
-    private Object[] key;
+    private EncryptionKey key;
 
     private BitString flags;
 
@@ -98,7 +98,7 @@
 
         Object[] values = (Object[]) ENC_AS_REP_PART.decode(in);
 
-        this.key = (Object[]) values[0];
+        this.key = (EncryptionKey) values[0];
         flags = (BitString) values[4];
         authtime = (Date) values[5];
         starttime = (Date) values[6];
@@ -156,7 +156,7 @@
         return sname;
     }
 
-    public Object[] getKey() {
+    public EncryptionKey getKey() {
         return key;
     }
 
@@ -213,13 +213,6 @@
     public static final ASN1Explicit AS_REP_ASN1 = new ASN1Explicit(
             ASN1Constants.CLASS_APPLICATION, AS_REP, KDC_REP_ASN1);
 
-    private static final ASN1Sequence ENCRYPTION_KEY = new ASN1Sequence(
-            new ASN1Type[] {
-            // TODO should we define Int32 type?
-                    new ASN1Explicit(0, ASN1Integer.getInstance()), // keytype
-                    new ASN1Explicit(1, ASN1OctetString.getInstance()), // keyvalue
-            });
-
     private static final ASN1SequenceOf LAST_REQ = new ASN1SequenceOf(
             new ASN1Sequence(new ASN1Type[] {
             // TODO should we define Int32 type?
@@ -235,7 +228,7 @@
             });
 
     private static final ASN1Sequence ENC_KDC_REP_PART = new ASN1Sequence(
-            new ASN1Type[] { new ASN1Explicit(0, ENCRYPTION_KEY), // key
+            new ASN1Type[] { new ASN1Explicit(0, EncryptionKey.ASN1), // key
                     new ASN1Explicit(1, LAST_REQ), // last-req
                     // TODO should we define UInt32 type?
                     new ASN1Explicit(2, ASN1Integer.getInstance()), // nonce

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java?view=diff&rev=472926&r1=472925&r2=472926
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/module/Krb5LoginModule.java
Thu Nov  9 06:55:05 2006
@@ -144,8 +144,8 @@
             KerberosPrincipal server = new KerberosPrincipal(buf.toString(),
                     reply.getSname().getType());
 
-            int keyType = (int) ((byte[]) reply.getKey()[0])[0];
-            byte[] sessionKey = (byte[]) reply.getKey()[1];
+            int keyType = reply.getKey().getType();
+            byte[] sessionKey = reply.getKey().getValue();
 
             boolean[] flags = reply.getFlags().toBooleanArray();
 

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.java?view=auto&rev=472926
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.java
Thu Nov  9 06:55:05 2006
@@ -0,0 +1,76 @@
+/*
+ *  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.harmony.auth.tests.javax.security.auth.kerberos.serialization;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import javax.security.auth.kerberos.KerberosKey;
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.testframework.serialization.SerializationTest;
+import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
+
+public class KerberosKeyTest extends TestCase {
+
+    private static final KerberosPrincipal PRINCIPAL = new KerberosPrincipal(
+            "principal@apache.org");
+
+    private static final byte[] KEY_BYTES = { 0x00, 0x01, 0x02, 0x03, 0x04,
+            0x05, 0x06, 0x07 };
+
+    private static final int KEY_TYPE = 22;
+
+    private static final int VERSION_NUM = 33;
+
+    // comparator for KerberosKey objects
+    private static final SerializableAssert COMPARATOR = new SerializableAssert() {
+        public void assertDeserialized(Serializable initial,
+                Serializable deserialized) {
+
+            KerberosKey initKey = (KerberosKey) initial;
+            KerberosKey desrKey = (KerberosKey) deserialized;
+
+            assertEquals("Principal", initKey.getPrincipal(), desrKey
+                    .getPrincipal());
+            assertTrue("Bytes", Arrays.equals(initKey.getEncoded(), desrKey
+                    .getEncoded()));
+            assertEquals("Type", initKey.getKeyType(), desrKey.getKeyType());
+            assertEquals("Version", initKey.getVersionNumber(), desrKey
+                    .getVersionNumber());
+        }
+    };
+
+    /**
+     * @tests serialization/deserialization compatibility.
+     */
+    public void testSerializationSelf() throws Exception {
+        SerializationTest.verifySelf(new KerberosKey(PRINCIPAL, KEY_BYTES,
+                KEY_TYPE, VERSION_NUM), COMPARATOR);
+    }
+
+    /**
+     * @tests serialization/deserialization compatibility with RI.
+     */
+    public void testSerializationCompatibility() throws Exception {
+        SerializationTest.verifyGolden(this, new KerberosKey(PRINCIPAL,
+                KEY_BYTES, KEY_TYPE, VERSION_NUM), COMPARATOR);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.golden.ser
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.golden.ser?view=auto&rev=472926
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosKeyTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message