directory-commits mailing list archives

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

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/decoder/EncKrbPrivPartDecoder.java
Log:
ASN.1 decoder for the encrypted payload of Kerberos Private Messages.

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/decoder/EncKrbPrivPartDecoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/decoder/EncKrbPrivPartDecoder.java
Tue Nov  2 20:36:19 2004
@@ -0,0 +1,80 @@
+/*
+ *   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.decoder;
+
+import org.apache.kerberos.messages.components.*;
+import org.bouncycastle.asn1.*;
+
+import java.io.*;
+import java.util.*;
+
+public class EncKrbPrivPartDecoder extends KerberosMessageDecoder {
+	
+	public EncKrbPrivPart decode(byte[] encodedPrivatePart) throws IOException {
+		
+		ByteArrayInputStream bais = new ByteArrayInputStream(encodedPrivatePart);
+		ASN1InputStream ais = new ASN1InputStream(bais);
+
+		DERApplicationSpecific app = (DERApplicationSpecific) ais.readObject();
+		
+		DERSequence privatePart = (DERSequence) app.getObject();
+		
+		return decodePrivatePartSequence(privatePart);
+	}
+	
+	private EncKrbPrivPart decodePrivatePartSequence(DERSequence sequence) {
+		
+		EncKrbPrivPartModifier modifier = new EncKrbPrivPartModifier();
+		
+		for (Enumeration e = sequence.getObjects(); e.hasMoreElements();) {
+			DERTaggedObject object = ((DERTaggedObject) e.nextElement());
+			int tag = object.getTagNo();
+			DERObject derObject = object.getObject();
+			switch (tag) {
+				case 0:
+					DEROctetString tag0 = (DEROctetString) derObject;
+					modifier.setUserData(tag0.getOctets());
+					break;
+				case 1:
+					DERGeneralizedTime tag1 = (DERGeneralizedTime) derObject;
+					modifier.setTimestamp(decodeKerberosTime(tag1));
+					break;
+				case 2:
+					DERInteger tag2 = (DERInteger)derObject;
+					modifier.setMicroSecond(new Integer(tag2.getValue().intValue()));
+					break;
+				case 3:
+					DERInteger tag3 = (DERInteger)derObject;
+					modifier.setSequenceNumber(new Integer(tag3.getValue().intValue()));
+					break;
+				case 4:
+					DERSequence tag4 = (DERSequence)derObject;
+					modifier.setSenderAddress(decodeHostAddress(tag4));
+					break;
+				case 5:
+					DERSequence tag5 = (DERSequence)derObject;
+					modifier.setRecipientAddress(decodeHostAddress(tag5));
+					break;
+			    default:
+			    	System.out.println(derObject);
+			    	break;
+			}
+		}
+		return modifier.getEncKrbPrivPart();
+	}
+}
+

Mime
View raw message