2 * Unix SMB/CIFS implementation.
4 * NTLMSSP Signing routines
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2001
6 * Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003-2005
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "auth/ntlmssp/ntlmssp.h"
24 #include "auth/gensec/gensec.h"
25 #include "auth/gensec/gensec_internal.h"
26 #include "auth/ntlmssp/ntlmssp_private.h"
28 NTSTATUS
gensec_ntlmssp_magic(struct gensec_security
*gensec_security
,
29 const DATA_BLOB
*first_packet
)
31 if (ntlmssp_blob_matches_magic(first_packet
)) {
34 return NT_STATUS_INVALID_PARAMETER
;
39 * Return the NTLMSSP master session key
41 * @param ntlmssp_state NTLMSSP State
44 NTSTATUS
gensec_ntlmssp_session_key(struct gensec_security
*gensec_security
,
46 DATA_BLOB
*session_key
)
48 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
49 talloc_get_type_abort(gensec_security
->private_data
,
50 struct gensec_ntlmssp_context
);
51 struct ntlmssp_state
*ntlmssp_state
= gensec_ntlmssp
->ntlmssp_state
;
53 if (ntlmssp_state
->expected_state
!= NTLMSSP_DONE
) {
54 return NT_STATUS_NO_USER_SESSION_KEY
;
57 if (!ntlmssp_state
->session_key
.data
) {
58 return NT_STATUS_NO_USER_SESSION_KEY
;
60 *session_key
= data_blob_talloc(mem_ctx
, ntlmssp_state
->session_key
.data
, ntlmssp_state
->session_key
.length
);
61 if (!session_key
->data
) {
62 return NT_STATUS_NO_MEMORY
;
68 bool gensec_ntlmssp_have_feature(struct gensec_security
*gensec_security
,
71 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
72 talloc_get_type_abort(gensec_security
->private_data
,
73 struct gensec_ntlmssp_context
);
74 struct ntlmssp_state
*ntlmssp_state
= gensec_ntlmssp
->ntlmssp_state
;
76 if (feature
& GENSEC_FEATURE_SIGN
) {
77 if (!ntlmssp_state
->session_key
.length
) {
80 if (ntlmssp_state
->neg_flags
& NTLMSSP_NEGOTIATE_SIGN
) {
84 if (feature
& GENSEC_FEATURE_SEAL
) {
85 if (!ntlmssp_state
->session_key
.length
) {
88 if (ntlmssp_state
->neg_flags
& NTLMSSP_NEGOTIATE_SEAL
) {
92 if (feature
& GENSEC_FEATURE_SESSION_KEY
) {
93 if (ntlmssp_state
->session_key
.length
) {
97 if (feature
& GENSEC_FEATURE_DCE_STYLE
) {
100 if (feature
& GENSEC_FEATURE_ASYNC_REPLIES
) {
101 if (ntlmssp_state
->neg_flags
& NTLMSSP_NEGOTIATE_NTLM2
) {
105 if (feature
& GENSEC_FEATURE_SIGN_PKT_HEADER
) {
112 NTSTATUS
gensec_ntlmssp_start(struct gensec_security
*gensec_security
)
114 struct gensec_ntlmssp_context
*gensec_ntlmssp
;
116 gensec_ntlmssp
= talloc_zero(gensec_security
,
117 struct gensec_ntlmssp_context
);
118 if (!gensec_ntlmssp
) {
119 return NT_STATUS_NO_MEMORY
;
122 gensec_security
->private_data
= gensec_ntlmssp
;
126 NTSTATUS
gensec_ntlmssp_sign_packet(struct gensec_security
*gensec_security
,
127 TALLOC_CTX
*sig_mem_ctx
,
128 const uint8_t *data
, size_t length
,
129 const uint8_t *whole_pdu
, size_t pdu_length
,
132 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
133 talloc_get_type_abort(gensec_security
->private_data
,
134 struct gensec_ntlmssp_context
);
137 nt_status
= ntlmssp_sign_packet(gensec_ntlmssp
->ntlmssp_state
,
140 whole_pdu
, pdu_length
,
146 NTSTATUS
gensec_ntlmssp_check_packet(struct gensec_security
*gensec_security
,
147 const uint8_t *data
, size_t length
,
148 const uint8_t *whole_pdu
, size_t pdu_length
,
149 const DATA_BLOB
*sig
)
151 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
152 talloc_get_type_abort(gensec_security
->private_data
,
153 struct gensec_ntlmssp_context
);
156 nt_status
= ntlmssp_check_packet(gensec_ntlmssp
->ntlmssp_state
,
158 whole_pdu
, pdu_length
,
164 NTSTATUS
gensec_ntlmssp_seal_packet(struct gensec_security
*gensec_security
,
165 TALLOC_CTX
*sig_mem_ctx
,
166 uint8_t *data
, size_t length
,
167 const uint8_t *whole_pdu
, size_t pdu_length
,
170 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
171 talloc_get_type_abort(gensec_security
->private_data
,
172 struct gensec_ntlmssp_context
);
175 nt_status
= ntlmssp_seal_packet(gensec_ntlmssp
->ntlmssp_state
,
178 whole_pdu
, pdu_length
,
185 wrappers for the ntlmssp_*() functions
187 NTSTATUS
gensec_ntlmssp_unseal_packet(struct gensec_security
*gensec_security
,
188 uint8_t *data
, size_t length
,
189 const uint8_t *whole_pdu
, size_t pdu_length
,
190 const DATA_BLOB
*sig
)
192 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
193 talloc_get_type_abort(gensec_security
->private_data
,
194 struct gensec_ntlmssp_context
);
197 nt_status
= ntlmssp_unseal_packet(gensec_ntlmssp
->ntlmssp_state
,
199 whole_pdu
, pdu_length
,
205 size_t gensec_ntlmssp_sig_size(struct gensec_security
*gensec_security
, size_t data_size
)
207 return NTLMSSP_SIG_SIZE
;
210 NTSTATUS
gensec_ntlmssp_wrap(struct gensec_security
*gensec_security
,
211 TALLOC_CTX
*out_mem_ctx
,
215 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
216 talloc_get_type_abort(gensec_security
->private_data
,
217 struct gensec_ntlmssp_context
);
219 return ntlmssp_wrap(gensec_ntlmssp
->ntlmssp_state
,
225 NTSTATUS
gensec_ntlmssp_unwrap(struct gensec_security
*gensec_security
,
226 TALLOC_CTX
*out_mem_ctx
,
230 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
231 talloc_get_type_abort(gensec_security
->private_data
,
232 struct gensec_ntlmssp_context
);
234 return ntlmssp_unwrap(gensec_ntlmssp
->ntlmssp_state
,