harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r441485 - in /incubator/harmony/enhanced/classlib/trunk/modules/auth/src: main/java/common/org/apache/harmony/auth/internal/kerberos/v5/ test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/
Date Fri, 08 Sep 2006 12:33:13 GMT
Author: smishura
Date: Fri Sep  8 05:33:12 2006
New Revision: 441485

URL: http://svn.apache.org/viewvc?view=rev&rev=441485
Log:
Prototyping Kerberos API: add EncryptedData type + regression test

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptedData.java
  (with props)
Modified:
    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/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KDCReplyTest.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptedData.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/EncryptedData.java?view=auto&rev=441485
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptedData.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptedData.java
Fri Sep  8 05:33:12 2006
@@ -0,0 +1,89 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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;
+
+/**
+ * TODO comment me
+ * 
+ * @see http://www.ietf.org/rfc/rfc4120.txt
+ */
+public class EncryptedData {
+
+    private final int etype;
+
+    private final int kvno;
+
+    private final byte[] cipher;
+
+    private EncryptedData(int etype, int kvno, byte[] cipher) {
+        this.etype = etype;
+        this.kvno = kvno;
+        this.cipher = cipher;
+    }
+
+    public int getEtype() {
+        return etype;
+    }
+
+    public int getKvno() {
+        return kvno;
+    }
+
+    public byte[] getCipher() {
+        return cipher;
+    }
+
+    //
+    // EncryptedData   ::= SEQUENCE {
+    //    etype   [0] Int32 -- EncryptionType --,
+    //    kvno    [1] UInt32 OPTIONAL,
+    //    cipher  [2] OCTET STRING -- ciphertext
+    // }
+    //
+    static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] {
+    // TODO should we define Int32 type?
+            new ASN1Explicit(0, ASN1Integer.getInstance()), // etype
+            // TODO should we define UInt32 type?
+            new ASN1Explicit(1, ASN1Integer.getInstance()), // kvno
+            // cipher
+            new ASN1Explicit(2, ASN1OctetString.getInstance()), }) {
+        {
+            setOptional(1); // kvno
+        }
+
+        protected Object getDecodedObject(BerInputStream in) throws IOException {
+
+            Object[] values = (Object[]) in.content;
+
+            return new EncryptedData(ASN1Integer.toIntValue(values[0]),
+                    ASN1Integer.toIntValue(values[1]), (byte[]) values[2]);
+        }
+
+        protected void getValues(Object object, Object[] values) {
+            throw new RuntimeException(); //FIXME message
+        }
+    };
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/EncryptedData.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=441485&r1=441484&r2=441485
==============================================================================
--- 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
Fri Sep  8 05:33:12 2006
@@ -54,12 +54,15 @@
 
     private final Ticket ticket;
 
+    private final EncryptedData encPart;
+
     private KDCReply(int msgType, String crealm, PrincipalName cname,
-            Ticket ticket) {
+            Ticket ticket, EncryptedData encPart) {
         this.msgType = msgType;
         this.cname = cname;
         this.crealm = crealm;
         this.ticket = ticket;
+        this.encPart = encPart;
     }
 
     public int getMsgtype() {
@@ -78,6 +81,10 @@
         return ticket;
     }
 
+    public EncryptedData getEncPart() {
+        return encPart;
+    }
+
     //
     // KDC-REP         ::= SEQUENCE {
     //    pvno            [0] INTEGER (5),
@@ -100,8 +107,7 @@
             new ASN1Explicit(3, ASN1StringType.GENERALSTRING), // crealm
             new ASN1Explicit(4, PrincipalName.ASN1), // cname
             new ASN1Explicit(5, Ticket.TICKET_ASN1), // ticket 
-            // FIXME ignored
-            new ASN1Explicit(6, ASN1Any.getInstance()), // enc-part 
+            new ASN1Explicit(6, EncryptedData.ASN1), // enc-part 
     }) {
         {
             setOptional(2); // padata
@@ -113,7 +119,7 @@
 
             return new KDCReply(ASN1Integer.toIntValue(values[1]),
                     (String) values[3], (PrincipalName) values[4],
-                    (Ticket) values[5]);
+                    (Ticket) values[5], (EncryptedData) values[6]);
         }
 
         protected void getValues(Object object, Object[] values) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KDCReplyTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KDCReplyTest.java?view=diff&rev=441485&r1=441484&r2=441485
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KDCReplyTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KDCReplyTest.java
Fri Sep  8 05:33:12 2006
@@ -17,9 +17,11 @@
 package org.apache.harmony.auth.tests.internal.kerberos.v5;
 
 import java.io.IOException;
+import java.util.Arrays;
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.auth.internal.kerberos.v5.EncryptedData;
 import org.apache.harmony.auth.internal.kerberos.v5.KDCReply;
 import org.apache.harmony.auth.internal.kerberos.v5.PrincipalName;
 import org.apache.harmony.auth.internal.kerberos.v5.Ticket;
@@ -35,20 +37,28 @@
         assertEquals("cname", new PrincipalName(1, new String[] { "me" }),
                 reply.getCname());
 
+        // ticket
         Ticket ticket = reply.getTicket();
         assertEquals("ticket's realm", "MY.REALM", ticket.getRealm());
         assertEquals("ticket's sname", new PrincipalName(0, new String[] {
                 "krbtgt", "MY.REALM" }), ticket.getSname());
+        
+        // enc-part
+        EncryptedData encPart = reply.getEncPart();
+        assertEquals("etype", 3, encPart.getEtype());
+        assertEquals("kvno", 1, encPart.getKvno());
+        assertTrue("cipher", Arrays.equals(new byte[] { 0x0f }, encPart
+                .getCipher()));
     }
 
     // testing array was created by hands according to RFC4120
     public static byte[] enc = new byte[] {
             // [APPLICATION 11] KDC-REP
             (byte) 0x6b,
-            (byte) 0x67,
+            (byte) 0x76,
             // KDC-REP ::= SEQUENCE 
             (byte) 0x30,
-            (byte) 0x65,
+            (byte) 0x74,
             // pvno [0] INTEGER (5)
             (byte) 0xa0,
             (byte) 0x03,
@@ -130,6 +140,13 @@
             (byte) 0xa3, (byte) 0x02, (byte) 0x00, (byte) 0x00,
 
             // enc-part [6] EncryptedData: empty for a while
-            (byte) 0xa6, (byte) 0x02, (byte) 0x00, (byte) 0x00, };
+            (byte) 0xa6, (byte) 0x11, (byte) 0x30, (byte) 0x0F,
+            // etype
+            (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x03,
+            // kvno
+            (byte) 0xA1, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x01,
+            // cipher  
+            (byte) 0xa2, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x0F,
+    };
 
 }



Mime
View raw message