Changeset 1bdc669
- Timestamp:
- 2023-02-23T23:48:10Z (22 months ago)
- Branches:
- master
- Children:
- 93d4d8f
- Parents:
- 7342cae
- git-author:
- Jelmer Vernooij <jelmer@…> (23-02-23 23:48:10)
- git-committer:
- GitHub <noreply@…> (23-02-23 23:48:10)
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/md5.c
r7342cae r1bdc669 28 28 void md5_digest_keep(md5_state_t *ctx, guint8 digest[MD5_HASH_SIZE]) 29 29 { 30 md5_state_t copy = g_checksum_copy(*ctx); 30 gsize digest_len = MD5_HASH_SIZE; 31 GChecksum *copy = g_checksum_copy(*ctx); 31 32 32 md5_finish(©, digest); 33 g_checksum_get_digest(copy, digest, &digest_len); 34 g_checksum_free(copy); 33 35 } 34 36 -
lib/md5.h
r7342cae r1bdc669 8 8 typedef GChecksum *md5_state_t; 9 9 10 11 10 #define MD5_HASH_SIZE 16 12 11 13 void md5_init(md5_state_t *); 14 void md5_append(md5_state_t *, const guint8 *, unsigned int); 15 void md5_finish(md5_state_t *, guint8 digest[MD5_HASH_SIZE]); 16 void md5_digest_keep(md5_state_t *, guint8 digest[MD5_HASH_SIZE]); 17 void md5_free(md5_state_t *); 12 #ifdef __GNUC__ 13 #define __MD5_NON_PUBLIC_DEPRECATION__ __attribute__((deprecated("md5.h will be removed from Bitlbee's public API. Please use another library (such as GLib's gchecksum) instead"))) 14 #else 15 #define __MD5_NON_PUBLIC_DEPRECATION__ 16 #endif 17 18 void md5_init(md5_state_t *) __MD5_NON_PUBLIC_DEPRECATION__; 19 void md5_append(md5_state_t *, const guint8 *, unsigned int) __MD5_NON_PUBLIC_DEPRECATION__; 20 void md5_finish(md5_state_t *, guint8 digest[MD5_HASH_SIZE]) __MD5_NON_PUBLIC_DEPRECATION__; 21 void md5_digest_keep(md5_state_t *, guint8 digest[MD5_HASH_SIZE]) __MD5_NON_PUBLIC_DEPRECATION__; 22 void md5_free(md5_state_t *) __MD5_NON_PUBLIC_DEPRECATION__; 18 23 19 24 #endif -
lib/misc.c
r7342cae r1bdc669 34 34 #include "nogaim.h" 35 35 #include "base64.h" 36 #include "md5.h"37 36 #include <stdio.h> 38 37 #include <stdlib.h> … … 47 46 #endif 48 47 49 #include "md5.h"50 48 #include "ssl_client.h" 51 49 … … 576 574 int md5_verify_password(char *password, char *hash) 577 575 { 578 md5_byte_t *pass_dec = NULL; 579 md5_byte_t pass_md5[16]; 580 md5_state_t md5_state; 576 guint8 *pass_dec = NULL; 577 guint8 pass_md5[16]; 578 GChecksum *md5_state; 579 gsize digest_len = MD5_HASH_SIZE; 581 580 int ret = -1, i; 582 581 583 582 if (base64_decode(hash, &pass_dec) == 21) { 584 md5_init(&md5_state); 585 md5_append(&md5_state, (md5_byte_t *) password, strlen(password)); 586 md5_append(&md5_state, (md5_byte_t *) pass_dec + 16, 5); /* Hmmm, salt! */ 587 md5_finish(&md5_state, pass_md5); 583 md5_state = g_checksum_new(G_CHECKSUM_MD5); 584 g_checksum_update(md5_state, (guint8 *) password, strlen(password)); 585 g_checksum_update(md5_state, (guint8 *) pass_dec + 16, 5); /* Hmmm, salt! */ 586 g_checksum_get_digest(md5_state, pass_md5, &digest_len); 587 g_checksum_free(md5_state); 588 588 589 589 for (i = 0; i < 16; i++) { -
protocols/jabber/jabber.c
r7342cae r1bdc669 33 33 #include "jabber.h" 34 34 #include "oauth.h" 35 #include "md5.h"36 35 37 36 GSList *jabber_connections; … … 301 300 } 302 301 303 /* This generates an unfinished md5_state_tvariable. Every time we generate302 /* This generates an unfinished g_checksum variable. Every time we generate 304 303 an ID, we finish the state by adding a sequence number and take the hash. */ 305 304 static void jabber_generate_id_hash(struct jabber_data *jd) 306 305 { 307 md5_byte_tbinbuf[4];306 guint8 binbuf[4]; 308 307 char *s; 309 308 310 md5_init(&jd->cached_id_prefix);311 md5_append(&jd->cached_id_prefix, (unsigned char *)jd->username, strlen(jd->username));312 md5_append(&jd->cached_id_prefix, (unsigned char *)jd->server, strlen(jd->server));309 jd->cached_id_prefix = g_checksum_new(G_CHECKSUM_MD5); 310 g_checksum_update(jd->cached_id_prefix, jd->username, strlen(jd->username)); 311 g_checksum_update(jd->cached_id_prefix, jd->server, strlen(jd->server)); 313 312 s = set_getstr(&jd->ic->acc->set, "resource"); 314 md5_append(&jd->cached_id_prefix, (unsigned char *)s, strlen(s));313 g_checksum_update(jd->cached_id_prefix, s, strlen(s)); 315 314 random_bytes(binbuf, 4); 316 md5_append(&jd->cached_id_prefix, binbuf, 4);315 g_checksum_update(jd->cached_id_prefix, binbuf, 4); 317 316 } 318 317 … … 371 370 xt_free(jd->xt); 372 371 373 md5_free(&jd->cached_id_prefix);372 g_checksum_free(jd->cached_id_prefix); 374 373 375 374 g_free(jd->oauth2_access_token); -
protocols/jabber/jabber.h
r7342cae r1bdc669 28 28 29 29 #include "bitlbee.h" 30 #include "md5.h"31 30 #include "xmltree.h" 32 31 … … 105 104 char *gmail_tid; 106 105 107 md5_state_tcached_id_prefix;106 GChecksum *cached_id_prefix; 108 107 GHashTable *node_cache; 109 108 GHashTable *buddies; -
protocols/jabber/jabber_util.c
r7342cae r1bdc669 23 23 24 24 #include "jabber.h" 25 #include "md5.h"26 25 #include "base64.h" 27 26 … … 141 140 struct jabber_data *jd = ic->proto_data; 142 141 struct jabber_cache_entry *entry = g_new0(struct jabber_cache_entry, 1); 143 md5_state_t id_hash; 144 md5_byte_t id_sum[16]; 142 GChecksum *id_hash; 143 gsize digest_len = MD5_HASH_SIZE; 144 guint8 id_sum[MD5_HASH_SIZE]; 145 145 char *id, *asc_hash; 146 146 … … 148 148 149 149 id_hash = jd->cached_id_prefix; 150 md5_append(&id_hash, (md5_byte_t *) &next_id, sizeof(next_id)); 151 md5_digest_keep(&id_hash, id_sum); 150 g_checksum_update(id_hash, (guint8 *) &next_id, sizeof(next_id)); 151 g_checksum_get_digest(id_hash, id_sum, &digest_len); 152 g_checksum_free(id_hash); 153 152 154 asc_hash = base64_encode(id_sum, 12); 153 155 -
protocols/jabber/sasl.c
r7342cae r1bdc669 302 302 if (!(s = sasl_get_part(dec, "rspauth"))) { 303 303 /* See RFC 2831 for for information. */ 304 md5_state_t A1, A2, H; 305 md5_byte_t A1r[16], A2r[16], Hr[16]; 304 GChecksum *A1, *A2, *H; 305 gsize digest_len = MD5_HASH_SIZE; 306 guint8 A1r[16], A2r[16], Hr[16]; 306 307 char A1h[33], A2h[33], Hh[33]; 307 308 int i; … … 327 328 /* Generate the MD5 hash of username:realm:password, 328 329 I decided to call it H. */ 329 md5_init(&H);330 H = g_checksum_new(G_CHECKSUM_MD5); 330 331 s = g_strdup_printf("%s:%s:%s", jd->username, realm, ic->acc->pass); 331 md5_append(&H, (unsigned char *)s, strlen(s));332 g_checksum_update(H, (guint8 *)s, strlen(s)); 332 333 g_free(s); 333 md5_finish(&H, Hr); 334 335 g_checksum_get_digest(H, Hr, &digest_len); 336 g_checksum_free(H); 334 337 335 338 /* Now generate the hex. MD5 hash of H:nonce:cnonce, called A1. */ 336 md5_init(&A1);339 A1 = g_checksum_new(G_CHECKSUM_MD5); 337 340 s = g_strdup_printf(":%s:%s", nonce, cnonce); 338 md5_append(&A1, Hr, 16);339 md5_append(&A1, (unsigned char *)s, strlen(s));341 g_checksum_update(A1, Hr, 16); 342 g_checksum_update(A1, (guint8 *)s, strlen(s)); 340 343 g_free(s); 341 md5_finish(&A1, A1r); 344 g_checksum_get_digest(A1, A1r, &digest_len); 345 g_checksum_free(A1); 342 346 for (i = 0; i < 16; i++) { 343 347 sprintf(A1h + i * 2, "%02x", A1r[i]); … … 345 349 346 350 /* A2... */ 347 md5_init(&A2);351 A2 = g_checksum_new(G_CHECKSUM_MD5); 348 352 s = g_strdup_printf("%s:%s", "AUTHENTICATE", digest_uri); 349 md5_append(&A2, (unsigned char *)s, strlen(s));353 g_checksum_update(A2, (guint8 *)s, strlen(s)); 350 354 g_free(s); 351 md5_finish(&A2, A2r); 355 g_checksum_get_digest(A2, A2r, &digest_len); 356 g_checksum_free(A2); 352 357 for (i = 0; i < 16; i++) { 353 358 sprintf(A2h + i * 2, "%02x", A2r[i]); … … 355 360 356 361 /* Final result: A1:nonce:00000001:cnonce:auth:A2. Let's reuse H for it. */ 357 md5_init(&H);362 H = g_checksum_new(G_CHECKSUM_MD5); 358 363 s = g_strdup_printf("%s:%s:%s:%s:%s:%s", A1h, nonce, "00000001", cnonce, "auth", A2h); 359 md5_append(&H, (unsigned char *)s, strlen(s));364 g_checksum_update(H, (guint8 *)s, strlen(s)); 360 365 g_free(s); 361 md5_finish(&H, Hr); 366 g_checksum_get_digest(H, Hr, &digest_len); 367 g_checksum_free(H); 368 362 369 for (i = 0; i < 16; i++) { 363 370 sprintf(Hh + i * 2, "%02x", Hr[i]); -
storage_xml.c
r7342cae r1bdc669 28 28 #include "base64.h" 29 29 #include "arc.h" 30 #include "md5.h"31 30 #include "xmltree.h" 32 31 … … 323 322 char *pass_buf = NULL; 324 323 account_t *acc; 325 md5_byte_tpass_md5[21];326 md5_state_tmd5_state;324 guint8 pass_md5[21]; 325 GChecksum *md5_state; 327 326 GSList *l; 328 327 struct xt_node *root, *cur; 328 gsize digest_len = MD5_HASH_SIZE; 329 329 330 330 root = cur = xt_new_node("user", NULL, NULL); … … 336 336 byte password hash, more convenient for base64 encoding. */ 337 337 random_bytes(pass_md5 + 16, 5); 338 md5_init(&md5_state); 339 md5_append(&md5_state, (md5_byte_t *) irc->password, strlen(irc->password)); 340 md5_append(&md5_state, pass_md5 + 16, 5); /* Add the salt. */ 341 md5_finish(&md5_state, pass_md5); 338 md5_state = g_checksum_new(G_CHECKSUM_MD5); 339 g_checksum_update(md5_state, (guint8 *) irc->password, strlen(irc->password)); 340 g_checksum_update(md5_state, pass_md5 + 16, 5); /* Add the salt. */ 341 g_checksum_get_digest(md5_state, pass_md5, &digest_len); 342 g_checksum_free(md5_state); 342 343 /* Save the hash in base64-encoded form. */ 343 344 pass_buf = base64_encode(pass_md5, 21); -
unix.c
r7342cae r1bdc669 261 261 g_free(pass_cl); 262 262 } else if (strcmp(argv[2], "hash") == 0) { 263 md5_byte_t pass_md5[21]; 264 md5_state_t md5_state; 263 guint8 pass_md5[21]; 264 GChecksum *md5_state; 265 gsize digest_len = MD5_HASH_SIZE; 265 266 char *encoded; 266 267 267 268 random_bytes(pass_md5 + 16, 5); 268 md5_init(&md5_state); 269 md5_append(&md5_state, (md5_byte_t *) argv[3], strlen(argv[3])); 270 md5_append(&md5_state, pass_md5 + 16, 5); /* Add the salt. */ 271 md5_finish(&md5_state, pass_md5); 269 md5_state = g_checksum_new(G_CHECKSUM_MD5); 270 g_checksum_update(md5_state, (guint8 *) argv[3], strlen(argv[3])); 271 g_checksum_update(md5_state, pass_md5 + 16, 5); /* Add the salt. */ 272 g_checksum_get_digest(md5_state, pass_md5, &digest_len); 273 g_checksum_free(md5_state); 272 274 273 275 encoded = base64_encode(pass_md5, 21);
Note: See TracChangeset
for help on using the changeset viewer.