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.krbSafe;
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.krbSafe.actions.CheckMsgType;
30 import org.apache.directory.shared.kerberos.codec.krbSafe.actions.KrbSafeInit;
31 import org.apache.directory.shared.kerberos.codec.krbSafe.actions.StoreChecksum;
32 import org.apache.directory.shared.kerberos.codec.krbSafe.actions.StorePvno;
33 import org.apache.directory.shared.kerberos.codec.krbSafe.actions.StoreSafeBody;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38 /**
39 * This class implements the KRB-SAFE structure. All the actions are declared
40 * in this class. As it is a singleton, these declaration are only done once. If
41 * an action is to be added or modified, this is where the work is to be done !
42 *
43 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
44 */
45 public final class KrbSafeGrammar extends AbstractGrammar<KrbSafeContainer>
46 {
47 /** The logger */
48 static final Logger LOG = LoggerFactory.getLogger( KrbSafeGrammar.class );
49
50 /** A speedup for logger */
51 static final boolean IS_DEBUG = LOG.isDebugEnabled();
52
53 /** The instance of grammar. KrbSafeGrammar is a singleton */
54 private static Grammar<KrbSafeContainer> instance = new KrbSafeGrammar();
55
56
57 /**
58 * Creates a new KrbSafeGrammar object.
59 */
60 @SuppressWarnings("unchecked")
61 private KrbSafeGrammar()
62 {
63 setName( KrbSafeGrammar.class.getName() );
64
65 // Create the transitions table
66 super.transitions = new GrammarTransition[KrbSafeStatesEnum.LAST_KRB_SAFE_STATE.ordinal()][256];
67
68 // ============================================================================================
69 // KRB-SAFE
70 // ============================================================================================
71 // --------------------------------------------------------------------------------------------
72 // Transition from KrbSafe init to KrbSafe tag
73 // --------------------------------------------------------------------------------------------
74 // KRB-SAFE ::= [APPLICATION 20]
75 super.transitions[KrbSafeStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_SAFE_TAG] =
76 new GrammarTransition<KrbSafeContainer>(
77 KrbSafeStatesEnum.START_STATE,
78 KrbSafeStatesEnum.KRB_SAFE_TAG_STATE,
79 KerberosConstants.KRB_SAFE_TAG,
80 new KrbSafeInit() );
81
82 // --------------------------------------------------------------------------------------------
83 // Transition from KrbSafe tag to KrbSafe SEQ
84 // --------------------------------------------------------------------------------------------
85 // KRB-SAFE ::= [APPLICATION 20] SEQUENCE {
86 super.transitions[KrbSafeStatesEnum.KRB_SAFE_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
87 new GrammarTransition<KrbSafeContainer>(
88 KrbSafeStatesEnum.KRB_SAFE_TAG_STATE,
89 KrbSafeStatesEnum.KRB_SAFE_SEQ_STATE,
90 UniversalTag.SEQUENCE,
91 new CheckNotNullLength<KrbSafeContainer>() );
92
93 // --------------------------------------------------------------------------------------------
94 // Transition from KrbSafe SEQ to pvno tag
95 // --------------------------------------------------------------------------------------------
96 // KRB-SAFE ::= SEQUENCE {
97 // pvno [0]
98 super.transitions[KrbSafeStatesEnum.KRB_SAFE_SEQ_STATE.ordinal()][KerberosConstants.KRB_SAFE_PVNO_TAG] =
99 new GrammarTransition<KrbSafeContainer>(
100 KrbSafeStatesEnum.KRB_SAFE_SEQ_STATE,
101 KrbSafeStatesEnum.KRB_SAFE_PVNO_TAG_STATE,
102 KerberosConstants.KRB_SAFE_PVNO_TAG,
103 new CheckNotNullLength<KrbSafeContainer>() );
104
105 // --------------------------------------------------------------------------------------------
106 // Transition from pvno tag to pvno value
107 // --------------------------------------------------------------------------------------------
108 // KRB-SAFE ::= SEQUENCE {
109 // pvno [0] INTEGER (5) ,
110 super.transitions[KrbSafeStatesEnum.KRB_SAFE_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
111 new GrammarTransition<KrbSafeContainer>(
112 KrbSafeStatesEnum.KRB_SAFE_PVNO_TAG_STATE,
113 KrbSafeStatesEnum.KRB_SAFE_PVNO_STATE,
114 UniversalTag.INTEGER,
115 new StorePvno() );
116
117 // --------------------------------------------------------------------------------------------
118 // Transition from pvno to msg-type tag
119 // --------------------------------------------------------------------------------------------
120 // msg-type [1]
121 super.transitions[KrbSafeStatesEnum.KRB_SAFE_PVNO_STATE.ordinal()][KerberosConstants.KRB_SAFE_MSGTYPE_TAG] =
122 new GrammarTransition<KrbSafeContainer>(
123 KrbSafeStatesEnum.KRB_SAFE_PVNO_STATE,
124 KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_TAG_STATE,
125 KerberosConstants.KRB_SAFE_MSGTYPE_TAG,
126 new CheckNotNullLength<KrbSafeContainer>() );
127
128 // --------------------------------------------------------------------------------------------
129 // Transition from msg-type tag to msg-type value
130 // --------------------------------------------------------------------------------------------
131 // msg-type [1] INTEGER (30)
132 super.transitions[KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
133 new GrammarTransition<KrbSafeContainer>(
134 KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_TAG_STATE,
135 KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_STATE,
136 UniversalTag.INTEGER,
137 new CheckMsgType() );
138
139 // --------------------------------------------------------------------------------------------
140 // Transition from msg-type value to safe-body tag
141 // --------------------------------------------------------------------------------------------
142 // safe-body [2] KRB-SAFE-BODY
143 super.transitions[KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_STATE.ordinal()][KerberosConstants.KRB_SAFE_SAFE_BODY_TAG] =
144 new GrammarTransition<KrbSafeContainer>(
145 KrbSafeStatesEnum.KRB_SAFE_MSGTYPE_STATE,
146 KrbSafeStatesEnum.KRB_SAFE_SAFE_BODY_TAG_STATE,
147 KerberosConstants.KRB_SAFE_SAFE_BODY_TAG,
148 new StoreSafeBody() );
149
150 // --------------------------------------------------------------------------------------------
151 // Transition from safe-body tag to cksum tag
152 // --------------------------------------------------------------------------------------------
153 // cksum [3] Checksum
154 super.transitions[KrbSafeStatesEnum.KRB_SAFE_SAFE_BODY_TAG_STATE.ordinal()][KerberosConstants.KRB_SAFE_CKSUM_TAG] =
155 new GrammarTransition<KrbSafeContainer>(
156 KrbSafeStatesEnum.KRB_SAFE_SAFE_BODY_TAG_STATE,
157 KrbSafeStatesEnum.KRB_SAFE_CKSUM_TAG_STATE,
158 KerberosConstants.KRB_SAFE_CKSUM_TAG,
159 new StoreChecksum() );
160 }
161
162
163 /**
164 * Get the instance of this grammar
165 *
166 * @return An instance on the KRB-SAFE Grammar
167 */
168 public static Grammar<KrbSafeContainer> getInstance()
169 {
170 return instance;
171 }
172 }