directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: rev 56296 - in incubator/directory/kerberos/trunk/source/main/org/apache/kerberos: io/decoder messages/application messages/components
Date Mon, 01 Nov 2004 23:27:46 GMT
Author: erodriguez
Date: Mon Nov  1 15:27:45 2004
New Revision: 56296

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/decoder/PrivateMessageDecoder.java
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/components/EncKrbPrivPartModifier.java
Modified:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/application/PrivateMessage.java
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/components/EncKrbPrivPart.java
Log:
Rounded out infrastructure for private message exchange.  Required for changepw service.

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/decoder/PrivateMessageDecoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/decoder/PrivateMessageDecoder.java
Mon Nov  1 15:27:45 2004
@@ -0,0 +1,68 @@
+/*
+ *   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.*;
+import org.apache.kerberos.messages.application.*;
+import org.bouncycastle.asn1.*;
+
+import java.io.*;
+import java.util.*;
+
+public class PrivateMessageDecoder extends KerberosMessageDecoder {
+	
+	public PrivateMessage decode(byte[] encodedPrivateMessage) throws IOException {
+		
+		ByteArrayInputStream bais = new ByteArrayInputStream(encodedPrivateMessage);
+		ASN1InputStream ais = new ASN1InputStream(bais);
+
+		DERApplicationSpecific app = (DERApplicationSpecific) ais.readObject();
+		
+		DERSequence privateMessage = (DERSequence) app.getObject();
+		return decodePrivateMessageSequence(privateMessage);
+	}
+	
+	private PrivateMessage decodePrivateMessageSequence(DERSequence sequence) {
+		
+		PrivateMessage message = new PrivateMessage();
+		
+		for (Enumeration e = sequence.getObjects(); e.hasMoreElements();) {
+			DERTaggedObject object = ((DERTaggedObject) e.nextElement());
+			int tag = object.getTagNo();
+			DERObject derObject = object.getObject();
+			switch (tag) {
+				case 0:
+					DERInteger tag0 = (DERInteger) derObject;
+					message.setProtocolVersionNumber(tag0.getValue().intValue());
+					break;
+				case 1:
+					DERInteger tag1 = (DERInteger) derObject;
+					message.setMessageType(MessageType.getTypeByOrdinal(tag1.getValue().intValue()));
+					break;
+				case 3:
+					DERSequence tag3 = (DERSequence)derObject;
+					message.setEncryptedPart(decodeEncryptedData(tag3));
+					break;
+			    default:
+			    	System.out.println(derObject);
+			    	break;
+			}
+		}
+		return message;
+	}
+}
+

Modified: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/application/PrivateMessage.java
==============================================================================
--- incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/application/PrivateMessage.java
(original)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/application/PrivateMessage.java
Mon Nov  1 15:27:45 2004
@@ -21,15 +21,24 @@
 
 public class PrivateMessage extends KerberosMessage {
 
-	private EncryptedData _encPart;
+	private EncryptedData _encryptedPart;
+	
+	public PrivateMessage() {
+		super(MessageType.KRB_PRIV);
+		// used by ASN.1 decoder
+	}
 
-	public PrivateMessage(EncryptedData encPart) {
+	public PrivateMessage(EncryptedData encryptedPart) {
 		super(MessageType.KRB_PRIV);
-		_encPart = encPart;
+		_encryptedPart = encryptedPart;
+	}
+	
+	public EncryptedData getEncryptedPart() {
+		return _encryptedPart;
 	}
 	
-	public EncryptedData getEncPart() {
-		return _encPart;
+	public void setEncryptedPart(EncryptedData encryptedData) {
+		_encryptedPart = encryptedData;
 	}
 }
 

Modified: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/components/EncKrbPrivPart.java
==============================================================================
--- incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/components/EncKrbPrivPart.java
(original)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/components/EncKrbPrivPart.java
Mon Nov  1 15:27:45 2004
@@ -19,44 +19,41 @@
 import org.apache.kerberos.messages.value.*;
 
 /**
- * Encrypted part of private message types
+ * Encrypted part of private messages
  */
 public class EncKrbPrivPart {
 
 	private byte[]       _userData;
-	private KerberosTime _timestamp; //optional
-	private Integer      _usec;      //optional
-	private Integer      _seqNumber; //optional
-	private HostAddress  _sAddress;  //optional
-	private HostAddress  _rAddress;  //optional
+	private KerberosTime _timestamp;        //optional
+	private int          _usec;             //optional
+	private int          _sequenceNumber;   //optional
+	private HostAddress  _senderAddress;    //optional
+	private HostAddress  _recipientAddress; //optional
 
-	/**
-	 * Class constructor
-	 */
-	public EncKrbPrivPart(byte[] userData, KerberosTime timestamp, Integer usec,
-			Integer seqNumber, HostAddress sAddress, HostAddress rAddress) {
+	public EncKrbPrivPart(byte[] userData, KerberosTime timestamp, int usec,
+			int sequenceNumber, HostAddress senderAddress, HostAddress recipientAddress) {
 		
-		_userData  = userData;
-		_timestamp = timestamp;
-		_usec      = usec;
-		_seqNumber = seqNumber;
-		_sAddress  = sAddress;
-		_rAddress  = rAddress;
+		_userData         = userData;
+		_timestamp        = timestamp;
+		_usec             = usec;
+		_sequenceNumber   = sequenceNumber;
+		_senderAddress    = senderAddress;
+		_recipientAddress = recipientAddress;
 	}
 
-	public HostAddress getRAddress() {
-		return _rAddress;
+	public HostAddress getRecipientAddress() {
+		return _recipientAddress;
 	}
-	public HostAddress getSAddress() {
-		return _sAddress;
+	public HostAddress getSenderAddress() {
+		return _senderAddress;
 	}
-	public Integer getSeqNumber() {
-		return _seqNumber;
+	public int getSequenceNumber() {
+		return _sequenceNumber;
 	}
 	public KerberosTime getTimestamp() {
 		return _timestamp;
 	}
-	public Integer getUsec() {
+	public int getMicroSecond() {
 		return _usec;
 	}
 	public byte[] getUserData() {

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/components/EncKrbPrivPartModifier.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/components/EncKrbPrivPartModifier.java
Mon Nov  1 15:27:45 2004
@@ -0,0 +1,54 @@
+/*
+ *   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.messages.components;
+
+import org.apache.kerberos.messages.value.*;
+
+public class EncKrbPrivPartModifier {
+
+	private byte[]       _userData;
+	private KerberosTime _timestamp;        //optional
+	private int          _usec;             //optional
+	private int          _sequenceNumber;   //optional
+	private HostAddress  _senderAddress;    //optional
+	private HostAddress  _recipientAddress; //optional
+
+	public EncKrbPrivPart getEncKrbPrivPart() {
+		return new EncKrbPrivPart(_userData, _timestamp, _usec, _sequenceNumber,
+				_senderAddress, _recipientAddress);
+	}
+
+	public void setRecipientAddress(HostAddress address) {
+		_recipientAddress = address;
+	}
+	public void setSenderAddress(HostAddress address) {
+		_senderAddress = address;
+	}
+	public void setSequenceNumber(int number) {
+		_sequenceNumber = number;
+	}
+	public void setTimestamp(KerberosTime timestamp) {
+		_timestamp = timestamp;
+	}
+	public void setMicroSecond(int usec) {
+		_usec = usec;
+	}
+	public void setUserData(byte[] data) {
+		_userData = data;
+	}
+}
+

Mime
View raw message