harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r439142 - 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/ test/java/common/org/apache/harmony/auth/tests...
Date Fri, 01 Sep 2006 02:35:01 GMT
Author: smishura
Date: Thu Aug 31 19:35:01 2006
New Revision: 439142

URL: http://svn.apache.org/viewvc?rev=439142&view=rev
Log:
Prototyping Kerberos API: add KerberosTime and KerberosErrorMessage types

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosErrorMessage.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosTime.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KerberosErrorMessageTest.java
  (with props)

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosErrorMessage.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/KerberosErrorMessage.java?rev=439142&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosErrorMessage.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosErrorMessage.java
Thu Aug 31 19:35:01 2006
@@ -0,0 +1,170 @@
+/*
+ *  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 java.util.Date;
+
+import org.apache.harmony.security.asn1.ASN1Any;
+import org.apache.harmony.security.asn1.ASN1Constants;
+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.ASN1StringType;
+import org.apache.harmony.security.asn1.ASN1Type;
+import org.apache.harmony.security.asn1.BerInputStream;
+import org.apache.harmony.security.asn1.DerInputStream;
+
+/**
+ * Kerberos Error Message type.
+ * 
+ * @see http://www.ietf.org/rfc/rfc4120.txt
+ */
+public class KerberosErrorMessage {
+
+    private Date ctime;
+
+    private int cusec;
+
+    private Date stime;
+
+    private int susec;
+
+    private int errorCode;
+
+    private String crealm;
+
+    private PrincipalName cname;
+
+    private String realm;
+
+    private PrincipalName sname;
+
+    private String etext;
+    
+    public KerberosErrorMessage() {
+    }
+
+    public static KerberosErrorMessage decode(DerInputStream in)
+            throws IOException {
+
+        return (KerberosErrorMessage) ASN1.decode(in);
+    }
+
+    public Date getCtime() {
+        return ctime;
+    }
+
+    public int getCusec() {
+        return cusec;
+    }
+
+    public Date getStime() {
+        return stime;
+    }
+
+    public int getSusec() {
+        return susec;
+    }
+
+    public int getErrorCode() {
+        return errorCode;
+    }
+
+    public String getCrealm() {
+        return crealm;
+    }
+
+    public PrincipalName getCname() {
+        return cname;
+    }
+
+    public String getRealm() {
+        return realm;
+    }
+
+    public PrincipalName getSname() {
+        return sname;
+    }
+
+    public String getEtext() {
+        return etext;
+    }
+
+    private static final ASN1Sequence KRB_ERROR = new ASN1Sequence(
+            new ASN1Type[] { new ASN1Explicit(0, ASN1Any.getInstance()), // TODO:ignored
+                    new ASN1Explicit(1, ASN1Any.getInstance()), // TODO: ignored
+                    new ASN1Explicit(2, KerberosTime.getASN1()),// ctime
+                    // TODO should we define Microseconds type?
+                    new ASN1Explicit(3, ASN1Integer.getInstance()), // cusec
+                    new ASN1Explicit(4, KerberosTime.getASN1()),// stime
+                    // TODO should we define Microseconds type?
+                    new ASN1Explicit(5, ASN1Integer.getInstance()), // susec
+                    // TODO should we define Int32 type?
+                    new ASN1Explicit(6, ASN1Integer.getInstance()),// error-code
+                    // TODO should we define Realm type?
+                    new ASN1Explicit(7, ASN1StringType.GENERALSTRING),// crealm
+                    new ASN1Explicit(8, PrincipalName.ASN1),// cname
+                    // TODO should we define Realm type?
+                    new ASN1Explicit(9, ASN1StringType.GENERALSTRING),// realm
+                    new ASN1Explicit(10, PrincipalName.ASN1),// sname
+                    // TODO should we define KerberosString type?
+                    new ASN1Explicit(11, ASN1StringType.GENERALSTRING),// e-text
+                    // TODO: ignored
+                    new ASN1Explicit(12, ASN1OctetString.getInstance()),// e-data
+            }) {
+        {
+            setOptional(2);// ctime
+            setOptional(3);// cusec
+            setOptional(7);// crealm
+            setOptional(8);// cname
+            setOptional(11);// e-text
+            setOptional(12);// e-data
+        }
+
+        protected Object getDecodedObject(BerInputStream in) throws IOException {
+
+            Object[] values = (Object[]) in.content;
+
+            KerberosErrorMessage message = new KerberosErrorMessage();
+
+            message.ctime = (Date) values[2];
+            if (values[3] != null) {
+                message.cusec = ASN1Integer.toIntValue(values[3]);
+            }
+            message.stime = (Date) values[4];
+            message.susec = ASN1Integer.toIntValue(values[5]);
+            message.errorCode = ASN1Integer.toIntValue(values[6]);
+            message.crealm = (String) values[7];
+            message.cname = (PrincipalName) values[8];
+            message.realm = (String) values[9];
+            message.sname = (PrincipalName) values[10];
+            message.etext = (String) values[11];
+
+            return message;
+        }
+
+        protected void getValues(Object object, Object[] values) {
+            throw new RuntimeException(
+                    "KerberosErrorMessage encoder is not implemented");
+        }
+    };
+
+    private static final ASN1Explicit ASN1 = new ASN1Explicit(
+            ASN1Constants.CLASS_APPLICATION, 30, KRB_ERROR);
+}

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

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosTime.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/KerberosTime.java?rev=439142&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosTime.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KerberosTime.java
Thu Aug 31 19:35:01 2006
@@ -0,0 +1,44 @@
+/*
+ *  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 org.apache.harmony.security.asn1.ASN1GeneralizedTime;
+import org.apache.harmony.security.asn1.ASN1Type;
+
+/**
+ * KerberosTime type.
+ * 
+ * @see http://www.ietf.org/rfc/rfc4120.txt
+ */
+public class KerberosTime {
+
+    private KerberosTime() {
+    }
+
+    // TODO: should we create encoder that handles fractional seconds?
+    private static final ASN1GeneralizedTime ASN1 = ASN1GeneralizedTime
+            .getInstance();
+
+    /**
+     * KerberosTime is defined as GeneralizedTime with no fractional seconds
+     * 
+     * @return ASN.1 decoder/encoder for KerberosTime
+     */
+    public static ASN1Type getASN1() {
+        return ASN1;
+    }
+}

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

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KerberosErrorMessageTest.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/KerberosErrorMessageTest.java?rev=439142&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KerberosErrorMessageTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/internal/kerberos/v5/KerberosErrorMessageTest.java
Thu Aug 31 19:35:01 2006
@@ -0,0 +1,281 @@
+/*
+ *  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.tests.internal.kerberos.v5;
+
+import java.io.IOException;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.auth.internal.kerberos.v5.KerberosErrorMessage;
+import org.apache.harmony.auth.internal.kerberos.v5.PrincipalName;
+import org.apache.harmony.security.asn1.DerInputStream;
+
+public class KerberosErrorMessageTest extends TestCase {
+
+    public void test_Ctor() throws IOException {
+
+        KerberosErrorMessage message = KerberosErrorMessage
+                .decode(new DerInputStream(err_resp));
+
+        assertEquals("ctime", new Date(1000), message.getCtime());
+        assertEquals("cusec", 65536, message.getCusec());
+
+        assertEquals("stime", new Date(0), message.getStime());
+        assertEquals("susec", 65793, message.getSusec());
+
+        assertEquals("error-code", 6, message.getErrorCode());
+
+        assertEquals("crealm", "MY.REALM", message.getCrealm());
+        assertEquals("cname", new PrincipalName(PrincipalName.NT_PRINCIPAL,
+                new String[] { "no_such_user" }), message.getCname());
+
+        assertEquals("realm", "MY.REALM", message.getRealm());
+        assertEquals("sname", new PrincipalName(PrincipalName.NT_UNKNOWN,
+                new String[] { "krbtgt", "MY.REALM" }), message.getSname());
+
+        assertEquals("etext", "e_text_string", message.getEtext());
+    }
+
+    // testing array was created by hands according to RFC4120
+    private static byte[] err_resp = new byte[] {
+    // KRB-ERROR ::= [APPLICATION 30]
+            (byte) 0x7e,
+            (byte) 0x81,
+            (byte) 0xA9,
+
+            // SEQUENCE
+            (byte) 0x30,
+            (byte) 0x81,
+            (byte) 0xA6,
+
+            // pvno [0] INTEGER (5)
+            (byte) 0xa0,
+            (byte) 0x03,
+            //
+            (byte) 0x02,
+            (byte) 0x01,
+            (byte) 0x05,
+
+            // msg-type [1] INTEGER (30)
+            (byte) 0xA1,
+            (byte) 0x03,
+            //
+            (byte) 0x02,
+            (byte) 0x01,
+            (byte) 0x1e,
+
+            // ctime [2] KerberosTime OPTIONAL,
+            (byte) 0xA2,
+            (byte) 0x11,
+            //
+            (byte) 0x18,
+            (byte) 0x0f,
+            (byte) 0x31,
+            (byte) 0x39,
+            (byte) 0x37,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x31,
+            (byte) 0x30,
+            (byte) 0x31,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x31,
+            (byte) 0x5A,
+
+            // cusec [3] Microseconds OPTIONAL,
+            (byte) 0xA3,
+            (byte) 0x05,
+            //
+            (byte) 0x02,
+            (byte) 0x03,
+            (byte) 0x01,
+            (byte) 0x00,
+            (byte) 0x00,
+
+            // stime [4] KerberosTime,
+            (byte) 0xA4,
+            (byte) 0x11,
+            //
+            (byte) 0x18,
+            (byte) 0x0f,
+            (byte) 0x31,
+            (byte) 0x39,
+            (byte) 0x37,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x31,
+            (byte) 0x30,
+            (byte) 0x31,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x30,
+            (byte) 0x5A,
+
+            // susec [5] Microseconds
+            (byte) 0xa5,
+            (byte) 0x05,
+            //
+            (byte) 0x02,
+            (byte) 0x03,
+            (byte) 0x01,
+            (byte) 0x01,
+            (byte) 0x01,
+
+            // error-code [6] Int32
+            (byte) 0xa6,
+            (byte) 0x03,
+            //
+            (byte) 0x02,
+            (byte) 0x01,
+            (byte) 0x06,
+
+            // crealm [7] Realm OPTIONAL
+            (byte) 0xa7,
+            (byte) 0x0a,
+            //
+            (byte) 0x1b,
+            (byte) 0x08,
+            (byte) 0x4d,
+            (byte) 0x59,
+            (byte) 0x2e,
+            (byte) 0x52,
+            (byte) 0x45,
+            (byte) 0x41,
+            (byte) 0x4c,
+            (byte) 0x4d,
+
+            // cname [8] PrincipalName OPTIONAL
+            (byte) 0xa8,
+            (byte) 0x19,
+            // SEQUENCE
+            (byte) 0x30,
+            (byte) 0x17,
+            // name-type
+            (byte) 0xa0,
+            (byte) 0x03,
+            //
+            (byte) 0x02,
+            (byte) 0x01,
+            (byte) 0x01,
+            // name-string
+            (byte) 0xa1,
+            (byte) 0x10,
+            // SEQUENCE OF
+            (byte) 0x30,
+            (byte) 0x0e,
+            // 1-st string
+            (byte) 0x1b,
+            (byte) 0x0c,
+            (byte) 0x6e,
+            (byte) 0x6f,
+            (byte) 0x5f,
+            (byte) 0x73,
+            (byte) 0x75,
+            (byte) 0x63,
+            (byte) 0x68,
+            (byte) 0x5f,
+            (byte) 0x75,
+            (byte) 0x73,
+            (byte) 0x65,
+            (byte) 0x72,
+
+            // realm [9] Realm -- service realm --,
+            (byte) 0xa9,
+            (byte) 0x0a,
+            //
+            (byte) 0x1b,
+            (byte) 0x08,
+            (byte) 0x4d,
+            (byte) 0x59,
+            (byte) 0x2e,
+            (byte) 0x52,
+            (byte) 0x45,
+            (byte) 0x41,
+            (byte) 0x4c,
+            (byte) 0x4d,
+
+            // sname [10] PrincipalName -- service name --,
+            (byte) 0xaa,
+            (byte) 0x1d,
+            // SEQUENCE
+            (byte) 0x30,
+            (byte) 0x1b,
+            // name-type
+            (byte) 0xa0,
+            (byte) 0x03,
+            //
+            (byte) 0x02,
+            (byte) 0x01,
+            (byte) 0x00,
+            // name-string
+            (byte) 0xa1,
+            (byte) 0x14,
+            // SEQUENCE OF
+            (byte) 0x30,
+            (byte) 0x12,
+            // 1-st string
+            (byte) 0x1b,
+            (byte) 0x06,
+            (byte) 0x6b,
+            (byte) 0x72,
+            (byte) 0x62,
+            (byte) 0x74,
+            (byte) 0x67,
+            (byte) 0x74,
+            // 2-nd string
+            (byte) 0x1b,
+            (byte) 0x08,
+            (byte) 0x4d,
+            (byte) 0x59,
+            (byte) 0x2e,
+            (byte) 0x52,
+            (byte) 0x45,
+            (byte) 0x41,
+            (byte) 0x4c,
+            (byte) 0x4d,
+
+            // e-text [11] KerberosString OPTIONAL
+            (byte) 0xab,
+            (byte) 0x0f,
+            (byte) 0x1b,
+            (byte) 0x0d,
+            (byte) 0x65,
+            (byte) 0x5f,
+            (byte) 0x74,
+            (byte) 0x65,
+            (byte) 0x78,
+            (byte) 0x74,
+            (byte) 0x5f,
+            (byte) 0x73,
+            (byte) 0x74,
+            (byte) 0x72,
+            (byte) 0x69,
+            (byte) 0x6e,
+            (byte) 0x67,
+
+    // e-data [12] OCTET STRING OPTIONAL: TODO add me for testing
+    };
+
+}

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



Mime
View raw message