1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Changed to use gnutls instead of openssl for sha1 hashing

This commit is contained in:
James Booth 2014-05-01 22:18:04 +01:00
parent f44cf86f23
commit 524b1f2383
8 changed files with 98 additions and 17 deletions

View File

@ -122,6 +122,9 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [],
[AC_MSG_ERROR([glib 2.26 or higher is required for profanity])])
PKG_CHECK_MODULES([curl], [libcurl], [],
[AC_MSG_ERROR([libcurl is required for profanity])])
PKG_CHECK_MODULES([gnutls], [gnutls >= 3.0.0], [],
[AC_MSG_ERROR([gnutls is required for profanity])])
AS_IF([test "x$PLATFORM" = xosx], [LIBS="$LIBS -lcurl"])
### Check for desktop notification support
@ -216,9 +219,9 @@ AC_CHECK_HEADERS([ncurses.h], [], [])
AM_CFLAGS="-Wall -Wno-deprecated-declarations"
AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
[AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"])
AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS"
AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS $gnutls_CFLAGS"
AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\""
LIBS="$LIBS $glib_LIBS $curl_LIBS $libnotify_LIBS"
LIBS="$LIBS $glib_LIBS $curl_LIBS $libnotify_LIBS $gnutls_LIBS"
AC_SUBST(AM_CFLAGS)
AC_SUBST(AM_CPPFLAGS)

View File

@ -31,6 +31,8 @@
#include <curl/curl.h>
#include <curl/easy.h>
#include <glib.h>
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>
#include "log.h"
#include "common.h"
@ -388,6 +390,21 @@ generate_unique_id(char *prefix)
return result;
}
char *
sha1_hash(char *str)
{
gnutls_hash_hd_t dig;
gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_SHA1;
gnutls_hash_init(&dig, algorithm);
gnutls_hash(dig, str, strlen(str));
unsigned char output[20];
gnutls_hash_output(dig, output);
return g_base64_encode(output, sizeof(output));
}
int
cmp_win_num(gconstpointer a, gconstpointer b)
{

View File

@ -88,6 +88,7 @@ const char * string_from_resource_presence(resource_presence_t presence);
resource_presence_t resource_presence_from_string(const char * const str);
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
char * sha1_hash(char *str);
char * generate_unique_id(char *prefix);
int cmp_win_num(gconstpointer a, gconstpointer b);

View File

@ -31,6 +31,7 @@
#include <string.h>
#include <glib.h>
#include <gnutls/gnutls.h>
#include "profanity.h"
#include "chat_session.h"
@ -254,6 +255,7 @@ _init(const int disable_tls, char *log_level)
setlocale(LC_ALL, "");
// ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
gnutls_global_init();
_create_directories();
log_level_t prof_log_level = log_level_from_string(log_level);
prefs_load();
@ -302,6 +304,7 @@ _shutdown(void)
accounts_close();
cmd_uninit();
log_close();
gnutls_global_deinit();
}
static void

View File

@ -30,7 +30,6 @@
#include <string.h>
#include <glib.h>
#include <openssl/evp.h>
#include <strophe.h>
#include "common.h"
@ -203,20 +202,7 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
curr = g_slist_next(curr);
}
EVP_MD_CTX mdctx;
const EVP_MD *md;
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len;
OpenSSL_add_all_digests();
md = EVP_get_digestbyname("SHA1");
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md, NULL);
EVP_DigestUpdate(&mdctx, s->str, strlen(s->str));
EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(&mdctx);
char *result = g_base64_encode(md_value, md_len);
char *result = sha1_hash(s->str);
g_string_free(s, TRUE);
g_slist_free_full(identities, g_free);

File diff suppressed because one or more lines are too long

View File

@ -38,3 +38,11 @@ void test_dnd_is_valid_resource_presence_string(void **state);
void test_available_is_not_valid_resource_presence_string(void **state);
void test_unavailable_is_not_valid_resource_presence_string(void **state);
void test_blah_is_not_valid_resource_presence_string(void **state);
void test_sha1_hash1(void **state);
void test_sha1_hash2(void **state);
void test_sha1_hash3(void **state);
void test_sha1_hash4(void **state);
void test_sha1_hash5(void **state);
void test_sha1_hash6(void **state);
void test_sha1_hash6(void **state);
void test_sha1_hash7(void **state);

View File

@ -74,6 +74,13 @@ int main(int argc, char* argv[]) {
unit_test(test_available_is_not_valid_resource_presence_string),
unit_test(test_unavailable_is_not_valid_resource_presence_string),
unit_test(test_blah_is_not_valid_resource_presence_string),
unit_test(test_sha1_hash1),
unit_test(test_sha1_hash2),
unit_test(test_sha1_hash3),
unit_test(test_sha1_hash4),
unit_test(test_sha1_hash5),
unit_test(test_sha1_hash6),
unit_test(test_sha1_hash7),
unit_test(clear_empty),
unit_test(reset_after_create),