2008-08-25 Dan Williams <dcbw@redhat.com>
* libnm-util/crypto_gnutls.c libnm-util/crypto_nss.c - (crypto_init, crypto_deinit): refcount init/deinit - (crypto_md5_hash): allow NULL salt git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4011 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2008-08-25 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
* libnm-util/crypto_gnutls.c
|
||||||
|
libnm-util/crypto_nss.c
|
||||||
|
- (crypto_init, crypto_deinit): refcount init/deinit
|
||||||
|
- (crypto_md5_hash): allow NULL salt
|
||||||
|
|
||||||
2008-08-22 Michael Biebl <mbiebl@gmail.com>
|
2008-08-22 Michael Biebl <mbiebl@gmail.com>
|
||||||
|
|
||||||
* libnm-glib/Makefile.am
|
* libnm-glib/Makefile.am
|
||||||
|
@@ -29,17 +29,23 @@
|
|||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
static guint32 refcount = 0;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
crypto_init (GError **error)
|
crypto_init (GError **error)
|
||||||
{
|
{
|
||||||
gnutls_global_init();
|
if (refcount == 0)
|
||||||
|
gnutls_global_init();
|
||||||
|
refcount++;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
crypto_deinit (void)
|
crypto_deinit (void)
|
||||||
{
|
{
|
||||||
gnutls_global_deinit();
|
refcount--;
|
||||||
|
if (refcount == 0)
|
||||||
|
gnutls_global_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@@ -59,8 +65,9 @@ crypto_md5_hash (const char *salt,
|
|||||||
char digest[MD5_HASH_LEN];
|
char digest[MD5_HASH_LEN];
|
||||||
char *p = buffer;
|
char *p = buffer;
|
||||||
|
|
||||||
g_return_val_if_fail (salt != NULL, FALSE);
|
if (salt)
|
||||||
g_return_val_if_fail (salt_len >= 8, FALSE);
|
g_return_val_if_fail (salt_len >= 8, FALSE);
|
||||||
|
|
||||||
g_return_val_if_fail (password != NULL, FALSE);
|
g_return_val_if_fail (password != NULL, FALSE);
|
||||||
g_return_val_if_fail (password_len > 0, FALSE);
|
g_return_val_if_fail (password_len > 0, FALSE);
|
||||||
g_return_val_if_fail (buffer != NULL, FALSE);
|
g_return_val_if_fail (buffer != NULL, FALSE);
|
||||||
@@ -81,7 +88,8 @@ crypto_md5_hash (const char *salt,
|
|||||||
if (count++)
|
if (count++)
|
||||||
gcry_md_write (ctx, digest, digest_len);
|
gcry_md_write (ctx, digest, digest_len);
|
||||||
gcry_md_write (ctx, password, password_len);
|
gcry_md_write (ctx, password, password_len);
|
||||||
gcry_md_write (ctx, salt, 8); /* Only use 8 bytes of salt */
|
if (salt)
|
||||||
|
gcry_md_write (ctx, salt, 8); /* Only use 8 bytes of salt */
|
||||||
gcry_md_final (ctx);
|
gcry_md_final (ctx);
|
||||||
memcpy (digest, gcry_md_read (ctx, 0), digest_len);
|
memcpy (digest, gcry_md_read (ctx, 0), digest_len);
|
||||||
gcry_md_reset (ctx);
|
gcry_md_reset (ctx);
|
||||||
|
@@ -32,20 +32,27 @@
|
|||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
static guint32 refcount = 0;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
crypto_init (GError **error)
|
crypto_init (GError **error)
|
||||||
{
|
{
|
||||||
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1);
|
if (refcount == 0) {
|
||||||
NSS_NoDB_Init (NULL);
|
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1);
|
||||||
|
NSS_NoDB_Init (NULL);
|
||||||
|
}
|
||||||
|
refcount++;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
crypto_deinit (void)
|
crypto_deinit (void)
|
||||||
{
|
{
|
||||||
NSS_Shutdown ();
|
refcount--;
|
||||||
PR_Cleanup ();
|
if (refcount == 0) {
|
||||||
|
NSS_Shutdown ();
|
||||||
|
PR_Cleanup ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@@ -64,8 +71,9 @@ crypto_md5_hash (const char *salt,
|
|||||||
char digest[MD5_HASH_LEN];
|
char digest[MD5_HASH_LEN];
|
||||||
char *p = buffer;
|
char *p = buffer;
|
||||||
|
|
||||||
g_return_val_if_fail (salt != NULL, FALSE);
|
if (salt)
|
||||||
g_return_val_if_fail (salt_len >= 8, FALSE);
|
g_return_val_if_fail (salt_len >= 8, FALSE);
|
||||||
|
|
||||||
g_return_val_if_fail (password != NULL, FALSE);
|
g_return_val_if_fail (password != NULL, FALSE);
|
||||||
g_return_val_if_fail (password_len > 0, FALSE);
|
g_return_val_if_fail (password_len > 0, FALSE);
|
||||||
g_return_val_if_fail (buffer != NULL, FALSE);
|
g_return_val_if_fail (buffer != NULL, FALSE);
|
||||||
@@ -87,7 +95,8 @@ crypto_md5_hash (const char *salt,
|
|||||||
if (count++)
|
if (count++)
|
||||||
PK11_DigestOp (ctx, (const unsigned char *) digest, digest_len);
|
PK11_DigestOp (ctx, (const unsigned char *) digest, digest_len);
|
||||||
PK11_DigestOp (ctx, (const unsigned char *) password, password_len);
|
PK11_DigestOp (ctx, (const unsigned char *) password, password_len);
|
||||||
PK11_DigestOp (ctx, (const unsigned char *) salt, 8); /* Only use 8 bytes of salt */
|
if (salt)
|
||||||
|
PK11_DigestOp (ctx, (const unsigned char *) salt, 8); /* Only use 8 bytes of salt */
|
||||||
PK11_DigestFinal (ctx, (unsigned char *) digest, &digest_len, sizeof (digest));
|
PK11_DigestFinal (ctx, (unsigned char *) digest, &digest_len, sizeof (digest));
|
||||||
|
|
||||||
while (nkey && (i < digest_len)) {
|
while (nkey && (i < digest_len)) {
|
||||||
|
Reference in New Issue
Block a user