[918] | 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 | /* NTLMSSP mode */
|
---|
| 26 | enum ntlmssp_role
|
---|
| 27 | {
|
---|
| 28 | NTLMSSP_SERVER,
|
---|
| 29 | NTLMSSP_CLIENT
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | /* NTLMSSP message types */
|
---|
| 33 | enum ntlmssp_message_type
|
---|
| 34 | {
|
---|
| 35 | NTLMSSP_INITIAL = 0 /* samba internal state */,
|
---|
| 36 | NTLMSSP_NEGOTIATE = 1,
|
---|
| 37 | NTLMSSP_CHALLENGE = 2,
|
---|
| 38 | NTLMSSP_AUTH = 3,
|
---|
| 39 | NTLMSSP_UNKNOWN = 4,
|
---|
| 40 | NTLMSSP_DONE = 5 /* samba final state */
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | #define NTLMSSP_FEATURE_SESSION_KEY 0x00000001
|
---|
| 44 | #define NTLMSSP_FEATURE_SIGN 0x00000002
|
---|
| 45 | #define NTLMSSP_FEATURE_SEAL 0x00000004
|
---|
| 46 | #define NTLMSSP_FEATURE_CCACHE 0x00000008
|
---|
| 47 |
|
---|
| 48 | union ntlmssp_crypt_state;
|
---|
| 49 |
|
---|
| 50 | struct ntlmssp_state
|
---|
| 51 | {
|
---|
| 52 | enum ntlmssp_role role;
|
---|
| 53 | uint32_t expected_state;
|
---|
| 54 |
|
---|
| 55 | bool unicode;
|
---|
| 56 | bool use_ntlmv2;
|
---|
| 57 | bool use_ccache;
|
---|
| 58 | bool use_nt_response; /* Set to 'False' to debug what happens when the NT response is omited */
|
---|
| 59 | bool allow_lm_key; /* The LM_KEY code is not very secure... */
|
---|
| 60 |
|
---|
| 61 | const char *user;
|
---|
| 62 | const char *domain;
|
---|
| 63 | uint8_t *nt_hash;
|
---|
| 64 | uint8_t *lm_hash;
|
---|
| 65 |
|
---|
| 66 | struct {
|
---|
| 67 | const char *netbios_name;
|
---|
| 68 | const char *netbios_domain;
|
---|
| 69 | } client;
|
---|
| 70 |
|
---|
| 71 | struct {
|
---|
| 72 | bool is_standalone;
|
---|
| 73 | const char *netbios_name;
|
---|
| 74 | const char *netbios_domain;
|
---|
| 75 | const char *dns_name;
|
---|
| 76 | const char *dns_domain;
|
---|
| 77 | } server;
|
---|
| 78 |
|
---|
| 79 | DATA_BLOB internal_chal; /* Random challenge as supplied to the client for NTLM authentication */
|
---|
| 80 |
|
---|
| 81 | DATA_BLOB chal; /* Random challenge as input into the actual NTLM (or NTLM2) authentication */
|
---|
| 82 | DATA_BLOB lm_resp;
|
---|
| 83 | DATA_BLOB nt_resp;
|
---|
| 84 | DATA_BLOB session_key;
|
---|
| 85 |
|
---|
[920] | 86 | uint32_t required_flags;
|
---|
[918] | 87 | uint32_t neg_flags; /* the current state of negotiation with the NTLMSSP partner */
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
| 90 | * Private data for the callback functions
|
---|
| 91 | */
|
---|
| 92 | void *callback_private;
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * Callback to get the 'challenge' used for NTLM authentication.
|
---|
| 96 | *
|
---|
| 97 | * @param ntlmssp_state This structure
|
---|
| 98 | * @return 8 bytes of challenge data, determined by the server to be the challenge for NTLM authentication
|
---|
| 99 | *
|
---|
| 100 | */
|
---|
| 101 | NTSTATUS (*get_challenge)(const struct ntlmssp_state *ntlmssp_state,
|
---|
| 102 | uint8_t challenge[8]);
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * Callback to find if the challenge used by NTLM authentication may be modified
|
---|
| 106 | *
|
---|
| 107 | * The NTLM2 authentication scheme modifies the effective challenge, but this is not compatiable with the
|
---|
| 108 | * current 'security=server' implementation..
|
---|
| 109 | *
|
---|
| 110 | * @param ntlmssp_state This structure
|
---|
| 111 | * @return Can the challenge be set to arbitary values?
|
---|
| 112 | *
|
---|
| 113 | */
|
---|
| 114 | bool (*may_set_challenge)(const struct ntlmssp_state *ntlmssp_state);
|
---|
| 115 |
|
---|
| 116 | /**
|
---|
| 117 | * Callback to set the 'challenge' used for NTLM authentication.
|
---|
| 118 | *
|
---|
| 119 | * The callback may use the void *auth_context to store state information, but the same value is always available
|
---|
| 120 | * from the DATA_BLOB chal on this structure.
|
---|
| 121 | *
|
---|
| 122 | * @param ntlmssp_state This structure
|
---|
| 123 | * @param challenge 8 bytes of data, agreed by the client and server to be the effective challenge for NTLM2 authentication
|
---|
| 124 | *
|
---|
| 125 | */
|
---|
| 126 | NTSTATUS (*set_challenge)(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge);
|
---|
| 127 |
|
---|
| 128 | /**
|
---|
| 129 | * Callback to check the user's password.
|
---|
| 130 | *
|
---|
| 131 | * The callback must reads the feilds of this structure for the information it needs on the user
|
---|
| 132 | * @param ntlmssp_state This structure
|
---|
| 133 | * @param mem_ctx Talloc context for LM and NT session key to be returned on
|
---|
| 134 | * @param nt_session_key If an NT session key is returned by the authentication process, return it here
|
---|
| 135 | * @param lm_session_key If an LM session key is returned by the authentication process, return it here
|
---|
| 136 | *
|
---|
| 137 | */
|
---|
| 138 | NTSTATUS (*check_password)(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
|
---|
| 139 | DATA_BLOB *nt_session_key, DATA_BLOB *lm_session_key);
|
---|
| 140 |
|
---|
| 141 | union ntlmssp_crypt_state *crypt;
|
---|
| 142 | };
|
---|
| 143 |
|
---|
| 144 | /* The following definitions come from libcli/auth/ntlmssp_sign.c */
|
---|
| 145 |
|
---|
| 146 | NTSTATUS ntlmssp_sign_packet(struct ntlmssp_state *ntlmssp_state,
|
---|
| 147 | TALLOC_CTX *sig_mem_ctx,
|
---|
| 148 | const uint8_t *data, size_t length,
|
---|
| 149 | const uint8_t *whole_pdu, size_t pdu_length,
|
---|
| 150 | DATA_BLOB *sig);
|
---|
| 151 | NTSTATUS ntlmssp_check_packet(struct ntlmssp_state *ntlmssp_state,
|
---|
| 152 | const uint8_t *data, size_t length,
|
---|
| 153 | const uint8_t *whole_pdu, size_t pdu_length,
|
---|
| 154 | const DATA_BLOB *sig) ;
|
---|
| 155 | NTSTATUS ntlmssp_seal_packet(struct ntlmssp_state *ntlmssp_state,
|
---|
| 156 | TALLOC_CTX *sig_mem_ctx,
|
---|
| 157 | uint8_t *data, size_t length,
|
---|
| 158 | const uint8_t *whole_pdu, size_t pdu_length,
|
---|
| 159 | DATA_BLOB *sig);
|
---|
| 160 | NTSTATUS ntlmssp_unseal_packet(struct ntlmssp_state *ntlmssp_state,
|
---|
| 161 | uint8_t *data, size_t length,
|
---|
| 162 | const uint8_t *whole_pdu, size_t pdu_length,
|
---|
| 163 | const DATA_BLOB *sig);
|
---|
| 164 | NTSTATUS ntlmssp_wrap(struct ntlmssp_state *ntlmssp_state,
|
---|
| 165 | TALLOC_CTX *out_mem_ctx,
|
---|
| 166 | const DATA_BLOB *in,
|
---|
| 167 | DATA_BLOB *out);
|
---|
| 168 | NTSTATUS ntlmssp_unwrap(struct ntlmssp_state *ntlmssp_stae,
|
---|
| 169 | TALLOC_CTX *out_mem_ctx,
|
---|
| 170 | const DATA_BLOB *in,
|
---|
| 171 | DATA_BLOB *out);
|
---|
| 172 | NTSTATUS ntlmssp_sign_init(struct ntlmssp_state *ntlmssp_state);
|
---|