1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.shared.kerberos.codec.kdcRep;
21
22
23 import org.apache.directory.api.asn1.actions.CheckNotNullLength;
24 import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
25 import org.apache.directory.api.asn1.ber.grammar.Grammar;
26 import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
27 import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
28 import org.apache.directory.shared.kerberos.KerberosConstants;
29 import org.apache.directory.shared.kerberos.codec.kdcRep.actions.AddPaData;
30 import org.apache.directory.shared.kerberos.codec.kdcRep.actions.CheckMsgType;
31 import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreCName;
32 import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreCRealm;
33 import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreEncPart;
34 import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StorePvno;
35 import org.apache.directory.shared.kerberos.codec.kdcRep.actions.StoreTicket;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39
40 /**
41 * This class implements the KdcReq structure. All the actions are declared
42 * in this class. As it is a singleton, these declaration are only done once. If
43 * an action is to be added or modified, this is where the work is to be done !
44 *
45 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
46 */
47 public final class KdcRepGrammar extends AbstractGrammar<KdcRepContainer>
48 {
49 /** The logger */
50 static final Logger LOG = LoggerFactory.getLogger( KdcRepGrammar.class );
51
52 /** A speedup for logger */
53 static final boolean IS_DEBUG = LOG.isDebugEnabled();
54
55 /** The instance of grammar. KdcReqGrammar is a singleton */
56 private static Grammar<KdcRepContainer> instance = new KdcRepGrammar();
57
58
59 /**
60 * Creates a new KdcRepGrammar object.
61 */
62 @SuppressWarnings("unchecked")
63 private KdcRepGrammar()
64 {
65 setName( KdcRepGrammar.class.getName() );
66
67 // Create the transitions table
68 super.transitions = new GrammarTransition[KdcRepStatesEnum.LAST_KDC_REP_STATE.ordinal()][256];
69
70 // ============================================================================================
71 // KdcReq
72 // ============================================================================================
73 // --------------------------------------------------------------------------------------------
74 // Transition from KdcRep init to KdcRep SEQ
75 // --------------------------------------------------------------------------------------------
76 // KDC-REP ::= SEQUENCE {
77 super.transitions[KdcRepStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
78 new GrammarTransition<KdcRepContainer>(
79 KdcRepStatesEnum.START_STATE,
80 KdcRepStatesEnum.KDC_REP_SEQ_STATE,
81 UniversalTag.SEQUENCE,
82 new CheckNotNullLength<KdcRepContainer>() );
83
84 // --------------------------------------------------------------------------------------------
85 // Transition from KdcRep SEQ to pvno tag
86 // --------------------------------------------------------------------------------------------
87 // KDC-REP ::= SEQUENCE {
88 // pvno [0]
89 super.transitions[KdcRepStatesEnum.KDC_REP_SEQ_STATE.ordinal()][KerberosConstants.KDC_REP_PVNO_TAG] =
90 new GrammarTransition<KdcRepContainer>(
91 KdcRepStatesEnum.KDC_REP_SEQ_STATE,
92 KdcRepStatesEnum.KDC_REP_PVNO_TAG_STATE,
93 KerberosConstants.KDC_REP_PVNO_TAG,
94 new CheckNotNullLength<KdcRepContainer>() );
95
96 // --------------------------------------------------------------------------------------------
97 // Transition from pvno tag to pvno value
98 // --------------------------------------------------------------------------------------------
99 // KDC-REP ::= SEQUENCE {
100 // pvno [0] INTEGER (5)
101 super.transitions[KdcRepStatesEnum.KDC_REP_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
102 new GrammarTransition<KdcRepContainer>(
103 KdcRepStatesEnum.KDC_REP_PVNO_TAG_STATE,
104 KdcRepStatesEnum.KDC_REP_PVNO_STATE,
105 UniversalTag.INTEGER,
106 new StorePvno() );
107
108 // --------------------------------------------------------------------------------------------
109 // Transition from pvno value to msg-type tag
110 // --------------------------------------------------------------------------------------------
111 // KDC-REP ::= SEQUENCE {
112 // ...
113 // msg-type [1]
114 super.transitions[KdcRepStatesEnum.KDC_REP_PVNO_STATE.ordinal()][KerberosConstants.KDC_REP_MSG_TYPE_TAG] =
115 new GrammarTransition<KdcRepContainer>(
116 KdcRepStatesEnum.KDC_REP_PVNO_STATE,
117 KdcRepStatesEnum.KDC_REP_MSG_TYPE_TAG_STATE,
118 KerberosConstants.KDC_REP_MSG_TYPE_TAG,
119 new CheckNotNullLength<KdcRepContainer>() );
120
121 // --------------------------------------------------------------------------------------------
122 // Transition from msg-type tag to msg-type value
123 // --------------------------------------------------------------------------------------------
124 // KDC-REP ::= SEQUENCE {
125 // ...
126 // msg-type [1] INTEGER (11 -- AS -- | 13 -- TGS --),
127 super.transitions[KdcRepStatesEnum.KDC_REP_MSG_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
128 new GrammarTransition<KdcRepContainer>(
129 KdcRepStatesEnum.KDC_REP_MSG_TYPE_TAG_STATE,
130 KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE,
131 UniversalTag.INTEGER,
132 new CheckMsgType() );
133
134 // --------------------------------------------------------------------------------------------
135 // Transition from msg-type value pa-data tag
136 // --------------------------------------------------------------------------------------------
137 // KDC-REP ::= SEQUENCE {
138 // ...
139 // padata [2]
140 super.transitions[KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE.ordinal()][KerberosConstants.KDC_REP_PA_DATA_TAG] =
141 new GrammarTransition<KdcRepContainer>(
142 KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE,
143 KdcRepStatesEnum.KDC_REP_PA_DATA_TAG_STATE,
144 KerberosConstants.KDC_REP_PA_DATA_TAG,
145 new CheckNotNullLength<KdcRepContainer>() );
146
147 // --------------------------------------------------------------------------------------------
148 // Transition from pa-data tag to pa-data sequence
149 // --------------------------------------------------------------------------------------------
150 // KDC-REP ::= SEQUENCE {
151 // ...
152 // padata [2] SEQUENCE OF
153 super.transitions[KdcRepStatesEnum.KDC_REP_PA_DATA_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
154 new GrammarTransition<KdcRepContainer>(
155 KdcRepStatesEnum.KDC_REP_PA_DATA_TAG_STATE,
156 KdcRepStatesEnum.KDC_REP_PA_DATA_STATE,
157 UniversalTag.SEQUENCE,
158 new CheckNotNullLength<KdcRepContainer>() );
159
160 // --------------------------------------------------------------------------------------------
161 // Transition from pa-data sequence to PA-DATA
162 // --------------------------------------------------------------------------------------------
163 // KDC-REP ::= SEQUENCE {
164 // ...
165 // padata [2] SEQUENCE OF PA-DATA
166 super.transitions[KdcRepStatesEnum.KDC_REP_PA_DATA_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
167 new GrammarTransition<KdcRepContainer>(
168 KdcRepStatesEnum.KDC_REP_PA_DATA_STATE,
169 KdcRepStatesEnum.KDC_REP_PA_DATA_STATE,
170 UniversalTag.SEQUENCE,
171 new AddPaData() );
172
173 // --------------------------------------------------------------------------------------------
174 // Transition from PA-DATA to crealm tag
175 // --------------------------------------------------------------------------------------------
176 // KDC-REP ::= SEQUENCE {
177 // ...
178 // crealm [3]
179 super.transitions[KdcRepStatesEnum.KDC_REP_PA_DATA_STATE.ordinal()][KerberosConstants.KDC_REP_CREALM_TAG] =
180 new GrammarTransition<KdcRepContainer>(
181 KdcRepStatesEnum.KDC_REP_PA_DATA_STATE,
182 KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE,
183 KerberosConstants.KDC_REP_CREALM_TAG,
184 new CheckNotNullLength<KdcRepContainer>() );
185
186 // --------------------------------------------------------------------------------------------
187 // Transition from msg-type value to crealm tag (pa-data is empty)
188 // --------------------------------------------------------------------------------------------
189 // KDC-REP ::= SEQUENCE {
190 // ...
191 // crealm [3]
192 super.transitions[KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE.ordinal()][KerberosConstants.KDC_REP_CREALM_TAG] =
193 new GrammarTransition<KdcRepContainer>(
194 KdcRepStatesEnum.KDC_REP_MSG_TYPE_STATE,
195 KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE,
196 KerberosConstants.KDC_REP_CREALM_TAG,
197 new CheckNotNullLength<KdcRepContainer>() );
198
199 // --------------------------------------------------------------------------------------------
200 // Transition from crealm tag to crealm value
201 // --------------------------------------------------------------------------------------------
202 // KDC-REP ::= SEQUENCE {
203 // ...
204 // crealm [3] Realm,
205 super.transitions[KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE.ordinal()][UniversalTag.GENERAL_STRING.getValue()] =
206 new GrammarTransition<KdcRepContainer>(
207 KdcRepStatesEnum.KDC_REP_CREALM_TAG_STATE,
208 KdcRepStatesEnum.KDC_REP_CREALM_STATE,
209 UniversalTag.GENERAL_STRING,
210 new StoreCRealm() );
211
212 // --------------------------------------------------------------------------------------------
213 // Transition from crealm value to cname
214 // --------------------------------------------------------------------------------------------
215 // KDC-REP ::= SEQUENCE {
216 // ...
217 // cname [4] PrincipalName,
218 super.transitions[KdcRepStatesEnum.KDC_REP_CREALM_STATE.ordinal()][KerberosConstants.KDC_REP_CNAME_TAG] =
219 new GrammarTransition<KdcRepContainer>(
220 KdcRepStatesEnum.KDC_REP_CREALM_STATE,
221 KdcRepStatesEnum.KDC_REP_CNAME_STATE,
222 KerberosConstants.KDC_REP_CNAME_TAG,
223 new StoreCName() );
224
225 // --------------------------------------------------------------------------------------------
226 // Transition from cname to ticket
227 // --------------------------------------------------------------------------------------------
228 // KDC-REP ::= SEQUENCE {
229 // ...
230 // ticket [5] Ticket,
231 super.transitions[KdcRepStatesEnum.KDC_REP_CNAME_STATE.ordinal()][KerberosConstants.KDC_REP_TICKET_TAG] =
232 new GrammarTransition<KdcRepContainer>(
233 KdcRepStatesEnum.KDC_REP_CNAME_STATE,
234 KdcRepStatesEnum.KDC_REP_TICKET_STATE,
235 KerberosConstants.KDC_REP_TICKET_TAG,
236 new StoreTicket() );
237
238 // --------------------------------------------------------------------------------------------
239 // Transition from ticket to enc-part
240 // --------------------------------------------------------------------------------------------
241 // KDC-REP ::= SEQUENCE {
242 // ...
243 // enc-part [6] EncryptedData
244 super.transitions[KdcRepStatesEnum.KDC_REP_TICKET_STATE.ordinal()][KerberosConstants.KDC_REP_ENC_PART_TAG] =
245 new GrammarTransition<KdcRepContainer>(
246 KdcRepStatesEnum.KDC_REP_TICKET_STATE,
247 KdcRepStatesEnum.KDC_REP_ENC_PART_STATE,
248 KerberosConstants.KDC_REP_ENC_PART_TAG,
249 new StoreEncPart() );
250 }
251
252
253 /**
254 * Get the instance of this grammar
255 *
256 * @return An instance on the KDC-REQ Grammar
257 */
258 public static Grammar<KdcRepContainer> getInstance()
259 {
260 return instance;
261 }
262 }