Author: erodriguez
Date: Wed Nov  3 10:29:27 2004
New Revision: 56503

Added:
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordDataDecoder.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordReplyEncoder.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordRequestDecoder.java
Log:
Codecs for the change password protocol request message, reply message, and 
password data payload.

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordDataDecoder.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordDataDecoder.java
       Wed Nov  3 10:29:27 2004
@@ -0,0 +1,67 @@
+/*
+ *   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.changepw.io;
+
+import org.apache.kerberos.changepw.value.*;
+import org.apache.kerberos.io.decoder.*;
+import org.bouncycastle.asn1.*;
+
+import java.io.*;
+import java.util.*;
+
+public class ChangePasswordDataDecoder extends KerberosMessageDecoder {
+       
+       public ChangePasswordData decodeChangePasswordData(byte[] 
encodedChangePasswdData) throws IOException {
+               
+               ByteArrayInputStream bais = new 
ByteArrayInputStream(encodedChangePasswdData);
+               ASN1InputStream ais = new ASN1InputStream(bais);
+               
+               DERSequence sequence = (DERSequence) ais.readObject();
+               
+               return decodeChangePasswdData(sequence);
+       }
+       
+       protected ChangePasswordData decodeChangePasswdData(DERSequence 
sequence) {
+               
+               ChangePasswordDataModifier modifier = new 
ChangePasswordDataModifier();
+
+               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.setNewPassword(tag0.getOctets());
+                                       break;
+                               case 1:
+                                       DERSequence tag1 = (DERSequence) 
derObject;
+                                       
modifier.setTargetName(decodePrincipalName(tag1));
+                                       break;
+                               case 2:
+                                       DERGeneralString tag2 = 
(DERGeneralString) derObject;
+                                       
modifier.setTargetRealm(tag2.getString());
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+               
+               return modifier.getChangePasswdData();
+       }
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordReplyEncoder.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordReplyEncoder.java
      Wed Nov  3 10:29:27 2004
@@ -0,0 +1,62 @@
+/*
+ *   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.changepw.io;
+
+import org.apache.kerberos.changepw.messages.*;
+import org.apache.kerberos.io.encoder.*;
+import org.apache.kerberos.messages.application.*;
+
+import java.io.*;
+import java.nio.*;
+
+public class ChangePasswordReplyEncoder {
+       
+       public byte[] encode(ChangePasswordReply message) throws IOException {
+               
+               // Build application reply bytes
+               ApplicationReply appReply = message.getApplicationReply();
+               ApplicationReplyEncoder appEncoder = new 
ApplicationReplyEncoder();
+               byte[] encodedAppReply = appEncoder.encode(appReply);
+
+               // Build private message bytes
+               PrivateMessage privateMessage = message.getPrivateMessage();
+               PrivateMessageEncoder privateEncoder = new 
PrivateMessageEncoder();
+               byte[] privateBytes = privateEncoder.encode(privateMessage);
+               
+               ByteBuffer buf = ByteBuffer.allocate(512);
+               
+               short headerLength = 6;
+               
+               short messageLength = (short)(headerLength + 
encodedAppReply.length + privateBytes.length);
+               
+               short protocolVersion = 1;
+               
+               buf.putShort(messageLength);
+               buf.putShort(protocolVersion);
+               buf.putShort((short)encodedAppReply.length);
+               
+               buf.put(encodedAppReply);
+               buf.put(privateBytes);
+               
+               byte[] reply = new byte[buf.position()];
+               buf.rewind();
+               buf.get(reply, 0, reply.length);
+               
+               return reply;
+       }
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordRequestDecoder.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/changepw/io/ChangePasswordRequestDecoder.java
    Wed Nov  3 10:29:27 2004
@@ -0,0 +1,60 @@
+/*
+ *   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.changepw.io;
+
+import org.apache.kerberos.changepw.messages.*;
+import org.apache.kerberos.io.decoder.*;
+import org.apache.kerberos.messages.*;
+import org.apache.kerberos.messages.application.*;
+
+import java.io.*;
+import java.nio.*;
+
+public class ChangePasswordRequestDecoder extends KerberosMessageDecoder {
+       
+       public ChangePasswordRequest decode(byte[] message) throws IOException {
+               
+               ByteBuffer buf = ByteBuffer.wrap(message);
+               
+               ChangePasswordRequestModifier modifier = new 
ChangePasswordRequestModifier();
+               
+               modifier.setMessageLength(buf.getShort());
+               modifier.setProtocolVersionNumber(buf.getShort());
+               
+               short authHeaderLength = buf.getShort();
+               modifier.setAuthHeaderLength(authHeaderLength);
+               
+               byte[] undecodedAuthHeader = new byte[authHeaderLength];
+               buf.get(undecodedAuthHeader, 0, authHeaderLength);
+               
+               ApplicationRequestDecoder decoder = new 
ApplicationRequestDecoder();
+               ApplicationRequest authHeader = 
decoder.decode(undecodedAuthHeader);
+               
+               modifier.setAuthHeader(authHeader);
+               
+               byte[] encodedPrivate = new byte[buf.remaining()];
+               buf.get(encodedPrivate, 0, buf.remaining());
+               
+               PrivateMessageDecoder privateDecoder = new 
PrivateMessageDecoder();
+               PrivateMessage privMessage = 
privateDecoder.decode(encodedPrivate);
+               
+               modifier.setPrivateMessage(privMessage);
+               
+               return modifier.getChangePasswordMessage();
+       }
+}
+

Reply via email to