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/ntlmssp/ntlmssp_private.h"
27 NTSTATUS
gensec_ntlmssp_magic(struct gensec_security
*gensec_security
,
28 const DATA_BLOB
*first_packet
)
30 if (ntlmssp_blob_matches_magic(first_packet
)) {
33 return NT_STATUS_INVALID_PARAMETER
;
38 * Return the NTLMSSP master session key
40 * @param ntlmssp_state NTLMSSP State
43 NTSTATUS
gensec_ntlmssp_session_key(struct gensec_security
*gensec_security
,
45 DATA_BLOB
*session_key
)
47 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
48 talloc_get_type_abort(gensec_security
->private_data
,
49 struct gensec_ntlmssp_context
);
50 struct ntlmssp_state
*ntlmssp_state
= gensec_ntlmssp
->ntlmssp_state
;
52 if (ntlmssp_state
->expected_state
!= NTLMSSP_DONE
) {
53 return NT_STATUS_NO_USER_SESSION_KEY
;
56 if (!ntlmssp_state
->session_key
.data
) {
57 return NT_STATUS_NO_USER_SESSION_KEY
;
59 *session_key
= data_blob_talloc(mem_ctx
, ntlmssp_state
->session_key
.data
, ntlmssp_state
->session_key
.length
);
60 if (!session_key
->data
) {
61 return NT_STATUS_NO_MEMORY
;
67 bool gensec_ntlmssp_have_feature(struct gensec_security
*gensec_security
,
70 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
71 talloc_get_type_abort(gensec_security
->private_data
,
72 struct gensec_ntlmssp_context
);
73 struct ntlmssp_state
*ntlmssp_state
= gensec_ntlmssp
->ntlmssp_state
;
75 if (feature
& GENSEC_FEATURE_SIGN
) {
76 if (!ntlmssp_state
->session_key
.length
) {
79 if (ntlmssp_state
->neg_flags
& NTLMSSP_NEGOTIATE_SIGN
) {
83 if (feature
& GENSEC_FEATURE_SEAL
) {
84 if (!ntlmssp_state
->session_key
.length
) {
87 if (ntlmssp_state
->neg_flags
& NTLMSSP_NEGOTIATE_SEAL
) {
91 if (feature
& GENSEC_FEATURE_SESSION_KEY
) {
92 if (ntlmssp_state
->session_key
.length
) {
96 if (feature
& GENSEC_FEATURE_DCE_STYLE
) {
99 if (feature
& GENSEC_FEATURE_ASYNC_REPLIES
) {
100 if (ntlmssp_state
->neg_flags
& NTLMSSP_NEGOTIATE_NTLM2
) {
107 NTSTATUS
gensec_ntlmssp_start(struct gensec_security
*gensec_security
)
109 struct gensec_ntlmssp_context
*gensec_ntlmssp
;
111 gensec_ntlmssp
= talloc_zero(gensec_security
,
112 struct gensec_ntlmssp_context
);
113 if (!gensec_ntlmssp
) {
114 return NT_STATUS_NO_MEMORY
;
117 gensec_security
->private_data
= gensec_ntlmssp
;
121 NTSTATUS
gensec_ntlmssp_sign_packet(struct gensec_security
*gensec_security
,
122 TALLOC_CTX
*sig_mem_ctx
,
123 const uint8_t *data
, size_t length
,
124 const uint8_t *whole_pdu
, size_t pdu_length
,
127 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
128 talloc_get_type_abort(gensec_security
->private_data
,
129 struct gensec_ntlmssp_context
);
132 nt_status
= ntlmssp_sign_packet(gensec_ntlmssp
->ntlmssp_state
,
135 whole_pdu
, pdu_length
,
141 NTSTATUS
gensec_ntlmssp_check_packet(struct gensec_security
*gensec_security
,
142 const uint8_t *data
, size_t length
,
143 const uint8_t *whole_pdu
, size_t pdu_length
,
144 const DATA_BLOB
*sig
)
146 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
147 talloc_get_type_abort(gensec_security
->private_data
,
148 struct gensec_ntlmssp_context
);
151 nt_status
= ntlmssp_check_packet(gensec_ntlmssp
->ntlmssp_state
,
153 whole_pdu
, pdu_length
,
159 NTSTATUS
gensec_ntlmssp_seal_packet(struct gensec_security
*gensec_security
,
160 TALLOC_CTX
*sig_mem_ctx
,
161 uint8_t *data
, size_t length
,
162 const uint8_t *whole_pdu
, size_t pdu_length
,
165 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
166 talloc_get_type_abort(gensec_security
->private_data
,
167 struct gensec_ntlmssp_context
);
170 nt_status
= ntlmssp_seal_packet(gensec_ntlmssp
->ntlmssp_state
,
173 whole_pdu
, pdu_length
,
180 wrappers for the ntlmssp_*() functions
182 NTSTATUS
gensec_ntlmssp_unseal_packet(struct gensec_security
*gensec_security
,
183 uint8_t *data
, size_t length
,
184 const uint8_t *whole_pdu
, size_t pdu_length
,
185 const DATA_BLOB
*sig
)
187 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
188 talloc_get_type_abort(gensec_security
->private_data
,
189 struct gensec_ntlmssp_context
);
192 nt_status
= ntlmssp_unseal_packet(gensec_ntlmssp
->ntlmssp_state
,
194 whole_pdu
, pdu_length
,
200 size_t gensec_ntlmssp_sig_size(struct gensec_security
*gensec_security
, size_t data_size
)
202 return NTLMSSP_SIG_SIZE
;
205 NTSTATUS
gensec_ntlmssp_wrap(struct gensec_security
*gensec_security
,
206 TALLOC_CTX
*out_mem_ctx
,
210 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
211 talloc_get_type_abort(gensec_security
->private_data
,
212 struct gensec_ntlmssp_context
);
214 return ntlmssp_wrap(gensec_ntlmssp
->ntlmssp_state
,
220 NTSTATUS
gensec_ntlmssp_unwrap(struct gensec_security
*gensec_security
,
221 TALLOC_CTX
*out_mem_ctx
,
225 struct gensec_ntlmssp_context
*gensec_ntlmssp
=
226 talloc_get_type_abort(gensec_security
->private_data
,
227 struct gensec_ntlmssp_context
);
229 return ntlmssp_unwrap(gensec_ntlmssp
->ntlmssp_state
,