chunk_to_hex() adaptations
This commit is contained in:
@@ -45,7 +45,7 @@ struct private_storage_t {
|
|||||||
static int login(private_storage_t *this, char *username, char *password)
|
static int login(private_storage_t *this, char *username, char *password)
|
||||||
{
|
{
|
||||||
hasher_t *hasher;
|
hasher_t *hasher;
|
||||||
chunk_t hash, data;
|
chunk_t hash, data, hex_str;
|
||||||
size_t username_len, password_len;
|
size_t username_len, password_len;
|
||||||
int uid = 0;
|
int uid = 0;
|
||||||
char *str;
|
char *str;
|
||||||
@@ -65,18 +65,18 @@ static int login(private_storage_t *this, char *username, char *password)
|
|||||||
memcpy(data.ptr + username_len, password, password_len);
|
memcpy(data.ptr + username_len, password, password_len);
|
||||||
hasher->get_hash(hasher, data, hash.ptr);
|
hasher->get_hash(hasher, data, hash.ptr);
|
||||||
hasher->destroy(hasher);
|
hasher->destroy(hasher);
|
||||||
str = chunk_to_hex(hash, FALSE);
|
hex_str = chunk_to_hex(hash, NULL, FALSE);
|
||||||
|
|
||||||
enumerator = this->db->query(this->db,
|
enumerator = this->db->query(this->db,
|
||||||
"SELECT oid FROM users WHERE username = ? AND password = ?;",
|
"SELECT oid FROM users WHERE username = ? AND password = ?;",
|
||||||
DB_TEXT, username, DB_TEXT, str,
|
DB_TEXT, username, DB_TEXT, hex_str.ptr,
|
||||||
DB_INT);
|
DB_INT);
|
||||||
if (enumerator)
|
if (enumerator)
|
||||||
{
|
{
|
||||||
enumerator->enumerate(enumerator, &uid);
|
enumerator->enumerate(enumerator, &uid);
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
}
|
}
|
||||||
free(str);
|
free(hex_str.ptr);
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-11
@@ -37,7 +37,6 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <asn1/asn1.h>
|
#include <asn1/asn1.h>
|
||||||
#include <asn1/pem.h>
|
#include <asn1/pem.h>
|
||||||
#include <asn1/ttodata.h>
|
|
||||||
#include <credentials/certificates/x509.h>
|
#include <credentials/certificates/x509.h>
|
||||||
#include <credentials/certificates/ac.h>
|
#include <credentials/certificates/ac.h>
|
||||||
#include <utils/optionsfrom.h>
|
#include <utils/optionsfrom.h>
|
||||||
@@ -115,7 +114,8 @@ static chunk_t read_serial(void)
|
|||||||
mpz_t number;
|
mpz_t number;
|
||||||
|
|
||||||
char buf[BUF_LEN], buf1[BUF_LEN];
|
char buf[BUF_LEN], buf1[BUF_LEN];
|
||||||
chunk_t last_serial = { buf1, BUF_LEN};
|
chunk_t hex_serial = { buf, BUF_LEN };
|
||||||
|
chunk_t last_serial = { buf1, BUF_LEN };
|
||||||
chunk_t serial;
|
chunk_t serial;
|
||||||
|
|
||||||
FILE *fd = fopen(OPENAC_SERIAL, "r");
|
FILE *fd = fopen(OPENAC_SERIAL, "r");
|
||||||
@@ -126,15 +126,10 @@ static chunk_t read_serial(void)
|
|||||||
|
|
||||||
if (fd)
|
if (fd)
|
||||||
{
|
{
|
||||||
if (fscanf(fd, "%s", buf))
|
if (fscanf(fd, "%s", hex_serial.ptr))
|
||||||
{
|
{
|
||||||
err_t ugh = ttodata(buf, 0, 16, last_serial.ptr, BUF_LEN, &last_serial.len);
|
hex_serial.len = strlen(hex_serial.ptr);
|
||||||
|
last_serial = chunk_from_hex(hex_serial, last_serial.ptr);
|
||||||
if (ugh != NULL)
|
|
||||||
{
|
|
||||||
DBG1(" error reading serial number from %s: %s",
|
|
||||||
OPENAC_SERIAL, ugh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
}
|
}
|
||||||
@@ -166,9 +161,13 @@ static void write_serial(chunk_t serial)
|
|||||||
|
|
||||||
if (fd)
|
if (fd)
|
||||||
{
|
{
|
||||||
|
chunk_t hex_serial;
|
||||||
|
|
||||||
DBG1(" serial number is %#B", &serial);
|
DBG1(" serial number is %#B", &serial);
|
||||||
fprintf(fd, "%#B\n", &serial);
|
hex_serial = chunk_to_hex(serial, NULL, FALSE);
|
||||||
|
fprintf(fd, "%.*s\n", hex_serial.len, hex_serial.ptr);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
free(hex_serial.ptr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user