libpurple/protocols/mxit/cipher.c

Thu, 03 Apr 2014 03:52:31 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Thu, 03 Apr 2014 03:52:31 +0200
changeset 35677
16b1b8711b89
parent 34148
62a874e41930
child 35678
97cb9646c26f
permissions
-rw-r--r--

Mxit: partially switch to libpurple's AES

28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * MXit Protocol libPurple Plugin
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
4 * -- encryption --
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * Pieter Loubser <libpurple@mxit.com>
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * (C) Copyright 2009 MXit Lifestyle (Pty) Ltd.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * <http://www.mxitlifestyle.com>
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * (at your option) any later version.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * GNU General Public License for more details.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
24 */
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
25
33844
e8edfd4e26ae MXit: Cleanup the #includes (no purple.h) so that it atleast compiles within InstantBird.
Andrew Victor <andrew.victor@mxit.com>
parents: 33713
diff changeset
26 #include "internal.h"
e8edfd4e26ae MXit: Cleanup the #includes (no purple.h) so that it atleast compiles within InstantBird.
Andrew Victor <andrew.victor@mxit.com>
parents: 33713
diff changeset
27 #include "debug.h"
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
28 #include "libpurple/cipher.h"
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
29 #include "ciphers/aescipher.h"
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31 #include "mxit.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 #include "cipher.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 #include "aes.h"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
36 /* encryption */
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 #define INITIAL_KEY "6170383452343567"
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38 #define SECRET_HEADER "<mxit/>"
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
39 #define ENCRYPT_HEADER "<mxitencrypted ver=\"5.2\"/>"
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
40
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
41
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
42 /*------------------------------------------------------------------------
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
43 * Add ISO10126 Padding to the data.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
44 *
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
45 * @param data The data to pad.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
46 */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
47 static void padding_add( GString* data )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
48 {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
49 unsigned int blocks = ( data->len / 16 ) + 1;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
50 unsigned int padding = ( blocks * 16 ) - data->len;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
51
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
52 g_string_set_size( data, blocks * 16 );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
53 data->str[data->len - 1] = padding;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
54 }
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57 /*------------------------------------------------------------------------
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
58 * Remove ISO10126 Padding from the data.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 *
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
60 * @param data The data from which to remove padding.
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
61 */
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
62 static void padding_remove( GString* data )
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63 {
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
64 unsigned int padding;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
65
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
66 if ( data->len == 0 )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
67 return;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
68
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
69 padding = data->str[data->len - 1];
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
70 g_string_truncate( data, data->len - padding );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
71 }
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
72
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
73
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
74 /*------------------------------------------------------------------------
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
75 * Generate the Transport-Layer crypto key.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
76 * (Note: this function is not-thread safe)
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
77 *
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
78 * @param session The MXit Session object
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
79 * @return The transport-layer crypto key.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
80 */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
81 static char* transport_layer_key( struct MXitSession* session )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
82 {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
83 static char key[16 + 1];
34024
9155cf9d26fa Fix MXit plugin compile.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32438
diff changeset
84 const char* password = purple_connection_get_password( session->con );
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
85 int passlen = strlen( password );
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
87 /* initialize with initial key */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
88 g_strlcpy( key, INITIAL_KEY, sizeof( key ) );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
89
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
90 /* client key (8 bytes) */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
91 memcpy( key, session->clientkey, strlen( session->clientkey ) );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
92
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
93 /* add last 8 characters of the PIN (no padding if less characters) */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
94 if ( passlen <= 8 )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
95 memcpy( key + 8, password, passlen );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
96 else
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
97 memcpy( key + 8, password + ( passlen - 8 ), 8 );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
98
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
99 return key;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 /*------------------------------------------------------------------------
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104 * Encrypt the user's cleartext password using the AES 128-bit (ECB)
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
105 * encryption algorithm.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
106 *
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 * @param session The MXit session object
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
108 * @return The encrypted & encoded password. Must be g_free'd when no longer needed.
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 */
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
110 gchar *
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
111 mxit_encrypt_password(struct MXitSession* session)
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
112 {
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
113 guchar key[16];
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
114 size_t clientkey_len, header_len, pass_len, plaintext_len;
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
115 const gchar *plaintext_passwd;
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
116 guchar *plaintext;
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
117 guchar encrypted[64]; /* shouldn't be longer than 17 */
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
118 PurpleCipher *cipher;
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
119 ssize_t encrypted_size;
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
121 purple_debug_info(MXIT_PLUGIN_ID, "mxit_encrypt_password");
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
122
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
123 /* build the AES encryption key */
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
124 g_assert(strlen(INITIAL_KEY) == sizeof(key));
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
125 memcpy(key, INITIAL_KEY, sizeof(key));
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
126 clientkey_len = strlen(session->clientkey);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
127 if (clientkey_len > sizeof(key))
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
128 clientkey_len = sizeof(key);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
129 memcpy(key, session->clientkey, clientkey_len);
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
130
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
131 /* build the secret data to be encrypted: SECRET_HEADER + password */
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
132 plaintext_passwd = purple_connection_get_password(session->con);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
133 g_return_val_if_fail(plaintext_passwd, NULL);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
134 pass_len = strlen(plaintext_passwd);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
135 header_len = strlen(SECRET_HEADER);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
136 /* Trailing NUL, just to be safe. But PKCS#7 seems to be enough. */
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
137 plaintext_len = header_len + pass_len + 1;
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
138 plaintext = g_new0(guchar, plaintext_len);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
139 memcpy(plaintext, SECRET_HEADER, header_len);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
140 memcpy(plaintext + header_len, plaintext_passwd, pass_len);
33713
3c21af28962e MXit: Rather use a GString to store the raw encrypted password.
Andrew Victor <andrew.victor@mxit.com>
parents: 33679
diff changeset
141
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
142 /* encrypt */
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
143 cipher = purple_aes_cipher_new();
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
144 purple_cipher_set_key(cipher, key, sizeof(key));
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
145 purple_cipher_set_batch_mode(cipher, PURPLE_CIPHER_BATCH_MODE_ECB);
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
146 encrypted_size = purple_cipher_encrypt(cipher,
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
147 plaintext, plaintext_len, encrypted, sizeof(encrypted));
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
148 g_return_val_if_fail(encrypted_size > 0, NULL);
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
149
35677
16b1b8711b89 Mxit: partially switch to libpurple's AES
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34148
diff changeset
150 return purple_base64_encode(encrypted, encrypted_size);
28841
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
151 }
6b9568572bcb Initial addition of the MXit protocol plugin, provided by the MXit folks
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
152
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
153
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
154 /*------------------------------------------------------------------------
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
155 * Decrypt a message using transport-layer encryption.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
156 *
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
157 * @param session The MXit session object
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
158 * @param message The encrypted message data (is base64-encoded).
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
159 * @return The decrypted message. Must be g_free'd when no longer needed.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
160 */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
161 char* mxit_decrypt_message( struct MXitSession* session, char* message )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
162 {
33845
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
163 guchar* raw_message;
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
164 gsize raw_len;
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
165 char exkey[512];
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
166 GString* decoded = NULL;
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
167 unsigned int i;
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
168
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
169 /* remove optional header: <mxitencrypted ver="5.2"/> */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
170 if ( strncmp( message, ENCRYPT_HEADER, strlen( ENCRYPT_HEADER ) ) == 0 )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
171 message += strlen( ENCRYPT_HEADER );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
172
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
173 /* base64 decode the message */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
174 raw_message = purple_base64_decode( message, &raw_len );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
175
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
176 /* AES-encrypted data is always blocks of 16 bytes */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
177 if ( ( raw_len == 0 ) || ( raw_len % 16 != 0 ) )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
178 return NULL;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
179
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
180 /* build the AES key */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
181 ExpandKey( (unsigned char*) transport_layer_key( session ), (unsigned char*) exkey );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
182
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
183 /* AES decrypt each block */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
184 decoded = g_string_sized_new( raw_len );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
185 for ( i = 0; i < raw_len; i += 16 ) {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
186 char block[16];
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
187
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
188 Decrypt( (unsigned char*) raw_message + i, (unsigned char*) exkey, (unsigned char*) block );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
189 g_string_append_len( decoded, block, 16 );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
190 }
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
191 g_free( raw_message );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
192
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
193 /* check that the decrypted message starts with header: <mxit/> */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
194 if ( strncmp( decoded->str, SECRET_HEADER, strlen( SECRET_HEADER ) != 0 ) ) {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
195 g_string_free( decoded, TRUE );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
196 return NULL; /* message could not be decrypted */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
197 }
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
198
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
199 /* remove ISO10126 padding */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
200 padding_remove( decoded );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
201
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
202 /* remove encryption header */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
203 g_string_erase( decoded, 0, strlen( SECRET_HEADER ) );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
204
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
205 return g_string_free( decoded, FALSE );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
206 }
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
207
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
208
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
209 /*------------------------------------------------------------------------
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
210 * Encrypt a message using transport-layer encryption.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
211 *
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
212 * @param session The MXit session object
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
213 * @param message The message data.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
214 * @return The encrypted message. Must be g_free'd when no longer needed.
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
215 */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
216 char* mxit_encrypt_message( struct MXitSession* session, char* message )
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
217 {
33845
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
218 GString* raw_message = NULL;
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
219 char exkey[512];
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
220 GString* encoded = NULL;
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
221 gchar* base64;
53109a1846ae MXit: Fix compiler warnings related to "comparison between signed and unsigned integer expressions".
Andrew Victor <andrew.victor@mxit.com>
parents: 33844
diff changeset
222 unsigned int i;
33679
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
223
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
224 purple_debug_info( MXIT_PLUGIN_ID, "encrypt message: '%s'\n", message );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
225
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
226 /* append encryption header to message data */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
227 raw_message = g_string_new( SECRET_HEADER );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
228 g_string_append( raw_message, message );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
229 padding_add( raw_message ); /* add ISO10126 padding */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
230
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
231 /* build the AES key */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
232 ExpandKey( (unsigned char*) transport_layer_key( session ), (unsigned char*) exkey );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
233
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
234 /* AES encrypt each block */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
235 encoded = g_string_sized_new( raw_message->len );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
236 for ( i = 0; i < raw_message->len; i += 16 ) {
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
237 char block[16];
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
238
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
239 Encrypt( (unsigned char*) raw_message->str + i, (unsigned char*) exkey, (unsigned char*) block );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
240 g_string_append_len( encoded, block, 16 );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
241 }
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
242 g_string_free( raw_message, TRUE );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
243
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
244 /* base64 encode the encrypted message */
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
245 base64 = purple_base64_encode( (unsigned char *) encoded->str, encoded->len );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
246 g_string_free( encoded, TRUE );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
247
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
248 purple_debug_info( MXIT_PLUGIN_ID, "encrypted message: '%s'\n", base64 );
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
249
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
250 return base64;
4074275c1007 MXit: Backport the password and transport-layer encryption code from 3.0.0.
Andrew Victor <andrew.victor@mxit.com>
parents: 31958
diff changeset
251 }

mercurial