Copyright (C) Andrew Tridgell 2001
Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
Copyright (C) Luke Howard 2003
-
+
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 3 of the License, or
#include "includes.h"
#include "../libcli/auth/spnego.h"
+#include "smb_krb5.h"
/*
generate a negTokenInit packet given a GUID, a list of supported
bool ret;
ASN1_DATA *data;
+ for (i = 0; i < ASN1_MAX_OIDS; i++) {
+ OIDs[i] = NULL;
+ }
+
data = asn1_init(talloc_tos());
if (data == NULL) {
return false;
asn1_start_tag(data,ASN1_APPLICATION(0));
asn1_check_OID(data,OID_SPNEGO);
+
+ /* negTokenInit [0] NegTokenInit */
asn1_start_tag(data,ASN1_CONTEXT(0));
asn1_start_tag(data,ASN1_SEQUENCE(0));
+ /* mechTypes [0] MechTypeList OPTIONAL */
+
+ /* Not really optional, we depend on this to decide
+ * what mechanisms we have to work with. */
+
asn1_start_tag(data,ASN1_CONTEXT(0));
asn1_start_tag(data,ASN1_SEQUENCE(0));
for (i=0; asn1_tag_remaining(data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
const char *oid_str = NULL;
asn1_read_OID(data,talloc_autofree_context(),&oid_str);
+ if (data->has_error) {
+ break;
+ }
OIDs[i] = CONST_DISCARD(char *, oid_str);
}
OIDs[i] = NULL;
asn1_end_tag(data);
*principal = NULL;
- if (asn1_tag_remaining(data) > 0) {
+
+ /*
+ Win7 + Live Sign-in Assistant attaches a mechToken
+ ASN1_CONTEXT(2) to the negTokenInit packet
+ which breaks our negotiation if we just assume
+ the next tag is ASN1_CONTEXT(3).
+ */
+
+ if (asn1_peek_tag(data, ASN1_CONTEXT(1))) {
+ uint8 flags;
+
+ /* reqFlags [1] ContextFlags OPTIONAL */
+ asn1_start_tag(data, ASN1_CONTEXT(1));
+ asn1_start_tag(data, ASN1_BIT_STRING);
+ while (asn1_tag_remaining(data) > 0) {
+ asn1_read_uint8(data, &flags);
+ }
+ asn1_end_tag(data);
+ asn1_end_tag(data);
+ }
+
+ if (asn1_peek_tag(data, ASN1_CONTEXT(2))) {
+ /* mechToken [2] OCTET STRING OPTIONAL */
+ DATA_BLOB token;
+ asn1_start_tag(data, ASN1_CONTEXT(2));
+ asn1_read_OctetString(data, talloc_autofree_context(),
+ &token);
+ asn1_end_tag(data);
+ /* Throw away the token - not used. */
+ data_blob_free(&token);
+ }
+
+ if (asn1_peek_tag(data, ASN1_CONTEXT(3))) {
+ /* mechListMIC [3] OCTET STRING OPTIONAL */
asn1_start_tag(data, ASN1_CONTEXT(3));
asn1_start_tag(data, ASN1_SEQUENCE(0));
asn1_start_tag(data, ASN1_CONTEXT(0));
- asn1_read_GeneralString(data,talloc_autofree_context(),principal);
+ asn1_read_GeneralString(data,talloc_autofree_context(),
+ principal);
asn1_end_tag(data);
asn1_end_tag(data);
asn1_end_tag(data);
/* get a kerberos ticket for the service and extract the session key */
retval = cli_krb5_get_ticket(principal, time_offset,
&tkt, session_key_krb5, extra_ap_opts, NULL,
- expire_time);
+ expire_time, NULL);
if (retval)
return retval;
*/
bool spnego_parse_auth(DATA_BLOB blob, DATA_BLOB *auth)
{
- ASN1_DATA *data;
+ ssize_t len;
+ struct spnego_data token;
- data = asn1_init(talloc_tos());
- if (data == NULL) {
+ len = spnego_read_data(talloc_tos(), blob, &token);
+ if (len == -1) {
+ DEBUG(3,("spnego_parse_auth: spnego_read_data failed\n"));
return false;
}
- asn1_load(data, blob);
- asn1_start_tag(data, ASN1_CONTEXT(1));
- asn1_start_tag(data, ASN1_SEQUENCE(0));
- asn1_start_tag(data, ASN1_CONTEXT(2));
- asn1_read_OctetString(data, talloc_autofree_context(), auth);
- asn1_end_tag(data);
- asn1_end_tag(data);
- asn1_end_tag(data);
-
- if (data->has_error) {
- DEBUG(3,("spnego_parse_auth failed at %d\n", (int)data->ofs));
- data_blob_free(auth);
- asn1_free(data);
- return False;
+ if (token.type != SPNEGO_NEG_TOKEN_TARG) {
+ DEBUG(3,("spnego_parse_auth: wrong token type: %d\n",
+ token.type));
+ spnego_free_data(&token);
+ return false;
}
- asn1_free(data);
- return True;
+ *auth = data_blob_talloc(talloc_tos(),
+ token.negTokenTarg.responseToken.data,
+ token.negTokenTarg.responseToken.length);
+ spnego_free_data(&token);
+
+ return true;
}
/*