2 * FreeRDP: A Remote Desktop Protocol Client
3 * NT LAN Manager Security Support Provider (NTLMSSP)
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <freerdp/freerdp.h>
26 #include <freerdp/utils/blob.h>
27 #include <freerdp/utils/debug.h>
28 #include <freerdp/utils/unicode.h>
35 typedef struct _AV_PAIR AV_PAIR;
39 AV_PAIR NbComputerName;
41 AV_PAIR DnsComputerName;
42 AV_PAIR DnsDomainName;
47 AV_PAIR ChannelBindings;
50 typedef struct _AV_PAIRS AV_PAIRS;
66 typedef enum _AV_ID AV_ID;
70 NTLMSSP_STATE_INITIAL,
71 NTLMSSP_STATE_NEGOTIATE,
72 NTLMSSP_STATE_CHALLENGE,
73 NTLMSSP_STATE_AUTHENTICATE,
76 typedef enum _NTLMSSP_STATE NTLMSSP_STATE;
89 uint32 negotiate_flags;
91 uint8 server_challenge[8];
92 uint8 client_challenge[8];
93 uint8 session_base_key[16];
94 uint8 key_exchange_key[16];
95 uint8 random_session_key[16];
96 uint8 exported_session_key[16];
97 uint8 encrypted_random_session_key[16];
98 uint8 client_signing_key[16];
99 uint8 client_sealing_key[16];
100 uint8 server_signing_key[16];
101 uint8 server_sealing_key[16];
102 uint8 message_integrity_check[16];
103 rdpBlob nt_challenge_response;
104 rdpBlob lm_challenge_response;
105 rdpBlob negotiate_message;
106 rdpBlob challenge_message;
107 rdpBlob authenticate_message;
108 CryptoRc4 send_rc4_seal;
109 CryptoRc4 recv_rc4_seal;
115 typedef struct _NTLMSSP NTLMSSP;
117 void ntlmssp_set_username(NTLMSSP* ntlmssp, char* username);
118 void ntlmssp_set_domain(NTLMSSP* ntlmssp, char* domain);
119 void ntlmssp_set_password(NTLMSSP* ntlmssp, char* password);
120 void ntlmssp_set_workstation(NTLMSSP* ntlmssp, char* workstation);
122 void ntlmssp_generate_client_challenge(NTLMSSP* ntlmssp);
123 void ntlmssp_generate_key_exchange_key(NTLMSSP* ntlmssp);
124 void ntlmssp_generate_random_session_key(NTLMSSP* ntlmssp);
125 void ntlmssp_generate_exported_session_key(NTLMSSP* ntlmssp);
126 void ntlmssp_encrypt_random_session_key(NTLMSSP* ntlmssp);
128 void ntlmssp_generate_timestamp(NTLMSSP* ntlmssp);
129 void ntlmssp_generate_client_signing_key(NTLMSSP* ntlmssp);
130 void ntlmssp_generate_server_signing_key(NTLMSSP* ntlmssp);
131 void ntlmssp_generate_client_sealing_key(NTLMSSP* ntlmssp);
132 void ntlmssp_generate_server_sealing_key(NTLMSSP* ntlmssp);
133 void ntlmssp_init_rc4_seal_states(NTLMSSP* ntlmssp);
135 void ntlmssp_compute_lm_hash(char* password, char* hash);
136 void ntlmssp_compute_ntlm_hash(rdpBlob* password, char* hash);
137 void ntlmssp_compute_ntlm_v2_hash(NTLMSSP* ntlmssp, char* hash);
139 void ntlmssp_compute_lm_response(char* password, char* challenge, char* response);
140 void ntlmssp_compute_lm_v2_response(NTLMSSP* ntlmssp);
141 void ntlmssp_compute_ntlm_v2_response(NTLMSSP* ntlmssp);
143 void ntlmssp_populate_av_pairs(NTLMSSP* ntlmssp);
144 void ntlmssp_input_av_pairs(NTLMSSP* ntlmssp, STREAM* s);
145 void ntlmssp_output_av_pairs(NTLMSSP* ntlmssp, STREAM* s);
146 void ntlmssp_free_av_pairs(NTLMSSP* ntlmssp);
148 void ntlmssp_compute_message_integrity_check(NTLMSSP* ntlmssp);
150 void ntlmssp_encrypt_message(NTLMSSP* ntlmssp, rdpBlob* msg, rdpBlob* encrypted_msg, uint8* signature);
151 int ntlmssp_decrypt_message(NTLMSSP* ntlmssp, rdpBlob* encrypted_msg, rdpBlob* msg, uint8* signature);
153 int ntlmssp_recv(NTLMSSP* ntlmssp, STREAM* s);
154 int ntlmssp_send(NTLMSSP* ntlmssp, STREAM* s);
156 NTLMSSP* ntlmssp_new();
157 void ntlmssp_init(NTLMSSP* ntlmssp);
158 void ntlmssp_free(NTLMSSP* ntlmssp);
160 #ifdef WITH_DEBUG_NLA
161 #define DEBUG_NLA(fmt, ...) DEBUG_CLASS(NLA, fmt, ## __VA_ARGS__)
163 #define DEBUG_NLA(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
166 #endif /* __NTLMSSP_H */