Blame spnego.c

Packit 5f9837
/* 
Packit 5f9837
   Unix SMB/CIFS implementation.
Packit 5f9837
   simple kerberos5/SPNEGO routines
Packit 5f9837
   Copyright (C) Andrew Tridgell 2001
Packit 5f9837
   Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
Packit 5f9837
   Copyright (C) Luke Howard     2003
Packit 5f9837
   
Packit 5f9837
   This program is free software; you can redistribute it and/or modify
Packit 5f9837
   it under the terms of the GNU General Public License as published by
Packit 5f9837
   the Free Software Foundation; either version 3 of the License, or
Packit 5f9837
   (at your option) any later version.
Packit 5f9837
   
Packit 5f9837
   This program is distributed in the hope that it will be useful,
Packit 5f9837
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5f9837
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 5f9837
   GNU General Public License for more details.
Packit 5f9837
   
Packit 5f9837
   You should have received a copy of the GNU General Public License
Packit 5f9837
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 5f9837
*/
Packit 5f9837
Packit 5f9837
#include <talloc.h>
Packit 5f9837
#include <stdint.h>
Packit 5f9837
#include <stdbool.h>
Packit 5f9837
Packit 5f9837
#include "data_blob.h"
Packit 5f9837
#include "asn1.h"
Packit 5f9837
#include "spnego.h"
Packit 5f9837
Packit 5f9837
/*
Packit 5f9837
  generate a krb5 GSS-API wrapper packet given a ticket
Packit 5f9837
*/
Packit 5f9837
DATA_BLOB spnego_gen_krb5_wrap(const DATA_BLOB ticket, const uint8_t tok_id[2])
Packit 5f9837
{
Packit 5f9837
	ASN1_DATA *data;
Packit 5f9837
	DATA_BLOB ret;
Packit 5f9837
	TALLOC_CTX *mem_ctx = talloc_init("gssapi");
Packit 5f9837
Packit 5f9837
	data = asn1_init(mem_ctx);
Packit 5f9837
	if (data == NULL) {
Packit 5f9837
		return data_blob_null;
Packit 5f9837
	}
Packit 5f9837
Packit 5f9837
	asn1_push_tag(data, ASN1_APPLICATION(0));
Packit 5f9837
	asn1_write_OID(data, OID_KERBEROS5);
Packit 5f9837
Packit 5f9837
	asn1_write(data, tok_id, 2);
Packit 5f9837
	asn1_write(data, ticket.data, ticket.length);
Packit 5f9837
	asn1_pop_tag(data);
Packit 5f9837
Packit 5f9837
#if 0
Packit 5f9837
	if (data->has_error) {
Packit 5f9837
		DEBUG(1,("Failed to build krb5 wrapper at offset %d\n", (int)data->ofs));
Packit 5f9837
	}
Packit 5f9837
#endif
Packit 5f9837
Packit 5f9837
	ret = data_blob(data->data, data->length);
Packit 5f9837
	asn1_free(data);
Packit 5f9837
	talloc_free(mem_ctx);
Packit 5f9837
Packit 5f9837
	return ret;
Packit 5f9837
}
Packit 5f9837
Packit 5f9837
/*
Packit 5f9837
  Generate a negTokenInit as used by the client side ... It has a mechType
Packit 5f9837
  (OID), and a mechToken (a security blob) ... 
Packit 5f9837
Packit 5f9837
  Really, we need to break out the NTLMSSP stuff as well, because it could be
Packit 5f9837
  raw in the packets!
Packit 5f9837
*/
Packit 5f9837
DATA_BLOB gen_negTokenInit(const char *OID, DATA_BLOB blob)
Packit 5f9837
{
Packit 5f9837
	ASN1_DATA *data;
Packit 5f9837
	DATA_BLOB ret;
Packit 5f9837
	TALLOC_CTX *mem_ctx = talloc_init("spnego");
Packit 5f9837
Packit 5f9837
	data = asn1_init(mem_ctx);
Packit 5f9837
	if (data == NULL) {
Packit 5f9837
		return data_blob_null;
Packit 5f9837
	}
Packit 5f9837
Packit 5f9837
	asn1_push_tag(data, ASN1_APPLICATION(0));
Packit 5f9837
	asn1_write_OID(data,OID_SPNEGO);
Packit 5f9837
	asn1_push_tag(data, ASN1_CONTEXT(0));
Packit 5f9837
	asn1_push_tag(data, ASN1_SEQUENCE(0));
Packit 5f9837
Packit 5f9837
	asn1_push_tag(data, ASN1_CONTEXT(0));
Packit 5f9837
	asn1_push_tag(data, ASN1_SEQUENCE(0));
Packit 5f9837
	asn1_write_OID(data, OID);
Packit 5f9837
	asn1_pop_tag(data);
Packit 5f9837
	asn1_pop_tag(data);
Packit 5f9837
Packit 5f9837
	asn1_push_tag(data, ASN1_CONTEXT(2));
Packit 5f9837
	asn1_write_OctetString(data,blob.data,blob.length);
Packit 5f9837
	asn1_pop_tag(data);
Packit 5f9837
Packit 5f9837
	asn1_pop_tag(data);
Packit 5f9837
	asn1_pop_tag(data);
Packit 5f9837
Packit 5f9837
	asn1_pop_tag(data);
Packit 5f9837
Packit 5f9837
#if 0
Packit 5f9837
	if (data->has_error) {
Packit 5f9837
		DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data->ofs));
Packit 5f9837
	}
Packit 5f9837
#endif
Packit 5f9837
Packit 5f9837
	ret = data_blob(data->data, data->length);
Packit 5f9837
	asn1_free(data);
Packit 5f9837
	talloc_free(mem_ctx);
Packit 5f9837
Packit 5f9837
	return ret;
Packit 5f9837
}
Packit 5f9837