Mercurial > pidgin
comparison libpurple/ntlm.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 7df46d8bf114 |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * @file ntlm.c | 2 * @file ntlm.c |
3 * | 3 * |
4 * gaim | 4 * purple |
5 * | 5 * |
6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de> | 6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de> |
7 * | 7 * |
8 * hashing done according to description of NTLM on | 8 * hashing done according to description of NTLM on |
9 * http://www.innovation.ch/java/ntlm.html | 9 * http://www.innovation.ch/java/ntlm.html |
106 #endif | 106 #endif |
107 }; | 107 }; |
108 | 108 |
109 /* TODO: Will this work on both little-endian and big-endian machines? */ | 109 /* TODO: Will this work on both little-endian and big-endian machines? */ |
110 gchar * | 110 gchar * |
111 gaim_ntlm_gen_type1(const gchar *hostname, const gchar *domain) | 111 purple_ntlm_gen_type1(const gchar *hostname, const gchar *domain) |
112 { | 112 { |
113 int hostnamelen; | 113 int hostnamelen; |
114 int domainlen; | 114 int domainlen; |
115 unsigned char *msg; | 115 unsigned char *msg; |
116 struct type1_message *tmsg; | 116 struct type1_message *tmsg; |
135 tmsg->host_len1 = tmsg->host_len2 = hostnamelen; | 135 tmsg->host_len1 = tmsg->host_len2 = hostnamelen; |
136 tmsg->host_off = sizeof(struct type1_message); | 136 tmsg->host_off = sizeof(struct type1_message); |
137 memcpy(msg + tmsg->host_off, hostname, hostnamelen); | 137 memcpy(msg + tmsg->host_off, hostname, hostnamelen); |
138 memcpy(msg + tmsg->dom_off, domain, domainlen); | 138 memcpy(msg + tmsg->dom_off, domain, domainlen); |
139 | 139 |
140 tmp = gaim_base64_encode(msg, sizeof(struct type1_message) + hostnamelen + domainlen); | 140 tmp = purple_base64_encode(msg, sizeof(struct type1_message) + hostnamelen + domainlen); |
141 g_free(msg); | 141 g_free(msg); |
142 | 142 |
143 return tmp; | 143 return tmp; |
144 } | 144 } |
145 | 145 |
146 guint8 * | 146 guint8 * |
147 gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags) | 147 purple_ntlm_parse_type2(const gchar *type2, guint32 *flags) |
148 { | 148 { |
149 gsize retlen; | 149 gsize retlen; |
150 struct type2_message *tmsg; | 150 struct type2_message *tmsg; |
151 static guint8 nonce[8]; | 151 static guint8 nonce[8]; |
152 | 152 |
153 tmsg = (struct type2_message*)gaim_base64_decode(type2, &retlen); | 153 tmsg = (struct type2_message*)purple_base64_decode(type2, &retlen); |
154 memcpy(nonce, tmsg->nonce, 8); | 154 memcpy(nonce, tmsg->nonce, 8); |
155 if (flags != NULL) | 155 if (flags != NULL) |
156 *flags = tmsg->flags; | 156 *flags = tmsg->flags; |
157 g_free(tmsg); | 157 g_free(tmsg); |
158 | 158 |
175 key[6] = ((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6); | 175 key[6] = ((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6); |
176 key[7] = (key_56[6] << 1) & 0xFF; | 176 key[7] = (key_56[6] << 1) & 0xFF; |
177 } | 177 } |
178 | 178 |
179 /* | 179 /* |
180 * helper function for gaim cipher.c | 180 * helper function for purple cipher.c |
181 */ | 181 */ |
182 static void | 182 static void |
183 des_ecb_encrypt(const guint8 *plaintext, guint8 *result, const guint8 *key) | 183 des_ecb_encrypt(const guint8 *plaintext, guint8 *result, const guint8 *key) |
184 { | 184 { |
185 GaimCipher *cipher; | 185 PurpleCipher *cipher; |
186 GaimCipherContext *context; | 186 PurpleCipherContext *context; |
187 gsize outlen; | 187 gsize outlen; |
188 | 188 |
189 cipher = gaim_ciphers_find_cipher("des"); | 189 cipher = purple_ciphers_find_cipher("des"); |
190 context = gaim_cipher_context_new(cipher, NULL); | 190 context = purple_cipher_context_new(cipher, NULL); |
191 gaim_cipher_context_set_key(context, key); | 191 purple_cipher_context_set_key(context, key); |
192 gaim_cipher_context_encrypt(context, plaintext, 8, result, &outlen); | 192 purple_cipher_context_encrypt(context, plaintext, 8, result, &outlen); |
193 gaim_cipher_context_destroy(context); | 193 purple_cipher_context_destroy(context); |
194 } | 194 } |
195 | 195 |
196 /* | 196 /* |
197 * takes a 21 byte array and treats it as 3 56-bit DES keys. The | 197 * takes a 21 byte array and treats it as 3 56-bit DES keys. The |
198 * 8 byte plaintext is encrypted with each key and the resulting 24 | 198 * 8 byte plaintext is encrypted with each key and the resulting 24 |
224 memcpy(buffer, oldkey, 16); | 224 memcpy(buffer, oldkey, 16); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 gchar * | 228 gchar * |
229 gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags) | 229 purple_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags) |
230 { | 230 { |
231 char lm_pw[14]; | 231 char lm_pw[14]; |
232 unsigned char lm_hpw[21]; | 232 unsigned char lm_hpw[21]; |
233 char sesskey[16]; | 233 char sesskey[16]; |
234 guint8 key[8]; | 234 guint8 key[8]; |
240 int passwlen, lennt; | 240 int passwlen, lennt; |
241 unsigned char lm_resp[24], nt_resp[24]; | 241 unsigned char lm_resp[24], nt_resp[24]; |
242 unsigned char magic[] = { 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 }; | 242 unsigned char magic[] = { 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 }; |
243 unsigned char nt_hpw[21]; | 243 unsigned char nt_hpw[21]; |
244 char nt_pw[128]; | 244 char nt_pw[128]; |
245 GaimCipher *cipher; | 245 PurpleCipher *cipher; |
246 GaimCipherContext *context; | 246 PurpleCipherContext *context; |
247 char *tmp; | 247 char *tmp; |
248 int idx; | 248 int idx; |
249 gchar *ucs2le; | 249 gchar *ucs2le; |
250 | 250 |
251 domainlen = strlen(domain) * 2; | 251 domainlen = strlen(domain) * 2; |
330 { | 330 { |
331 nt_pw[2 * idx] = passw[idx]; | 331 nt_pw[2 * idx] = passw[idx]; |
332 nt_pw[2 * idx + 1] = 0; | 332 nt_pw[2 * idx + 1] = 0; |
333 } | 333 } |
334 | 334 |
335 cipher = gaim_ciphers_find_cipher("md4"); | 335 cipher = purple_ciphers_find_cipher("md4"); |
336 context = gaim_cipher_context_new(cipher, NULL); | 336 context = purple_cipher_context_new(cipher, NULL); |
337 gaim_cipher_context_append(context, (guint8 *)nt_pw, 2 * lennt); | 337 purple_cipher_context_append(context, (guint8 *)nt_pw, 2 * lennt); |
338 gaim_cipher_context_digest(context, 21, nt_hpw, NULL); | 338 purple_cipher_context_digest(context, 21, nt_hpw, NULL); |
339 gaim_cipher_context_destroy(context); | 339 purple_cipher_context_destroy(context); |
340 | 340 |
341 memset(nt_hpw + 16, 0, 5); | 341 memset(nt_hpw + 16, 0, 5); |
342 calc_resp(nt_hpw, nonce, nt_resp); | 342 calc_resp(nt_hpw, nonce, nt_resp); |
343 memcpy(tmp, nt_resp, 0x18); | 343 memcpy(tmp, nt_resp, 0x18); |
344 tmp += 0x18; | 344 tmp += 0x18; |
351 } | 351 } |
352 | 352 |
353 /*tmsg->flags2 = 0x0a280105; | 353 /*tmsg->flags2 = 0x0a280105; |
354 tmsg->flags3 = 0x0f000000;*/ | 354 tmsg->flags3 = 0x0f000000;*/ |
355 | 355 |
356 tmp = gaim_base64_encode((guchar *)tmsg, msglen); | 356 tmp = purple_base64_encode((guchar *)tmsg, msglen); |
357 g_free(tmsg); | 357 g_free(tmsg); |
358 | 358 |
359 return tmp; | 359 return tmp; |
360 } | 360 } |