annotate src/ntlm.c @ 13933:ad171112d52c

[gaim-migrate @ 16461] Autoreply messages are no longer sent in response to autoreply messages committer: Tailor Script <tailor@pidgin.im>
author Evan Schoenberg <evan.s@dreskin.net>
date Sat, 08 Jul 2006 15:38:45 +0000
parents 1983a8fc8e72
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
1 /**
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
2 * @file ntlm.c
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
3 *
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
4 * gaim
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
5 *
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
7 *
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
8 * hashing done according to description of NTLM on
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
9 * http://www.innovation.ch/java/ntlm.html
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
10 *
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
14 * (at your option) any later version.
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
15 *
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
19 * GNU General Public License for more details.
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
20 *
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
24 */
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
25
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
26 #include <glib.h>
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
27 #include <stdlib.h>
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
28 #include "util.h"
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
29 #include "ntlm.h"
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
30 #include "cipher.h"
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
31 #include <string.h>
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
32
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
33 #define NTLM_NEGOTIATE_NTLM2_KEY 0x00080000
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
34
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
35 struct type1_message {
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
36 guint8 protocol[8]; /* 'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0' */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
37 guint32 type; /* 0x00000001 */
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
38 guint32 flags; /* 0x0000b203 */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
39
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
40 short dom_len1; /* domain string length */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
41 short dom_len2; /* domain string length */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
42 guint32 dom_off; /* domain string offset */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
43
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
44 short host_len1; /* host string length */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
45 short host_len2; /* host string length */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
46 guint32 host_off; /* host string offset (always 0x00000020) */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
47
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
48 #if 0
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
49 guint8 host[*]; /* host string (ASCII) */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
50 guint8 dom[*]; /* domain string (ASCII) */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
51 #endif
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
52 };
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
53
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
54 struct type2_message {
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
55 guint8 protocol[8]; /* 'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0'*/
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
56 guint32 type; /* 0x00000002 */
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
57
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
58 short msg_len1; /* target name length */
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
59 short msg_len2; /* target name length */
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
60 guint32 msg_off; /* target name offset (always 0x00000048) */
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
61
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
62 guint32 flags; /* 0x00008201 */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
63
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
64 guint8 nonce[8]; /* nonce */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
65 guint8 context[8];
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
66 };
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
67
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
68 struct type3_message {
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
69 guint8 protocol[8]; /* 'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0'*/
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
70 guint32 type; /* 0x00000003 */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
71
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
72 short lm_resp_len1; /* LanManager response length (always 0x18)*/
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
73 short lm_resp_len2; /* LanManager response length (always 0x18)*/
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
74 guint32 lm_resp_off; /* LanManager response offset */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
75
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
76 short nt_resp_len1; /* NT response length (always 0x18) */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
77 short nt_resp_len2; /* NT response length (always 0x18) */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
78 guint32 nt_resp_off; /* NT response offset */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
79
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
80 short dom_len1; /* domain string length */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
81 short dom_len2; /* domain string length */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
82 guint32 dom_off; /* domain string offset (always 0x00000040) */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
83
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
84 short user_len1; /* username string length */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
85 short user_len2; /* username string length */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
86 guint32 user_off; /* username string offset */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
87
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
88 short host_len1; /* host string length */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
89 short host_len2; /* host string length */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
90 guint32 host_off; /* host string offset */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
91
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
92 short sess_len1;
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
93 short sess_len2;
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
94 guint32 sess_off; /* message length */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
95
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
96 guint32 flags; /* 0x00008201 */
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
97 /* guint32 flags2; */ /* unknown, used in windows messenger */
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
98 /* guint32 flags3; */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
99
11829
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
100 #if 0
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
101 guint8 dom[*]; /* domain string (unicode UTF-16LE) */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
102 guint8 user[*]; /* username string (unicode UTF-16LE) */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
103 guint8 host[*]; /* host string (unicode UTF-16LE) */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
104 guint8 lm_resp[*]; /* LanManager response */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
105 guint8 nt_resp[*]; /* NT response */
4669e7461968 [gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
106 #endif
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
107 };
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
108
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
109 /* TODO: Will this work on both little-endian and big-endian machines? */
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
110 gchar *
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
111 gaim_ntlm_gen_type1(const gchar *hostname, const gchar *domain)
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
112 {
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
113 int hostnamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
114 int domainlen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
115 unsigned char *msg;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
116 struct type1_message *tmsg;
13704
1a1248de26ed [gaim-migrate @ 16107]
Mark Doliner <mark@kingant.net>
parents: 13699
diff changeset
117 gchar *tmp;
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
118
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
119 hostnamelen = strlen(hostname);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
120 domainlen = strlen(domain);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
121 msg = g_malloc0(sizeof(struct type1_message) + hostnamelen + domainlen);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
122 tmsg = (struct type1_message*)msg;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
123 tmsg->protocol[0] = 'N';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
124 tmsg->protocol[1] = 'T';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
125 tmsg->protocol[2] = 'L';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
126 tmsg->protocol[3] = 'M';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
127 tmsg->protocol[4] = 'S';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
128 tmsg->protocol[5] = 'S';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
129 tmsg->protocol[6] = 'P';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
130 tmsg->protocol[7] = '\0';
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
131 tmsg->type = 0x00000001;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
132 tmsg->flags = 0x0000b202;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
133 tmsg->dom_len1 = tmsg->dom_len2 = domainlen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
134 tmsg->dom_off = sizeof(struct type1_message) + hostnamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
135 tmsg->host_len1 = tmsg->host_len2 = hostnamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
136 tmsg->host_off = sizeof(struct type1_message);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
137 memcpy(msg + tmsg->host_off, hostname, hostnamelen);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
138 memcpy(msg + tmsg->dom_off, domain, domainlen);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
139
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
140 tmp = gaim_base64_encode(msg, sizeof(struct type1_message) + hostnamelen + domainlen);
13704
1a1248de26ed [gaim-migrate @ 16107]
Mark Doliner <mark@kingant.net>
parents: 13699
diff changeset
141 g_free(msg);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
142
13704
1a1248de26ed [gaim-migrate @ 16107]
Mark Doliner <mark@kingant.net>
parents: 13699
diff changeset
143 return tmp;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
144 }
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
145
13698
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13677
diff changeset
146 guint8 *
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
147 gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags)
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
148 {
11586
03cd74ca2562 [gaim-migrate @ 13856]
Nathan Walp <nwalp@pidgin.im>
parents: 11427
diff changeset
149 gsize retlen;
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
150 struct type2_message *tmsg;
13698
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13677
diff changeset
151 static guint8 nonce[8];
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
152
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
153 tmsg = (struct type2_message*)gaim_base64_decode(type2, &retlen);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
154 memcpy(nonce, tmsg->nonce, 8);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
155 if (flags != NULL)
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
156 *flags = tmsg->flags;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
157 g_free(tmsg);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
158
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
159 return nonce;
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
160 }
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
161
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
162 /**
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
163 * Create a 64bit DES key by taking a 56bit key and adding
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
164 * a parity bit after every 7th bit.
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
165 */
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
166 static void
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
167 setup_des_key(const guint8 key_56[], guint8 *key)
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
168 {
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
169 key[0] = key_56[0];
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
170 key[1] = ((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
171 key[2] = ((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
172 key[3] = ((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
173 key[4] = ((key_56[3] << 4) & 0xFF) | (key_56[4] >> 4);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
174 key[5] = ((key_56[4] << 3) & 0xFF) | (key_56[5] >> 5);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
175 key[6] = ((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
176 key[7] = (key_56[6] << 1) & 0xFF;
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
177 }
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
178
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
179 /*
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
180 * helper function for gaim cipher.c
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
181 */
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
182 static void
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
183 des_ecb_encrypt(const guint8 *plaintext, guint8 *result, const guint8 *key)
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
184 {
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
185 GaimCipher *cipher;
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
186 GaimCipherContext *context;
11586
03cd74ca2562 [gaim-migrate @ 13856]
Nathan Walp <nwalp@pidgin.im>
parents: 11427
diff changeset
187 gsize outlen;
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
188
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
189 cipher = gaim_ciphers_find_cipher("des");
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
190 context = gaim_cipher_context_new(cipher, NULL);
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
191 gaim_cipher_context_set_key(context, key);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
192 gaim_cipher_context_encrypt(context, plaintext, 8, result, &outlen);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
193 gaim_cipher_context_destroy(context);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
194 }
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
195
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
196 /*
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
197 * takes a 21 byte array and treats it as 3 56-bit DES keys. The
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
198 * 8 byte plaintext is encrypted with each key and the resulting 24
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
199 * bytes are stored in the results array.
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
200 */
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
201 static void
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
202 calc_resp(guint8 *keys, const guint8 *plaintext, unsigned char *results)
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
203 {
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
204 guint8 key[8];
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
205 setup_des_key(keys, key);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
206 des_ecb_encrypt(plaintext, results, key);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
207
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
208 setup_des_key(keys + 7, key);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
209 des_ecb_encrypt(plaintext, results + 8, key);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
210
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
211 setup_des_key(keys + 14, key);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
212 des_ecb_encrypt(plaintext, results + 16, key);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
213 }
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
214
13677
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
215 static void
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
216 gensesskey(char *buffer, const char *oldkey)
7f5b3313dd07 [gaim-migrate @ 16079]
Mark Doliner <mark@kingant.net>
parents: 13088
diff changeset
217 {
13087
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
218 int i = 0;
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
219 if(oldkey == NULL) {
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
220 for(i=0; i<16; i++) {
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
221 buffer[i] = (char)(rand() & 0xff);
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
222 }
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
223 } else {
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
224 memcpy(buffer, oldkey, 16);
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
225 }
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
226 }
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
227
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13087
diff changeset
228 gchar *
13698
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13677
diff changeset
229 gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags)
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13087
diff changeset
230 {
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
231 char lm_pw[14];
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
232 unsigned char lm_hpw[21];
13087
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
233 char sesskey[16];
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
234 guint8 key[8];
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
235 int domainlen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
236 int usernamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
237 int hostnamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
238 int msglen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
239 struct type3_message *tmsg;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
240 int passwlen, lennt;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
241 unsigned char lm_resp[24], nt_resp[24];
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
242 unsigned char magic[] = { 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
243 unsigned char nt_hpw[21];
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
244 char nt_pw[128];
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
245 GaimCipher *cipher;
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
246 GaimCipherContext *context;
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
247 char *tmp;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
248 int idx;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
249 gchar *ucs2le;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
250
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
251 domainlen = strlen(domain) * 2;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
252 usernamelen = strlen(username) * 2;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
253 hostnamelen = strlen(hostname) * 2;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
254 msglen = sizeof(struct type3_message) + domainlen +
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
255 usernamelen + hostnamelen + 0x18 + 0x18 + ((flags) ? 0x10 : 0);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
256 tmsg = g_malloc0(msglen);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
257 passwlen = strlen(passw);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
258
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13087
diff changeset
259 /* type3 message initialization */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
260 tmsg->protocol[0] = 'N';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
261 tmsg->protocol[1] = 'T';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
262 tmsg->protocol[2] = 'L';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
263 tmsg->protocol[3] = 'M';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
264 tmsg->protocol[4] = 'S';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
265 tmsg->protocol[5] = 'S';
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
266 tmsg->protocol[6] = 'P';
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
267 tmsg->type = 0x00000003;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
268 tmsg->lm_resp_len1 = tmsg->lm_resp_len2 = 0x18;
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
269 tmsg->lm_resp_off = sizeof(struct type3_message) + domainlen + usernamelen + hostnamelen;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
270 tmsg->nt_resp_len1 = tmsg->nt_resp_len2 = 0x18;
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
271 tmsg->nt_resp_off = sizeof(struct type3_message) + domainlen + usernamelen + hostnamelen + 0x18;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
272
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
273 tmsg->dom_len1 = tmsg->dom_len2 = domainlen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
274 tmsg->dom_off = sizeof(struct type3_message);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
275
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
276 tmsg->user_len1 = tmsg->user_len2 = usernamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
277 tmsg->user_off = sizeof(struct type3_message) + domainlen;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
278
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
279 tmsg->host_len1 = tmsg->host_len2 = hostnamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
280 tmsg->host_off = sizeof(struct type3_message) + domainlen + usernamelen;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
281
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
282 if(flags) {
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
283 tmsg->sess_off = sizeof(struct type3_message) + domainlen + usernamelen + hostnamelen + 0x18 + 0x18;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
284 tmsg->sess_len1 = tmsg->sess_len2 = 0x0010;
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
285 }
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
286
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
287 tmsg->flags = 0x00008200;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
288
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
289 tmp = (char *)tmsg + sizeof(struct type3_message);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
290
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
291 ucs2le = g_convert(domain, -1, "UCS-2LE", "UTF-8", NULL, NULL, NULL);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
292 memcpy(tmp, ucs2le, domainlen);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
293 g_free(ucs2le);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
294 tmp += domainlen;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
295
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
296 ucs2le = g_convert(username, -1, "UCS-2LE", "UTF-8", NULL, NULL, NULL);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
297 memcpy(tmp, ucs2le, usernamelen);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
298 g_free(ucs2le);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
299 tmp += usernamelen;
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
300
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
301 ucs2le = g_convert(hostname, -1, "UCS-2LE", "UTF-8", NULL, NULL, NULL);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
302 memcpy(tmp, ucs2le, hostnamelen);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
303 g_free(ucs2le);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
304 tmp += hostnamelen;
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13087
diff changeset
305
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
306 /* LM */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
307 if (passwlen > 14)
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
308 passwlen = 14;
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
309
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
310 for (idx = 0; idx < passwlen; idx++)
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
311 lm_pw[idx] = g_ascii_toupper(passw[idx]);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
312 for (; idx < 14; idx++)
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
313 lm_pw[idx] = 0;
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
314
13699
c8043f9a4ce2 [gaim-migrate @ 16102]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
315 setup_des_key((unsigned char*)lm_pw, key);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
316 des_ecb_encrypt(magic, lm_hpw, key);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
317
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
318 setup_des_key((unsigned char*)(lm_pw + 7), key);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
319 des_ecb_encrypt(magic, lm_hpw + 8, key);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
320
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
321 memset(lm_hpw + 16, 0, 5);
13698
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13677
diff changeset
322 calc_resp(lm_hpw, nonce, lm_resp);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
323 memcpy(tmp, lm_resp, 0x18);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
324 tmp += 0x18;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
325
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
326 /* NTLM */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
327 /* Convert the password to UCS-2LE */
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
328 lennt = strlen(passw);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
329 for (idx = 0; idx < lennt; idx++)
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
330 {
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
331 nt_pw[2 * idx] = passw[idx];
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
332 nt_pw[2 * idx + 1] = 0;
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
333 }
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
334
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
335 cipher = gaim_ciphers_find_cipher("md4");
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
336 context = gaim_cipher_context_new(cipher, NULL);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
337 gaim_cipher_context_append(context, (guint8 *)nt_pw, 2 * lennt);
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
338 gaim_cipher_context_digest(context, 21, nt_hpw, NULL);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
339 gaim_cipher_context_destroy(context);
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
340
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
341 memset(nt_hpw + 16, 0, 5);
13698
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13677
diff changeset
342 calc_resp(nt_hpw, nonce, nt_resp);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
343 memcpy(tmp, nt_resp, 0x18);
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
344 tmp += 0x18;
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
345
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
346 /* LCS Stuff */
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
347 if (flags) {
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
348 tmsg->flags = 0x409082d4;
13087
a62e694b35e4 [gaim-migrate @ 15449]
Thomas Butter <tbutter>
parents: 13084
diff changeset
349 gensesskey(sesskey, NULL);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
350 memcpy(tmp, sesskey, 0x10);
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
351 }
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
352
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
353 /*tmsg->flags2 = 0x0a280105;
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 11829
diff changeset
354 tmsg->flags3 = 0x0f000000;*/
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13087
diff changeset
355
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
356 tmp = gaim_base64_encode((guchar *)tmsg, msglen);
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
357 g_free(tmsg);
13723
1983a8fc8e72 [gaim-migrate @ 16132]
Mark Doliner <mark@kingant.net>
parents: 13704
diff changeset
358
11375
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
359 return tmp;
7e98b3bf2fdf [gaim-migrate @ 13601]
Thomas Butter <tbutter>
parents:
diff changeset
360 }