directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: rev 56473 - incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder
Date Wed, 03 Nov 2004 04:27:47 GMT
Author: erodriguez
Date: Tue Nov  2 20:27:46 2004
New Revision: 56473

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java
Log:
ASN.1 DER encoders for Kerberos Private Messages and their Encrypted Private Message Parts.

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/EncKrbPrivPartEncoder.java
Tue Nov  2 20:27:46 2004
@@ -0,0 +1,57 @@
+/*
+ *   Copyright 2004 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 org.apache.kerberos.messages.components.*;
+import org.bouncycastle.asn1.*;
+
+import java.io.*;
+
+public class EncKrbPrivPartEncoder extends KerberosMessageEncoder {
+	
+	public static final int APPLICATION_CODE = 28;
+	
+	public byte[] encode(EncKrbPrivPart privPart) throws IOException {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		
+		DERSequence privPartSequence = encodePrivatePartSequence(privPart);
+		aos.writeObject(new DERApplicationSpecific(APPLICATION_CODE, privPartSequence));
+		aos.close();
+		
+		return baos.toByteArray();
+	}
+	
+	private DERSequence encodePrivatePartSequence(EncKrbPrivPart message) {
+		
+		ASN1EncodableVector vector = new ASN1EncodableVector();
+		
+		vector.add(new DERTaggedObject(0, new DEROctetString(message.getUserData())));
+		if (message.getTimestamp() != null)
+			vector.add(new DERTaggedObject(1, encodeKerberosTime(message.getTimestamp())));
+		if (message.getMicroSecond() != null)
+			vector.add(new DERTaggedObject(2, new DERInteger(message.getMicroSecond().intValue())));
+		if (message.getSequenceNumber() != null)
+			vector.add(new DERTaggedObject(3, new DERInteger(message.getSequenceNumber().intValue())));
+		vector.add(new DERTaggedObject(4, encodeHostAddress(message.getSenderAddress())));
+		if (message.getRecipientAddress() != null)
+			vector.add(new DERTaggedObject(5, encodeHostAddress(message.getRecipientAddress())));
+		
+		return new DERSequence(vector);
+	}
+}
+

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/PrivateMessageEncoder.java
Tue Nov  2 20:27:46 2004
@@ -0,0 +1,48 @@
+/*
+ *   Copyright 2004 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 org.apache.kerberos.messages.application.*;
+import org.bouncycastle.asn1.*;
+
+import java.io.*;
+
+public class PrivateMessageEncoder extends KerberosMessageEncoder {
+	
+	public byte[] encode(PrivateMessage message) throws IOException {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ASN1OutputStream aos = new ASN1OutputStream(baos);
+		
+		DERSequence privateMessageSequence = encodePrivateMessageSequence(message);
+		aos.writeObject(new DERApplicationSpecific(message.getMessageType().getOrdinal(), privateMessageSequence));
+		aos.close();
+		
+		return baos.toByteArray();
+	}
+	
+	private DERSequence encodePrivateMessageSequence(PrivateMessage message) {
+		
+		ASN1EncodableVector vector = new ASN1EncodableVector();
+		
+		vector.add(new DERTaggedObject(0, new DERInteger(message.getProtocolVersionNumber())));
+		vector.add(new DERTaggedObject(1, new DERInteger(message.getMessageType().getOrdinal())));
+		vector.add(new DERTaggedObject(3, encodeEncryptedData(message.getEncryptedPart())));
+		
+		return new DERSequence(vector);
+	}
+}
+

Mime
View raw message