Author: erodriguez Date: Tue Nov 2 20:31:28 2004 New Revision: 56474 Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java Log: ASN.1 DER encoders for Kerberos Application Reply messages and their encrypted payload.
Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/ApplicationReplyEncoder.java Tue Nov 2 20:31:28 2004 @@ -0,0 +1,50 @@ +/* + * 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 ApplicationReplyEncoder extends KerberosMessageEncoder { + + public static final int APPLICATION_CODE = 15; + + public byte[] encode(ApplicationReply reply) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ASN1OutputStream aos = new ASN1OutputStream(baos); + + DERSequence replySequence = encodeReplySequence(reply); + aos.writeObject(new DERApplicationSpecific(APPLICATION_CODE, replySequence)); + aos.close(); + + return baos.toByteArray(); + } + + private DERSequence encodeReplySequence(ApplicationReply 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(2, encodeEncryptedData(message.getEncPart()))); + + return new DERSequence(vector); + } +} + Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/io/encoder/EncApRepPartEncoder.java Tue Nov 2 20:31:28 2004 @@ -0,0 +1,53 @@ +/* + * 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 EncApRepPartEncoder extends KerberosMessageEncoder { + + public static final int APPLICATION_CODE = 27; + + public byte[] encode(EncApRepPart apRepPart) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ASN1OutputStream aos = new ASN1OutputStream(baos); + + DERSequence privPartSequence = encodeApRepPartSequence(apRepPart); + aos.writeObject(new DERApplicationSpecific(APPLICATION_CODE, privPartSequence)); + aos.close(); + + return baos.toByteArray(); + } + + private DERSequence encodeApRepPartSequence(EncApRepPart message) { + + ASN1EncodableVector vector = new ASN1EncodableVector(); + + vector.add(new DERTaggedObject(0, encodeKerberosTime(message.getClientTime()))); + vector.add(new DERTaggedObject(1, new DERInteger(message.getClientMicroSecond()))); + if (message.getSubSessionKey() != null) + vector.add(new DERTaggedObject(2, encodeEncryptionKey(message.getSubSessionKey()))); + if (message.getSequenceNumber() != null) + vector.add(new DERTaggedObject(3, new DERInteger(message.getSequenceNumber().intValue()))); + + return new DERSequence(vector); + } +} +
