// Copyright 1997 The Open Group Research Institute.  All rights reserved.

// test of lib classes

import krb5.lib.*;
import krb5.lib.asn1.*;
import krb5.lib.crypto.*;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class libtest {

	public static byte[] sample_as_req1() throws
		Asn1Exception,
		BitStringException,
		KrbApErrException,
		RealmException,
		UnknownHostException {

		KDCOptions kdc_options = new KDCOptions();
		kdc_options.set(Krb5.KDC_OPTS_FORWARDABLE);

		PrincipalName cname = new PrincipalName(
			"sanfilip", Krb5.KRB_NT_PRINCIPAL);

		Realm crealm = new Realm("booboo.osf.org");

		PrincipalName sname = new PrincipalName(
			"krbtgt/booboo.osf.org", Krb5.KRB_NT_UNKNOWN);

		KerberosTime till = new KerberosTime();

		int nonce = Nonce.value();

		HostAddress[] host_addresses = new HostAddress[1];
		host_addresses[0] = new HostAddress(Krb5.ADDRTYPE_INET,
			InetAddress.getLocalHost().getAddress());
		HostAddresses addresses = new HostAddresses(host_addresses);
		
		KDCReqBody kdc_req_body = new KDCReqBody(
			kdc_options,
			cname,
			crealm,
			sname,
			null,
			till,
			null,
			nonce,
			Config.ETYPE_LIST_DEFAULT,
			addresses,
			null,
			null
			);

		ASReq as_req = new ASReq(null, kdc_req_body);

		byte[] result = as_req.asn1Encode();

		return result;
	}

	public static byte[] as_req(
		KDCOptions kdc_options,
		PrincipalName cname,
		Realm crealm
		) throws
		Asn1Exception,
		BitStringException,
		KrbApErrException,
		RealmException,
		UnknownHostException {

		PrincipalName sname = new PrincipalName(
			Krb5.TGS + String.valueOf(Krb5.NAME_COMPONENT_SEPARATOR) +
			crealm.toString(), Krb5.KRB_NT_UNKNOWN);
			
		KDCReqBody kdc_req_body = new KDCReqBody(
			kdc_options,
			cname,
			crealm,
			sname,
			null,
			new KerberosTime(),
			null,
			Nonce.value(),
			Config.ETYPE_LIST_DEFAULT,
			null, //XXX new HostAddresses(),
			null,
			null
			);

		ASReq asReq = new ASReq(null, kdc_req_body);

		return asReq.asn1Encode();
	}

	public static byte[] sample_as_req2() throws Asn1Exception,
		UnknownHostException {

		byte[] kdc_options = { (byte)0x40, (byte)0x0, (byte)0x0,
			(byte)0x0 }; //forwardable set

		byte[][] name_string = {
			encode.GeneralString("sanfilip")
		};

		byte[][] cname = {
			encode.prependExplicitTag(0, encode.Integer(1)), //name type -- NT_PRINCIPAL
			encode.prependExplicitTag(1, encode.Sequence(name_string)) //name components
		};

		byte[][] name_string2 = {
			encode.GeneralString("krbtgt"),
			encode.GeneralString("booboo.osf.org")
		};

		byte[][] sname = {
			encode.prependExplicitTag(0, encode.Integer(0)), //name type -- NT_DEFAULT
			encode.prependExplicitTag(1, encode.Sequence(name_string2)) //name components
		};

		byte[][] etype = {
			encode.Integer(3), //encryption type -- des-cbc-md5
			encode.Integer(1), //encryption type -- des-cbc-crc
		};

		byte[] octet_string = InetAddress.getLocalHost().getAddress(); //ip address

		byte[][] host_address = {
			encode.prependExplicitTag(0, encode.Integer(2)), //host address type -- Internet
			encode.prependExplicitTag(1, encode.OctetString(octet_string)) //host address data
		};

		byte[][] host_addresses = {
			encode.Sequence(host_address) //host address
		};

		byte[][] kdc_req_body = {
			encode.prependExplicitTag(0, encode.BitString(kdc_options)), //options -- none
			encode.prependExplicitTag(1, encode.Sequence(cname)), //client principal
			encode.prependExplicitTag(2, encode.GeneralString("booboo.osf.org")), //realm
			encode.prependExplicitTag(3, encode.Sequence(sname)), //server principal
			encode.prependExplicitTag(5, encode.GeneralizedTime("19700101000000Z")), //exp time
			encode.prependExplicitTag(7, encode.Integer((int)(System.currentTimeMillis() / 1000))),  //nonce from current time
			encode.prependExplicitTag(8, encode.Sequence(etype)), //encryption types
			encode.prependExplicitTag(9, encode.Sequence(host_addresses)) //host addresses
		};

		byte[][] kdc_req = {
			encode.prependExplicitTag(1, encode.Integer(5)), //version
			encode.prependExplicitTag(2, encode.Integer(10)), //msg-type
			encode.prependExplicitTag(4, encode.Sequence(kdc_req_body))
		};

		return encode.prependExplicitTag(asn1Class.APPLICATION, 10,
			encode.Sequence(kdc_req));
	}

	public static final byte[] sample_as_rep2 = {
		(byte)0x6b, (byte)0x82, (byte)0x02, (byte)0x20, (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x1c, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x05, (byte)0xa1, (byte)0x03, (byte)0x02,
		(byte)0x01, (byte)0x0b, (byte)0xa3, (byte)0x10, (byte)0x1b, (byte)0x0e, (byte)0x62, (byte)0x6f, (byte)0x6f, (byte)0x62, (byte)0x6f, (byte)0x6f, (byte)0x2e, (byte)0x6f, (byte)0x73, (byte)0x66,
		(byte)0x2e, (byte)0x6f, (byte)0x72, (byte)0x67, (byte)0xa4, (byte)0x15, (byte)0x30, (byte)0x13, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x0c, (byte)0x30,
		(byte)0x0a, (byte)0x1b, (byte)0x08, (byte)0x73, (byte)0x61, (byte)0x6e, (byte)0x66, (byte)0x69, (byte)0x6c, (byte)0x69, (byte)0x70, (byte)0xa5, (byte)0x81, (byte)0xf8, (byte)0x61, (byte)0x81,
		(byte)0xf5, (byte)0x30, (byte)0x81, (byte)0xf2, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x05, (byte)0xa1, (byte)0x10, (byte)0x1b, (byte)0x0e, (byte)0x62, (byte)0x6f, (byte)0x6f,
		(byte)0x62, (byte)0x6f, (byte)0x6f, (byte)0x2e, (byte)0x6f, (byte)0x73, (byte)0x66, (byte)0x2e, (byte)0x6f, (byte)0x72, (byte)0x67, (byte)0xa2, (byte)0x23, (byte)0x30, (byte)0x21, (byte)0xa0,
		(byte)0x03, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0xa1, (byte)0x1a, (byte)0x30, (byte)0x18, (byte)0x1b, (byte)0x06, (byte)0x6b, (byte)0x72, (byte)0x62, (byte)0x74, (byte)0x67, (byte)0x74,
		(byte)0x1b, (byte)0x0e, (byte)0x62, (byte)0x6f, (byte)0x6f, (byte)0x62, (byte)0x6f, (byte)0x6f, (byte)0x2e, (byte)0x6f, (byte)0x73, (byte)0x66, (byte)0x2e, (byte)0x6f, (byte)0x72, (byte)0x67,
		(byte)0xa3, (byte)0x81, (byte)0xb3, (byte)0x30, (byte)0x81, (byte)0xb0, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01,
		(byte)0xa2, (byte)0x81, (byte)0xa3, (byte)0x04, (byte)0x81, (byte)0xa0, (byte)0x96, (byte)0x7e, (byte)0x72, (byte)0x48, (byte)0x39, (byte)0x81, (byte)0x7e, (byte)0x22, (byte)0x9e, (byte)0x40,
		(byte)0x2e, (byte)0xc1, (byte)0x44, (byte)0xf0, (byte)0x71, (byte)0x9a, (byte)0xab, (byte)0xb1, (byte)0x3c, (byte)0xc0, (byte)0x09, (byte)0x18, (byte)0x59, (byte)0xdd, (byte)0x46, (byte)0x36,
		(byte)0x67, (byte)0x0e, (byte)0x85, (byte)0xe4, (byte)0x5c, (byte)0xec, (byte)0x35, (byte)0x7f, (byte)0x25, (byte)0xff, (byte)0x97, (byte)0xfc, (byte)0xe7, (byte)0x61, (byte)0xcd, (byte)0x05,
		(byte)0xd4, (byte)0x1c, (byte)0x1e, (byte)0xa5, (byte)0x8b, (byte)0x67, (byte)0x16, (byte)0x10, (byte)0xcc, (byte)0x35, (byte)0xe5, (byte)0x3b, (byte)0xa8, (byte)0x71, (byte)0xc5, (byte)0xbf,
		(byte)0xfe, (byte)0xb4, (byte)0xc3, (byte)0x70, (byte)0x29, (byte)0x9a, (byte)0xde, (byte)0x13, (byte)0xe3, (byte)0x8b, (byte)0x2e, (byte)0xb1, (byte)0x45, (byte)0x1e, (byte)0x4e, (byte)0x7c,
		(byte)0x10, (byte)0xa1, (byte)0xb8, (byte)0x66, (byte)0xdd, (byte)0x5b, (byte)0xa7, (byte)0x23, (byte)0x11, (byte)0x54, (byte)0x0c, (byte)0x6e, (byte)0x54, (byte)0xba, (byte)0x51, (byte)0x6d,
		(byte)0xf6, (byte)0xb4, (byte)0x43, (byte)0xe0, (byte)0xb9, (byte)0xfc, (byte)0xac, (byte)0x21, (byte)0x38, (byte)0xa4, (byte)0xdd, (byte)0x58, (byte)0x7f, (byte)0xb5, (byte)0xad, (byte)0x13,
		(byte)0x11, (byte)0x8d, (byte)0xb2, (byte)0x22, (byte)0x82, (byte)0x1f, (byte)0xc3, (byte)0x83, (byte)0x73, (byte)0x47, (byte)0xd0, (byte)0x3b, (byte)0xeb, (byte)0xea, (byte)0xdf, (byte)0xd5,
		(byte)0x1d, (byte)0x57, (byte)0xc3, (byte)0x06, (byte)0x63, (byte)0xa6, (byte)0x94, (byte)0xb9, (byte)0x67, (byte)0xbb, (byte)0x66, (byte)0xfc, (byte)0x33, (byte)0xa0, (byte)0x1d, (byte)0x13,
		(byte)0xf8, (byte)0xa2, (byte)0xdc, (byte)0xec, (byte)0x43, (byte)0x23, (byte)0x25, (byte)0x3a, (byte)0x42, (byte)0x4c, (byte)0x36, (byte)0x81, (byte)0x11, (byte)0x73, (byte)0x66, (byte)0x49,
		(byte)0xdb, (byte)0x61, (byte)0x56, (byte)0xc3, (byte)0xc6, (byte)0x7f, (byte)0xa6, (byte)0x81, (byte)0xeb, (byte)0x30, (byte)0x81, (byte)0xe8, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01,
		(byte)0x03, (byte)0xa1, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa2, (byte)0x81, (byte)0xdb, (byte)0x04, (byte)0x81, (byte)0xd8, (byte)0xda, (byte)0xef, (byte)0x70, (byte)0x14,
		(byte)0xe1, (byte)0x32, (byte)0xa5, (byte)0x61, (byte)0x46, (byte)0xe4, (byte)0x45, (byte)0xb3, (byte)0x84, (byte)0x78, (byte)0xa1, (byte)0xb5, (byte)0x32, (byte)0x20, (byte)0xb0, (byte)0xe0,
		(byte)0x06, (byte)0xba, (byte)0x84, (byte)0x10, (byte)0x27, (byte)0xb4, (byte)0xc3, (byte)0x83, (byte)0x45, (byte)0x5f, (byte)0x20, (byte)0xdc, (byte)0x19, (byte)0x13, (byte)0x1a, (byte)0x7b,
		(byte)0xa5, (byte)0xb7, (byte)0xd2, (byte)0x8a, (byte)0x37, (byte)0x40, (byte)0x53, (byte)0xe0, (byte)0x51, (byte)0x57, (byte)0x22, (byte)0x9e, (byte)0x70, (byte)0xe4, (byte)0x90, (byte)0xe7,
		(byte)0xbd, (byte)0x1b, (byte)0x29, (byte)0x49, (byte)0x21, (byte)0xe6, (byte)0x66, (byte)0xdb, (byte)0x8b, (byte)0x4a, (byte)0x7d, (byte)0x1a, (byte)0x3f, (byte)0xaa, (byte)0x7f, (byte)0x98,
		(byte)0x20, (byte)0xa1, (byte)0x29, (byte)0x13, (byte)0x79, (byte)0x62, (byte)0x4a, (byte)0xbe, (byte)0x0a, (byte)0xa5, (byte)0x12, (byte)0x2d, (byte)0x9f, (byte)0x91, (byte)0x6a, (byte)0x04,
		(byte)0xd4, (byte)0xdb, (byte)0x3e, (byte)0x7c, (byte)0x81, (byte)0x5a, (byte)0x25, (byte)0x26, (byte)0x7e, (byte)0x05, (byte)0xe2, (byte)0x2f, (byte)0x78, (byte)0x36, (byte)0x1b, (byte)0x3b,
		(byte)0xb1, (byte)0xaf, (byte)0xd5, (byte)0x3c, (byte)0xb2, (byte)0xc8, (byte)0xff, (byte)0x38, (byte)0x44, (byte)0xe9, (byte)0x66, (byte)0xe0, (byte)0x26, (byte)0xf8, (byte)0xcd, (byte)0x06,
		(byte)0xe0, (byte)0xe6, (byte)0x5e, (byte)0xb9, (byte)0x3e, (byte)0x8b, (byte)0x28, (byte)0xcc, (byte)0x85, (byte)0xe5, (byte)0xe1, (byte)0xcd, (byte)0x69, (byte)0xc6, (byte)0x3b, (byte)0x35,
		(byte)0xca, (byte)0x33, (byte)0x7e, (byte)0x1c, (byte)0xb5, (byte)0x6d, (byte)0x44, (byte)0xb1, (byte)0x95, (byte)0x1b, (byte)0x9c, (byte)0x11, (byte)0x05, (byte)0x03, (byte)0x0b, (byte)0xae,
		(byte)0x72, (byte)0x74, (byte)0x41, (byte)0x06, (byte)0x7e, (byte)0x73, (byte)0xd7, (byte)0xfe, (byte)0x5c, (byte)0xc9, (byte)0x23, (byte)0x19, (byte)0xa5, (byte)0x0a, (byte)0x93, (byte)0xaf,
		(byte)0xf2, (byte)0x03, (byte)0x15, (byte)0xec, (byte)0x53, (byte)0x6a, (byte)0xc6, (byte)0xa0, (byte)0x9d, (byte)0x96, (byte)0xcd, (byte)0xaa, (byte)0xaa, (byte)0x07, (byte)0x0c, (byte)0xf8,
		(byte)0x62, (byte)0x92, (byte)0xe9, (byte)0xf0, (byte)0x29, (byte)0x74, (byte)0x6a, (byte)0xa3, (byte)0x06, (byte)0xe0, (byte)0x42, (byte)0x50, (byte)0x8d, (byte)0x21, (byte)0x51, (byte)0x35,
		(byte)0x88, (byte)0xcd, (byte)0x80, (byte)0xb8, (byte)0x39, (byte)0x8a, (byte)0xfd, (byte)0x94, (byte)0x08, (byte)0x37, (byte)0xab, (byte)0x7f, (byte)0x46, (byte)0x7a, (byte)0xf3, (byte)0xae,
		(byte)0xac, (byte)0xb4, (byte)0x33, (byte)0xbf
	};

	public static final byte[] sample_as_rep3 = {
		(byte)0x6b, (byte)0x80, (byte)0x30, (byte)0x80, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x05, (byte)0xa1, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x0b, (byte)0xa3, (byte)0x17,
		(byte)0x1b, (byte)0x15, (byte)0x63, (byte)0x6f, (byte)0x72, (byte)0x64, (byte)0x65, (byte)0x6c, (byte)0x69, (byte)0x61, (byte)0x2e, (byte)0x63, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x2e,
		(byte)0x6f, (byte)0x73, (byte)0x66, (byte)0x2e, (byte)0x6f, (byte)0x72, (byte)0x67, (byte)0xa4, (byte)0x15, (byte)0x30, (byte)0x13, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01,
		(byte)0xa1, (byte)0x0c, (byte)0x30, (byte)0x0a, (byte)0x1b, (byte)0x08, (byte)0x73, (byte)0x61, (byte)0x6e, (byte)0x66, (byte)0x69, (byte)0x6c, (byte)0x69, (byte)0x70, (byte)0xa5, (byte)0x80,
		(byte)0x61, (byte)0x80, (byte)0x30, (byte)0x80, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x05, (byte)0xa1, (byte)0x17, (byte)0x1b, (byte)0x15, (byte)0x63, (byte)0x6f, (byte)0x72,
		(byte)0x64, (byte)0x65, (byte)0x6c, (byte)0x69, (byte)0x61, (byte)0x2e, (byte)0x63, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x2e, (byte)0x6f, (byte)0x73, (byte)0x66, (byte)0x2e, (byte)0x6f,
		(byte)0x72, (byte)0x67, (byte)0xa2, (byte)0x2a, (byte)0x30, (byte)0x28, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x21, (byte)0x30, (byte)0x1f, (byte)0x1b,
		(byte)0x06, (byte)0x6b, (byte)0x72, (byte)0x62, (byte)0x74, (byte)0x67, (byte)0x74, (byte)0x1b, (byte)0x15, (byte)0x63, (byte)0x6f, (byte)0x72, (byte)0x64, (byte)0x65, (byte)0x6c, (byte)0x69,
		(byte)0x61, (byte)0x2e, (byte)0x63, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x2e, (byte)0x6f, (byte)0x73, (byte)0x66, (byte)0x2e, (byte)0x6f, (byte)0x72, (byte)0x67, (byte)0xa3, (byte)0x80,
		(byte)0x30, (byte)0x80, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa2, (byte)0x80, (byte)0x04, (byte)0x81,
		(byte)0xa8, (byte)0x9b, (byte)0xe8, (byte)0xb3, (byte)0xda, (byte)0xbc, (byte)0x8f, (byte)0x46, (byte)0x2f, (byte)0x19, (byte)0xa0, (byte)0x4e, (byte)0x26, (byte)0x6a, (byte)0xaa, (byte)0x92,
		(byte)0x38, (byte)0x22, (byte)0x1f, (byte)0x8b, (byte)0xb3, (byte)0x79, (byte)0x82, (byte)0x07, (byte)0x51, (byte)0x25, (byte)0xed, (byte)0x22, (byte)0x9a, (byte)0x7d, (byte)0xf7, (byte)0xc5,
		(byte)0x18, (byte)0x79, (byte)0x31, (byte)0x52, (byte)0x5c, (byte)0xdd, (byte)0x55, (byte)0x41, (byte)0x5a, (byte)0xad, (byte)0x26, (byte)0x7f, (byte)0xe5, (byte)0xe2, (byte)0xe9, (byte)0xc1,
		(byte)0xfd, (byte)0x76, (byte)0x5e, (byte)0x96, (byte)0xbe, (byte)0xf8, (byte)0x64, (byte)0x7b, (byte)0xe0, (byte)0x9a, (byte)0x2d, (byte)0xe5, (byte)0xff, (byte)0x23, (byte)0xc1, (byte)0x5b,
		(byte)0x9b, (byte)0x11, (byte)0x5b, (byte)0xd4, (byte)0xfa, (byte)0xda, (byte)0x0c, (byte)0x1f, (byte)0x95, (byte)0xd7, (byte)0xfd, (byte)0x58, (byte)0xbc, (byte)0x28, (byte)0x90, (byte)0xb0,
		(byte)0x7e, (byte)0xea, (byte)0xd9, (byte)0x9f, (byte)0x0d, (byte)0xe1, (byte)0x0a, (byte)0x2e, (byte)0x25, (byte)0x08, (byte)0x4c, (byte)0x17, (byte)0xa3, (byte)0x9a, (byte)0xa2, (byte)0x91,
		(byte)0xde, (byte)0xa2, (byte)0xaa, (byte)0xcd, (byte)0x52, (byte)0x51, (byte)0x98, (byte)0x8d, (byte)0xa6, (byte)0x35, (byte)0x7c, (byte)0x23, (byte)0xfa, (byte)0x88, (byte)0x49, (byte)0x28,
		(byte)0xfc, (byte)0x05, (byte)0xd7, (byte)0x33, (byte)0x31, (byte)0xc7, (byte)0xa5, (byte)0x04, (byte)0x0f, (byte)0xba, (byte)0xc5, (byte)0xe9, (byte)0x6a, (byte)0x93, (byte)0x54, (byte)0x37,
		(byte)0x1e, (byte)0x6e, (byte)0x8b, (byte)0x1e, (byte)0x1b, (byte)0xcc, (byte)0x23, (byte)0x2e, (byte)0x85, (byte)0xaa, (byte)0x2c, (byte)0xa1, (byte)0x1d, (byte)0x76, (byte)0xe5, (byte)0x20,
		(byte)0xac, (byte)0xcf, (byte)0x77, (byte)0xde, (byte)0xed, (byte)0xb6, (byte)0x89, (byte)0x10, (byte)0x6e, (byte)0xd7, (byte)0x57, (byte)0x58, (byte)0x2f, (byte)0x92, (byte)0x96, (byte)0x38,
		(byte)0xf8, (byte)0xed, (byte)0x78, (byte)0x65, (byte)0xbc, (byte)0x3c, (byte)0xeb, (byte)0xd0, (byte)0x3e, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
		(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xa6, (byte)0x80, (byte)0x30, (byte)0x80, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x03,
		(byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa2, (byte)0x80, (byte)0x04, (byte)0x81, (byte)0xf0, (byte)0x7d, (byte)0xb1, (byte)0x5b, (byte)0x60, (byte)0x53, (byte)0x49, (byte)0x58, (byte)0x02,
		(byte)0x94, (byte)0xb5, (byte)0xd0, (byte)0x5f, (byte)0x8c, (byte)0x24, (byte)0x85, (byte)0x38, (byte)0x40, (byte)0xf1, (byte)0xb7, (byte)0x2e, (byte)0x8d, (byte)0x42, (byte)0xf3, (byte)0x40,
		(byte)0x1a, (byte)0x56, (byte)0xd5, (byte)0x4f, (byte)0xf2, (byte)0xab, (byte)0xc4, (byte)0x78, (byte)0x66, (byte)0xa5, (byte)0x6b, (byte)0x22, (byte)0x72, (byte)0x27, (byte)0xd4, (byte)0xb6,
		(byte)0xe4, (byte)0x23, (byte)0x16, (byte)0x7d, (byte)0xab, (byte)0xdf, (byte)0xf5, (byte)0x4d, (byte)0xef, (byte)0xaa, (byte)0x41, (byte)0x50, (byte)0x1e, (byte)0xd6, (byte)0x8d, (byte)0xcf,
		(byte)0x8a, (byte)0x4c, (byte)0x00, (byte)0xb1, (byte)0x59, (byte)0x5c, (byte)0x8c, (byte)0x35, (byte)0x32, (byte)0xe3, (byte)0xd2, (byte)0x74, (byte)0x59, (byte)0x77, (byte)0x2d, (byte)0x47,
		(byte)0xa2, (byte)0xc8, (byte)0x03, (byte)0x4d, (byte)0xfe, (byte)0xb2, (byte)0x56, (byte)0xf5, (byte)0x33, (byte)0xee, (byte)0x68, (byte)0x3c, (byte)0xdb, (byte)0xd8, (byte)0xec, (byte)0xb7,
		(byte)0x18, (byte)0x89, (byte)0xa3, (byte)0x6f, (byte)0x46, (byte)0x30, (byte)0xba, (byte)0x2f, (byte)0x67, (byte)0xa1, (byte)0xab, (byte)0x7b, (byte)0x9e, (byte)0x9a, (byte)0x82, (byte)0x3a,
		(byte)0x7d, (byte)0x2b, (byte)0x4c, (byte)0xdf, (byte)0x8d, (byte)0x9e, (byte)0x3d, (byte)0xbf, (byte)0x4b, (byte)0xbc, (byte)0xb8, (byte)0x65, (byte)0x69, (byte)0x2d, (byte)0x28, (byte)0xe6,
		(byte)0xd0, (byte)0xf3, (byte)0xfc, (byte)0x41, (byte)0x3f, (byte)0x4a, (byte)0x3d, (byte)0xa2, (byte)0x5a, (byte)0x16, (byte)0xe8, (byte)0xb8, (byte)0x7f, (byte)0xe5, (byte)0xc5, (byte)0xfa,
		(byte)0xce, (byte)0x48, (byte)0x04, (byte)0xec, (byte)0x4a, (byte)0xbc, (byte)0x9c, (byte)0x84, (byte)0x4b, (byte)0x1e, (byte)0x6f, (byte)0xca, (byte)0x48, (byte)0xd0, (byte)0x04, (byte)0xb6,
		(byte)0x6a, (byte)0x69, (byte)0xe9, (byte)0xac, (byte)0xb0, (byte)0x48, (byte)0x7c, (byte)0xe9, (byte)0xc9, (byte)0x8e, (byte)0x42, (byte)0xde, (byte)0x02, (byte)0x22, (byte)0xc7, (byte)0xb9,
		(byte)0x3b, (byte)0x5c, (byte)0x7d, (byte)0x93, (byte)0x6a, (byte)0xbd, (byte)0xce, (byte)0x6e, (byte)0x53, (byte)0x97, (byte)0x5f, (byte)0xf0, (byte)0x5b, (byte)0x07, (byte)0x56, (byte)0xc0,
		(byte)0x66, (byte)0xdf, (byte)0xa2, (byte)0x18, (byte)0x81, (byte)0x58, (byte)0x87, (byte)0xbf, (byte)0x34, (byte)0x4c, (byte)0x56, (byte)0xc9, (byte)0xda, (byte)0x30, (byte)0xfd, (byte)0x07,
		(byte)0xd3, (byte)0x79, (byte)0x67, (byte)0x40, (byte)0xd8, (byte)0x30, (byte)0x90, (byte)0xd6, (byte)0x9a, (byte)0x46, (byte)0xe9, (byte)0x10, (byte)0x71, (byte)0x27, (byte)0xc4, (byte)0x97,
		(byte)0x43, (byte)0x86, (byte)0xa1, (byte)0x70, (byte)0xaf, (byte)0x24, (byte)0xd5, (byte)0x60, (byte)0xfc, (byte)0x00, (byte)0xf5, (byte)0x7f, (byte)0x41, (byte)0xa0, (byte)0xf8, (byte)0xd2,
		(byte)0xf6, (byte)0x09, (byte)0x5d, (byte)0x67, (byte)0x09, (byte)0x95, (byte)0x3e, (byte)0xd9, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
		(byte)0x00, (byte)0x00
	};


	public static final byte[] sample_encPart = {
		(byte)0x30, (byte)0x80, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa2, (byte)0x80, (byte)0x04, (byte)0x81,
		(byte)0xa8, (byte)0x9b, (byte)0xe8, (byte)0xb3, (byte)0xda, (byte)0xbc, (byte)0x8f, (byte)0x46, (byte)0x2f, (byte)0x19, (byte)0xa0, (byte)0x4e, (byte)0x26, (byte)0x6a, (byte)0xaa, (byte)0x92,
		(byte)0x38, (byte)0x22, (byte)0x1f, (byte)0x8b, (byte)0xb3, (byte)0x79, (byte)0x82, (byte)0x07, (byte)0x51, (byte)0x25, (byte)0xed, (byte)0x22, (byte)0x9a, (byte)0x7d, (byte)0xf7, (byte)0xc5,
		(byte)0x18, (byte)0x79, (byte)0x31, (byte)0x52, (byte)0x5c, (byte)0xdd, (byte)0x55, (byte)0x41, (byte)0x5a, (byte)0xad, (byte)0x26, (byte)0x7f, (byte)0xe5, (byte)0xe2, (byte)0xe9, (byte)0xc1,
		(byte)0xfd, (byte)0x76, (byte)0x5e, (byte)0x96, (byte)0xbe, (byte)0xf8, (byte)0x64, (byte)0x7b, (byte)0xe0, (byte)0x9a, (byte)0x2d, (byte)0xe5, (byte)0xff, (byte)0x23, (byte)0xc1, (byte)0x5b,
		(byte)0x9b, (byte)0x11, (byte)0x5b, (byte)0xd4, (byte)0xfa, (byte)0xda, (byte)0x0c, (byte)0x1f, (byte)0x95, (byte)0xd7, (byte)0xfd, (byte)0x58, (byte)0xbc, (byte)0x28, (byte)0x90, (byte)0xb0,
		(byte)0x7e, (byte)0xea, (byte)0xd9, (byte)0x9f, (byte)0x0d, (byte)0xe1, (byte)0x0a, (byte)0x2e, (byte)0x25, (byte)0x08, (byte)0x4c, (byte)0x17, (byte)0xa3, (byte)0x9a, (byte)0xa2, (byte)0x91,
		(byte)0xde, (byte)0xa2, (byte)0xaa, (byte)0xcd, (byte)0x52, (byte)0x51, (byte)0x98, (byte)0x8d, (byte)0xa6, (byte)0x35, (byte)0x7c, (byte)0x23, (byte)0xfa, (byte)0x88, (byte)0x49, (byte)0x28,
		(byte)0xfc, (byte)0x05, (byte)0xd7, (byte)0x33, (byte)0x31, (byte)0xc7, (byte)0xa5, (byte)0x04, (byte)0x0f, (byte)0xba, (byte)0xc5, (byte)0xe9, (byte)0x6a, (byte)0x93, (byte)0x54, (byte)0x37,
		(byte)0x1e, (byte)0x6e, (byte)0x8b, (byte)0x1e, (byte)0x1b, (byte)0xcc, (byte)0x23, (byte)0x2e, (byte)0x85, (byte)0xaa, (byte)0x2c, (byte)0xa1, (byte)0x1d, (byte)0x76, (byte)0xe5, (byte)0x20,
		(byte)0xac, (byte)0xcf, (byte)0x77, (byte)0xde, (byte)0xed, (byte)0xb6, (byte)0x89, (byte)0x10, (byte)0x6e, (byte)0xd7, (byte)0x57, (byte)0x58, (byte)0x2f, (byte)0x92, (byte)0x96, (byte)0x38,
		(byte)0xf8, (byte)0xed, (byte)0x78, (byte)0x65, (byte)0xbc, (byte)0x3c, (byte)0xeb, (byte)0xd0, (byte)0x3e, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
		(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
	};


	public static final byte[] sample_ticket = {
		(byte)0x61, (byte)0x80, (byte)0x30, (byte)0x80, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x05, (byte)0xa1, (byte)0x17, (byte)0x1b, (byte)0x15, (byte)0x63, (byte)0x6f, (byte)0x72,
		(byte)0x64, (byte)0x65, (byte)0x6c, (byte)0x69, (byte)0x61, (byte)0x2e, (byte)0x63, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x2e, (byte)0x6f, (byte)0x73, (byte)0x66, (byte)0x2e, (byte)0x6f,
		(byte)0x72, (byte)0x67, (byte)0xa2, (byte)0x2a, (byte)0x30, (byte)0x28, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x21, (byte)0x30, (byte)0x1f, (byte)0x1b,
		(byte)0x06, (byte)0x6b, (byte)0x72, (byte)0x62, (byte)0x74, (byte)0x67, (byte)0x74, (byte)0x1b, (byte)0x15, (byte)0x63, (byte)0x6f, (byte)0x72, (byte)0x64, (byte)0x65, (byte)0x6c, (byte)0x69,
		(byte)0x61, (byte)0x2e, (byte)0x63, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x2e, (byte)0x6f, (byte)0x73, (byte)0x66, (byte)0x2e, (byte)0x6f, (byte)0x72, (byte)0x67, (byte)0xa3, (byte)0x80,
		(byte)0x30, (byte)0x80, (byte)0xa0, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa1, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x01, (byte)0xa2, (byte)0x80, (byte)0x04, (byte)0x81,
		(byte)0xa8, (byte)0x9b, (byte)0xe8, (byte)0xb3, (byte)0xda, (byte)0xbc, (byte)0x8f, (byte)0x46, (byte)0x2f, (byte)0x19, (byte)0xa0, (byte)0x4e, (byte)0x26, (byte)0x6a, (byte)0xaa, (byte)0x92,
		(byte)0x38, (byte)0x22, (byte)0x1f, (byte)0x8b, (byte)0xb3, (byte)0x79, (byte)0x82, (byte)0x07, (byte)0x51, (byte)0x25, (byte)0xed, (byte)0x22, (byte)0x9a, (byte)0x7d, (byte)0xf7, (byte)0xc5,
		(byte)0x18, (byte)0x79, (byte)0x31, (byte)0x52, (byte)0x5c, (byte)0xdd, (byte)0x55, (byte)0x41, (byte)0x5a, (byte)0xad, (byte)0x26, (byte)0x7f, (byte)0xe5, (byte)0xe2, (byte)0xe9, (byte)0xc1,
		(byte)0xfd, (byte)0x76, (byte)0x5e, (byte)0x96, (byte)0xbe, (byte)0xf8, (byte)0x64, (byte)0x7b, (byte)0xe0, (byte)0x9a, (byte)0x2d, (byte)0xe5, (byte)0xff, (byte)0x23, (byte)0xc1, (byte)0x5b,
		(byte)0x9b, (byte)0x11, (byte)0x5b, (byte)0xd4, (byte)0xfa, (byte)0xda, (byte)0x0c, (byte)0x1f, (byte)0x95, (byte)0xd7, (byte)0xfd, (byte)0x58, (byte)0xbc, (byte)0x28, (byte)0x90, (byte)0xb0,
		(byte)0x7e, (byte)0xea, (byte)0xd9, (byte)0x9f, (byte)0x0d, (byte)0xe1, (byte)0x0a, (byte)0x2e, (byte)0x25, (byte)0x08, (byte)0x4c, (byte)0x17, (byte)0xa3, (byte)0x9a, (byte)0xa2, (byte)0x91,
		(byte)0xde, (byte)0xa2, (byte)0xaa, (byte)0xcd, (byte)0x52, (byte)0x51, (byte)0x98, (byte)0x8d, (byte)0xa6, (byte)0x35, (byte)0x7c, (byte)0x23, (byte)0xfa, (byte)0x88, (byte)0x49, (byte)0x28,
		(byte)0xfc, (byte)0x05, (byte)0xd7, (byte)0x33, (byte)0x31, (byte)0xc7, (byte)0xa5, (byte)0x04, (byte)0x0f, (byte)0xba, (byte)0xc5, (byte)0xe9, (byte)0x6a, (byte)0x93, (byte)0x54, (byte)0x37,
		(byte)0x1e, (byte)0x6e, (byte)0x8b, (byte)0x1e, (byte)0x1b, (byte)0xcc, (byte)0x23, (byte)0x2e, (byte)0x85, (byte)0xaa, (byte)0x2c, (byte)0xa1, (byte)0x1d, (byte)0x76, (byte)0xe5, (byte)0x20,
		(byte)0xac, (byte)0xcf, (byte)0x77, (byte)0xde, (byte)0xed, (byte)0xb6, (byte)0x89, (byte)0x10, (byte)0x6e, (byte)0xd7, (byte)0x57, (byte)0x58, (byte)0x2f, (byte)0x92, (byte)0x96, (byte)0x38,
		(byte)0xf8, (byte)0xed, (byte)0x78, (byte)0x65, (byte)0xbc, (byte)0x3c, (byte)0xeb, (byte)0xd0, (byte)0x3e, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
		(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
	};

	public static byte[] ap_req(
			APOptions apOptions,
			Ticket ticket,
			EncryptionKey key,
			Realm crealm,
			PrincipalName cname,
			Checksum cksum
		) throws Asn1Exception, BitStringException, KdcErrException {

		KerberosTime ctime = new KerberosTime();
		ctime.setNow();
		int cusec = ctime.getMicroSeconds();

		//System.out.println("Authenticator.ctime=" +
		//	ctime.toGeneralizedTimeString());

		Authenticator unencrypted_authenticator = new Authenticator(
			crealm,
			cname,
			cksum,
			cusec,
			ctime,
			null,
			null,
			null
		);

		byte[] temp = unencrypted_authenticator.asn1Encode();
		//System.out.println("unencrypted_authenticator: " + temp.length + " bytes");
		//asn1.util.print(temp);
		//System.out.println();

		EncryptedData authenticator = new EncryptedData(
			key,
			temp
		);

		APReq ap_req = new APReq(
			apOptions,
			ticket,
			authenticator
		);
		temp = ap_req.asn1Encode();
		//System.out.println("authenticator: " + temp.length + " bytes");
		//asn1.util.print(temp);
		//System.out.println();

		return ap_req.asn1Encode();
	}

	public static byte[] tgs_req(
			KDCOptions kdc_options,
			Ticket ticket,
			EncryptionKey key,
			PrincipalName cname,
			Realm crealm,
			PrincipalName sname
		) throws Asn1Exception, BitStringException, KdcErrException,
		UnknownHostException {

		KDCReqBody reqBody = new KDCReqBody(
			kdc_options,
			cname,
			crealm,
			sname,
			null,
			new KerberosTime(),
			null,
			Nonce.value(),
			Config.ETYPE_LIST_DEFAULT,
			null, //XXX new HostAddresses(),
			null,
			null
			);

		byte[] temp = reqBody.asn1Encode(Krb5.KRB_TGS_REQ);
		//System.out.println("tgs_req_body: " + temp.length + " bytes");
		//asn1.util.print(temp);
		//System.out.println();

		Checksum cksum = new Checksum(temp);
		
		byte[] tgs_ap_req = ap_req(
			new APOptions(),
			ticket,
			key,
			crealm,
			cname,
			cksum
		);
		
		PAData[] tgsPAData = new PAData[1];
		tgsPAData[0] = new PAData(Krb5.PA_TGS_REQ, tgs_ap_req);

		TGSReq tgs_req = new TGSReq(tgsPAData, reqBody);

		return tgs_req.asn1Encode();
	}

	public static byte[] mk_priv(
		byte[] userData,
		EncryptionKey key,
		Integer seqNumber,
		HostAddress sAddress,
		HostAddress rAddress
		) throws Asn1Exception, BitStringException, KdcErrException {

		KerberosTime timestamp = new KerberosTime();
		timestamp.setNow();
		Integer usec = new Integer(timestamp.getMicroSeconds());

		EncKrbPrivPart unencrypted_encKrbPrivPart = new EncKrbPrivPart(
			userData,
			timestamp,
			usec,
			seqNumber,
			sAddress,
			rAddress
		);

		byte[] temp = unencrypted_encKrbPrivPart.asn1Encode();

		EncryptedData encKrbPrivPart = new EncryptedData(
			key,
			temp
		);

		KRBPriv krb_priv = new KRBPriv(encKrbPrivPart);

		temp = krb_priv.asn1Encode();
		//System.out.println("krb_priv: " + temp.length + " bytes");
		//asn1.util.print(temp);
		//System.out.println();

		return krb_priv.asn1Encode();
	}

	public static byte[] rd_priv(
		KRBPriv krb_priv,
		EncryptionKey key,
		Integer seqNumber,
		HostAddress sAddress,
		HostAddresses rAddress
		) throws Asn1Exception, KdcErrException, KrbApErrException {
		
		byte[] temp = krb_priv.encPart.decrypt(key);
		EncodeRef ref = new EncodeRef(temp);
		EncKrbPrivPart enc_part = new EncKrbPrivPart(ref);

		//XXX check for matching fields

		return enc_part.userData;
	}

	public static byte[] mk_safe(
		byte[] userData,
		EncryptionKey key,
		Integer seqNumber,
		HostAddress sAddress,
		HostAddress rAddress
		) throws Asn1Exception, BitStringException, KdcErrException, KrbApErrException {

		KerberosTime timestamp = new KerberosTime();
		timestamp.setNow();
		Integer usec = new Integer(timestamp.getMicroSeconds());

		KRBSafeBody krb_safeBody = new KRBSafeBody(
			userData,
			timestamp,
			usec,
			seqNumber,
			sAddress,
			rAddress
		);

		byte[] temp = krb_safeBody.asn1Encode();

		Checksum cksum = new Checksum(
			Config.SAFECKSUMTYPE_DEFAULT,
			temp,
			key
		);

		KRBSafe krb_safe = new KRBSafe(
			krb_safeBody,
			cksum
		);

		temp = krb_safe.asn1Encode();
		//System.out.println("krb_safe: " + temp.length + " bytes");
		//asn1.util.print(temp);
		//System.out.println();

		return krb_safe.asn1Encode();
	}

	public static byte[] rd_safe(
		KRBSafe krb_safe,
		EncryptionKey key,
		Integer seqNumber,
		HostAddress sAddress,
		HostAddresses rAddress
		) throws Asn1Exception, KdcErrException, KrbApErrException {
		
		byte[] temp = krb_safe.safeBody.asn1Encode();

		if (!krb_safe.cksum.verifyKeyedChecksum(temp, key))
			throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED);

		//XXX check for matching fields

		return krb_safe.safeBody.userData;
	}

	public static void main(String args[]) throws
		Asn1Exception,
		BitStringException,
		KdcErrException,
		KrbApErrException,
		RealmException,
		UnknownHostException {

		byte[] msg1 = sample_as_req1();
		System.out.println("AS_REQ[1]: " + msg1.length + " bytes");
		util.print(msg1);
		System.out.println();

		byte[] msg2 = sample_as_req2();
		System.out.println("AS_REQ[2]: " + msg2.length + " bytes");
		util.print(msg2);
		System.out.println();

		EncodeRef ref = new EncodeRef(msg2);
		ASReq req = new ASReq(ref);

		byte[] msg3 = req.asn1Encode();
		System.out.println("AS_REQ[3]: " + msg3.length + " bytes");
		util.print(msg3);
		System.out.println();

		byte[] msg4 = sample_as_rep2;
		System.out.println("AS_REP[1]: " + msg4.length + " bytes");
		util.print(msg4);
		System.out.println();

		EncodeRef ref2 = new EncodeRef(msg4);
		ASRep rep2 = new ASRep(ref2);

		byte[] msg5 = rep2.asn1Encode();
		System.out.println("AS_REP[2]: " + msg5.length + " bytes");
		util.print(msg5);
		System.out.println();

		PrincipalName pn = new PrincipalName("sanfilip@booboo.osf.org");
		String salt = pn.getSalt();
		String passwd = "sanfilip";
		byte[] key = des.string_to_key_bytes(passwd + salt);
		long[] key_sched = new long[16];
		long ivec = 0;
		des.des_set_key(key, key_sched);

		System.out.println("ENC_AS_REP_PART[2] ciphertext bytes:");
		System.out.println(util.byte2hexString(rep2.encPart.cipher));
		System.out.println();

		byte[] msg6 = new byte[rep2.encPart.cipher.length];
		byte[] msg7 = new byte[msg6.length];

		System.arraycopy(rep2.encPart.cipher, 0, msg7, 0, msg7.length);
		des.cbc_encrypt(rep2.encPart.cipher, msg6,
			key_sched, ivec, false);
//		EncodeRef ref6 = new EncodeRef(msg6, 24);
//		System.out.println("ENC_AS_REP_PART[2]: " + (msg6.length - 24)
//			+ " bytes");
//		util.print(ref6);
//		System.out.println();

//		System.out.println("ENC_AS_REP_PART[2] plaintext bytes:");
//		byte[] msg7 = new byte[msg6.length - 24];
//		System.arraycopy(msg6, 24, msg7, 0, msg7.length);
		System.out.println("ENC_AS_REP_PART[2] plaintext bytes:");
		System.out.println(util.byte2hexString(msg6));
		System.out.println();

		System.out.println("ENC_AS_REP_PART[2] plaintext bytes:");
		EType eType = EType.getInstance(Krb5.ETYPE_DES_CBC_MD5);
		eType.decrypt(msg7, key);
		System.out.println(util.byte2hexString(msg7));
		System.out.println();

		System.out.println("eType.eType()=" + eType.eType());
		System.out.println("eType.checksumType()=" + eType.checksumType());
		System.out.println("eType.checksumSize()=" + eType.checksumSize());
		System.out.println("eType.blockSize()=" + eType.blockSize());
		System.out.println("eType.confounderSize()=" + eType.confounderSize());
		System.out.println("eType.minimumPadSize()=" + eType.minimumPadSize());
		System.out.println("eType.keyType()=" + eType.keyType());
		System.out.println("eType.keySize()=" + eType.keySize());
		System.out.println();

		byte[] md5hash = eType.generateChecksum(msg7);
		System.out.println("eType.generateChecksum()=" +
			util.byte2hexString(md5hash));
		System.out.println();

		System.out.println("eType.isChecksumValid()=" + 
			eType.isChecksumValid(msg7));

		byte[] msg8 = eType.decryptedData(msg7);
		System.out.println("eType.decryptedData():\n" +
			util.byte2hexString(msg8));
		System.out.println();

		util.print(msg8);
		System.out.println();

		ref = new EncodeRef(msg8);
		EncASRepPart encASRepPart = new EncASRepPart(ref);
		System.out.println();

		byte[] msg9 = encASRepPart.asn1Encode();
		util.print(msg9);
		System.out.println();

		byte[] msg10 = eType.encrypt(msg9, key);
		System.out.println("eType.encrypt():\n" +
			util.byte2hexString(msg10));
		System.out.println();

		//Testing AP_REQ...
		System.out.println("Testing AP_REQ...");
		System.out.println();

		Realm crealm = new Realm("booboo.osf.org");
		PrincipalName cname = new PrincipalName("sanfilip");

		byte[] msg11 = ap_req(
			new APOptions(),
			rep2.ticket,
			encASRepPart.key,
			crealm,
			cname,
			null
		);
		
		System.out.println("AP_REQ: " + msg11.length + " bytes");
		util.print(msg11);
		System.out.println();
		
//		EncodeRef ap_req2_ref = new EncodeRef(msg11);
//		APReq ap_req2 = new APReq(ap_req2_ref);
//		ap_req2.authenticator.decrypt(encASRepPart.key);
//		byte[] msg12 = ap_req2.authenticator.decryptedData();
//		EncodeRef authn_ref = new EncodeRef(msg12);
//		Authenticator authenticator2 = new Authenticator(new EncodeRef(msg12));

		APReq ap_req2 = new APReq(msg11);
		byte[] msg12 = ap_req2.authenticator.decrypt(encASRepPart.key);
		Authenticator authenticator2 = new Authenticator(msg12);

		System.out.println("Authenticator: " + msg12.length + " bytes");
		util.print(msg12);
		System.out.println();

		byte[] msg13 = authenticator2.asn1Encode();

		System.out.println("Authenticator[2]: " + msg13.length + " bytes");
		util.print(msg13);
		System.out.println();

		//Testing TGS_REQ...
		System.out.println("Testing TGS_REQ...");
		System.out.println();

		KDCOptions kdc_options = new KDCOptions();

		cname = new PrincipalName("sanfilip", Krb5.KRB_NT_PRINCIPAL);

		crealm = new Realm("booboo.osf.org");

		PrincipalName sname = new PrincipalName(
			"khttp/bluesky.osf.org", Krb5.KRB_NT_UNKNOWN);

		KerberosTime till = new KerberosTime();

		int nonce = Nonce.value();

		int[] etypes = { 3, 1 };

		HostAddress[] host_addresses = new HostAddress[1];
		host_addresses[0] = new HostAddress(Krb5.ADDRTYPE_INET,
			InetAddress.getLocalHost().getAddress());
		HostAddresses addresses = new HostAddresses(host_addresses);

		KDCReqBody reqBody = new KDCReqBody(
			kdc_options,
			cname,
			crealm,
			sname,
			null,
			till,
			null,
			nonce,
			etypes,
			addresses,
			null,
			null
			);

		Checksum cksum = new Checksum(reqBody.asn1Encode(Krb5.KRB_TGS_REQ));
		
		byte[] tgs_ap_req = ap_req(
			new APOptions(),
			rep2.ticket,
			encASRepPart.key,
			crealm,
			cname,
			cksum
		);
		
		PAData[] tgsPAData = new PAData[1];
		tgsPAData[0] = new PAData(Krb5.PA_TGS_REQ, tgs_ap_req);

		TGSReq tgsReq = new TGSReq(tgsPAData, reqBody);

		byte[] msg14 = tgsReq.asn1Encode();

		System.out.println("TGS_REQ: " + msg14.length + " bytes");
		util.print(msg14);
		System.out.println();

		byte[] msg15 = tgsReq.pAData[0].pADataValue;

		System.out.println("[TGS_AP_REQ]: " + msg15.length + " bytes");
		util.print(msg15);
		System.out.println();

		byte[] msg16 = tgs_req(
			new KDCOptions(),
			rep2.ticket,
			encASRepPart.key,
			new PrincipalName("sanfilip", Krb5.KRB_NT_PRINCIPAL),
			new Realm("booboo.osf.org"),
			new PrincipalName("khttp/bluesky.osf.org")
		);

		System.out.println("TGS_REQ[2]: " + msg16.length + " bytes");
		util.print(msg16);
		System.out.println();

		TGSReq tgsReq2 = new TGSReq(msg16);
		byte[] msg17 = tgsReq2.pAData[0].pADataValue;

		System.out.println("[TGS_AP_REQ][2]: " + msg17.length + " bytes");
		util.print(msg17);
		System.out.println();
		//System.out.println("AS_REP[3]: " + sample_as_rep3.length + " bytes");
		//krb5.lib.asn1.util.print(sample_as_rep3);
		//System.out.println();

		//DCE related test cases...

		//System.out.println("EncryptedData: " + sample_encPart.length + " bytes");
		//util.print(sample_encPart);
		//System.out.println();

		//EncodeRef ref_encPart = new EncodeRef(sample_encPart);
		//EncryptedData encPart = new EncryptedData(ref_encPart);
		//byte[] msg18 = encPart.asn1Encode();

		//System.out.println("Ticket: " + msg18.length + " bytes");
		//util.print(msg18);
		//System.out.println();

		//System.out.println("Ticket: " + sample_ticket.length + " bytes");
		//util.print(sample_ticket);
		//System.out.println();

		//EncodeRef ref_ticket = new EncodeRef(sample_ticket);
		//Ticket ticket = new Ticket(ref_ticket);
		//byte[] msg19 = ticket.asn1Encode();

		//System.out.println("Ticket: " + msg19.length + " bytes");
		//util.print(msg19);
		//System.out.println();

		System.out.println("AS_REP[3]: " + sample_as_rep3.length + " bytes");
		util.print(sample_as_rep3);
		System.out.println();

		EncodeRef ref_dce_as_rep = new EncodeRef(sample_as_rep3);
		ASRep dce_as_rep = new ASRep(ref_dce_as_rep);
		byte[] msg20 = dce_as_rep.asn1Encode();

		System.out.println("AS_REP[4]: " + msg20.length + " bytes");
		util.print(msg20);
		System.out.println();

		byte[] enc_as_rep_part =
			dce_as_rep.encPart.decrypt("somewha0cordelia.cell.osf.orgsanfilip");
		System.out.println("dce_as_rep.encPart: " +
			enc_as_rep_part.length + " bytes\n" +
			util.byte2hexString(enc_as_rep_part));
		System.out.println();

		EncodeRef ref20 = new EncodeRef(enc_as_rep_part);
		EncASRepPart enc_part = new EncASRepPart(ref20);
		util.print(enc_part.asn1Encode());
		System.out.println();

	}

}