1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.kerberos.shared.io.encoder;
21
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
25
26 import org.apache.directory.server.kerberos.shared.messages.Encodable;
27 import org.apache.directory.server.kerberos.shared.messages.KdcReply;
28 import org.apache.directory.shared.asn1.der.ASN1OutputStream;
29 import org.apache.directory.shared.asn1.der.DERApplicationSpecific;
30 import org.apache.directory.shared.asn1.der.DERBitString;
31 import org.apache.directory.shared.asn1.der.DERGeneralString;
32 import org.apache.directory.shared.asn1.der.DERInteger;
33 import org.apache.directory.shared.asn1.der.DERSequence;
34 import org.apache.directory.shared.asn1.der.DERTaggedObject;
35
36
37
38
39
40
41 public abstract class EncKdcRepPartEncoder implements Encoder
42 {
43 private int applicationCode;
44
45
46 protected EncKdcRepPartEncoder(int applicationCode)
47 {
48 this.applicationCode = applicationCode;
49 }
50
51
52 public byte[] encode( Encodable app ) throws IOException
53 {
54 ByteArrayOutputStream baos = new ByteArrayOutputStream();
55 ASN1OutputStream aos = new ASN1OutputStream( baos );
56
57 DERSequence initialSequence = encodeInitialSequence( ( KdcReply ) app );
58 aos.writeObject( DERApplicationSpecific.valueOf( applicationCode, initialSequence ) );
59
60 return baos.toByteArray();
61 }
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 protected DERSequence encodeInitialSequence( KdcReply reply )
82 {
83 DERSequence sequence = new DERSequence();
84
85 sequence.add( new DERTaggedObject( 0, EncryptionKeyEncoder.encodeSequence( reply.getKey() ) ) );
86 sequence.add( new DERTaggedObject( 1, LastRequestEncoder.encode( reply.getLastRequest() ) ) );
87 sequence.add( new DERTaggedObject( 2, DERInteger.valueOf( reply.getNonce() ) ) );
88
89
90 if ( reply.getKeyExpiration() != null )
91 {
92 sequence.add( new DERTaggedObject( 3, KerberosTimeEncoder.encode( reply.getKeyExpiration() ) ) );
93 }
94
95 sequence.add( new DERTaggedObject( 4, new DERBitString( reply.getFlags().getBytes() ) ) );
96 sequence.add( new DERTaggedObject( 5, KerberosTimeEncoder.encode( reply.getAuthTime() ) ) );
97
98
99 if ( reply.getStartTime() != null )
100 {
101 sequence.add( new DERTaggedObject( 6, KerberosTimeEncoder.encode( reply.getStartTime() ) ) );
102 }
103
104 sequence.add( new DERTaggedObject( 7, KerberosTimeEncoder.encode( reply.getEndTime() ) ) );
105
106
107 if ( reply.getRenewTill() != null )
108 {
109 sequence.add( new DERTaggedObject( 8, KerberosTimeEncoder.encode( reply.getRenewTill() ) ) );
110 }
111
112 sequence.add( new DERTaggedObject( 9, DERGeneralString.valueOf( reply.getServerRealm().toString() ) ) );
113 sequence.add( new DERTaggedObject( 10, PrincipalNameEncoder.encode( reply.getServerPrincipal() ) ) );
114
115
116 if ( reply.getClientAddresses() != null )
117 {
118 sequence.add( new DERTaggedObject( 11, HostAddressesEncoder.encodeSequence( reply.getClientAddresses() ) ) );
119 }
120
121 return sequence;
122 }
123 }