2 Unix SMB/CIFS implementation.
3 simple kerberos5/SPNEGO routines
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
6 Copyright (C) Luke Howard 2003
7 Copyright (C) Jeremy Allison 2010
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "../libcli/auth/spnego.h"
26 #include "../lib/util/asn1.h"
29 parse a negTokenInit packet giving a GUID, a list of supported
30 OIDs (the mechanisms) and a principal name string
32 bool spnego_parse_negTokenInit(TALLOC_CTX
*ctx
,
34 char *OIDs
[ASN1_MAX_OIDS
],
42 for (i
= 0; i
< ASN1_MAX_OIDS
; i
++) {
50 *secblob
= data_blob_null
;
53 data
= asn1_init(talloc_tos());
58 if (!asn1_load(data
, blob
)) goto err
;
60 if (!asn1_start_tag(data
,ASN1_APPLICATION(0))) goto err
;
62 if (!asn1_check_OID(data
,OID_SPNEGO
)) goto err
;
64 /* negTokenInit [0] NegTokenInit */
65 if (!asn1_start_tag(data
,ASN1_CONTEXT(0))) goto err
;
66 if (!asn1_start_tag(data
,ASN1_SEQUENCE(0))) goto err
;
68 /* mechTypes [0] MechTypeList OPTIONAL */
70 /* Not really optional, we depend on this to decide
71 * what mechanisms we have to work with. */
73 if (!asn1_start_tag(data
,ASN1_CONTEXT(0))) goto err
;
74 if (!asn1_start_tag(data
,ASN1_SEQUENCE(0))) goto err
;
75 for (i
=0; asn1_tag_remaining(data
) > 0 && i
< ASN1_MAX_OIDS
-1; i
++) {
76 if (!asn1_read_OID(data
,ctx
, &OIDs
[i
])) {
79 if (asn1_has_error(data
)) {
84 if (!asn1_end_tag(data
)) goto err
;
85 if (!asn1_end_tag(data
)) goto err
;
88 Win7 + Live Sign-in Assistant attaches a mechToken
89 ASN1_CONTEXT(2) to the negTokenInit packet
90 which breaks our negotiation if we just assume
91 the next tag is ASN1_CONTEXT(3).
94 if (asn1_peek_tag(data
, ASN1_CONTEXT(1))) {
97 /* reqFlags [1] ContextFlags OPTIONAL */
98 if (!asn1_start_tag(data
, ASN1_CONTEXT(1))) goto err
;
99 if (!asn1_start_tag(data
, ASN1_BIT_STRING
)) goto err
;
100 while (asn1_tag_remaining(data
) > 0) {
101 if (!asn1_read_uint8(data
, &flags
)) goto err
;
103 if (!asn1_end_tag(data
)) goto err
;
104 if (!asn1_end_tag(data
)) goto err
;
107 if (asn1_peek_tag(data
, ASN1_CONTEXT(2))) {
108 DATA_BLOB sblob
= data_blob_null
;
109 /* mechToken [2] OCTET STRING OPTIONAL */
110 if (!asn1_start_tag(data
, ASN1_CONTEXT(2))) goto err
;
111 if (!asn1_read_OctetString(data
, ctx
, &sblob
)) goto err
;
112 if (!asn1_end_tag(data
)) {
113 data_blob_free(&sblob
);
119 data_blob_free(&sblob
);
123 if (asn1_peek_tag(data
, ASN1_CONTEXT(3))) {
125 /* mechListMIC [3] OCTET STRING OPTIONAL */
126 if (!asn1_start_tag(data
, ASN1_CONTEXT(3))) goto err
;
127 if (!asn1_start_tag(data
, ASN1_SEQUENCE(0))) goto err
;
128 if (!asn1_start_tag(data
, ASN1_CONTEXT(0))) goto err
;
129 if (!asn1_read_GeneralString(data
, ctx
, &princ
)) goto err
;
130 if (!asn1_end_tag(data
)) goto err
;
131 if (!asn1_end_tag(data
)) goto err
;
132 if (!asn1_end_tag(data
)) goto err
;
140 if (!asn1_end_tag(data
)) goto err
;
141 if (!asn1_end_tag(data
)) goto err
;
143 if (!asn1_end_tag(data
)) goto err
;
145 ret
= !asn1_has_error(data
);
149 if (asn1_has_error(data
)) {
152 TALLOC_FREE(*principal
);
155 data_blob_free(secblob
);
157 for(j
= 0; j
< i
&& j
< ASN1_MAX_OIDS
-1; j
++) {
158 TALLOC_FREE(OIDs
[j
]);
167 generate a krb5 GSS-API wrapper packet given a ticket
169 DATA_BLOB
spnego_gen_krb5_wrap(TALLOC_CTX
*ctx
, const DATA_BLOB ticket
, const uint8_t tok_id
[2])
172 DATA_BLOB ret
= data_blob_null
;
174 data
= asn1_init(talloc_tos());
176 return data_blob_null
;
179 if (!asn1_push_tag(data
, ASN1_APPLICATION(0))) goto err
;
180 if (!asn1_write_OID(data
, OID_KERBEROS5
)) goto err
;
182 if (!asn1_write(data
, tok_id
, 2)) goto err
;
183 if (!asn1_write(data
, ticket
.data
, ticket
.length
)) goto err
;
184 if (!asn1_pop_tag(data
)) goto err
;
186 if (!asn1_extract_blob(data
, ctx
, &ret
)) {
196 if (asn1_has_error(data
)) {
197 DEBUG(1, ("Failed to build krb5 wrapper at offset %d\n",
198 (int)asn1_current_ofs(data
)));