Fix changelog email address
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-core / ntlmssp.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * NT LAN Manager Security Support Provider (NTLMSSP)
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #ifndef __NTLMSSP_H
21 #define __NTLMSSP_H
22
23 #include "credssp.h"
24
25 #include <freerdp/freerdp.h>
26 #include <freerdp/utils/blob.h>
27 #include <freerdp/utils/debug.h>
28 #include <freerdp/utils/unicode.h>
29
30 struct _AV_PAIR
31 {
32         uint16 length;
33         uint8* value;
34 };
35 typedef struct _AV_PAIR AV_PAIR;
36
37 struct _AV_PAIRS
38 {
39         AV_PAIR NbComputerName;
40         AV_PAIR NbDomainName;
41         AV_PAIR DnsComputerName;
42         AV_PAIR DnsDomainName;
43         AV_PAIR DnsTreeName;
44         AV_PAIR Timestamp;
45         AV_PAIR Restrictions;
46         AV_PAIR TargetName;
47         AV_PAIR ChannelBindings;
48         uint32 Flags;
49 };
50 typedef struct _AV_PAIRS AV_PAIRS;
51
52 enum _AV_ID
53 {
54         MsvAvEOL,
55         MsvAvNbComputerName,
56         MsvAvNbDomainName,
57         MsvAvDnsComputerName,
58         MsvAvDnsDomainName,
59         MsvAvDnsTreeName,
60         MsvAvFlags,
61         MsvAvTimestamp,
62         MsvAvRestrictions,
63         MsvAvTargetName,
64         MsvChannelBindings
65 };
66 typedef enum _AV_ID AV_ID;
67
68 enum _NTLMSSP_STATE
69 {
70         NTLMSSP_STATE_INITIAL,
71         NTLMSSP_STATE_NEGOTIATE,
72         NTLMSSP_STATE_CHALLENGE,
73         NTLMSSP_STATE_AUTHENTICATE,
74         NTLMSSP_STATE_FINAL
75 };
76 typedef enum _NTLMSSP_STATE NTLMSSP_STATE;
77
78 struct _NTLMSSP
79 {
80         NTLMSSP_STATE state;
81         rdpBlob password;
82         rdpBlob username;
83         rdpBlob domain;
84         rdpBlob workstation;
85         rdpBlob target_info;
86         rdpBlob target_name;
87         rdpBlob spn;
88         UNICONV *uniconv;
89         uint32 negotiate_flags;
90         uint8 timestamp[8];
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;
110         AV_PAIRS *av_pairs;
111         int send_seq_num;
112         int recv_seq_num;
113         int ntlm_v2;
114 };
115 typedef struct _NTLMSSP NTLMSSP;
116
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);
121
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);
127
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);
134
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);
138
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);
142
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);
147
148 void ntlmssp_compute_message_integrity_check(NTLMSSP* ntlmssp);
149
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);
152
153 int ntlmssp_recv(NTLMSSP* ntlmssp, STREAM* s);
154 int ntlmssp_send(NTLMSSP* ntlmssp, STREAM* s);
155
156 NTLMSSP* ntlmssp_new();
157 void ntlmssp_init(NTLMSSP* ntlmssp);
158 void ntlmssp_free(NTLMSSP* ntlmssp);
159
160 #ifdef WITH_DEBUG_NLA
161 #define DEBUG_NLA(fmt, ...) DEBUG_CLASS(NLA, fmt, ## __VA_ARGS__)
162 #else
163 #define DEBUG_NLA(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
164 #endif
165
166 #endif /* __NTLMSSP_H */