20 #include <linux/module.h>
21 #include <linux/types.h>
22 #include <linux/kernel.h>
24 #include <linux/slab.h>
55 #define ASN1_NUMSTR 18
56 #define ASN1_PRNSTR 19
57 #define ASN1_TEXSTR 20
58 #define ASN1_VIDSTR 21
59 #define ASN1_IA5STR 22
60 #define ASN1_UNITIM 23
61 #define ASN1_GENTIM 24
62 #define ASN1_GRASTR 25
63 #define ASN1_VISSTR 26
64 #define ASN1_GENSTR 27
73 #define ASN1_ERR_NOERROR 0
74 #define ASN1_ERR_DEC_EMPTY 2
75 #define ASN1_ERR_DEC_EOC_MISMATCH 3
76 #define ASN1_ERR_DEC_LENGTH_MISMATCH 4
77 #define ASN1_ERR_DEC_BADVALUE 5
79 #define SPNEGO_OID_LEN 7
80 #define NTLMSSP_OID_LEN 10
81 #define KRB5_OID_LEN 7
82 #define KRB5U2U_OID_LEN 8
83 #define MSKRB5_OID_LEN 7
84 static unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 };
85 static unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 };
86 static unsigned long KRB5_OID[7] = { 1, 2, 840, 113554, 1, 2, 2 };
87 static unsigned long KRB5U2U_OID[8] = { 1, 2, 840, 113554, 1, 2, 2, 3 };
88 static unsigned long MSKRB5_OID[7] = { 1, 2, 840, 48018, 1, 2, 2 };
109 asn1_open(
struct asn1_ctx *
ctx,
unsigned char *
buf,
unsigned int len)
112 ctx->
end = buf + len;
118 asn1_octet_decode(
struct asn1_ctx *
ctx,
unsigned char *ch)
151 asn1_tag_decode(
struct asn1_ctx *ctx,
unsigned int *
tag)
158 if (!asn1_octet_decode(ctx, &ch))
162 }
while ((ch & 0x80) == 0x80);
167 asn1_id_decode(
struct asn1_ctx *ctx,
168 unsigned int *cls,
unsigned int *
con,
unsigned int *tag)
172 if (!asn1_octet_decode(ctx, &ch))
175 *cls = (ch & 0xC0) >> 6;
176 *con = (ch & 0x20) >> 5;
180 if (!asn1_tag_decode(ctx, tag))
187 asn1_length_decode(
struct asn1_ctx *ctx,
unsigned int *def,
unsigned int *len)
189 unsigned char ch,
cnt;
191 if (!asn1_octet_decode(ctx, &ch))
202 cnt = (
unsigned char) (ch & 0x7F);
206 if (!asn1_octet_decode(ctx, &ch))
223 asn1_header_decode(
struct asn1_ctx *ctx,
225 unsigned int *cls,
unsigned int *con,
unsigned int *tag)
227 unsigned int def = 0;
228 unsigned int len = 0;
230 if (!asn1_id_decode(ctx, cls, con, tag))
233 if (!asn1_length_decode(ctx, &def, &len))
248 asn1_eoc_decode(
struct asn1_ctx *ctx,
unsigned char *eoc)
253 if (!asn1_octet_decode(ctx, &ch))
261 if (!asn1_octet_decode(ctx, &ch))
401 asn1_subid_decode(
struct asn1_ctx *ctx,
unsigned long *subid)
408 if (!asn1_octet_decode(ctx, &ch))
413 }
while ((ch & 0x80) == 0x80);
418 asn1_oid_decode(
struct asn1_ctx *ctx,
419 unsigned char *eoc,
unsigned long **
oid,
unsigned int *len)
428 if (size < 2 || size >
UINT_MAX/
sizeof(
unsigned long))
437 if (!asn1_subid_decode(ctx, &subid)) {
446 }
else if (subid < 80) {
448 optr[1] = subid - 40;
451 optr[1] = subid - 80;
458 if (++(*len) > size) {
465 if (!asn1_subid_decode(ctx, optr++)) {
475 compare_oid(
unsigned long *oid1,
unsigned int oid1len,
476 unsigned long *oid2,
unsigned int oid2len)
480 if (oid1len != oid2len)
483 for (i = 0; i < oid1len; i++) {
484 if (oid1[i] != oid2[i])
499 unsigned char *sequence_end;
500 unsigned long *oid =
NULL;
501 unsigned int cls,
con,
tag, oidlen,
rc;
505 asn1_open(&ctx, security_blob, length);
508 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
509 cFYI(1,
"Error decoding negTokenInit header");
513 cFYI(1,
"cls = %d con = %d tag = %d", cls, con, tag);
518 rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
522 rc = asn1_oid_decode(&ctx, end, &oid, &oidlen);
524 rc = compare_oid(oid, oidlen, SPNEGO_OID,
534 cFYI(1,
"Error decoding negTokenInit header");
539 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
540 cFYI(1,
"Error decoding negTokenInit");
544 cFYI(1,
"cls = %d con = %d tag = %d end = %p (%d) exit 0",
545 cls, con, tag, end, *end);
550 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
551 cFYI(1,
"Error decoding negTokenInit");
555 cFYI(1,
"cls = %d con = %d tag = %d end = %p (%d) exit 1",
556 cls, con, tag, end, *end);
561 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
562 cFYI(1,
"Error decoding 2nd part of negTokenInit");
566 cFYI(1,
"cls = %d con = %d tag = %d end = %p (%d) exit 0",
567 cls, con, tag, end, *end);
572 if (asn1_header_decode
573 (&ctx, &sequence_end, &cls, &con, &tag) == 0) {
574 cFYI(1,
"Error decoding 2nd part of negTokenInit");
578 cFYI(1,
"cls = %d con = %d tag = %d end = %p (%d) exit 1",
579 cls, con, tag, end, *end);
584 while (!asn1_eoc_decode(&ctx, sequence_end)) {
585 rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
587 cFYI(1,
"Error decoding negTokenInit hdr exit2");
591 if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) {
593 cFYI(1,
"OID len = %d oid = 0x%lx 0x%lx "
594 "0x%lx 0x%lx", oidlen, *oid,
595 *(oid + 1), *(oid + 2), *(oid + 3));
597 if (compare_oid(oid, oidlen, MSKRB5_OID,
600 else if (compare_oid(oid, oidlen, KRB5U2U_OID,
603 else if (compare_oid(oid, oidlen, KRB5_OID,
606 else if (compare_oid(oid, oidlen, NTLMSSP_OID,
613 cFYI(1,
"Should be an oid what is going on?");
618 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
622 goto decode_negtoken_exit;
623 cFYI(1,
"Error decoding last part negTokenInit exit3");
627 cFYI(1,
"Exit 4 cls = %d con = %d tag = %d end = %p (%d)",
628 cls, con, tag, end, *end);
633 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
634 cFYI(1,
"Error decoding last part negTokenInit exit5");
638 cFYI(1,
"cls = %d con = %d tag = %d end = %p (%d)",
639 cls, con, tag, end, *end);
643 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
644 cFYI(1,
"Error decoding last part negTokenInit exit 7");
647 cFYI(1,
"Exit 8 cls = %d con = %d tag = %d end = %p (%d)",
648 cls, con, tag, end, *end);
653 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
654 cFYI(1,
"Error decoding last part negTokenInit exit9");
658 cFYI(1,
"Exit10 cls = %d con = %d tag = %d end = %p (%d)",
659 cls, con, tag, end, *end);
662 cFYI(1,
"Need to call asn1_octets_decode() function for %s",
664 decode_negtoken_exit: