Fri, 18 Jan 2013 03:51:05 -0500
Move blist loading into purple_core_init.
The comments say we want to move this into purple_blist_init, but that
seems like it would be problematic. We need the UI ops to be set, which
moves blist init after UI init. But stuff needs blist signals to be
registered before UI init, etc., etc. It seemed like a pain to work that
all out. I made purple_blist_boot for purple_core_init to call after the
UI init happened. It could have been called _load, but I didn't want
people to accidentally continue calling it.
| 10684 | 1 | /* |
| 15884 | 2 | * purple |
| 10684 | 3 | * |
| 15884 | 4 | * Purple is the legal property of its developers, whose names are too numerous |
| 10684 | 5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 6 | * source distribution. | |
| 7 | * | |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
8 | * Original des taken from gpg |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
9 | * |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
10 | * des.c - DES and Triple-DES encryption/decryption Algorithm |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
11 | * Copyright (C) 1998 Free Software Foundation, Inc. |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
12 | * |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
13 | * Please see below for more legal information! |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
14 | * |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
15 | * According to the definition of DES in FIPS PUB 46-2 from December 1993. |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
16 | * For a description of triple encryption, see: |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
17 | * Bruce Schneier: Applied Cryptography. Second Edition. |
|
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
18 | * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff. |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
19 | * |
|
11335
8e8d266179bb
[gaim-migrate @ 13548]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11333
diff
changeset
|
20 | * This file is part of GnuPG. |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13760
diff
changeset
|
21 | * |
| 10684 | 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by | |
| 24 | * the Free Software Foundation; either version 2 of the License, or | |
| 25 | * (at your option) any later version. | |
| 26 | * | |
| 27 | * This program is distributed in the hope that it will be useful, | |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 30 | * GNU General Public License for more details. | |
| 31 | * | |
| 32 | * You should have received a copy of the GNU General Public License | |
| 33 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19832
diff
changeset
|
34 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 10684 | 35 | */ |
| 36 | #include "internal.h" | |
| 37 | #include "cipher.h" | |
|
13760
09669e542e2f
[gaim-migrate @ 16169]
Mark Doliner <markdoliner@pidgin.im>
parents:
13699
diff
changeset
|
38 | #include "dbus-maybe.h" |
| 10684 | 39 | #include "debug.h" |
| 40 | #include "signals.h" | |
| 41 | #include "value.h" | |
| 42 | ||
|
11329
5ca3cf4e502e
[gaim-migrate @ 13541]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
11183
diff
changeset
|
43 | /******************************************************************************* |
| 10684 | 44 | * Structs |
| 45 | ******************************************************************************/ | |
| 15884 | 46 | struct _PurpleCipher { |
|
17435
a42f7e095cfd
- Add documentation for the internal CipherContext struct
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17155
diff
changeset
|
47 | gchar *name; /**< Internal name - used for searching */ |
|
a42f7e095cfd
- Add documentation for the internal CipherContext struct
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17155
diff
changeset
|
48 | PurpleCipherOps *ops; /**< Operations supported by this cipher */ |
|
a42f7e095cfd
- Add documentation for the internal CipherContext struct
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17155
diff
changeset
|
49 | guint ref; /**< Reference count */ |
| 10684 | 50 | }; |
| 51 | ||
| 15884 | 52 | struct _PurpleCipherContext { |
|
17435
a42f7e095cfd
- Add documentation for the internal CipherContext struct
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17155
diff
changeset
|
53 | PurpleCipher *cipher; /**< Cipher this context is under */ |
|
a42f7e095cfd
- Add documentation for the internal CipherContext struct
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17155
diff
changeset
|
54 | gpointer data; /**< Internal cipher state data */ |
| 10684 | 55 | }; |
| 56 | ||
| 57 | /****************************************************************************** | |
| 58 | * Globals | |
| 59 | *****************************************************************************/ | |
| 60 | static GList *ciphers = NULL; | |
| 61 | ||
| 62 | /****************************************************************************** | |
| 15884 | 63 | * PurpleCipher API |
| 10684 | 64 | *****************************************************************************/ |
| 65 | const gchar * | |
| 15884 | 66 | purple_cipher_get_name(PurpleCipher *cipher) { |
| 10684 | 67 | g_return_val_if_fail(cipher, NULL); |
| 68 | ||
| 69 | return cipher->name; | |
| 70 | } | |
| 71 | ||
| 72 | guint | |
| 15884 | 73 | purple_cipher_get_capabilities(PurpleCipher *cipher) { |
| 74 | PurpleCipherOps *ops = NULL; | |
| 10684 | 75 | guint caps = 0; |
| 76 | ||
| 77 | g_return_val_if_fail(cipher, 0); | |
| 78 | ||
| 79 | ops = cipher->ops; | |
| 80 | g_return_val_if_fail(ops, 0); | |
| 81 | ||
| 82 | if(ops->set_option) | |
| 15884 | 83 | caps |= PURPLE_CIPHER_CAPS_SET_OPT; |
| 10684 | 84 | if(ops->get_option) |
| 15884 | 85 | caps |= PURPLE_CIPHER_CAPS_GET_OPT; |
| 10684 | 86 | if(ops->init) |
| 15884 | 87 | caps |= PURPLE_CIPHER_CAPS_INIT; |
| 10684 | 88 | if(ops->reset) |
| 15884 | 89 | caps |= PURPLE_CIPHER_CAPS_RESET; |
| 10684 | 90 | if(ops->uninit) |
| 15884 | 91 | caps |= PURPLE_CIPHER_CAPS_UNINIT; |
| 10684 | 92 | if(ops->set_iv) |
| 15884 | 93 | caps |= PURPLE_CIPHER_CAPS_SET_IV; |
| 10684 | 94 | if(ops->append) |
| 15884 | 95 | caps |= PURPLE_CIPHER_CAPS_APPEND; |
| 10684 | 96 | if(ops->digest) |
| 15884 | 97 | caps |= PURPLE_CIPHER_CAPS_DIGEST; |
| 10684 | 98 | if(ops->encrypt) |
| 15884 | 99 | caps |= PURPLE_CIPHER_CAPS_ENCRYPT; |
| 10684 | 100 | if(ops->decrypt) |
| 15884 | 101 | caps |= PURPLE_CIPHER_CAPS_DECRYPT; |
| 10684 | 102 | if(ops->set_salt) |
| 15884 | 103 | caps |= PURPLE_CIPHER_CAPS_SET_SALT; |
| 10684 | 104 | if(ops->get_salt_size) |
| 15884 | 105 | caps |= PURPLE_CIPHER_CAPS_GET_SALT_SIZE; |
| 10684 | 106 | if(ops->set_key) |
| 15884 | 107 | caps |= PURPLE_CIPHER_CAPS_SET_KEY; |
| 10684 | 108 | if(ops->get_key_size) |
| 15884 | 109 | caps |= PURPLE_CIPHER_CAPS_GET_KEY_SIZE; |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
110 | if(ops->set_batch_mode) |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
111 | caps |= PURPLE_CIPHER_CAPS_SET_BATCH_MODE; |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
112 | if(ops->get_batch_mode) |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
113 | caps |= PURPLE_CIPHER_CAPS_GET_BATCH_MODE; |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
114 | if(ops->get_block_size) |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
115 | caps |= PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE; |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
116 | if(ops->set_key_with_len) |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
117 | caps |= PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN; |
| 10684 | 118 | |
| 119 | return caps; | |
| 120 | } | |
| 121 | ||
| 10687 | 122 | gboolean |
| 15884 | 123 | purple_cipher_digest_region(const gchar *name, const guchar *data, |
| 10687 | 124 | size_t data_len, size_t in_len, |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11143
diff
changeset
|
125 | guchar digest[], size_t *out_len) |
| 10684 | 126 | { |
| 15884 | 127 | PurpleCipher *cipher; |
| 128 | PurpleCipherContext *context; | |
| 10687 | 129 | gboolean ret = FALSE; |
| 10684 | 130 | |
| 10687 | 131 | g_return_val_if_fail(name, FALSE); |
| 132 | g_return_val_if_fail(data, FALSE); | |
| 10684 | 133 | |
| 15884 | 134 | cipher = purple_ciphers_find_cipher(name); |
| 10684 | 135 | |
| 10687 | 136 | g_return_val_if_fail(cipher, FALSE); |
| 10684 | 137 | |
| 138 | if(!cipher->ops->append || !cipher->ops->digest) { | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
139 | purple_debug_warning("cipher", "purple_cipher_region failed: " |
| 10684 | 140 | "the %s cipher does not support appending and or " |
| 141 | "digesting.", cipher->name); | |
| 10687 | 142 | return FALSE; |
| 10684 | 143 | } |
| 144 | ||
| 15884 | 145 | context = purple_cipher_context_new(cipher, NULL); |
| 146 | purple_cipher_context_append(context, data, data_len); | |
| 147 | ret = purple_cipher_context_digest(context, in_len, digest, out_len); | |
| 148 | purple_cipher_context_destroy(context); | |
| 10687 | 149 | |
| 150 | return ret; | |
| 10684 | 151 | } |
| 152 | ||
| 153 | /****************************************************************************** | |
| 15884 | 154 | * PurpleCiphers API |
| 10684 | 155 | *****************************************************************************/ |
| 15884 | 156 | PurpleCipher * |
| 157 | purple_ciphers_find_cipher(const gchar *name) { | |
| 158 | PurpleCipher *cipher; | |
| 10684 | 159 | GList *l; |
| 160 | ||
| 161 | g_return_val_if_fail(name, NULL); | |
| 162 | ||
| 163 | for(l = ciphers; l; l = l->next) { | |
| 15884 | 164 | cipher = PURPLE_CIPHER(l->data); |
| 10684 | 165 | |
| 166 | if(!g_ascii_strcasecmp(cipher->name, name)) | |
| 167 | return cipher; | |
| 168 | } | |
| 169 | ||
| 170 | return NULL; | |
| 171 | } | |
| 172 | ||
| 15884 | 173 | PurpleCipher * |
| 174 | purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops) { | |
| 175 | PurpleCipher *cipher = NULL; | |
| 10684 | 176 | |
| 177 | g_return_val_if_fail(name, NULL); | |
| 178 | g_return_val_if_fail(ops, NULL); | |
| 15884 | 179 | g_return_val_if_fail(!purple_ciphers_find_cipher(name), NULL); |
| 10684 | 180 | |
| 15884 | 181 | cipher = g_new0(PurpleCipher, 1); |
| 182 | PURPLE_DBUS_REGISTER_POINTER(cipher, PurpleCipher); | |
| 10684 | 183 | |
| 184 | cipher->name = g_strdup(name); | |
| 185 | cipher->ops = ops; | |
| 186 | ||
| 187 | ciphers = g_list_append(ciphers, cipher); | |
| 188 | ||
| 15884 | 189 | purple_signal_emit(purple_ciphers_get_handle(), "cipher-added", cipher); |
| 10684 | 190 | |
| 191 | return cipher; | |
| 192 | } | |
| 193 | ||
| 194 | gboolean | |
| 15884 | 195 | purple_ciphers_unregister_cipher(PurpleCipher *cipher) { |
| 10684 | 196 | g_return_val_if_fail(cipher, FALSE); |
| 197 | g_return_val_if_fail(cipher->ref == 0, FALSE); | |
| 198 | ||
| 15884 | 199 | purple_signal_emit(purple_ciphers_get_handle(), "cipher-removed", cipher); |
| 10684 | 200 | |
| 201 | ciphers = g_list_remove(ciphers, cipher); | |
| 202 | ||
| 203 | g_free(cipher->name); | |
|
13760
09669e542e2f
[gaim-migrate @ 16169]
Mark Doliner <markdoliner@pidgin.im>
parents:
13699
diff
changeset
|
204 | |
| 15884 | 205 | PURPLE_DBUS_UNREGISTER_POINTER(cipher); |
| 10684 | 206 | g_free(cipher); |
| 207 | ||
| 208 | return TRUE; | |
| 209 | } | |
| 210 | ||
| 211 | GList * | |
| 15884 | 212 | purple_ciphers_get_ciphers() { |
| 10684 | 213 | return ciphers; |
| 214 | } | |
| 215 | ||
| 216 | /****************************************************************************** | |
| 15884 | 217 | * PurpleCipher Subsystem API |
| 10684 | 218 | *****************************************************************************/ |
| 219 | gpointer | |
| 15884 | 220 | purple_ciphers_get_handle() { |
| 10684 | 221 | static gint handle; |
| 222 | ||
| 223 | return &handle; | |
| 224 | } | |
| 225 | ||
| 31431 | 226 | /* These are implemented in the purple-ciphers sublibrary built in the ciphers |
|
31426
290d182e7bf9
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
31425
diff
changeset
|
227 | * directory. We could put a header file in there, but it's less hassle for |
|
290d182e7bf9
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
31425
diff
changeset
|
228 | * the developer to just add it here since they have to register it here as |
|
290d182e7bf9
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
31425
diff
changeset
|
229 | * well. |
|
290d182e7bf9
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
31425
diff
changeset
|
230 | */ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
31426
diff
changeset
|
231 | PurpleCipherOps *purple_des_cipher_get_ops(); |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
31426
diff
changeset
|
232 | PurpleCipherOps *purple_des3_cipher_get_ops(); |
|
31423
8483c092dbc4
Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
31421
diff
changeset
|
233 | PurpleCipherOps *purple_hmac_cipher_get_ops(); |
|
31421
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
31407
diff
changeset
|
234 | PurpleCipherOps *purple_md4_cipher_get_ops(); |
|
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
31407
diff
changeset
|
235 | PurpleCipherOps *purple_md5_cipher_get_ops(); |
|
31425
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
31424
diff
changeset
|
236 | PurpleCipherOps *purple_rc4_cipher_get_ops(); |
| 31424 | 237 | PurpleCipherOps *purple_sha1_cipher_get_ops(); |
|
31426
290d182e7bf9
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
31425
diff
changeset
|
238 | PurpleCipherOps *purple_sha256_cipher_get_ops(); |
|
31421
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
31407
diff
changeset
|
239 | |
| 10684 | 240 | void |
| 15884 | 241 | purple_ciphers_init() { |
| 10684 | 242 | gpointer handle; |
| 243 | ||
| 15884 | 244 | handle = purple_ciphers_get_handle(); |
| 10684 | 245 | |
| 15884 | 246 | purple_signal_register(handle, "cipher-added", |
| 247 | purple_marshal_VOID__POINTER, NULL, 1, | |
| 248 | purple_value_new(PURPLE_TYPE_SUBTYPE, | |
| 249 | PURPLE_SUBTYPE_CIPHER)); | |
| 250 | purple_signal_register(handle, "cipher-removed", | |
| 251 | purple_marshal_VOID__POINTER, NULL, 1, | |
| 252 | purple_value_new(PURPLE_TYPE_SUBTYPE, | |
| 253 | PURPLE_SUBTYPE_CIPHER)); | |
| 10684 | 254 | |
|
31421
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
31407
diff
changeset
|
255 | purple_ciphers_register_cipher("md5", purple_md5_cipher_get_ops()); |
| 31424 | 256 | purple_ciphers_register_cipher("sha1", purple_sha1_cipher_get_ops()); |
|
31426
290d182e7bf9
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
31425
diff
changeset
|
257 | purple_ciphers_register_cipher("sha256", purple_sha256_cipher_get_ops()); |
|
31421
713fb035d563
Created a new branch to break the ciphers out to their own files. Also I've now exposed purple_g_checksum_* if we're on glib >= 2.16.0
Gary Kramlich <grim@reaperworld.com>
parents:
31407
diff
changeset
|
258 | purple_ciphers_register_cipher("md4", purple_md4_cipher_get_ops()); |
|
31423
8483c092dbc4
Broke out the hmac cipher to it's own file. Removed already transitioned info in the fileheader of cipher.c
Gary Kramlich <grim@reaperworld.com>
parents:
31421
diff
changeset
|
259 | purple_ciphers_register_cipher("hmac", purple_hmac_cipher_get_ops()); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
31426
diff
changeset
|
260 | purple_ciphers_register_cipher("des", purple_des_cipher_get_ops()); |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
31426
diff
changeset
|
261 | purple_ciphers_register_cipher("des3", purple_des3_cipher_get_ops()); |
|
31425
e8113737ec1a
Moved rc4 to the ciphers sublibrary
Gary Kramlich <grim@reaperworld.com>
parents:
31424
diff
changeset
|
262 | purple_ciphers_register_cipher("rc4", purple_rc4_cipher_get_ops()); |
| 10684 | 263 | } |
| 264 | ||
| 265 | void | |
| 15884 | 266 | purple_ciphers_uninit() { |
| 267 | PurpleCipher *cipher; | |
| 10684 | 268 | GList *l, *ll; |
| 269 | ||
| 270 | for(l = ciphers; l; l = ll) { | |
| 271 | ll = l->next; | |
| 272 | ||
| 15884 | 273 | cipher = PURPLE_CIPHER(l->data); |
| 274 | purple_ciphers_unregister_cipher(cipher); | |
| 10684 | 275 | } |
| 276 | ||
| 277 | g_list_free(ciphers); | |
| 278 | ||
| 15884 | 279 | purple_signals_unregister_by_instance(purple_ciphers_get_handle()); |
| 10684 | 280 | } |
|
31426
290d182e7bf9
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
31425
diff
changeset
|
281 | |
| 10684 | 282 | /****************************************************************************** |
| 15884 | 283 | * PurpleCipherContext API |
| 10684 | 284 | *****************************************************************************/ |
| 285 | void | |
| 15884 | 286 | purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, |
| 10684 | 287 | gpointer value) |
| 288 | { | |
| 15884 | 289 | PurpleCipher *cipher = NULL; |
| 10684 | 290 | |
| 291 | g_return_if_fail(context); | |
| 292 | g_return_if_fail(name); | |
| 293 | ||
| 294 | cipher = context->cipher; | |
| 295 | g_return_if_fail(cipher); | |
| 296 | ||
| 297 | if(cipher->ops && cipher->ops->set_option) | |
| 298 | cipher->ops->set_option(context, name, value); | |
| 299 | else | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
300 | purple_debug_warning("cipher", "the %s cipher does not support the " |
| 10684 | 301 | "set_option operation\n", cipher->name); |
| 302 | } | |
| 303 | ||
| 304 | gpointer | |
| 15884 | 305 | purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name) { |
| 306 | PurpleCipher *cipher = NULL; | |
| 10684 | 307 | |
| 308 | g_return_val_if_fail(context, NULL); | |
| 309 | g_return_val_if_fail(name, NULL); | |
| 310 | ||
| 311 | cipher = context->cipher; | |
| 312 | g_return_val_if_fail(cipher, NULL); | |
| 313 | ||
| 314 | if(cipher->ops && cipher->ops->get_option) | |
| 315 | return cipher->ops->get_option(context, name); | |
| 316 | else { | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
317 | purple_debug_warning("cipher", "the %s cipher does not support the " |
| 10684 | 318 | "get_option operation\n", cipher->name); |
| 319 | ||
| 320 | return NULL; | |
| 321 | } | |
| 322 | } | |
| 323 | ||
| 15884 | 324 | PurpleCipherContext * |
| 325 | purple_cipher_context_new(PurpleCipher *cipher, void *extra) { | |
| 326 | PurpleCipherContext *context = NULL; | |
| 10684 | 327 | |
| 328 | g_return_val_if_fail(cipher, NULL); | |
| 329 | ||
| 330 | cipher->ref++; | |
| 331 | ||
| 15884 | 332 | context = g_new0(PurpleCipherContext, 1); |
| 10684 | 333 | context->cipher = cipher; |
| 334 | ||
| 335 | if(cipher->ops->init) | |
| 336 | cipher->ops->init(context, extra); | |
| 337 | ||
| 338 | return context; | |
| 339 | } | |
| 340 | ||
| 15884 | 341 | PurpleCipherContext * |
| 342 | purple_cipher_context_new_by_name(const gchar *name, void *extra) { | |
| 343 | PurpleCipher *cipher; | |
| 10684 | 344 | |
| 345 | g_return_val_if_fail(name, NULL); | |
| 346 | ||
| 15884 | 347 | cipher = purple_ciphers_find_cipher(name); |
| 10684 | 348 | |
| 349 | g_return_val_if_fail(cipher, NULL); | |
| 350 | ||
| 15884 | 351 | return purple_cipher_context_new(cipher, extra); |
| 10684 | 352 | } |
| 353 | ||
| 354 | void | |
| 15884 | 355 | purple_cipher_context_reset(PurpleCipherContext *context, void *extra) { |
| 356 | PurpleCipher *cipher = NULL; | |
| 10684 | 357 | |
| 358 | g_return_if_fail(context); | |
| 359 | ||
| 360 | cipher = context->cipher; | |
| 361 | g_return_if_fail(cipher); | |
| 362 | ||
| 363 | if(cipher->ops && cipher->ops->reset) | |
| 364 | context->cipher->ops->reset(context, extra); | |
| 365 | } | |
| 366 | ||
| 367 | void | |
| 15884 | 368 | purple_cipher_context_destroy(PurpleCipherContext *context) { |
| 369 | PurpleCipher *cipher = NULL; | |
| 10684 | 370 | |
| 371 | g_return_if_fail(context); | |
| 372 | ||
| 373 | cipher = context->cipher; | |
| 374 | g_return_if_fail(cipher); | |
| 375 | ||
| 376 | cipher->ref--; | |
| 377 | ||
| 378 | if(cipher->ops && cipher->ops->uninit) | |
| 379 | cipher->ops->uninit(context); | |
| 380 | ||
|
31407
8c850977cb42
Fix a potential information leak in cipher.c.
Julia Lawall <julia@diku.dk>
parents:
28762
diff
changeset
|
381 | memset(context, 0, sizeof(*context)); |
| 10684 | 382 | g_free(context); |
| 383 | context = NULL; | |
| 384 | } | |
| 385 | ||
| 386 | void | |
| 15884 | 387 | purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len) |
| 10684 | 388 | { |
| 15884 | 389 | PurpleCipher *cipher = NULL; |
| 10684 | 390 | |
| 391 | g_return_if_fail(context); | |
| 392 | g_return_if_fail(iv); | |
| 393 | ||
| 394 | cipher = context->cipher; | |
| 395 | g_return_if_fail(cipher); | |
| 396 | ||
| 397 | if(cipher->ops && cipher->ops->set_iv) | |
| 398 | cipher->ops->set_iv(context, iv, len); | |
| 399 | else | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
400 | purple_debug_warning("cipher", "the %s cipher does not support the set" |
| 10684 | 401 | "initialization vector operation\n", cipher->name); |
| 402 | } | |
| 403 | ||
| 404 | void | |
| 15884 | 405 | purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, |
| 10684 | 406 | size_t len) |
| 407 | { | |
| 15884 | 408 | PurpleCipher *cipher = NULL; |
| 10684 | 409 | |
| 410 | g_return_if_fail(context); | |
| 411 | ||
| 412 | cipher = context->cipher; | |
| 413 | g_return_if_fail(cipher); | |
| 414 | ||
| 415 | if(cipher->ops && cipher->ops->append) | |
| 416 | cipher->ops->append(context, data, len); | |
| 417 | else | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
418 | purple_debug_warning("cipher", "the %s cipher does not support the append " |
| 10684 | 419 | "operation\n", cipher->name); |
| 420 | } | |
| 421 | ||
| 422 | gboolean | |
| 15884 | 423 | purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11143
diff
changeset
|
424 | guchar digest[], size_t *out_len) |
| 10684 | 425 | { |
| 15884 | 426 | PurpleCipher *cipher = NULL; |
| 10684 | 427 | |
| 428 | g_return_val_if_fail(context, FALSE); | |
| 429 | ||
| 430 | cipher = context->cipher; | |
| 431 | ||
| 432 | if(cipher->ops && cipher->ops->digest) | |
| 10687 | 433 | return cipher->ops->digest(context, in_len, digest, out_len); |
| 10684 | 434 | else { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
435 | purple_debug_warning("cipher", "the %s cipher does not support the digest " |
| 10684 | 436 | "operation\n", cipher->name); |
| 437 | return FALSE; | |
| 438 | } | |
| 439 | } | |
| 440 | ||
| 441 | gboolean | |
| 15884 | 442 | purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, |
| 10687 | 443 | gchar digest_s[], size_t *out_len) |
| 10684 | 444 | { |
| 10687 | 445 | /* 8k is a bit excessive, will tweak later. */ |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11143
diff
changeset
|
446 | guchar digest[BUF_LEN * 4]; |
| 10684 | 447 | gint n = 0; |
| 448 | size_t dlen = 0; | |
| 449 | ||
| 450 | g_return_val_if_fail(context, FALSE); | |
| 451 | g_return_val_if_fail(digest_s, FALSE); | |
| 452 | ||
| 15884 | 453 | if(!purple_cipher_context_digest(context, sizeof(digest), digest, &dlen)) |
| 10684 | 454 | return FALSE; |
| 455 | ||
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
456 | /* in_len must be greater than dlen * 2 so we have room for the NUL. */ |
|
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
457 | if(in_len <= dlen * 2) |
| 10687 | 458 | return FALSE; |
| 10684 | 459 | |
| 460 | for(n = 0; n < dlen; n++) | |
| 461 | sprintf(digest_s + (n * 2), "%02x", digest[n]); | |
| 462 | ||
| 463 | digest_s[n * 2] = '\0'; | |
| 464 | ||
| 10687 | 465 | if(out_len) |
| 466 | *out_len = dlen * 2; | |
| 467 | ||
| 10684 | 468 | return TRUE; |
| 469 | } | |
| 470 | ||
| 471 | gint | |
| 15884 | 472 | purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11143
diff
changeset
|
473 | size_t len, guchar output[], size_t *outlen) |
| 10684 | 474 | { |
| 15884 | 475 | PurpleCipher *cipher = NULL; |
| 10684 | 476 | |
| 477 | g_return_val_if_fail(context, -1); | |
| 478 | ||
| 479 | cipher = context->cipher; | |
| 480 | g_return_val_if_fail(cipher, -1); | |
| 481 | ||
| 482 | if(cipher->ops && cipher->ops->encrypt) | |
| 483 | return cipher->ops->encrypt(context, data, len, output, outlen); | |
| 484 | else { | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
485 | purple_debug_warning("cipher", "the %s cipher does not support the encrypt" |
| 10684 | 486 | "operation\n", cipher->name); |
| 487 | ||
| 488 | if(outlen) | |
| 489 | *outlen = -1; | |
| 490 | ||
| 491 | return -1; | |
| 492 | } | |
| 493 | } | |
| 494 | ||
| 495 | gint | |
| 15884 | 496 | purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], |
|
11183
be87fe695c93
[gaim-migrate @ 13295]
Mark Doliner <markdoliner@pidgin.im>
parents:
11143
diff
changeset
|
497 | size_t len, guchar output[], size_t *outlen) |
| 10684 | 498 | { |
| 15884 | 499 | PurpleCipher *cipher = NULL; |
| 10684 | 500 | |
| 501 | g_return_val_if_fail(context, -1); | |
| 502 | ||
| 503 | cipher = context->cipher; | |
| 504 | g_return_val_if_fail(cipher, -1); | |
| 505 | ||
| 506 | if(cipher->ops && cipher->ops->decrypt) | |
| 507 | return cipher->ops->decrypt(context, data, len, output, outlen); | |
| 508 | else { | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
509 | purple_debug_warning("cipher", "the %s cipher does not support the decrypt" |
| 10684 | 510 | "operation\n", cipher->name); |
| 511 | ||
| 512 | if(outlen) | |
| 513 | *outlen = -1; | |
| 514 | ||
| 515 | return -1; | |
| 516 | } | |
| 517 | } | |
| 518 | ||
| 519 | void | |
| 15884 | 520 | purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt) { |
| 521 | PurpleCipher *cipher = NULL; | |
| 10684 | 522 | |
| 523 | g_return_if_fail(context); | |
| 524 | ||
| 525 | cipher = context->cipher; | |
| 526 | g_return_if_fail(cipher); | |
| 527 | ||
| 528 | if(cipher->ops && cipher->ops->set_salt) | |
| 529 | cipher->ops->set_salt(context, salt); | |
| 530 | else | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
531 | purple_debug_warning("cipher", "the %s cipher does not support the " |
| 10684 | 532 | "set_salt operation\n", cipher->name); |
| 533 | } | |
| 534 | ||
| 535 | size_t | |
| 15884 | 536 | purple_cipher_context_get_salt_size(PurpleCipherContext *context) { |
| 537 | PurpleCipher *cipher = NULL; | |
| 10684 | 538 | |
| 539 | g_return_val_if_fail(context, -1); | |
| 540 | ||
| 541 | cipher = context->cipher; | |
| 542 | g_return_val_if_fail(cipher, -1); | |
| 543 | ||
| 544 | if(cipher->ops && cipher->ops->get_salt_size) | |
| 545 | return cipher->ops->get_salt_size(context); | |
| 546 | else { | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
547 | purple_debug_warning("cipher", "the %s cipher does not support the " |
| 10684 | 548 | "get_salt_size operation\n", cipher->name); |
| 549 | ||
| 550 | return -1; | |
| 551 | } | |
| 552 | } | |
| 553 | ||
| 554 | void | |
| 15884 | 555 | purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key) { |
| 556 | PurpleCipher *cipher = NULL; | |
| 10684 | 557 | |
| 558 | g_return_if_fail(context); | |
| 559 | ||
| 560 | cipher = context->cipher; | |
| 561 | g_return_if_fail(cipher); | |
| 562 | ||
| 563 | if(cipher->ops && cipher->ops->set_key) | |
| 564 | cipher->ops->set_key(context, key); | |
| 565 | else | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
566 | purple_debug_warning("cipher", "the %s cipher does not support the " |
| 10684 | 567 | "set_key operation\n", cipher->name); |
| 568 | } | |
| 569 | ||
| 570 | size_t | |
| 15884 | 571 | purple_cipher_context_get_key_size(PurpleCipherContext *context) { |
| 572 | PurpleCipher *cipher = NULL; | |
| 10684 | 573 | |
| 574 | g_return_val_if_fail(context, -1); | |
| 575 | ||
| 576 | cipher = context->cipher; | |
| 577 | g_return_val_if_fail(cipher, -1); | |
| 578 | ||
| 579 | if(cipher->ops && cipher->ops->get_key_size) | |
| 580 | return cipher->ops->get_key_size(context); | |
| 581 | else { | |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
582 | purple_debug_warning("cipher", "the %s cipher does not support the " |
| 10684 | 583 | "get_key_size operation\n", cipher->name); |
| 584 | ||
| 585 | return -1; | |
| 586 | } | |
| 587 | } | |
| 588 | ||
| 589 | void | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
590 | purple_cipher_context_set_batch_mode(PurpleCipherContext *context, |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
591 | PurpleCipherBatchMode mode) |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
592 | { |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
593 | PurpleCipher *cipher = NULL; |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
594 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
595 | g_return_if_fail(context); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
596 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
597 | cipher = context->cipher; |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
598 | g_return_if_fail(cipher); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
599 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
600 | if(cipher->ops && cipher->ops->set_batch_mode) |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
601 | cipher->ops->set_batch_mode(context, mode); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
602 | else |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
603 | purple_debug_warning("cipher", "The %s cipher does not support the " |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
604 | "set_batch_mode operation\n", cipher->name); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
605 | } |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
606 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
607 | PurpleCipherBatchMode |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
608 | purple_cipher_context_get_batch_mode(PurpleCipherContext *context) |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
609 | { |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
610 | PurpleCipher *cipher = NULL; |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
611 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
612 | g_return_val_if_fail(context, -1); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
613 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
614 | cipher = context->cipher; |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
615 | g_return_val_if_fail(cipher, -1); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
616 | |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
617 | if(cipher->ops && cipher->ops->get_batch_mode) |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
618 | return cipher->ops->get_batch_mode(context); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
619 | else { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
620 | purple_debug_warning("cipher", "The %s cipher does not support the " |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
621 | "get_batch_mode operation\n", cipher->name); |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
622 | return -1; |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
623 | } |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
624 | } |
|
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
625 | |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
626 | size_t |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
627 | purple_cipher_context_get_block_size(PurpleCipherContext *context) |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
628 | { |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
629 | PurpleCipher *cipher = NULL; |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
630 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
631 | g_return_val_if_fail(context, -1); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
632 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
633 | cipher = context->cipher; |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
634 | g_return_val_if_fail(cipher, -1); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
635 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
636 | if(cipher->ops && cipher->ops->get_block_size) |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
637 | return cipher->ops->get_block_size(context); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
638 | else { |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
639 | purple_debug_warning("cipher", "The %s cipher does not support the " |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
640 | "get_block_size operation\n", cipher->name); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
641 | return -1; |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
642 | } |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
643 | } |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
644 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
645 | void |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
646 | purple_cipher_context_set_key_with_len(PurpleCipherContext *context, |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
647 | const guchar *key, size_t len) |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
648 | { |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
649 | PurpleCipher *cipher = NULL; |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
650 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
651 | g_return_if_fail(context); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
652 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
653 | cipher = context->cipher; |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
654 | g_return_if_fail(cipher); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
655 | |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
656 | if(cipher->ops && cipher->ops->set_key_with_len) |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
657 | cipher->ops->set_key_with_len(context, key, len); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
658 | else |
|
27497
2dc5a0e0c4c2
Increase the logging level of some debugging messages that seemed to be a
Mauro Brasil <mauro.brasil@tqi.com.br>
parents:
27383
diff
changeset
|
659 | purple_debug_warning("cipher", "The %s cipher does not support the " |
|
22025
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
660 | "set_key_with_len operation\n", cipher->name); |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
661 | } |
|
23756775175d
HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22024
diff
changeset
|
662 | |
|
22024
3fd5e4fff1be
Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
21091
diff
changeset
|
663 | void |
| 15884 | 664 | purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data) { |
| 10684 | 665 | g_return_if_fail(context); |
| 666 | ||
| 667 | context->data = data; | |
| 668 | } | |
| 669 | ||
| 670 | gpointer | |
| 15884 | 671 | purple_cipher_context_get_data(PurpleCipherContext *context) { |
| 10684 | 672 | g_return_val_if_fail(context, NULL); |
| 673 | ||
| 674 | return context->data; | |
| 675 | } | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
676 | |
| 15884 | 677 | gchar *purple_cipher_http_digest_calculate_session_key( |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
678 | const gchar *algorithm, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
679 | const gchar *username, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
680 | const gchar *realm, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
681 | const gchar *password, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
682 | const gchar *nonce, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
683 | const gchar *client_nonce) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
684 | { |
| 15884 | 685 | PurpleCipher *cipher; |
| 686 | PurpleCipherContext *context; | |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
687 | gchar hash[33]; /* We only support MD5. */ |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
688 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
689 | g_return_val_if_fail(username != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
690 | g_return_val_if_fail(realm != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
691 | g_return_val_if_fail(password != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
692 | g_return_val_if_fail(nonce != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
693 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
694 | /* Check for a supported algorithm. */ |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
695 | g_return_val_if_fail(algorithm == NULL || |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
696 | *algorithm == '\0' || |
|
17155
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
697 | g_ascii_strcasecmp(algorithm, "MD5") || |
|
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
698 | g_ascii_strcasecmp(algorithm, "MD5-sess"), NULL); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
699 | |
| 15884 | 700 | cipher = purple_ciphers_find_cipher("md5"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
701 | g_return_val_if_fail(cipher != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
702 | |
| 15884 | 703 | context = purple_cipher_context_new(cipher, NULL); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
704 | |
| 15884 | 705 | purple_cipher_context_append(context, (guchar *)username, strlen(username)); |
| 706 | purple_cipher_context_append(context, (guchar *)":", 1); | |
| 707 | purple_cipher_context_append(context, (guchar *)realm, strlen(realm)); | |
| 708 | purple_cipher_context_append(context, (guchar *)":", 1); | |
| 709 | purple_cipher_context_append(context, (guchar *)password, strlen(password)); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
710 | |
|
17155
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
711 | if (algorithm != NULL && !g_ascii_strcasecmp(algorithm, "MD5-sess")) |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
712 | { |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
713 | guchar digest[16]; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
714 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
715 | if (client_nonce == NULL) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
716 | { |
| 15884 | 717 | purple_cipher_context_destroy(context); |
|
19832
84b69b21672b
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17435
diff
changeset
|
718 | purple_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation.\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
719 | return NULL; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
720 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
721 | |
| 15884 | 722 | purple_cipher_context_digest(context, sizeof(digest), digest, NULL); |
| 723 | purple_cipher_context_destroy(context); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
724 | |
| 15884 | 725 | context = purple_cipher_context_new(cipher, NULL); |
| 726 | purple_cipher_context_append(context, digest, sizeof(digest)); | |
| 727 | purple_cipher_context_append(context, (guchar *)":", 1); | |
| 728 | purple_cipher_context_append(context, (guchar *)nonce, strlen(nonce)); | |
| 729 | purple_cipher_context_append(context, (guchar *)":", 1); | |
| 730 | purple_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce)); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
731 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
732 | |
| 15884 | 733 | purple_cipher_context_digest_to_str(context, sizeof(hash), hash, NULL); |
| 734 | purple_cipher_context_destroy(context); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
735 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
736 | return g_strdup(hash); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
737 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
738 | |
| 15884 | 739 | gchar *purple_cipher_http_digest_calculate_response( |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
740 | const gchar *algorithm, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
741 | const gchar *method, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
742 | const gchar *digest_uri, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
743 | const gchar *qop, |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
744 | const gchar *entity, |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
745 | const gchar *nonce, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
746 | const gchar *nonce_count, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
747 | const gchar *client_nonce, |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
748 | const gchar *session_key) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
749 | { |
| 15884 | 750 | PurpleCipher *cipher; |
| 751 | PurpleCipherContext *context; | |
|
12388
3a25d96abdaf
[gaim-migrate @ 14694]
Richard Laager <rlaager@pidgin.im>
parents:
12382
diff
changeset
|
752 | static gchar hash2[33]; /* We only support MD5. */ |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
753 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
754 | g_return_val_if_fail(method != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
755 | g_return_val_if_fail(digest_uri != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
756 | g_return_val_if_fail(nonce != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
757 | g_return_val_if_fail(session_key != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
758 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
759 | /* Check for a supported algorithm. */ |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
760 | g_return_val_if_fail(algorithm == NULL || |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
761 | *algorithm == '\0' || |
|
17155
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
762 | g_ascii_strcasecmp(algorithm, "MD5") || |
|
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
763 | g_ascii_strcasecmp(algorithm, "MD5-sess"), NULL); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
764 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
765 | /* Check for a supported "quality of protection". */ |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
766 | g_return_val_if_fail(qop == NULL || |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
767 | *qop == '\0' || |
|
17155
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
768 | g_ascii_strcasecmp(qop, "auth") || |
|
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
769 | g_ascii_strcasecmp(qop, "auth-int"), NULL); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
770 | |
| 15884 | 771 | cipher = purple_ciphers_find_cipher("md5"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
772 | g_return_val_if_fail(cipher != NULL, NULL); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
773 | |
| 15884 | 774 | context = purple_cipher_context_new(cipher, NULL); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
775 | |
| 15884 | 776 | purple_cipher_context_append(context, (guchar *)method, strlen(method)); |
| 777 | purple_cipher_context_append(context, (guchar *)":", 1); | |
| 778 | purple_cipher_context_append(context, (guchar *)digest_uri, strlen(digest_uri)); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
779 | |
|
17155
143ff2796376
Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents:
17065
diff
changeset
|
780 | if (qop != NULL && !g_ascii_strcasecmp(qop, "auth-int")) |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
781 | { |
| 15884 | 782 | PurpleCipherContext *context2; |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
783 | gchar entity_hash[33]; |
|
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
784 | |
|
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
785 | if (entity == NULL) |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
786 | { |
| 15884 | 787 | purple_cipher_context_destroy(context); |
|
19832
84b69b21672b
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17435
diff
changeset
|
788 | purple_debug_error("cipher", "Required entity missing for auth-int digest calculation.\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
789 | return NULL; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
790 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
791 | |
| 15884 | 792 | context2 = purple_cipher_context_new(cipher, NULL); |
| 793 | purple_cipher_context_append(context2, (guchar *)entity, strlen(entity)); | |
| 794 | purple_cipher_context_digest_to_str(context2, sizeof(entity_hash), entity_hash, NULL); | |
| 795 | purple_cipher_context_destroy(context2); | |
|
12389
7196ba664097
[gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents:
12388
diff
changeset
|
796 | |
| 15884 | 797 | purple_cipher_context_append(context, (guchar *)":", 1); |
| 798 | purple_cipher_context_append(context, (guchar *)entity_hash, strlen(entity_hash)); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
799 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
800 | |
| 15884 | 801 | purple_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL); |
| 802 | purple_cipher_context_destroy(context); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
803 | |
| 15884 | 804 | context = purple_cipher_context_new(cipher, NULL); |
| 805 | purple_cipher_context_append(context, (guchar *)session_key, strlen(session_key)); | |
| 806 | purple_cipher_context_append(context, (guchar *)":", 1); | |
| 807 | purple_cipher_context_append(context, (guchar *)nonce, strlen(nonce)); | |
| 808 | purple_cipher_context_append(context, (guchar *)":", 1); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
809 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
810 | if (qop != NULL && *qop != '\0') |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
811 | { |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
812 | if (nonce_count == NULL) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
813 | { |
| 15884 | 814 | purple_cipher_context_destroy(context); |
|
19832
84b69b21672b
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17435
diff
changeset
|
815 | purple_debug_error("cipher", "Required nonce_count missing for digest calculation.\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
816 | return NULL; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
817 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
818 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
819 | if (client_nonce == NULL) |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
820 | { |
| 15884 | 821 | purple_cipher_context_destroy(context); |
|
19832
84b69b21672b
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
17435
diff
changeset
|
822 | purple_debug_error("cipher", "Required client_nonce missing for digest calculation.\n"); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
823 | return NULL; |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
824 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
825 | |
| 15884 | 826 | purple_cipher_context_append(context, (guchar *)nonce_count, strlen(nonce_count)); |
| 827 | purple_cipher_context_append(context, (guchar *)":", 1); | |
| 828 | purple_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce)); | |
| 829 | purple_cipher_context_append(context, (guchar *)":", 1); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
830 | |
| 15884 | 831 | purple_cipher_context_append(context, (guchar *)qop, strlen(qop)); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
832 | |
| 15884 | 833 | purple_cipher_context_append(context, (guchar *)":", 1); |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
834 | } |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
835 | |
| 15884 | 836 | purple_cipher_context_append(context, (guchar *)hash2, strlen(hash2)); |
| 837 | purple_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL); | |
| 838 | purple_cipher_context_destroy(context); | |
|
12382
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
839 | |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
840 | return g_strdup(hash2); |
|
5ef67596b420
[gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents:
11677
diff
changeset
|
841 | } |