-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspnego.c
114 lines (90 loc) · 2.78 KB
/
spnego.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
51
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Unix SMB/CIFS implementation.
simple kerberos5/SPNEGO routines
Copyright (C) Andrew Tridgell 2001
Copyright (C) Jim McDonough <[email protected]> 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
(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, see <http://www.gnu.org/licenses/>.
*/
#include <talloc.h>
#include <stdint.h>
#include <stdbool.h>
#include "data_blob.h"
#include "asn1.h"
#include "spnego.h"
/*
generate a krb5 GSS-API wrapper packet given a ticket
*/
DATA_BLOB spnego_gen_krb5_wrap(const DATA_BLOB ticket, const uint8_t tok_id[2])
{
ASN1_DATA *data;
DATA_BLOB ret;
TALLOC_CTX *mem_ctx = talloc_init("gssapi");
data = asn1_init(mem_ctx);
if (data == NULL) {
return data_blob_null;
}
asn1_push_tag(data, ASN1_APPLICATION(0));
asn1_write_OID(data, OID_KERBEROS5);
asn1_write(data, tok_id, 2);
asn1_write(data, ticket.data, ticket.length);
asn1_pop_tag(data);
#if 0
if (data->has_error) {
DEBUG(1,("Failed to build krb5 wrapper at offset %d\n", (int)data->ofs));
}
#endif
ret = data_blob(data->data, data->length);
asn1_free(data);
talloc_free(mem_ctx);
return ret;
}
/*
Generate a negTokenInit as used by the client side ... It has a mechType
(OID), and a mechToken (a security blob) ...
Really, we need to break out the NTLMSSP stuff as well, because it could be
raw in the packets!
*/
DATA_BLOB gen_negTokenInit(const char *OID, DATA_BLOB blob)
{
ASN1_DATA *data;
DATA_BLOB ret;
TALLOC_CTX *mem_ctx = talloc_init("spnego");
data = asn1_init(mem_ctx);
if (data == NULL) {
return data_blob_null;
}
asn1_push_tag(data, ASN1_APPLICATION(0));
asn1_write_OID(data,OID_SPNEGO);
asn1_push_tag(data, ASN1_CONTEXT(0));
asn1_push_tag(data, ASN1_SEQUENCE(0));
asn1_push_tag(data, ASN1_CONTEXT(0));
asn1_push_tag(data, ASN1_SEQUENCE(0));
asn1_write_OID(data, OID);
asn1_pop_tag(data);
asn1_pop_tag(data);
asn1_push_tag(data, ASN1_CONTEXT(2));
asn1_write_OctetString(data,blob.data,blob.length);
asn1_pop_tag(data);
asn1_pop_tag(data);
asn1_pop_tag(data);
asn1_pop_tag(data);
#if 0
if (data->has_error) {
DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data->ofs));
}
#endif
ret = data_blob(data->data, data->length);
asn1_free(data);
talloc_free(mem_ctx);
return ret;
}