directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r151104 - in incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder: EncryptedTimestampEncoder.java PreAuthenticationDataEncoder.java
Date Thu, 03 Feb 2005 02:40:00 GMT
Author: erodriguez
Date: Wed Feb  2 18:40:00 2005
New Revision: 151104

URL: http://svn.apache.org/viewcvs?view=rev&rev=151104
Log:
ASN.1 encoders for pre-authentication and encrypted timestamps.

Added:
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java
    incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java?view=auto&rev=151104
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java
(added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/EncryptedTimestampEncoder.java
Wed Feb  2 18:40:00 2005
@@ -0,0 +1,63 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.kerberos.io.encoder;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.asn1.der.ASN1OutputStream;
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.EncryptedTimeStamp;
+
+
+public class EncryptedTimestampEncoder extends KerberosMessageEncoder
+{
+	public byte[] encode( EncryptedTimeStamp encryptedTimestamp ) throws IOException
+	{
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
+		
+		aos.writeObject( encodeTimestamp( encryptedTimestamp ) );
+		aos.close();
+
+		return baos.toByteArray();
+	}
+	
+	/**
+     * PA-ENC-TS-ENC   ::= SEQUENCE {
+     *         patimestamp[0]               KerberosTime, -- client's time
+     *         pausec[1]                    INTEGER OPTIONAL
+     * }
+	 */
+	private DERSequence encodeTimestamp( EncryptedTimeStamp encryptedTimestamp )
+	{
+		DERSequence sequence = new DERSequence();
+		
+		sequence.add( new DERTaggedObject( 0, encodeKerberosTime( encryptedTimestamp.getTimeStamp()
) ) );
+		
+		if ( encryptedTimestamp.getMicroSeconds() > 0)
+		{
+		    sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( encryptedTimestamp.getMicroSeconds()
) ) );
+		}
+		
+		return sequence;
+	}
+}
+

Added: incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java?view=auto&rev=151104
==============================================================================
--- incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java
(added)
+++ incubator/directory/kerberos/trunk/core/src/java/org/apache/kerberos/io/encoder/PreAuthenticationDataEncoder.java
Wed Feb  2 18:40:00 2005
@@ -0,0 +1,60 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.kerberos.io.encoder;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.asn1.der.ASN1OutputStream;
+import org.apache.asn1.der.DERInteger;
+import org.apache.asn1.der.DEROctetString;
+import org.apache.asn1.der.DERSequence;
+import org.apache.asn1.der.DERTaggedObject;
+import org.apache.kerberos.messages.value.PreAuthenticationData;
+
+
+public class PreAuthenticationDataEncoder extends KerberosMessageEncoder
+{
+	public byte[] encode( PreAuthenticationData preAuth ) throws IOException
+	{
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ASN1OutputStream aos = new ASN1OutputStream( baos );
+		
+		aos.writeObject( encodePreAuth( preAuth ) );
+		aos.close();
+
+		return baos.toByteArray();
+	}
+	
+	/**
+	 * PA-DATA ::=        SEQUENCE {
+	 *         padata-type[1]        INTEGER,
+	 *         padata-value[2]       OCTET STRING
+	 * }
+	 */
+	private DERSequence encodePreAuth( PreAuthenticationData preAuth )
+	{
+		DERSequence sequence = new DERSequence();
+		
+		sequence.add( new DERTaggedObject( 1, DERInteger.valueOf( preAuth.getDataType().getOrdinal()
) ) );
+		sequence.add( new DERTaggedObject( 2, new DEROctetString( preAuth.getDataValue() ) ) );
+		
+		return sequence;
+	}
+}
+



Mime
View raw message