r3453: - split out the auth and popt includes
[kai/samba-autobuild/.git] / source4 / torture / auth / ntlmssp.c
1 /* 
2    Unix SMB/CIFS implementation.
3    basic raw test suite for change notify
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004
5    
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.
10    
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.
15    
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.
19 */
20
21 #include "includes.h"
22 #include "auth/auth.h"
23
24 BOOL torture_ntlmssp_self_check(void) 
25 {
26         struct ntlmssp_state *ntlmssp_state;
27         DATA_BLOB data;
28         DATA_BLOB sig, expected_sig;
29         NTSTATUS status;
30
31         if (!NT_STATUS_IS_OK(ntlmssp_client_start(NULL, &ntlmssp_state))) {
32                 return False;
33         }
34
35         ntlmssp_state->session_key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f00");
36         dump_data_pw("NTLMSSP session key: \n", 
37                      ntlmssp_state->session_key.data,  
38                      ntlmssp_state->session_key.length);
39
40         ntlmssp_state->server_use_session_keys = True;
41         ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_KEY_EXCH | NTLMSSP_NEGOTIATE_NTLM2;
42
43         if (!NT_STATUS_IS_OK(status = ntlmssp_sign_init(ntlmssp_state))) {
44                 printf("Failed to sign_init: %s\n", nt_errstr(status));
45                 return False;
46         }
47
48         data = strhex_to_data_blob("6a43494653");
49         ntlmssp_sign_packet(ntlmssp_state, ntlmssp_state, 
50                             data.data, data.length, data.data, data.length, &sig);
51
52         expected_sig = strhex_to_data_blob("01000000e37f97f2544f4d7e00000000");
53
54         dump_data_pw("NTLMSSP calc sig:     ", sig.data, sig.length);
55         dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
56
57         if (sig.length != expected_sig.length) {
58                 printf("Wrong sig length: %d != %d\n", sig.length, expected_sig.length);
59                 return False;
60         }
61
62         if (memcmp(sig.data, expected_sig.data, sig.length)) {
63                 return False;
64         }
65
66         ntlmssp_end(&ntlmssp_state);
67
68         if (!NT_STATUS_IS_OK(ntlmssp_client_start(NULL, &ntlmssp_state))) {
69                 return False;
70         }
71
72         ntlmssp_state->session_key = strhex_to_data_blob("0102030405e538b0");
73         dump_data_pw("NTLMSSP session key: \n", 
74                      ntlmssp_state->session_key.data,  
75                      ntlmssp_state->session_key.length);
76
77         ntlmssp_state->server_use_session_keys = True;
78         ntlmssp_state->neg_flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_KEY_EXCH;
79
80         if (!NT_STATUS_IS_OK(status = ntlmssp_sign_init(ntlmssp_state))) {
81                 printf("Failed to sign_init: %s\n", nt_errstr(status));
82                 return False;
83         }
84
85         data = strhex_to_data_blob("6a43494653");
86         ntlmssp_sign_packet(ntlmssp_state, ntlmssp_state, 
87                             data.data, data.length, data.data, data.length, &sig);
88
89         expected_sig = strhex_to_data_blob("0100000078010900397420fe0e5a0f89");
90
91         dump_data_pw("NTLMSSP calc sig:     ", sig.data, sig.length);
92         dump_data_pw("NTLMSSP expected sig: ", expected_sig.data, expected_sig.length);
93
94         if (sig.length != expected_sig.length) {
95                 printf("Wrong sig length: %d != %d\n", sig.length, expected_sig.length);
96                 return False;
97         }
98
99         if (memcmp(sig.data+8, expected_sig.data+8, sig.length-8)) {
100                 return False;
101         }
102
103         return True;
104 }