r2098: The first 8 bytes of this sig is not used in the 'is it correct' calculation.
[Samba/ekacnet.git] / source4 / torture / auth / ntlmssp.c
blob57b337693f58b0379343ed271a0473f23945e138
1 /*
2 Unix SMB/CIFS implementation.
3 basic raw test suite for change notify
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.
21 #include "includes.h"
23 BOOL torture_ntlmssp_self_check(int dummy)
25 struct ntlmssp_state *ntlmssp_state;
26 DATA_BLOB data;
27 DATA_BLOB sig, expected_sig;
28 NTSTATUS status;
30 if (!NT_STATUS_IS_OK(ntlmssp_client_start(&ntlmssp_state))) {
31 return False;
34 ntlmssp_state->session_key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f00");
35 dump_data_pw("NTLMSSP session key: \n",
36 ntlmssp_state->session_key.data,
37 ntlmssp_state->session_key.length);
39 ntlmssp_state->server_use_session_keys = True;
40 ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_KEY_EXCH | NTLMSSP_NEGOTIATE_NTLM2;
42 if (!NT_STATUS_IS_OK(status = ntlmssp_sign_init(ntlmssp_state))) {
43 printf("Failed to sign_init: %s\n", nt_errstr(status));
44 return False;
47 data = strhex_to_data_blob("6a43494653");
48 ntlmssp_sign_packet(ntlmssp_state, ntlmssp_state->mem_ctx,
49 data.data, data.length, &sig);
51 expected_sig = strhex_to_data_blob("01000000e37f97f2544f4d7e00000000");
53 dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length);
54 dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
56 if (sig.length != expected_sig.length) {
57 printf("Wrong sig length: %d != %d\n", sig.length, expected_sig.length);
58 return False;
61 if (memcmp(sig.data, expected_sig.data, sig.length)) {
62 return False;
65 ntlmssp_end(&ntlmssp_state);
67 if (!NT_STATUS_IS_OK(ntlmssp_client_start(&ntlmssp_state))) {
68 return False;
71 ntlmssp_state->session_key = strhex_to_data_blob("0102030405e538b0");
72 dump_data_pw("NTLMSSP session key: \n",
73 ntlmssp_state->session_key.data,
74 ntlmssp_state->session_key.length);
76 ntlmssp_state->server_use_session_keys = True;
77 ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH;
79 if (!NT_STATUS_IS_OK(status = ntlmssp_sign_init(ntlmssp_state))) {
80 printf("Failed to sign_init: %s\n", nt_errstr(status));
81 return False;
84 data = strhex_to_data_blob("6a43494653");
85 ntlmssp_sign_packet(ntlmssp_state, ntlmssp_state->mem_ctx,
86 data.data, data.length, &sig);
88 expected_sig = strhex_to_data_blob("0100000078010900397420fe0e5a0f89");
90 dump_data_pw("NTLMSSP calc sig: ", sig.data, sig.length);
91 dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
93 if (sig.length != expected_sig.length) {
94 printf("Wrong sig length: %d != %d\n", sig.length, expected_sig.length);
95 return False;
98 if (memcmp(sig.data+8, expected_sig.data+8, sig.length-8)) {
99 return False;
102 return True;