Small cleanups mostly related to proto_reg_handoff
[obnox/wireshark/wip.git] / asn1 / spnego / spnego.cnf
1 # spnego.cnf
2 # spnego conformation file
3
4 # $Id$
5
6 #.EXPORTS
7
8 #.PDU
9
10 #.NO_EMIT
11
12 #.TYPE_RENAME
13 NegTokenInit/mechListMIC T_NegTokenInit_mechListMIC
14
15 #.FIELD_RENAME
16 NegTokenInit/mechListMIC negTokenInit_mechListMIC
17
18 #.FN_PARS MechType
19
20   FN_VARIANT = _str  VAL_PTR = &MechType_oid
21
22 #.FN_BODY MechType
23
24   gssapi_oid_value *value;
25
26 %(DEFAULT_BODY)s
27
28   value = gssapi_lookup_oid_str(MechType_oid);
29
30   /*
31    * Tell our caller the first mechanism we see, so that if
32    * this is a negTokenInit with a mechToken, it can interpret
33    * the mechToken according to the first mechType.  (There
34    * might not have been any indication of the mechType
35    * in prior frames, so we can't necessarily use the
36    * mechanism from the conversation; i.e., a negTokenInit
37    * can contain the initial security token for the desired
38    * mechanism of the initiator - that's the first mechanism
39    * in the list.)
40    */
41   if (!saw_mechanism) {
42     if (value)
43       next_level_value = value;
44     saw_mechanism = TRUE;
45   }
46
47 #.FN_BODY InnerContextToken
48
49   gssapi_oid_value *next_level_value;
50   proto_item *item;
51   proto_tree *subtree;
52   tvbuff_t *token_tvb;
53   int len;
54
55   /*
56    * XXX - what should we do if this OID doesn't match the value
57    * attached to the frame or conversation?  (That would be
58    * bogus, but that's not impossible - some broken implementation
59    * might negotiate some security mechanism but put the OID
60    * for some other security mechanism in GSS_Wrap tokens.)
61    * Does it matter?
62    */
63   next_level_value = gssapi_lookup_oid_str(MechType_oid);
64
65   /*
66    * Now dissect the GSS_Wrap token; it's assumed to be in the
67    * rest of the tvbuff.
68    */
69   item = proto_tree_add_item(tree, hf_spnego_wraptoken, tvb, offset, -1, FALSE); 
70
71   subtree = proto_item_add_subtree(item, ett_spnego_wraptoken);
72
73   /*
74    * Now, we should be able to dispatch after creating a new TVB.
75    * The subdissector must return the length of the part of the
76    * token it dissected, so we can return the length of the part
77    * we (and it) dissected.
78    */
79   token_tvb = tvb_new_subset(tvb, offset, -1, -1);
80   if (next_level_value && next_level_value->wrap_handle) {
81     len = call_dissector(next_level_value->wrap_handle, token_tvb, actx->pinfo,
82                          subtree);
83     if (len == 0)
84       offset = tvb_length(tvb);
85     else
86       offset = offset + len;
87   } else
88     offset = tvb_length(tvb);
89
90 #.FN_BODY MechTypeList
91
92   conversation_t *conversation;
93
94   saw_mechanism = FALSE;
95
96 %(DEFAULT_BODY)s
97
98   /* 
99    * If we saw a mechType we need to store it in case the negTokenTarg
100    * does not provide a supportedMech.
101    */
102   if(saw_mechanism){
103     conversation = find_conversation(actx->pinfo->fd->num, 
104                                         &actx->pinfo->src, &actx->pinfo->dst,
105                                         actx->pinfo->ptype, 
106                                         actx->pinfo->srcport, actx->pinfo->destport, 0);
107     if(!conversation){
108       conversation = conversation_new(actx->pinfo->fd->num, 
109                                         &actx->pinfo->src, &actx->pinfo->dst,
110                                         actx->pinfo->ptype,
111                                         actx->pinfo->srcport, actx->pinfo->destport, 0);
112     }
113     conversation_add_proto_data(conversation, proto_spnego, next_level_value);
114   }
115
116 #.FN_PARS NegTokenInit/mechToken
117
118   VAL_PTR = &mechToken_tvb
119
120 #.FN_BODY NegTokenInit/mechToken
121
122   tvbuff_t *mechToken_tvb = NULL;
123
124 %(DEFAULT_BODY)s
125
126   /*
127    * Now, we should be able to dispatch, if we've gotten a tvbuff for
128    * the token and we have information on how to dissect its contents.
129    */
130   if (mechToken_tvb && next_level_value)
131      call_dissector(next_level_value->handle, mechToken_tvb, actx->pinfo, tree);
132
133
134 #.FN_BODY NegTokenInit/mechListMIC
135
136   gint8 class;
137   gboolean pc;
138   gint32 tag;
139   tvbuff_t *mechListMIC_tvb;
140
141   /*
142    * There seems to be two different forms this can take,
143    * one as an octet string, and one as a general string in a 
144    * sequence.
145    *
146    * Peek at the header, and then decide which it is we're seeing.
147    */
148   get_ber_identifier(tvb, offset, &class, &pc, &tag);
149   if (class == BER_CLASS_UNI && pc && tag == BER_UNI_TAG_SEQUENCE) {
150     /*
151      * It's a sequence.
152      */
153     return dissect_spnego_PrincipalSeq(FALSE, tvb, offset, actx, tree,
154                                        hf_spnego_mechListMIC);
155   } else {
156     /*
157      * It's not a sequence, so dissect it as an octet string,
158      * which is what it's supposed to be; that'll cause the
159      * right error report if it's not an octet string, either.
160      */
161     offset = dissect_ber_octet_string(FALSE, actx, tree, tvb, offset,
162                                       hf_spnego_mechListMIC, &mechListMIC_tvb);
163
164     /*
165      * Now, we should be able to dispatch with that tvbuff.
166      */
167     if (mechListMIC_tvb && next_level_value)
168       call_dissector(next_level_value->handle, mechListMIC_tvb, actx->pinfo, tree);
169     return offset;
170   }
171
172 #.FN_BODY NegTokenTarg/supportedMech
173
174   conversation_t *conversation;
175
176   saw_mechanism = FALSE;
177
178 %(DEFAULT_BODY)s
179
180   /*
181    * If we saw an explicit mechType we store this in the conversation so that
182    * it will override any mechType we might have picked up from the 
183    * negTokenInit.
184    */
185   if(saw_mechanism){
186     conversation = find_conversation(actx->pinfo->fd->num, 
187                                         &actx->pinfo->src, &actx->pinfo->dst,
188                                         actx->pinfo->ptype, 
189                                         actx->pinfo->srcport, actx->pinfo->destport, 0);
190     if(!conversation){
191       conversation = conversation_new(actx->pinfo->fd->num, 
192                                         &actx->pinfo->src, &actx->pinfo->dst,
193                                         actx->pinfo->ptype,
194                                         actx->pinfo->srcport, actx->pinfo->destport, 0);
195     }
196     conversation_add_proto_data(conversation, proto_spnego, next_level_value);
197   }
198
199
200 #.FN_PARS NegTokenTarg/responseToken
201
202   VAL_PTR = &responseToken_tvb
203
204 #.FN_BODY NegTokenTarg/responseToken
205
206   tvbuff_t *responseToken_tvb;
207
208
209 %(DEFAULT_BODY)s
210
211
212   /*
213    * Now, we should be able to dispatch, if we've gotten a tvbuff for
214    * the token and we have information on how to dissect its contents.
215    * However, we should make sure that there is something in the 
216    * response token ...
217    */
218   if (responseToken_tvb && (tvb_reported_length(responseToken_tvb) > 0) ){
219     gssapi_oid_value *value=next_level_value;
220
221     if(value){
222       call_dissector(value->handle, responseToken_tvb, actx->pinfo, tree);
223     }
224   }
225
226
227 #.FN_PARS NegTokenTarg/mechListMIC
228
229   VAL_PTR = &mechListMIC_tvb
230
231 #.FN_BODY NegTokenTarg/mechListMIC
232
233   tvbuff_t *mechListMIC_tvb;
234
235
236 %(DEFAULT_BODY)s
237
238
239   /*
240    * Now, we should be able to dispatch, if we've gotten a tvbuff for
241    * the MIC and we have information on how to dissect its contents.
242    */
243   if (mechListMIC_tvb && (tvb_reported_length(mechListMIC_tvb) > 0) ){
244     gssapi_oid_value *value=next_level_value;
245
246     if(value){
247       call_dissector(value->handle, mechListMIC_tvb, actx->pinfo, tree);
248     }
249   }
250
251
252 #.END