2 Unix SMB/CIFS implementation.
3 Small self-tests for the NTLMSSP code
4 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "auth/auth.h"
23 #include "auth/ntlmssp/ntlmssp.h"
24 #include "lib/cmdline/popt_common.h"
26 BOOL torture_ntlmssp_self_check(void)
28 struct gensec_security *gensec_security;
29 struct gensec_ntlmssp_state *gensec_ntlmssp_state;
31 DATA_BLOB sig, expected_sig;
34 status = gensec_client_start(NULL, &gensec_security);
36 if (!NT_STATUS_IS_OK(status)) {
40 gensec_set_credentials(gensec_security, cmdline_credentials);
42 status = gensec_start_mech_by_oid(gensec_security, GENSEC_OID_NTLMSSP);
44 if (!NT_STATUS_IS_OK(status)) {
48 gensec_ntlmssp_state = gensec_security->private_data;
50 gensec_ntlmssp_state->session_key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f00");
51 dump_data_pw("NTLMSSP session key: \n",
52 gensec_ntlmssp_state->session_key.data,
53 gensec_ntlmssp_state->session_key.length);
55 gensec_ntlmssp_state->server_use_session_keys = True;
56 gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_KEY_EXCH | NTLMSSP_NEGOTIATE_NTLM2;
58 if (!NT_STATUS_IS_OK(status = ntlmssp_sign_init(gensec_ntlmssp_state))) {
59 printf("Failed to sign_init: %s\n", nt_errstr(status));
63 data = strhex_to_data_blob("6a43494653");
64 gensec_ntlmssp_sign_packet(gensec_security, gensec_security,
65 data.data, data.length, data.data, data.length, &sig);
67 expected_sig = strhex_to_data_blob("01000000e37f97f2544f4d7e00000000");
69 dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length);
70 dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
72 if (sig.length != expected_sig.length) {
73 printf("Wrong sig length: %d != %d\n", sig.length, expected_sig.length);
77 if (memcmp(sig.data, expected_sig.data, sig.length)) {
81 talloc_free(gensec_security);
83 status = gensec_client_start(NULL, &gensec_security);
85 if (!NT_STATUS_IS_OK(status)) {
89 gensec_set_credentials(gensec_security, cmdline_credentials);
91 status = gensec_start_mech_by_oid(gensec_security, GENSEC_OID_NTLMSSP);
93 if (!NT_STATUS_IS_OK(status)) {
97 gensec_ntlmssp_state = gensec_security->private_data;
99 gensec_ntlmssp_state->session_key = strhex_to_data_blob("0102030405e538b0");
100 dump_data_pw("NTLMSSP session key: \n",
101 gensec_ntlmssp_state->session_key.data,
102 gensec_ntlmssp_state->session_key.length);
104 gensec_ntlmssp_state->server_use_session_keys = True;
105 gensec_ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH;
107 if (!NT_STATUS_IS_OK(status = ntlmssp_sign_init(gensec_ntlmssp_state))) {
108 printf("Failed to sign_init: %s\n", nt_errstr(status));
112 data = strhex_to_data_blob("6a43494653");
113 gensec_ntlmssp_sign_packet(gensec_security, gensec_security,
114 data.data, data.length, data.data, data.length, &sig);
116 expected_sig = strhex_to_data_blob("0100000078010900397420fe0e5a0f89");
118 dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length);
119 dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
121 if (sig.length != expected_sig.length) {
122 printf("Wrong sig length: %d != %d\n", sig.length, expected_sig.length);
126 if (memcmp(sig.data+8, expected_sig.data+8, sig.length-8)) {
130 talloc_free(gensec_security);