CVE-2016-2110: auth/ntlmssp: implement gensec_ntlmssp_may_reset_crypto()
[samba.git] / auth / ntlmssp / ntlmssp.h
1 /*
2    Unix SMB/CIFS implementation.
3    SMB parameters and setup
4    Copyright (C) Andrew Tridgell 1992-1997
5    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
6    Copyright (C) Paul Ashton 1997
7    Copyright (C) Andrew Bartlett 2010
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "../librpc/gen_ndr/ntlmssp.h"
24
25 struct auth_context;
26 struct auth_serversupplied_info;
27 struct tsocket_address;
28 struct auth_user_info_dc;
29 struct gensec_security;
30 struct ntlmssp_state;
31
32 /* NTLMSSP mode */
33 enum ntlmssp_role
34 {
35         NTLMSSP_SERVER,
36         NTLMSSP_CLIENT
37 };
38
39 /* NTLMSSP message types */
40 enum ntlmssp_message_type
41 {
42         NTLMSSP_INITIAL = 0 /* samba internal state */,
43         NTLMSSP_NEGOTIATE = 1,
44         NTLMSSP_CHALLENGE = 2,
45         NTLMSSP_AUTH      = 3,
46         NTLMSSP_UNKNOWN   = 4,
47         NTLMSSP_DONE      = 5 /* samba final state */
48 };
49
50 #define NTLMSSP_FEATURE_SESSION_KEY        0x00000001
51 #define NTLMSSP_FEATURE_SIGN               0x00000002
52 #define NTLMSSP_FEATURE_SEAL               0x00000004
53 #define NTLMSSP_FEATURE_CCACHE             0x00000008
54
55 union ntlmssp_crypt_state;
56
57 struct ntlmssp_state
58 {
59         enum ntlmssp_role role;
60         uint32_t expected_state;
61
62         bool unicode;
63         bool use_ntlmv2;
64         bool use_ccache;
65         bool resume_ccache;
66         bool use_nt_response;  /* Set to 'False' to debug what happens when the NT response is omited */
67         bool allow_lm_response;/* The LM_RESPONSE code is not very secure... */
68         bool allow_lm_key;     /* The LM_KEY code is not very secure... */
69
70         const char *user;
71         const char *domain;
72         uint8_t *nt_hash;
73         uint8_t *lm_hash;
74
75         struct {
76                 const char *netbios_name;
77                 const char *netbios_domain;
78         } client;
79
80         struct {
81                 bool is_standalone;
82                 const char *netbios_name;
83                 const char *netbios_domain;
84                 const char *dns_name;
85                 const char *dns_domain;
86                 struct AV_PAIR_LIST av_pair_list;
87         } server;
88
89         DATA_BLOB internal_chal; /* Random challenge as supplied to the client for NTLM authentication */
90
91         DATA_BLOB chal; /* Random challenge as input into the actual NTLM (or NTLM2) authentication */
92         DATA_BLOB lm_resp;
93         DATA_BLOB nt_resp;
94         DATA_BLOB session_key;
95
96         uint32_t conf_flags;
97         uint32_t required_flags;
98         uint32_t neg_flags; /* the current state of negotiation with the NTLMSSP partner */
99
100         bool force_wrap_seal;
101
102         union ntlmssp_crypt_state *crypt;
103 };
104
105 /* The following definitions come from libcli/auth/ntlmssp_sign.c  */
106
107 NTSTATUS ntlmssp_sign_packet(struct ntlmssp_state *ntlmssp_state,
108                              TALLOC_CTX *sig_mem_ctx,
109                              const uint8_t *data, size_t length,
110                              const uint8_t *whole_pdu, size_t pdu_length,
111                              DATA_BLOB *sig);
112 NTSTATUS ntlmssp_check_packet(struct ntlmssp_state *ntlmssp_state,
113                               const uint8_t *data, size_t length,
114                               const uint8_t *whole_pdu, size_t pdu_length,
115                               const DATA_BLOB *sig) ;
116 NTSTATUS ntlmssp_seal_packet(struct ntlmssp_state *ntlmssp_state,
117                              TALLOC_CTX *sig_mem_ctx,
118                              uint8_t *data, size_t length,
119                              const uint8_t *whole_pdu, size_t pdu_length,
120                              DATA_BLOB *sig);
121 NTSTATUS ntlmssp_unseal_packet(struct ntlmssp_state *ntlmssp_state,
122                                uint8_t *data, size_t length,
123                                const uint8_t *whole_pdu, size_t pdu_length,
124                                const DATA_BLOB *sig);
125 NTSTATUS ntlmssp_wrap(struct ntlmssp_state *ntlmssp_state,
126                       TALLOC_CTX *out_mem_ctx,
127                       const DATA_BLOB *in,
128                       DATA_BLOB *out);
129 NTSTATUS ntlmssp_unwrap(struct ntlmssp_state *ntlmssp_stae,
130                         TALLOC_CTX *out_mem_ctx,
131                         const DATA_BLOB *in,
132                         DATA_BLOB *out);
133 NTSTATUS ntlmssp_sign_reset(struct ntlmssp_state *ntlmssp_state,
134                             bool reset_seqnums);
135 NTSTATUS ntlmssp_sign_init(struct ntlmssp_state *ntlmssp_state);
136
137 bool ntlmssp_blob_matches_magic(const DATA_BLOB *blob);
138
139 /* The following definitions come from auth/ntlmssp/gensec_ntlmssp.c  */
140
141 NTSTATUS gensec_ntlmssp_init(void);
142
143 uint32_t gensec_ntlmssp_neg_flags(struct gensec_security *gensec_security);
144 const char *gensec_ntlmssp_server_domain(struct gensec_security *gensec_security);