You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dr...@apache.org on 2015/01/22 01:56:50 UTC

[26/50] [abbrv] directory-kerberos git commit: Many changes with newname

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/asreq.token
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/asreq.token b/kerby-kerb/kerb-core-test/src/main/resources/asreq.token
new file mode 100644
index 0000000..6d503b3
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/asreq.token differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/des-kerberos-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/des-kerberos-data b/kerby-kerb/kerb-core-test/src/main/resources/des-kerberos-data
new file mode 100644
index 0000000..3db6963
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/des-kerberos-data differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/des-key-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/des-key-data b/kerby-kerb/kerb-core-test/src/main/resources/des-key-data
new file mode 100644
index 0000000..84a0c50
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/main/resources/des-key-data
@@ -0,0 +1 @@
+��2^�L�
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/des-pac-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/des-pac-data b/kerby-kerb/kerb-core-test/src/main/resources/des-pac-data
new file mode 100644
index 0000000..7408111
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/des-pac-data differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/des-spnego-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/des-spnego-data b/kerby-kerb/kerb-core-test/src/main/resources/des-spnego-data
new file mode 100644
index 0000000..04a56e8
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/des-spnego-data differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/exceptions.properties
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/exceptions.properties b/kerby-kerb/kerb-core-test/src/main/resources/exceptions.properties
new file mode 100644
index 0000000..c9cc814
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/main/resources/exceptions.properties
@@ -0,0 +1,55 @@
+# 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.
+object.cast.fail=Unable to cast object from {0} to {1}.
+
+spnego.token.empty=Empty SPNego token.
+spnego.token.invalid=Not a valid SPNego token: {0}.
+spnego.token.malformed=Malformed SPNego token.
+spnego.field.invalid=Not a valid SPNego token field: {0}.
+
+
+kerberos.object.cast=Unable to cast Kerberos object from {0} to {1}.
+kerberos.token.empty=Empty Kerberos token.
+kerberos.token.invalid=Not a Kerberos token.
+kerberos.token.malformed=Malformed Kerberos token.
+kerberos.kdcReq.empty=Empty message.
+kerberos.kdcReq.invalid=Not a KRB_AP_REQ message.
+kerberos.ticket.empty=Empty Kerberos ticket.
+kerberos.ticket.invalid=Not a Kerberos v5 ticket.
+kerberos.ticket.malformed=Malformed Kerberos ticket.
+kerberos.field.invalid=Not a valid Kerberos ticket field: {0}.
+kerberos.field.malformed=Malformed Kerberos ticket field.
+kerberos.key.notfound=Unable to find appropriate key of type {0}.
+kerberos.version.invalid=Invalid version of Kerberos ticket: {0}.
+kerberos.login.fail=Unable to get server keys.
+kerberos.decrypt.fail=Unable to decrypt encrypted data using key of type {0}.
+
+pac.token.empty=Empty PAC token.
+pac.token.malformed=Malformed PAC token.
+pac.logoninfo.malformed=Malformed PAC logon info.
+pac.signature.malformed=Malformed PAC signature.
+pac.signature.invalid=Invalid PAC signature.
+pac.string.notempty=String not empty while expected null.
+pac.string.malformed.size=Inconsistent string lengths.
+pac.string.invalid.size=Inconsistent string size: {1}, expecting {0}.
+pac.groups.invalid.size=Group count ({0}) doesn't match the real number of groups ({1}) in the PAC.
+pac.extrasids.invalid.size=Extra SID count ({0}) doesn't match the real number of extra SID ({1}) in the PAC.
+pac.resourcegroups.invalid.size=Resource group count ({0}) doesn't match the real number of resource groups ({1}) in the PAC.
+pac.sid.malformed.size=Inconsistent SID length.
+pac.subauthority.malformed.size=Incorrect byte array length: {0}; must be multiple of 4.
+pac.version.invalid=Invalid version of PAC token: {0}.
+pac.check.fail=Unable to check PAC signature.

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/rc4-kerberos-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/rc4-kerberos-data b/kerby-kerb/kerb-core-test/src/main/resources/rc4-kerberos-data
new file mode 100644
index 0000000..6be7086
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/rc4-kerberos-data differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/rc4-key-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/rc4-key-data b/kerby-kerb/kerb-core-test/src/main/resources/rc4-key-data
new file mode 100644
index 0000000..64f9d9c
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/main/resources/rc4-key-data
@@ -0,0 +1 @@
+l�܇y#�l�mv��k�
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/rc4-pac-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/rc4-pac-data b/kerby-kerb/kerb-core-test/src/main/resources/rc4-pac-data
new file mode 100644
index 0000000..df45f91
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/rc4-pac-data differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/rc4-spnego-data
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/rc4-spnego-data b/kerby-kerb/kerb-core-test/src/main/resources/rc4-spnego-data
new file mode 100644
index 0000000..91cbe26
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/rc4-spnego-data differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/server.keytab
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/server.keytab b/kerby-kerb/kerb-core-test/src/main/resources/server.keytab
new file mode 100644
index 0000000..b44347c
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/server.keytab differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/tgsrep.token
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/tgsrep.token b/kerby-kerb/kerb-core-test/src/main/resources/tgsrep.token
new file mode 100644
index 0000000..25d6270
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/tgsrep.token differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/main/resources/tgsreq.token
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/main/resources/tgsreq.token b/kerby-kerb/kerb-core-test/src/main/resources/tgsreq.token
new file mode 100644
index 0000000..69f6b46
Binary files /dev/null and b/kerby-kerb/kerb-core-test/src/main/resources/tgsreq.token differ

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/README.txt
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/README.txt b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/README.txt
new file mode 100644
index 0000000..f1e0a3f
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/README.txt
@@ -0,0 +1,5 @@
+This project is simple for integration testing purpose. It's inspired by and originated from JaasLaunge.
+Eventually I will replace most of the codes by mine or get the granting permission of the author.
+
+http://jaaslounge.sourceforge.net/
+

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/AuthzDataUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/AuthzDataUtil.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/AuthzDataUtil.java
new file mode 100644
index 0000000..fce9bb4
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/AuthzDataUtil.java
@@ -0,0 +1,67 @@
+/**
+ *  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.kerberos.kerb.codec.kerberos;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.codec.pac.Pac;
+import org.apache.kerby.kerberos.kerb.spec.common.AuthorizationData;
+import org.apache.kerby.kerberos.kerb.spec.common.AuthorizationDataEntry;
+import org.apache.kerby.kerberos.kerb.spec.common.AuthorizationType;
+
+import java.io.IOException;
+import java.util.List;
+
+public class AuthzDataUtil {
+
+    public static Pac getPac(AuthorizationData authzData, byte[] serverKey) throws IOException, KrbException {
+        AuthorizationDataEntry ifRelevantAd = null;
+        for (AuthorizationDataEntry entry : authzData.getElements()) {
+            if (entry.getAuthzType() == AuthorizationType.AD_IF_RELEVANT) {
+                ifRelevantAd = entry;
+                break;
+            }
+        }
+
+        if (ifRelevantAd != null) {
+            List<AuthorizationDataEntry> entries = decode(ifRelevantAd);
+            for (AuthorizationDataEntry entry : entries) {
+                if (entry.getAuthzType() == AuthorizationType.AD_WIN2K_PAC) {
+                    return decodeAsPac(entry, serverKey);
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static List<AuthorizationDataEntry> decode(AuthorizationDataEntry entry) throws IOException {
+        AuthorizationData authzData = new AuthorizationData();
+        authzData.decode(entry.getAuthzData());
+        return authzData.getElements();
+    }
+
+    public static Pac decodeAsPac(AuthorizationDataEntry entry, byte[] key) throws IOException, KrbException {
+        if (entry.getAuthzType() != AuthorizationType.AD_WIN2K_PAC) {
+            throw new IllegalArgumentException("Not AD_WIN2K_PAC type: " + entry.getAuthzType().name());
+        }
+
+        return new Pac(entry.getAuthzData(), key);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosApRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosApRequest.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosApRequest.java
new file mode 100644
index 0000000..4266ea6
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosApRequest.java
@@ -0,0 +1,51 @@
+/**
+ *  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.kerberos.kerb.codec.kerberos;
+
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.codec.KrbCodec;
+import org.apache.kerby.kerberos.kerb.spec.ap.ApOptions;
+import org.apache.kerby.kerberos.kerb.spec.ap.ApReq;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+
+import java.io.IOException;
+
+public class KerberosApRequest {
+    private ApReq apReq;
+    private KerberosTicket ticket;
+
+    public KerberosApRequest(byte[] token, EncryptionKey key) throws Exception {
+        if(token.length <= 0) {
+            throw new IOException("kerberos request empty");
+        }
+
+        apReq = KrbCodec.decode(token, ApReq.class);
+        ticket = new KerberosTicket(apReq.getTicket(), apReq.getApOptions(), key);
+    }
+
+    public ApOptions getApOptions() throws KrbException {
+        return apReq.getApOptions();
+    }
+
+    public KerberosTicket getTicket() {
+        return ticket;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosConstants.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosConstants.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosConstants.java
new file mode 100644
index 0000000..a02cda3
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosConstants.java
@@ -0,0 +1,44 @@
+/**
+ *  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.kerberos.kerb.codec.kerberos;
+
+public interface KerberosConstants {
+
+    static final String KERBEROS_OID = "1.2.840.113554.1.2.2";
+    static final String KERBEROS_VERSION = "5";
+
+    static final String KERBEROS_AP_REQ = "14";
+    
+    static final int AF_INTERNET = 2;
+    static final int AF_CHANET = 5;
+    static final int AF_XNS = 6;
+    static final int AF_ISO = 7;
+    
+    static final int AUTH_DATA_RELEVANT = 1;
+    static final int AUTH_DATA_PAC = 128;
+
+    static final int DES_ENC_TYPE = 3;
+    static final int RC4_ENC_TYPE = 23;
+    static final String RC4_ALGORITHM = "ARCFOUR";
+    static final String HMAC_ALGORITHM = "HmacMD5";
+    static final int CONFOUNDER_SIZE = 8;
+    static final int CHECKSUM_SIZE = 16;
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosCredentials.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosCredentials.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosCredentials.java
new file mode 100644
index 0000000..087fe42
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosCredentials.java
@@ -0,0 +1,55 @@
+/**
+ *  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.kerberos.kerb.codec.kerberos;
+
+import org.apache.kerby.kerberos.kerb.keytab.Keytab;
+import org.apache.kerby.kerberos.kerb.keytab.KeytabEntry;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionType;
+import org.apache.kerby.kerberos.kerb.spec.common.PrincipalName;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class KerberosCredentials {
+
+    private static Keytab keytab;
+
+    private static void init() throws IOException {
+        InputStream kis = KerberosCredentials.class.getResourceAsStream("/server.keytab");
+        keytab = new Keytab();
+        keytab.load(kis);
+    }
+
+    public static EncryptionKey getServerKey(EncryptionType etype) throws IOException {
+        if (keytab == null) {
+            init();
+        }
+
+        for (PrincipalName principal : keytab.getPrincipals()) {
+            for (KeytabEntry entry : keytab.getKeytabEntries(principal)) {
+                if (entry.getKey().getKeyType() == etype) {
+                    return entry.getKey();
+                }
+            }
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosTicket.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosTicket.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosTicket.java
new file mode 100644
index 0000000..a47f0ef
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosTicket.java
@@ -0,0 +1,86 @@
+/**
+ *  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.kerberos.kerb.codec.kerberos;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.codec.KrbCodec;
+import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
+import org.apache.kerby.kerberos.kerb.spec.ap.ApOptions;
+import org.apache.kerby.kerberos.kerb.spec.common.AuthorizationData;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptedData;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.common.KeyUsage;
+import org.apache.kerby.kerberos.kerb.spec.ticket.EncTicketPart;
+import org.apache.kerby.kerberos.kerb.spec.ticket.Ticket;
+
+import java.util.Arrays;
+
+public class KerberosTicket {
+    private String serverPrincipalName;
+    private String serverRealm;
+    private Ticket ticket;
+
+    public KerberosTicket(Ticket ticket, ApOptions apOptions, EncryptionKey key)
+            throws Exception {
+        this.ticket = ticket;
+
+        byte[] decrypted = EncryptionHandler.decrypt(
+                ticket.getEncryptedEncPart(), key, KeyUsage.KDC_REP_TICKET);
+
+        EncTicketPart encPart = KrbCodec.decode(decrypted, EncTicketPart.class);
+        ticket.setEncPart(encPart);
+
+        /**
+         * Also test encryption by the way
+         */
+        EncryptedData encrypted = EncryptionHandler.encrypt(
+                decrypted, key, KeyUsage.KDC_REP_TICKET);
+
+        byte[] decrypted2 = EncryptionHandler.decrypt(
+                encrypted, key, KeyUsage.KDC_REP_TICKET);
+        if (!Arrays.equals(decrypted, decrypted2)) {
+            throw new KrbException("Encryption checking failed after decryption");
+        }
+    }
+
+    public String getUserPrincipalName() throws KrbException {
+        return ticket.getEncPart().getCname().getName();
+    }
+
+    public String getUserRealm() throws KrbException {
+        return ticket.getEncPart().getCrealm();
+    }
+
+    public String getServerPrincipalName() throws KrbException {
+        return ticket.getSname().getName();
+    }
+
+    public String getServerRealm() throws KrbException {
+        return ticket.getRealm();
+    }
+
+    public AuthorizationData getAuthorizationData() throws KrbException {
+        return ticket.getEncPart().getAuthorizationData();
+    }
+
+    public Ticket getTicket() {
+        return ticket;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosToken.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosToken.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosToken.java
new file mode 100644
index 0000000..f3488c3
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/kerberos/KerberosToken.java
@@ -0,0 +1,58 @@
+/**
+ *  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.kerberos.kerb.codec.kerberos;
+
+import org.apache.kerby.asn1.Asn1InputBuffer;
+import org.apache.kerby.asn1.type.Asn1Item;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+
+import java.io.IOException;
+
+public class KerberosToken {
+
+    private KerberosApRequest apRequest;
+
+    public KerberosToken(byte[] token) throws Exception {
+        this(token, null);
+    }
+
+    public KerberosToken(byte[] token, EncryptionKey key) throws Exception {
+
+        if(token.length <= 0)
+            throw new IOException("kerberos.token.empty");
+
+        Asn1InputBuffer buffer = new Asn1InputBuffer(token);
+
+        Asn1Item value = (Asn1Item) buffer.read();
+        if(! value.isAppSpecific() && ! value.isConstructed())
+            throw new IOException("kerberos.token.malformed");
+
+        buffer = new Asn1InputBuffer(value.getBodyContent());
+        buffer.skipNext();
+
+        buffer.skipBytes(2);
+
+        apRequest = new KerberosApRequest(buffer.readAllLeftBytes(), key);
+    }
+
+    public KerberosApRequest getApRequest() {
+        return apRequest;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/Pac.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/Pac.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/Pac.java
new file mode 100644
index 0000000..9a3d0e0
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/Pac.java
@@ -0,0 +1,113 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.crypto.CheckSumHandler;
+import org.apache.kerby.kerberos.kerb.spec.common.CheckSum;
+import org.apache.kerby.kerberos.kerb.spec.common.KeyUsage;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+public class Pac {
+
+    private PacLogonInfo logonInfo;
+    private PacCredentialType credentialType;
+    private PacSignature serverSignature;
+    private PacSignature kdcSignature;
+
+    public Pac(byte[] data, byte[] key) throws KrbException {
+        byte[] checksumData = data.clone();
+        try {
+            PacDataInputStream pacStream = new PacDataInputStream(new DataInputStream(
+                    new ByteArrayInputStream(data)));
+
+            if(data.length <= 8)
+                throw new IOException("pac.token.empty");
+
+            int bufferCount = pacStream.readInt();
+            int version = pacStream.readInt();
+
+            if(version != PacConstants.PAC_VERSION) {
+                Object[] args = new Object[]{version};
+                throw new IOException("pac.version.invalid");
+            }
+
+            for(int bufferIndex = 0; bufferIndex < bufferCount; bufferIndex++) {
+                int bufferType = pacStream.readInt();
+                int bufferSize = pacStream.readInt();
+                long bufferOffset = pacStream.readLong();
+                byte[] bufferData = new byte[bufferSize];
+                System.arraycopy(data, (int)bufferOffset, bufferData, 0, bufferSize);
+
+                switch (bufferType) {
+                case PacConstants.LOGON_INFO:
+                    // PAC Credential Information
+                    logonInfo = new PacLogonInfo(bufferData);
+                    break;
+                case PacConstants.CREDENTIAL_TYPE:
+                    // PAC Credential Type
+                    credentialType = new PacCredentialType(bufferData);
+                    break;
+                case PacConstants.SERVER_CHECKSUM:
+                    // PAC Server Signature
+                    serverSignature = new PacSignature(bufferData);
+                    // Clear signature from checksum copy
+                    for(int i = 0; i < bufferSize; i++)
+                        checksumData[(int)bufferOffset + 4 + i] = 0;
+                    break;
+                case PacConstants.PRIVSVR_CHECKSUM:
+                    // PAC KDC Signature
+                    kdcSignature = new PacSignature(bufferData);
+                    // Clear signature from checksum copy
+                    for(int i = 0; i < bufferSize; i++)
+                        checksumData[(int)bufferOffset + 4 + i] = 0;
+                    break;
+                default:
+                }
+            }
+        } catch(IOException e) {
+            throw new KrbException("pac.token.malformed", e);
+        }
+
+        CheckSum checksum = new CheckSum(serverSignature.getType(), serverSignature.getChecksum());
+        if (! CheckSumHandler.verifyWithKey(checksum, checksumData, key, KeyUsage.APP_DATA_CKSUM)) {
+            throw new KrbException("Check sum verifying failed");
+        }
+    }
+
+    public PacLogonInfo getLogonInfo() {
+        return logonInfo;
+    }
+
+    public PacCredentialType getCredentialType() {
+        return credentialType;
+    }
+
+    public PacSignature getServerSignature() {
+        return serverSignature;
+    }
+
+    public PacSignature getKdcSignature() {
+        return kdcSignature;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacConstants.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacConstants.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacConstants.java
new file mode 100644
index 0000000..3aea971
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacConstants.java
@@ -0,0 +1,39 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+public interface PacConstants {
+
+    static final int PAC_VERSION = 0;
+
+    static final int LOGON_INFO = 1;
+    static final int CREDENTIAL_TYPE = 2;
+    static final int SERVER_CHECKSUM = 6;
+    static final int PRIVSVR_CHECKSUM = 7;
+
+    static final int LOGON_EXTRA_SIDS = 0x20;
+    static final int LOGON_RESOURCE_GROUPS = 0x200;
+
+    static final long FILETIME_BASE = -11644473600000L;
+
+    static final int MD5_KRB_SALT = 17;
+    static final int MD5_BLOCK_LENGTH = 64;
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacCredentialType.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacCredentialType.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacCredentialType.java
new file mode 100644
index 0000000..9e395f2
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacCredentialType.java
@@ -0,0 +1,41 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+import java.io.IOException;
+
+public class PacCredentialType {
+
+    private static final int MINIMAL_BUFFER_SIZE = 32;
+
+    private byte[] credentialType;
+
+    public PacCredentialType(byte[] data) throws IOException {
+        credentialType = data;
+        if(!isCredentialTypeCorrect()) {
+            throw new IOException("pac.credentialtype.malformed");
+        }
+    }
+
+    public boolean isCredentialTypeCorrect() {
+        return credentialType != null && credentialType.length < MINIMAL_BUFFER_SIZE;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacDataInputStream.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacDataInputStream.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacDataInputStream.java
new file mode 100644
index 0000000..74e21db
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacDataInputStream.java
@@ -0,0 +1,158 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.util.Date;
+
+public class PacDataInputStream {
+
+    private DataInputStream dis;
+    private int size;
+
+    public PacDataInputStream(InputStream in) throws IOException {
+        dis = new DataInputStream(in);
+        size = in.available();
+    }
+
+    public void align(int mask) throws IOException {
+        int position = size - dis.available();
+        int shift = position & mask - 1;
+        if(mask != 0 && shift != 0)
+            dis.skip(mask - shift);
+    }
+
+    public int available() throws IOException {
+        return dis.available();
+    }
+
+    public void readFully(byte[] b) throws IOException {
+        dis.readFully(b);
+    }
+
+    public void readFully(byte[] b, int off, int len) throws IOException {
+        dis.readFully(b, off, len);
+    }
+
+    public char readChar() throws IOException {
+        align(2);
+        return dis.readChar();
+    }
+
+    public byte readByte() throws IOException {
+        return dis.readByte();
+    }
+
+    public short readShort() throws IOException {
+        align(2);
+        return Short.reverseBytes((short)dis.readShort());
+    }
+
+    public int readInt() throws IOException {
+        align(4);
+        return Integer.reverseBytes(dis.readInt());
+    }
+
+    public long readLong() throws IOException {
+        align(8);
+        return Long.reverseBytes(dis.readLong());
+    }
+
+    public int readUnsignedByte() throws IOException {
+        return ((int)readByte()) & 0xff;
+    }
+
+    public long readUnsignedInt() throws IOException {
+        return ((long)readInt()) & 0xffffffffL;
+    }
+
+    public int readUnsignedShort() throws IOException {
+        return ((int)readShort()) & 0xffff;
+    }
+
+    public Date readFiletime() throws IOException {
+        Date date = null;
+
+        long last = readUnsignedInt();
+        long first = readUnsignedInt();
+        if(first != 0x7fffffffL && last != 0xffffffffL) {
+            BigInteger lastBigInt = BigInteger.valueOf(last);
+            BigInteger firstBigInt = BigInteger.valueOf(first);
+            BigInteger completeBigInt = lastBigInt.add(firstBigInt.shiftLeft(32));
+            completeBigInt = completeBigInt.divide(BigInteger.valueOf(10000L));
+            completeBigInt = completeBigInt.add(BigInteger.valueOf(PacConstants.FILETIME_BASE));
+            date = new Date(completeBigInt.longValue());
+        }
+
+        return date;
+    }
+
+    public PacUnicodeString readUnicodeString() throws IOException {
+        short length = readShort();
+        short maxLength = readShort();
+        int pointer = readInt();
+
+        if(maxLength < length) {
+            throw new IOException("pac.string.malformed.size");
+        }
+
+        return new PacUnicodeString(length, maxLength, pointer);
+    }
+
+    public String readString() throws IOException {
+        int totalChars = readInt();
+        int unusedChars = readInt();
+        int usedChars = readInt();
+
+        if(unusedChars > totalChars || usedChars > totalChars - unusedChars)
+            throw new IOException("pac.string.malformed.size");
+
+        dis.skip(unusedChars * 2);
+        char[] chars = new char[usedChars];
+        for(int l = 0; l < usedChars; l++)
+            chars[l] = (char)readShort();
+
+        return new String(chars);
+    }
+
+    public PacSid readId() throws IOException {
+        byte[] bytes = new byte[4];
+        readFully(bytes);
+
+        return PacSid.createFromSubs(bytes);
+    }
+
+    public PacSid readSid() throws IOException {
+        int sidSize = readInt();
+
+        byte[] bytes = new byte[8 + sidSize * 4];
+        readFully(bytes);
+
+        return new PacSid(bytes);
+    }
+
+    public int skipBytes(int n) throws IOException {
+        return dis.skipBytes(n);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacGroup.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacGroup.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacGroup.java
new file mode 100644
index 0000000..a3d9bb5
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacGroup.java
@@ -0,0 +1,41 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+public class PacGroup {
+
+    private PacSid id;
+    private int attributes;
+
+    public PacGroup(PacSid id, int attributes) {
+        super();
+        this.id = id;
+        this.attributes = attributes;
+    }
+
+    public PacSid getId() {
+        return id;
+    }
+
+    public int getAttributes() {
+        return attributes;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacLogonInfo.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacLogonInfo.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacLogonInfo.java
new file mode 100644
index 0000000..8b98753
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacLogonInfo.java
@@ -0,0 +1,322 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.util.Date;
+
+public class PacLogonInfo {
+
+    private Date logonTime;
+    private Date logoffTime;
+    private Date kickOffTime;
+    private Date pwdLastChangeTime;
+    private Date pwdCanChangeTime;
+    private Date pwdMustChangeTime;
+    private short logonCount;
+    private short badPasswordCount;
+    private String userName;
+    private String userDisplayName;
+    private String logonScript;
+    private String profilePath;
+    private String homeDirectory;
+    private String homeDrive;
+    private String serverName;
+    private String domainName;
+    private PacSid userSid;
+    private PacSid groupSid;
+    private PacSid[] groupSids;
+    private PacSid[] resourceGroupSids;
+    private PacSid[] extraSids;
+    private int userAccountControl;
+    private int userFlags;
+
+    public PacLogonInfo(byte[] data) throws IOException {
+        try {
+            PacDataInputStream pacStream = new PacDataInputStream(new DataInputStream(
+                    new ByteArrayInputStream(data)));
+
+            // Skip firsts
+            pacStream.skipBytes(20);
+
+            // Dates
+            logonTime = pacStream.readFiletime();
+            logoffTime = pacStream.readFiletime();
+            kickOffTime = pacStream.readFiletime();
+            pwdLastChangeTime = pacStream.readFiletime();
+            pwdCanChangeTime = pacStream.readFiletime();
+            pwdMustChangeTime = pacStream.readFiletime();
+
+            // User related strings as UnicodeStrings
+            PacUnicodeString userNameString = pacStream.readUnicodeString();
+            PacUnicodeString userDisplayNameString = pacStream.readUnicodeString();
+            PacUnicodeString logonScriptString = pacStream.readUnicodeString();
+            PacUnicodeString profilePathString = pacStream.readUnicodeString();
+            PacUnicodeString homeDirectoryString = pacStream.readUnicodeString();
+            PacUnicodeString homeDriveString = pacStream.readUnicodeString();
+
+            // Some counts
+            logonCount = pacStream.readShort();
+            badPasswordCount = pacStream.readShort();
+
+            // IDs for user
+            PacSid userId = pacStream.readId();
+            PacSid groupId = pacStream.readId();
+
+            // Groups information
+            int groupCount = pacStream.readInt();
+            int groupPointer = pacStream.readInt();
+
+            // User flags about PAC Logon Info content
+            userFlags = pacStream.readInt();
+            boolean hasExtraSids = (userFlags & PacConstants.LOGON_EXTRA_SIDS) == PacConstants.LOGON_EXTRA_SIDS;
+            boolean hasResourceGroups = (userFlags & PacConstants.LOGON_RESOURCE_GROUPS) == PacConstants.LOGON_RESOURCE_GROUPS;
+
+            // Skip some reserved fields (User Session Key)
+            pacStream.skipBytes(16);
+
+            // Server related strings as UnicodeStrings
+            PacUnicodeString serverNameString = pacStream.readUnicodeString();
+            PacUnicodeString domainNameString = pacStream.readUnicodeString();
+
+            // ID for domain (used with relative IDs to get SIDs)
+            int domainIdPointer = pacStream.readInt();
+
+            // Skip some reserved fields
+            pacStream.skipBytes(8);
+
+            userAccountControl = pacStream.readInt();
+
+            // Skip some reserved fields
+            pacStream.skipBytes(28);
+
+            // Extra SIDs information
+            int extraSidCount = pacStream.readInt();
+            int extraSidPointer = pacStream.readInt();
+
+            // ID for resource groups domain (used with IDs to get SIDs)
+            int resourceDomainIdPointer = pacStream.readInt();
+
+            // Resource groups information
+            int resourceGroupCount = pacStream.readInt();
+            int resourceGroupPointer = pacStream.readInt();
+
+            // User related strings
+            userName = userNameString.check(pacStream.readString());
+            userDisplayName = userDisplayNameString.check(pacStream.readString());
+            logonScript = logonScriptString.check(pacStream.readString());
+            profilePath = profilePathString.check(pacStream.readString());
+            homeDirectory = homeDirectoryString.check(pacStream.readString());
+            homeDrive = homeDriveString.check(pacStream.readString());
+
+            // Groups data
+            PacGroup[] groups = new PacGroup[0];
+            if(groupPointer != 0) {
+                int realGroupCount = pacStream.readInt();
+                if(realGroupCount != groupCount) {
+                    Object[] args = new Object[]{groupCount, realGroupCount};
+                    throw new IOException("pac.groups.invalid.size");
+                }
+                groups = new PacGroup[groupCount];
+                for(int i = 0; i < groupCount; i++) {
+                    pacStream.align(4);
+                    PacSid id = pacStream.readId();
+                    int attributes = pacStream.readInt();
+                    groups[i] = new PacGroup(id, attributes);
+                }
+            }
+
+            // Server related strings
+            serverName = serverNameString.check(pacStream.readString());
+            domainName = domainNameString.check(pacStream.readString());
+
+            // ID for domain (used with relative IDs to get SIDs)
+            PacSid domainId = null;
+            if(domainIdPointer != 0)
+                domainId = pacStream.readSid();
+
+            // Extra SIDs data
+            PacSidAttributes[] extraSidAtts = new PacSidAttributes[0];
+            if(hasExtraSids && extraSidPointer != 0) {
+                int realExtraSidCount = pacStream.readInt();
+                if(realExtraSidCount != extraSidCount) {
+                    Object[] args = new Object[]{extraSidCount, realExtraSidCount};
+                    throw new IOException("pac.extrasids.invalid.size");
+                }
+                extraSidAtts = new PacSidAttributes[extraSidCount];
+                int[] pointers = new int[extraSidCount];
+                int[] attributes = new int[extraSidCount];
+                for(int i = 0; i < extraSidCount; i++) {
+                    pointers[i] = pacStream.readInt();
+                    attributes[i] = pacStream.readInt();
+                }
+                for(int i = 0; i < extraSidCount; i++) {
+                    PacSid sid = (pointers[i] != 0) ? pacStream.readSid() : null;
+                    extraSidAtts[i] = new PacSidAttributes(sid, attributes[i]);
+                }
+            }
+
+            // ID for resource domain (used with relative IDs to get SIDs)
+            PacSid resourceDomainId = null;
+            if(resourceDomainIdPointer != 0)
+                resourceDomainId = pacStream.readSid();
+
+            // Resource groups data
+            PacGroup[] resourceGroups = new PacGroup[0];
+            if(hasResourceGroups && resourceGroupPointer != 0) {
+                int realResourceGroupCount = pacStream.readInt();
+                if(realResourceGroupCount != resourceGroupCount) {
+                    Object[] args = new Object[]{resourceGroupCount, realResourceGroupCount};
+                    throw new IOException("pac.resourcegroups.invalid.size");
+                }
+                resourceGroups = new PacGroup[resourceGroupCount];
+                for(int i = 0; i < resourceGroupCount; i++) {
+                    PacSid id = pacStream.readSid();
+                    int attributes = pacStream.readInt();
+                    resourceGroups[i] = new PacGroup(id, attributes);
+                }
+            }
+
+            // Extract Extra SIDs
+            extraSids = new PacSid[extraSidAtts.length];
+            for(int i = 0; i < extraSidAtts.length; i++) {
+                extraSids[i] = extraSidAtts[i].getId();
+            }
+
+            // Compute Resource Group IDs with Resource Domain ID to get SIDs
+            resourceGroupSids = new PacSid[resourceGroups.length];
+            for(int i = 0; i < resourceGroups.length; i++) {
+                resourceGroupSids[i] = PacSid.append(resourceDomainId, resourceGroups[i].getId());
+            }
+
+            // Compute User IDs with Domain ID to get User SIDs
+            // First extra is user if userId is empty
+            if(!userId.isEmpty() && !userId.isBlank()) {
+                userSid = PacSid.append(domainId, userId);
+            } else if(extraSids.length > 0) {
+                userSid = extraSids[0];
+            }
+            groupSid = PacSid.append(domainId, groupId);
+
+            // Compute Group IDs with Domain ID to get Group SIDs
+            groupSids = new PacSid[groups.length];
+            for(int i = 0; i < groups.length; i++) {
+                groupSids[i] = PacSid.append(domainId, groups[i].getId());
+            }
+        } catch(IOException e) {
+            throw new IOException("pac.logoninfo.malformed", e);
+        }
+    }
+
+    public Date getLogonTime() {
+        return logonTime;
+    }
+
+    public Date getLogoffTime() {
+        return logoffTime;
+    }
+
+    public Date getKickOffTime() {
+        return kickOffTime;
+    }
+
+    public Date getPwdLastChangeTime() {
+        return pwdLastChangeTime;
+    }
+
+    public Date getPwdCanChangeTime() {
+        return pwdCanChangeTime;
+    }
+
+    public Date getPwdMustChangeTime() {
+        return pwdMustChangeTime;
+    }
+
+    public short getLogonCount() {
+        return logonCount;
+    }
+
+    public short getBadPasswordCount() {
+        return badPasswordCount;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public String getUserDisplayName() {
+        return userDisplayName;
+    }
+
+    public String getLogonScript() {
+        return logonScript;
+    }
+
+    public String getProfilePath() {
+        return profilePath;
+    }
+
+    public String getHomeDirectory() {
+        return homeDirectory;
+    }
+
+    public String getHomeDrive() {
+        return homeDrive;
+    }
+
+    public String getServerName() {
+        return serverName;
+    }
+
+    public String getDomainName() {
+        return domainName;
+    }
+
+    public PacSid getUserSid() {
+        return userSid;
+    }
+
+    public PacSid getGroupSid() {
+        return groupSid;
+    }
+
+    public PacSid[] getGroupSids() {
+        return groupSids;
+    }
+
+    public PacSid[] getResourceGroupSids() {
+        return resourceGroupSids;
+    }
+
+    public PacSid[] getExtraSids() {
+        return extraSids;
+    }
+
+    public int getUserAccountControl() {
+        return userAccountControl;
+    }
+
+    public int getUserFlags() {
+        return userFlags;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSid.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSid.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSid.java
new file mode 100644
index 0000000..9a00e3b
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSid.java
@@ -0,0 +1,130 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+import java.io.IOException;
+
+public class PacSid {
+
+    private static final String FORMAT = "%1$02x";
+
+    private byte revision;
+    private byte subCount;
+    private byte[] authority;
+    private byte[] subs;
+
+    public PacSid(byte[] bytes) throws IOException {
+        if(bytes.length < 8 || ((bytes.length - 8) % 4) != 0
+                || ((bytes.length - 8) / 4) != bytes[1])
+            throw new IOException("pac.sid.malformed.size");
+
+        this.revision = bytes[0];
+        this.subCount = bytes[1];
+        this.authority = new byte[6];
+        System.arraycopy(bytes, 2, this.authority, 0, 6);
+        this.subs = new byte[bytes.length - 8];
+        System.arraycopy(bytes, 8, this.subs, 0, bytes.length - 8);
+    }
+
+    public PacSid(PacSid sid) {
+        this.revision = sid.revision;
+        this.subCount = sid.subCount;
+        this.authority = new byte[6];
+        System.arraycopy(sid.authority, 0, this.authority, 0, 6);
+        this.subs = new byte[sid.subs.length];
+        System.arraycopy(sid.subs, 0, this.subs, 0, sid.subs.length);
+    }
+
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+
+        builder.append("\\").append(String.format(FORMAT, ((int)revision) & 0xff));
+        builder.append("\\").append(String.format(FORMAT, ((int)subCount) & 0xff));
+        for(int i = 0; i < authority.length; i++) {
+            int unsignedByte = ((int)authority[i]) & 0xff;
+            builder.append("\\").append(String.format(FORMAT, unsignedByte));
+        }
+        for(int i = 0; i < subs.length; i++) {
+            int unsignedByte = ((int)subs[i]) & 0xff;
+            builder.append("\\").append(String.format(FORMAT, unsignedByte));
+        }
+
+        return builder.toString();
+    }
+
+    public boolean isEmpty() {
+        return subCount == 0;
+    }
+
+    public boolean isBlank() {
+        boolean blank = true;
+        for(byte sub : subs)
+            blank = blank && (sub == 0);
+        return blank;
+    }
+
+    public byte[] getBytes() {
+        byte[] bytes = new byte[8 + subCount * 4];
+        bytes[0] = revision;
+        bytes[1] = subCount;
+        System.arraycopy(authority, 0, bytes, 2, 6);
+        System.arraycopy(subs, 0, bytes, 8, subs.length);
+
+        return bytes;
+    }
+
+    public static String toString(byte[] bytes) {
+        StringBuilder builder = new StringBuilder();
+
+        for(int i = 0; i < bytes.length; i++) {
+            int unsignedByte = ((int)bytes[i]) & 0xff;
+            builder.append("\\").append(String.format(FORMAT, unsignedByte));
+        }
+
+        return builder.toString();
+    }
+
+    public static PacSid createFromSubs(byte[] bytes) throws IOException {
+        if((bytes.length % 4) != 0) {
+            Object[] args = new Object[]{bytes.length};
+            throw new IOException("pac.subauthority.malformed.size");
+        }
+
+        byte[] sidBytes = new byte[8 + bytes.length];
+        sidBytes[0] = 1;
+        sidBytes[1] = (byte)(bytes.length / 4);
+        System.arraycopy(new byte[]{0, 0, 0, 0, 0, 5}, 0, sidBytes, 2, 6);
+        System.arraycopy(bytes, 0, sidBytes, 8, bytes.length);
+
+        return new PacSid(sidBytes);
+    }
+
+    public static PacSid append(PacSid sid1, PacSid sid2) {
+        PacSid sid = new PacSid(sid1);
+
+        sid.subCount += sid2.subCount;
+        sid.subs = new byte[sid.subCount * 4];
+        System.arraycopy(sid1.subs, 0, sid.subs, 0, sid1.subs.length);
+        System.arraycopy(sid2.subs, 0, sid.subs, sid1.subs.length, sid2.subs.length);
+
+        return sid;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSidAttributes.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSidAttributes.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSidAttributes.java
new file mode 100644
index 0000000..33cb7f7
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSidAttributes.java
@@ -0,0 +1,41 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+public class PacSidAttributes {
+
+    private PacSid id;
+    private int attributes;
+
+    public PacSidAttributes(PacSid id, int attributes) {
+        super();
+        this.id = id;
+        this.attributes = attributes;
+    }
+
+    public PacSid getId() {
+        return id;
+    }
+
+    public int getAttributes() {
+        return attributes;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSignature.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSignature.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSignature.java
new file mode 100644
index 0000000..c8d5e08
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacSignature.java
@@ -0,0 +1,52 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+public class PacSignature {
+
+    private int type;
+    private byte[] checksum;
+
+    public PacSignature(byte[] data) throws IOException {
+        try {
+            PacDataInputStream bufferStream = new PacDataInputStream(new DataInputStream(
+                    new ByteArrayInputStream(data)));
+
+            type = bufferStream.readInt();
+            checksum = new byte[bufferStream.available()];
+            bufferStream.readFully(checksum);
+        } catch(IOException e) {
+            throw new IOException("pac.signature.malformed", e);
+        }
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public byte[] getChecksum() {
+        return checksum;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacUnicodeString.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacUnicodeString.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacUnicodeString.java
new file mode 100644
index 0000000..34b311d
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/pac/PacUnicodeString.java
@@ -0,0 +1,61 @@
+/**
+ *  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.kerberos.kerb.codec.pac;
+
+import java.io.IOException;
+
+public class PacUnicodeString {
+
+    private short length;
+    private short maxLength;
+    private int pointer;
+
+    public PacUnicodeString(short length, short maxLength, int pointer) {
+        super();
+        this.length = length;
+        this.maxLength = maxLength;
+        this.pointer = pointer;
+    }
+
+    public short getLength() {
+        return length;
+    }
+
+    public short getMaxLength() {
+        return maxLength;
+    }
+
+    public int getPointer() {
+        return pointer;
+    }
+
+    public String check(String string) throws IOException {
+        if(pointer == 0 && string != null)
+            throw new IOException("pac.string.notempty");
+
+        int expected = length / 2;
+        if(string.length() != expected) {
+            Object[] args = new Object[]{expected, string.length()};
+            throw new IOException("pac.string.invalid.size");
+        }
+
+        return string;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoConstants.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoConstants.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoConstants.java
new file mode 100644
index 0000000..9820a7e
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoConstants.java
@@ -0,0 +1,31 @@
+/**
+ *  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.kerberos.kerb.codec.spnego;
+
+public interface SpnegoConstants {
+
+    static final String SPNEGO_MECHANISM = "1.3.6.1.5.5.2";
+    static final String KERBEROS_MECHANISM = "1.2.840.113554.1.2.2";
+    static final String LEGACY_KERBEROS_MECHANISM = "1.2.840.48018.1.2.2";
+    static final String NTLMSSP_MECHANISM = "1.3.6.1.4.1.311.2.2.10";
+
+    static final String SPNEGO_OID = SPNEGO_MECHANISM;
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoInitToken.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoInitToken.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoInitToken.java
new file mode 100644
index 0000000..3e661ff
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoInitToken.java
@@ -0,0 +1,53 @@
+/**
+ *  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.kerberos.kerb.codec.spnego;
+
+import java.io.IOException;
+
+public class SpnegoInitToken extends SpnegoToken {
+
+    public static final int DELEGATION = 0x40;
+    public static final int MUTUAL_AUTHENTICATION = 0x20;
+    public static final int REPLAY_DETECTION = 0x10;
+    public static final int SEQUENCE_CHECKING = 0x08;
+    public static final int ANONYMITY = 0x04;
+    public static final int CONFIDENTIALITY = 0x02;
+    public static final int INTEGRITY = 0x01;
+
+    private String[] mechanisms;
+    private int contextFlags;
+
+    public SpnegoInitToken(byte[] token) throws IOException {
+
+    }
+
+    public int getContextFlags() {
+        return contextFlags;
+    }
+
+    public boolean getContextFlag(int flag) {
+        return (getContextFlags() & flag) == flag;
+    }
+
+    public String[] getMechanisms() {
+        return mechanisms;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoTargToken.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoTargToken.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoTargToken.java
new file mode 100644
index 0000000..b830d8b
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoTargToken.java
@@ -0,0 +1,41 @@
+/**
+ *  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.kerberos.kerb.codec.spnego;
+
+import java.io.IOException;
+
+public class SpnegoTargToken extends SpnegoToken {
+
+    public static final int UNSPECIFIED_RESULT = -1;
+    public static final int ACCEPT_COMPLETED = 0;
+    public static final int ACCEPT_INCOMPLETE = 1;
+    public static final int REJECTED = 2;
+
+    private int result = UNSPECIFIED_RESULT;
+
+    public SpnegoTargToken(byte[] token) throws IOException {
+
+    }
+
+    public int getResult() {
+        return result;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoToken.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoToken.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoToken.java
new file mode 100644
index 0000000..7c80a59
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/spnego/SpnegoToken.java
@@ -0,0 +1,67 @@
+/**
+ *  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.kerberos.kerb.codec.spnego;
+
+import java.io.IOException;
+
+public abstract class SpnegoToken {
+
+    // Default max size as 65K
+    public static int TOKEN_MAX_SIZE = 66560;
+
+    protected byte[] mechanismToken;
+    protected byte[] mechanismList;
+    protected String mechanism;
+
+    public static SpnegoToken parse(byte[] token) throws IOException {
+        SpnegoToken spnegoToken = null;
+
+        if(token.length <= 0)
+            throw new IOException("spnego.token.empty");
+
+        switch (token[0]) {
+        case (byte)0x60:
+            spnegoToken = new SpnegoInitToken(token);
+            break;
+        case (byte)0xa1:
+            spnegoToken = new SpnegoTargToken(token);
+            break;
+        default:
+            spnegoToken = null;
+            Object[] args = new Object[]{token[0]};
+            throw new IOException("spnego.token.invalid");
+        }
+
+        return spnegoToken;
+    }
+
+    public byte[] getMechanismToken() {
+        return mechanismToken;
+    }
+
+    public byte[] getMechanismList() {
+        return mechanismList;
+    }
+
+    public String getMechanism() {
+        return mechanism;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTest.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTest.java
new file mode 100644
index 0000000..58a57e4
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTest.java
@@ -0,0 +1,46 @@
+/**
+ *  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.kerberos.kerb.codec.test;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.codec.KrbCodec;
+import org.apache.kerby.kerberos.kerb.spec.common.CheckSum;
+import org.apache.kerby.kerberos.kerb.spec.common.CheckSumType;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+public class CodecTest {
+
+    @Test
+    public void testCodec() throws KrbException {
+        CheckSum mcs = new CheckSum();
+        mcs.setCksumtype(CheckSumType.CRC32);
+        mcs.setChecksum(new byte[] {0x10});
+        byte[] bytes = KrbCodec.encode(mcs);
+        Assert.assertNotNull(bytes);
+
+        CheckSum restored = KrbCodec.decode(bytes, CheckSum.class);
+        Assert.assertNotNull(restored);
+        Assert.assertEquals(mcs.getCksumtype(), restored.getCksumtype());
+        Assert.assertTrue(Arrays.equals(mcs.getChecksum(), restored.getChecksum()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTestUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTestUtil.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTestUtil.java
new file mode 100644
index 0000000..ed11259
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/CodecTestUtil.java
@@ -0,0 +1,32 @@
+/**
+ *  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.kerberos.kerb.codec.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class CodecTestUtil {
+  /*package*/ static byte[] readBinaryFile(String path) throws IOException {
+    InputStream is = CodecTestUtil.class.getResourceAsStream(path);
+    byte[] bytes = new byte[is.available()];
+    is.read(bytes);
+    return bytes;
+  }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/7d9261af/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/TestAsRepCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/TestAsRepCodec.java b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/TestAsRepCodec.java
new file mode 100644
index 0000000..1b336f0
--- /dev/null
+++ b/kerby-kerb/kerb-core-test/src/test/java/org/apache/kerby/kerberos/kerb/codec/test/TestAsRepCodec.java
@@ -0,0 +1,74 @@
+/**
+ *  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.kerberos.kerb.codec.test;
+
+import org.apache.kerby.kerberos.kerb.spec.common.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.spec.common.NameType;
+import org.apache.kerby.kerberos.kerb.spec.common.PrincipalName;
+import org.apache.kerby.kerberos.kerb.spec.kdc.AsRep;
+import org.apache.kerby.kerberos.kerb.spec.ticket.Ticket;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * Test AsRep message using a real 'correct' network packet captured from MS-AD to detective programming errors
+ * and compatibility issues particularly regarding Kerberos crypto.
+ */
+public class TestAsRepCodec {
+
+    @Test
+    public void test() throws IOException {
+        byte[] bytes = CodecTestUtil.readBinaryFile("/asrep.token");
+        ByteBuffer asRepToken = ByteBuffer.wrap(bytes);
+
+        AsRep asRep = new AsRep();
+        asRep.decode(asRepToken);
+
+        Assert.assertEquals(asRep.getPvno(), 5);
+        Assert.assertEquals(asRep.getMsgType(), KrbMessageType.AS_REP);
+        Assert.assertEquals(asRep.getCrealm(), "DENYDC.COM");
+
+        PrincipalName cname = asRep.getCname();
+        Assert.assertEquals(cname.getNameType(), NameType.NT_PRINCIPAL);
+        Assert.assertEquals(cname.getNameStrings().size(), 1);
+        Assert.assertEquals(cname.getNameStrings().get(0), "u5");
+
+        Ticket ticket = asRep.getTicket();
+        Assert.assertEquals(ticket.getTktvno(), 5);
+        Assert.assertEquals(ticket.getRealm(), "DENYDC.COM");
+        PrincipalName sname = ticket.getSname();
+        Assert.assertEquals(sname.getNameType(), NameType.NT_SRV_INST);
+        Assert.assertEquals(sname.getNameStrings().size(), 2);
+        Assert.assertEquals(sname.getNameStrings().get(0), "krbtgt");
+        Assert.assertEquals(sname.getNameStrings().get(1), "DENYDC.COM");
+        //EncTicketPart encTicketPart = ticket.getEncPart();//FIXME
+        //Assert.assertEquals(encTicketPart.getKey().getKvno(), 2);
+        //Assert.assertEquals(encTicketPart.getKey().getKeyType().getValue(), 0x0017);
+        //TODO decode cinpher
+
+        //EncKdcRepPart encKdcRepPart = asRep.getEncPart();//FIXME
+        //Assert.assertEquals(encKdcRepPart.getKey().getKeyType().getValue(), 0x0017);
+        //Assert.assertEquals(encKdcRepPart.getKey().getKvno(), 7);
+        //TODO decode cinpher
+    }
+}