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.decoder;
21
22
23 import java.io.IOException;
24 import java.util.Enumeration;
25
26 import org.apache.directory.server.kerberos.shared.KerberosMessageType;
27 import org.apache.directory.server.kerberos.shared.messages.ApplicationRequest;
28 import org.apache.directory.server.kerberos.shared.messages.value.ApOptions;
29 import org.apache.directory.shared.asn1.der.ASN1InputStream;
30 import org.apache.directory.shared.asn1.der.DERApplicationSpecific;
31 import org.apache.directory.shared.asn1.der.DERBitString;
32 import org.apache.directory.shared.asn1.der.DEREncodable;
33 import org.apache.directory.shared.asn1.der.DERInteger;
34 import org.apache.directory.shared.asn1.der.DERSequence;
35 import org.apache.directory.shared.asn1.der.DERTaggedObject;
36
37
38
39
40
41
42 public class ApplicationRequestDecoder
43 {
44
45
46
47
48
49
50
51 public ApplicationRequest decode( byte[] encodedAuthHeader ) throws IOException
52 {
53 ASN1InputStream ais = new ASN1InputStream( encodedAuthHeader );
54
55 DERApplicationSpecific app = ( DERApplicationSpecific ) ais.readObject();
56
57 DERSequence apreq = ( DERSequence ) app.getObject();
58
59 return decodeApplicationRequestSequence( apreq );
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73 private ApplicationRequest decodeApplicationRequestSequence( DERSequence sequence ) throws IOException
74 {
75 ApplicationRequest authHeader = new ApplicationRequest();
76
77 for ( Enumeration<DEREncodable> e = sequence.getObjects(); e.hasMoreElements(); )
78 {
79 DERTaggedObject object = ( ( DERTaggedObject ) e.nextElement() );
80 int tag = object.getTagNo();
81 DEREncodable derObject = object.getObject();
82
83 switch ( tag )
84 {
85 case 0:
86 DERInteger tag0 = ( DERInteger ) derObject;
87 authHeader.setProtocolVersionNumber( tag0.intValue() );
88 break;
89
90 case 1:
91 DERInteger tag1 = ( DERInteger ) derObject;
92 authHeader.setMessageType( KerberosMessageType.getTypeByOrdinal( tag1.intValue() ) );
93 break;
94
95 case 2:
96 DERBitString apOptions = ( DERBitString ) derObject;
97 authHeader.setApOptions( new ApOptions( apOptions.getOctets() ) );
98 break;
99 case 3:
100 DERApplicationSpecific tag3 = ( DERApplicationSpecific ) derObject;
101 authHeader.setTicket( TicketDecoder.decode( tag3 ) );
102 break;
103
104 case 4:
105 DERSequence tag4 = ( DERSequence ) derObject;
106 authHeader.setEncPart( EncryptedDataDecoder.decode( tag4 ) );
107 break;
108 }
109 }
110
111 return authHeader;
112 }
113 }