Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate sha1_* functions #172

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ char *sha1_random_uuid(sha1_state_t * context)
guint8 dig[SHA1_HASH_SIZE];
char *ret = g_new0(char, 40); /* 36 chars + \0 */
int i, p;
gsize digest_len = SHA1_HASH_SIZE;

g_checksum_get_digest(*context, dig, &digest_len);
g_checksum_free(*context);

sha1_finish(context, dig);
for (p = i = 0; i < 16; i++) {
if (i == 4 || i == 6 || i == 8 || i == 10) {
ret[p++] = '-';
Expand Down
14 changes: 10 additions & 4 deletions lib/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
#include <glib.h>
#include <gmodule.h>

#ifdef __GNUC__
#define __SHA1_NON_PUBLIC_DEPRECATION__ __attribute__((deprecated("sha1.h will be removed from Bitlbee's public API. Please use another library (such as GLib's gchecksum) instead")))
#else
#define __SHA1_NON_PUBLIC_DEPRECATION__
#endif

#define SHA1_HASH_SIZE 20

typedef GChecksum *sha1_state_t;

void sha1_init(sha1_state_t *);
void sha1_append(sha1_state_t *, const guint8 *, unsigned int);
void sha1_finish(sha1_state_t *, guint8 digest[SHA1_HASH_SIZE]);
void sha1_hmac(const char *, size_t, const char *, size_t, guint8 digest[SHA1_HASH_SIZE]);
void sha1_init(sha1_state_t *) __SHA1_NON_PUBLIC_DEPRECATION__;
void sha1_append(sha1_state_t *, const guint8 *, unsigned int) __SHA1_NON_PUBLIC_DEPRECATION__;
void sha1_finish(sha1_state_t *, guint8 digest[SHA1_HASH_SIZE]) __SHA1_NON_PUBLIC_DEPRECATION__;
void sha1_hmac(const char *, size_t, const char *, size_t, guint8 digest[SHA1_HASH_SIZE]) ;
char *sha1_random_uuid(sha1_state_t *);

#endif
13 changes: 6 additions & 7 deletions protocols/jabber/conference.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
\***************************************************************************/

#include "jabber.h"
#include "sha1.h"

static xt_status jabber_chat_join_failed(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
static xt_status jabber_chat_self_message(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
Expand Down Expand Up @@ -78,15 +77,15 @@ struct groupchat *jabber_chat_with(struct im_connection *ic, char *who)
struct jabber_data *jd = ic->proto_data;
struct jabber_chat *jc;
struct groupchat *c;
sha1_state_t sum;
GChecksum *sum;
double now = gettime();
char *uuid, *rjid, *cserv;

sha1_init(&sum);
sha1_append(&sum, (uint8_t *) ic->acc->user, strlen(ic->acc->user));
sha1_append(&sum, (uint8_t *) &now, sizeof(now));
sha1_append(&sum, (uint8_t *) who, strlen(who));
uuid = sha1_random_uuid(&sum);
sum = g_checksum_new(G_CHECKSUM_SHA1);
g_checksum_update(sum, (uint8_t *) ic->acc->user, strlen(ic->acc->user));
g_checksum_update(sum, (uint8_t *) &now, sizeof(now));
g_checksum_update(sum, (uint8_t *) who, strlen(who));
uuid = sha1_random_uuid(sum);

if (jd->flags & JFLAG_GTALK) {
cserv = g_strdup("groupchat.google.com");
Expand Down
13 changes: 7 additions & 6 deletions protocols/jabber/iq.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
\***************************************************************************/

#include "jabber.h"
#include "sha1.h"

static xt_status jabber_parse_roster(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
static xt_status jabber_iq_display_vcard(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
Expand Down Expand Up @@ -244,15 +243,17 @@ static xt_status jabber_do_iq_auth(struct im_connection *ic, struct xt_node *nod
if (xt_find_node(query->children, "digest") && (s = xt_find_attr(jd->xt->root, "id"))) {
/* We can do digest authentication, it seems, and of
course we prefer that. */
sha1_state_t sha;
GChecksum *sha;
char hash_hex[41];
unsigned char hash[20];
int i;
gsize digest_len = 20;

sha1_init(&sha);
sha1_append(&sha, (unsigned char *) s, strlen(s));
sha1_append(&sha, (unsigned char *) ic->acc->pass, strlen(ic->acc->pass));
sha1_finish(&sha, hash);
sha = g_checksum_new(G_CHECKSUM_SHA1);
g_checksum_update(sha, (unsigned char *) s, strlen(s));
g_checksum_update(sha, (unsigned char *) ic->acc->pass, strlen(ic->acc->pass));
g_checksum_get_digest(sha, hash, &digest_len);
g_checksum_free(sha);

for (i = 0; i < 20; i++) {
sprintf(hash_hex + i * 2, "%02x", hash[i]);
Expand Down
1 change: 0 additions & 1 deletion protocols/jabber/si.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
\***************************************************************************/

#include "jabber.h"
#include "sha1.h"

void jabber_si_answer_request(file_transfer_t *ft);
int jabber_si_send_request(struct im_connection *ic, char *who, struct jabber_transfer *tf);
Expand Down