Blame view

fs/cifs/asn1.c 13.6 KB
50c2f7538   Steve French   [CIFS] whitespace...
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
   * The ASB.1/BER parsing code is derived from ip_nat_snmp_basic.c which was in
   * turn derived from the gxsnmp package by Gregory McLean & Jochen Friedrich
50c2f7538   Steve French   [CIFS] whitespace...
4
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
12
13
14
15
16
17
18
   * Copyright (c) 2000 RP Internet (www.rpi.net.au).
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  #include <linux/module.h>
  #include <linux/types.h>
  #include <linux/kernel.h>
  #include <linux/mm.h>
  #include <linux/slab.h>
  #include "cifspdu.h"
  #include "cifsglob.h"
  #include "cifs_debug.h"
  #include "cifsproto.h"
  
  /*****************************************************************************
   *
   * Basic ASN.1 decoding routines (gxsnmp author Dirk Wisse)
   *
   *****************************************************************************/
  
  /* Class */
  #define ASN1_UNI	0	/* Universal */
  #define ASN1_APL	1	/* Application */
  #define ASN1_CTX	2	/* Context */
  #define ASN1_PRV	3	/* Private */
  
  /* Tag */
  #define ASN1_EOC	0	/* End Of Contents or N/A */
  #define ASN1_BOL	1	/* Boolean */
  #define ASN1_INT	2	/* Integer */
  #define ASN1_BTS	3	/* Bit String */
  #define ASN1_OTS	4	/* Octet String */
  #define ASN1_NUL	5	/* Null */
  #define ASN1_OJI	6	/* Object Identifier  */
  #define ASN1_OJD	7	/* Object Description */
  #define ASN1_EXT	8	/* External */
f46c7234e   Steve French   [CIFS] cleanup as...
51
  #define ASN1_ENUM	10	/* Enumerated */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  #define ASN1_SEQ	16	/* Sequence */
  #define ASN1_SET	17	/* Set */
  #define ASN1_NUMSTR	18	/* Numerical String */
  #define ASN1_PRNSTR	19	/* Printable String */
  #define ASN1_TEXSTR	20	/* Teletext String */
  #define ASN1_VIDSTR	21	/* Video String */
  #define ASN1_IA5STR	22	/* IA5 String */
  #define ASN1_UNITIM	23	/* Universal Time */
  #define ASN1_GENTIM	24	/* General Time */
  #define ASN1_GRASTR	25	/* Graphical String */
  #define ASN1_VISSTR	26	/* Visible String */
  #define ASN1_GENSTR	27	/* General String */
  
  /* Primitive / Constructed methods*/
  #define ASN1_PRI	0	/* Primitive */
  #define ASN1_CON	1	/* Constructed */
  
  /*
   * Error codes.
   */
  #define ASN1_ERR_NOERROR		0
  #define ASN1_ERR_DEC_EMPTY		2
  #define ASN1_ERR_DEC_EOC_MISMATCH	3
  #define ASN1_ERR_DEC_LENGTH_MISMATCH	4
  #define ASN1_ERR_DEC_BADVALUE		5
  
  #define SPNEGO_OID_LEN 7
  #define NTLMSSP_OID_LEN  10
e545937a5   Jeff Layton   [CIFS] add OIDs f...
80
  #define KRB5_OID_LEN  7
f46c7234e   Steve French   [CIFS] cleanup as...
81
  #define KRB5U2U_OID_LEN  8
e545937a5   Jeff Layton   [CIFS] add OIDs f...
82
  #define MSKRB5_OID_LEN  7
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
  static unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 };
  static unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 };
e545937a5   Jeff Layton   [CIFS] add OIDs f...
85
  static unsigned long KRB5_OID[7] = { 1, 2, 840, 113554, 1, 2, 2 };
f46c7234e   Steve French   [CIFS] cleanup as...
86
  static unsigned long KRB5U2U_OID[8] = { 1, 2, 840, 113554, 1, 2, 2, 3 };
e545937a5   Jeff Layton   [CIFS] add OIDs f...
87
  static unsigned long MSKRB5_OID[7] = { 1, 2, 840, 48018, 1, 2, 2 };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88

50c2f7538   Steve French   [CIFS] whitespace...
89
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
   * ASN.1 context.
   */
  struct asn1_ctx {
  	int error;		/* Error condition */
  	unsigned char *pointer;	/* Octet just to be decoded */
  	unsigned char *begin;	/* First octet */
  	unsigned char *end;	/* Octet after last octet */
  };
  
  /*
   * Octet string (not null terminated)
   */
  struct asn1_octstr {
  	unsigned char *data;
  	unsigned int len;
  };
  
  static void
  asn1_open(struct asn1_ctx *ctx, unsigned char *buf, unsigned int len)
  {
  	ctx->begin = buf;
  	ctx->end = buf + len;
  	ctx->pointer = buf;
  	ctx->error = ASN1_ERR_NOERROR;
  }
  
  static unsigned char
  asn1_octet_decode(struct asn1_ctx *ctx, unsigned char *ch)
  {
  	if (ctx->pointer >= ctx->end) {
  		ctx->error = ASN1_ERR_DEC_EMPTY;
  		return 0;
  	}
  	*ch = *(ctx->pointer)++;
  	return 1;
  }
f46c7234e   Steve French   [CIFS] cleanup as...
126
127
128
129
130
131
132
133
134
135
  #if 0 /* will be needed later by spnego decoding/encoding of ntlmssp */
  static unsigned char
  asn1_enum_decode(struct asn1_ctx *ctx, __le32 *val)
  {
  	unsigned char ch;
  
  	if (ctx->pointer >= ctx->end) {
  		ctx->error = ASN1_ERR_DEC_EMPTY;
  		return 0;
  	}
1537a3638   Daniel Mack   tree-wide: fix 'l...
136
  	ch = *(ctx->pointer)++; /* ch has 0xa, ptr points to length octet */
f46c7234e   Steve French   [CIFS] cleanup as...
137
138
139
140
141
142
143
144
145
  	if ((ch) == ASN1_ENUM)  /* if ch value is ENUM, 0xa */
  		*val = *(++(ctx->pointer)); /* value has enum value */
  	else
  		return 0;
  
  	ctx->pointer++;
  	return 1;
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  static unsigned char
  asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag)
  {
  	unsigned char ch;
  
  	*tag = 0;
  
  	do {
  		if (!asn1_octet_decode(ctx, &ch))
  			return 0;
  		*tag <<= 7;
  		*tag |= ch & 0x7F;
  	} while ((ch & 0x80) == 0x80);
  	return 1;
  }
  
  static unsigned char
  asn1_id_decode(struct asn1_ctx *ctx,
  	       unsigned int *cls, unsigned int *con, unsigned int *tag)
  {
  	unsigned char ch;
  
  	if (!asn1_octet_decode(ctx, &ch))
  		return 0;
  
  	*cls = (ch & 0xC0) >> 6;
  	*con = (ch & 0x20) >> 5;
  	*tag = (ch & 0x1F);
  
  	if (*tag == 0x1F) {
  		if (!asn1_tag_decode(ctx, tag))
  			return 0;
  	}
  	return 1;
  }
  
  static unsigned char
  asn1_length_decode(struct asn1_ctx *ctx, unsigned int *def, unsigned int *len)
  {
  	unsigned char ch, cnt;
  
  	if (!asn1_octet_decode(ctx, &ch))
  		return 0;
  
  	if (ch == 0x80)
  		*def = 0;
  	else {
  		*def = 1;
  
  		if (ch < 0x80)
  			*len = ch;
  		else {
  			cnt = (unsigned char) (ch & 0x7F);
  			*len = 0;
  
  			while (cnt > 0) {
  				if (!asn1_octet_decode(ctx, &ch))
  					return 0;
  				*len <<= 8;
  				*len |= ch;
  				cnt--;
  			}
  		}
  	}
ddb2c4359   Chris Wright   asn1: additional ...
210
211
212
213
  
  	/* don't trust len bigger than ctx buffer */
  	if (*len > ctx->end - ctx->pointer)
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
214
215
216
217
218
219
220
221
  	return 1;
  }
  
  static unsigned char
  asn1_header_decode(struct asn1_ctx *ctx,
  		   unsigned char **eoc,
  		   unsigned int *cls, unsigned int *con, unsigned int *tag)
  {
50c2f7538   Steve French   [CIFS] whitespace...
222
  	unsigned int def = 0;
ab2f218f4   Steve French   [CIFS] Fix compil...
223
  	unsigned int len = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
225
226
227
228
229
  
  	if (!asn1_id_decode(ctx, cls, con, tag))
  		return 0;
  
  	if (!asn1_length_decode(ctx, &def, &len))
  		return 0;
ddb2c4359   Chris Wright   asn1: additional ...
230
231
232
  	/* primitive shall be definite, indefinite shall be constructed */
  	if (*con == ASN1_PRI && !def)
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
  	if (def)
  		*eoc = ctx->pointer + len;
  	else
  		*eoc = NULL;
  	return 1;
  }
  
  static unsigned char
  asn1_eoc_decode(struct asn1_ctx *ctx, unsigned char *eoc)
  {
  	unsigned char ch;
  
  	if (eoc == NULL) {
  		if (!asn1_octet_decode(ctx, &ch))
  			return 0;
  
  		if (ch != 0x00) {
  			ctx->error = ASN1_ERR_DEC_EOC_MISMATCH;
  			return 0;
  		}
  
  		if (!asn1_octet_decode(ctx, &ch))
  			return 0;
  
  		if (ch != 0x00) {
  			ctx->error = ASN1_ERR_DEC_EOC_MISMATCH;
  			return 0;
  		}
  		return 1;
  	} else {
  		if (ctx->pointer != eoc) {
  			ctx->error = ASN1_ERR_DEC_LENGTH_MISMATCH;
  			return 0;
  		}
  		return 1;
  	}
  }
  
  /* static unsigned char asn1_null_decode(struct asn1_ctx *ctx,
  				      unsigned char *eoc)
  {
  	ctx->pointer = eoc;
  	return 1;
  }
  
  static unsigned char asn1_long_decode(struct asn1_ctx *ctx,
  				      unsigned char *eoc, long *integer)
  {
  	unsigned char ch;
  	unsigned int len;
  
  	if (!asn1_octet_decode(ctx, &ch))
  		return 0;
  
  	*integer = (signed char) ch;
  	len = 1;
  
  	while (ctx->pointer < eoc) {
  		if (++len > sizeof(long)) {
  			ctx->error = ASN1_ERR_DEC_BADVALUE;
  			return 0;
  		}
  
  		if (!asn1_octet_decode(ctx, &ch))
  			return 0;
  
  		*integer <<= 8;
  		*integer |= ch;
  	}
  	return 1;
  }
  
  static unsigned char asn1_uint_decode(struct asn1_ctx *ctx,
  				      unsigned char *eoc,
  				      unsigned int *integer)
  {
  	unsigned char ch;
  	unsigned int len;
  
  	if (!asn1_octet_decode(ctx, &ch))
  		return 0;
  
  	*integer = ch;
  	if (ch == 0)
  		len = 0;
  	else
  		len = 1;
  
  	while (ctx->pointer < eoc) {
  		if (++len > sizeof(unsigned int)) {
  			ctx->error = ASN1_ERR_DEC_BADVALUE;
  			return 0;
  		}
  
  		if (!asn1_octet_decode(ctx, &ch))
  			return 0;
  
  		*integer <<= 8;
  		*integer |= ch;
  	}
  	return 1;
  }
  
  static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx,
  				       unsigned char *eoc,
  				       unsigned long *integer)
  {
  	unsigned char ch;
  	unsigned int len;
  
  	if (!asn1_octet_decode(ctx, &ch))
  		return 0;
  
  	*integer = ch;
  	if (ch == 0)
  		len = 0;
  	else
  		len = 1;
  
  	while (ctx->pointer < eoc) {
  		if (++len > sizeof(unsigned long)) {
  			ctx->error = ASN1_ERR_DEC_BADVALUE;
  			return 0;
  		}
  
  		if (!asn1_octet_decode(ctx, &ch))
  			return 0;
  
  		*integer <<= 8;
  		*integer |= ch;
  	}
  	return 1;
50c2f7538   Steve French   [CIFS] whitespace...
365
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
  
  static unsigned char
  asn1_octets_decode(struct asn1_ctx *ctx,
  		   unsigned char *eoc,
  		   unsigned char **octets, unsigned int *len)
  {
  	unsigned char *ptr;
  
  	*len = 0;
  
  	*octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
  	if (*octets == NULL) {
  		return 0;
  	}
  
  	ptr = *octets;
  	while (ctx->pointer < eoc) {
  		if (!asn1_octet_decode(ctx, (unsigned char *) ptr++)) {
  			kfree(*octets);
  			*octets = NULL;
  			return 0;
  		}
  		(*len)++;
  	}
  	return 1;
  } */
  
  static unsigned char
  asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
  {
  	unsigned char ch;
  
  	*subid = 0;
  
  	do {
  		if (!asn1_octet_decode(ctx, &ch))
  			return 0;
  
  		*subid <<= 7;
  		*subid |= ch & 0x7F;
  	} while ((ch & 0x80) == 0x80);
  	return 1;
  }
50c2f7538   Steve French   [CIFS] whitespace...
409
  static int
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
410
411
412
413
414
415
416
417
  asn1_oid_decode(struct asn1_ctx *ctx,
  		unsigned char *eoc, unsigned long **oid, unsigned int *len)
  {
  	unsigned long subid;
  	unsigned int size;
  	unsigned long *optr;
  
  	size = eoc - ctx->pointer + 1;
ddb2c4359   Chris Wright   asn1: additional ...
418
419
  
  	/* first subid actually encodes first two subids */
04e1e0ccc   Jan Beulich   [CIFS] Fix compil...
420
  	if (size < 2 || size > UINT_MAX/sizeof(unsigned long))
ddb2c4359   Chris Wright   asn1: additional ...
421
  		return 0;
26f57364d   Steve French   [CIFS] formatting...
422
423
  	*oid = kmalloc(size * sizeof(unsigned long), GFP_ATOMIC);
  	if (*oid == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
  
  	optr = *oid;
  
  	if (!asn1_subid_decode(ctx, &subid)) {
  		kfree(*oid);
  		*oid = NULL;
  		return 0;
  	}
  
  	if (subid < 40) {
  		optr[0] = 0;
  		optr[1] = subid;
  	} else if (subid < 80) {
  		optr[0] = 1;
  		optr[1] = subid - 40;
  	} else {
  		optr[0] = 2;
  		optr[1] = subid - 80;
  	}
  
  	*len = 2;
  	optr += 2;
  
  	while (ctx->pointer < eoc) {
  		if (++(*len) > size) {
  			ctx->error = ASN1_ERR_DEC_BADVALUE;
  			kfree(*oid);
  			*oid = NULL;
  			return 0;
  		}
  
  		if (!asn1_subid_decode(ctx, optr++)) {
  			kfree(*oid);
  			*oid = NULL;
  			return 0;
  		}
  	}
  	return 1;
  }
  
  static int
  compare_oid(unsigned long *oid1, unsigned int oid1len,
  	    unsigned long *oid2, unsigned int oid2len)
  {
  	unsigned int i;
  
  	if (oid1len != oid2len)
  		return 0;
  	else {
  		for (i = 0; i < oid1len; i++) {
  			if (oid1[i] != oid2[i])
  				return 0;
  		}
  		return 1;
  	}
  }
  
  	/* BB check for endian conversion issues here */
  
  int
  decode_negTokenInit(unsigned char *security_blob, int length,
26efa0bac   Jeff Layton   cifs: have decode...
486
  		    struct TCP_Server_Info *server)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
487
488
489
490
491
492
  {
  	struct asn1_ctx ctx;
  	unsigned char *end;
  	unsigned char *sequence_end;
  	unsigned long *oid = NULL;
  	unsigned int cls, con, tag, oidlen, rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
494
495
496
  	/* cifs_dump_mem(" Received SecBlob ", security_blob, length); */
  
  	asn1_open(&ctx, security_blob, length);
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
497
  	/* GSSAPI header */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
498
  	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
499
500
  		cifs_dbg(FYI, "Error decoding negTokenInit header
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501
502
503
  		return 0;
  	} else if ((cls != ASN1_APL) || (con != ASN1_CON)
  		   || (tag != ASN1_EOC)) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
504
505
  		cifs_dbg(FYI, "cls = %d con = %d tag = %d
  ", cls, con, tag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
  		return 0;
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
507
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508

2f0e58ac3   Jeff Layton   [CIFS] remove lev...
509
510
511
512
513
514
515
516
517
518
519
520
521
522
  	/* Check for SPNEGO OID -- remember to free obj->oid */
  	rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
  	if (rc) {
  		if ((tag == ASN1_OJI) && (con == ASN1_PRI) &&
  		    (cls == ASN1_UNI)) {
  			rc = asn1_oid_decode(&ctx, end, &oid, &oidlen);
  			if (rc) {
  				rc = compare_oid(oid, oidlen, SPNEGO_OID,
  						 SPNEGO_OID_LEN);
  				kfree(oid);
  			}
  		} else
  			rc = 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
523

2f0e58ac3   Jeff Layton   [CIFS] remove lev...
524
525
  	/* SPNEGO OID not present or garbled -- bail out */
  	if (!rc) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
526
527
  		cifs_dbg(FYI, "Error decoding negTokenInit header
  ");
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
528
529
  		return 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530

f46c7234e   Steve French   [CIFS] cleanup as...
531
  	/* SPNEGO */
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
532
  	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
533
534
  		cifs_dbg(FYI, "Error decoding negTokenInit
  ");
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
535
536
537
  		return 0;
  	} else if ((cls != ASN1_CTX) || (con != ASN1_CON)
  		   || (tag != ASN1_EOC)) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
538
539
540
  		cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 0
  ",
  			 cls, con, tag, end, *end);
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
541
542
  		return 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
543

f46c7234e   Steve French   [CIFS] cleanup as...
544
  	/* negTokenInit */
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
545
  	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
546
547
  		cifs_dbg(FYI, "Error decoding negTokenInit
  ");
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
548
549
550
  		return 0;
  	} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
  		   || (tag != ASN1_SEQ)) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
551
552
553
  		cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 1
  ",
  			 cls, con, tag, end, *end);
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
554
555
  		return 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556

f46c7234e   Steve French   [CIFS] cleanup as...
557
  	/* sequence */
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
558
  	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
559
560
  		cifs_dbg(FYI, "Error decoding 2nd part of negTokenInit
  ");
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
561
562
563
  		return 0;
  	} else if ((cls != ASN1_CTX) || (con != ASN1_CON)
  		   || (tag != ASN1_EOC)) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
564
565
566
  		cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 0
  ",
  			 cls, con, tag, end, *end);
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
567
568
  		return 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
569

f46c7234e   Steve French   [CIFS] cleanup as...
570
  	/* sequence of */
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
571
572
  	if (asn1_header_decode
  	    (&ctx, &sequence_end, &cls, &con, &tag) == 0) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
573
574
  		cifs_dbg(FYI, "Error decoding 2nd part of negTokenInit
  ");
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
575
576
577
  		return 0;
  	} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
  		   || (tag != ASN1_SEQ)) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
578
579
580
  		cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 1
  ",
  			 cls, con, tag, end, *end);
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
581
582
  		return 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
583

f46c7234e   Steve French   [CIFS] cleanup as...
584
  	/* list of security mechanisms */
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
585
586
587
  	while (!asn1_eoc_decode(&ctx, sequence_end)) {
  		rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
  		if (!rc) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
588
589
  			cifs_dbg(FYI, "Error decoding negTokenInit hdr exit2
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
590
591
  			return 0;
  		}
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
592
593
  		if ((tag == ASN1_OJI) && (con == ASN1_PRI)) {
  			if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
594
595
596
597
  				cifs_dbg(FYI, "OID len = %d oid = 0x%lx 0x%lx 0x%lx 0x%lx
  ",
  					 oidlen, *oid, *(oid + 1), *(oid + 2),
  					 *(oid + 3));
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
598
599
  
  				if (compare_oid(oid, oidlen, MSKRB5_OID,
26efa0bac   Jeff Layton   cifs: have decode...
600
601
  						MSKRB5_OID_LEN))
  					server->sec_mskerberos = true;
c8e56f1f4   Steve French   Revert "[CIFS] Fi...
602
  				else if (compare_oid(oid, oidlen, KRB5U2U_OID,
26efa0bac   Jeff Layton   cifs: have decode...
603
604
  						     KRB5U2U_OID_LEN))
  					server->sec_kerberosu2u = true;
c8e56f1f4   Steve French   Revert "[CIFS] Fi...
605
  				else if (compare_oid(oid, oidlen, KRB5_OID,
26efa0bac   Jeff Layton   cifs: have decode...
606
607
  						     KRB5_OID_LEN))
  					server->sec_kerberos = true;
c8e56f1f4   Steve French   Revert "[CIFS] Fi...
608
  				else if (compare_oid(oid, oidlen, NTLMSSP_OID,
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
609
  						     NTLMSSP_OID_LEN))
26efa0bac   Jeff Layton   cifs: have decode...
610
  					server->sec_ntlmssp = true;
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
611
612
613
614
  
  				kfree(oid);
  			}
  		} else {
f96637be0   Joe Perches   [CIFS] cifs: Rena...
615
616
  			cifs_dbg(FYI, "Should be an oid what is going on?
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
617
  		}
2f0e58ac3   Jeff Layton   [CIFS] remove lev...
618
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
619

f853c6168   Jeff Layton   cifs: ignore ever...
620
621
622
623
624
  	/*
  	 * We currently ignore anything at the end of the SPNEGO blob after
  	 * the mechTypes have been parsed, since none of that info is
  	 * used at the moment.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
625
626
  	return 1;
  }