implemented SHA1 encrypted passwords for manager
This commit is contained in:
@@ -248,6 +248,35 @@ bool chunk_write(chunk_t chunk, const char *path, const char *label, mode_t mask
|
||||
}
|
||||
}
|
||||
|
||||
/** hex conversion digits */
|
||||
static char hexdig_upper[] = "0123456789ABCDEF";
|
||||
static char hexdig_lower[] = "0123456789abcdef";
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
char *chunk_to_hex(chunk_t chunk, bool uppercase)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
char *hexdig = hexdig_lower;
|
||||
|
||||
if (uppercase)
|
||||
{
|
||||
hexdig = hexdig_upper;
|
||||
}
|
||||
|
||||
str = malloc(chunk.len * 2 + 1);
|
||||
str[chunk.len * 2] = '\0';
|
||||
|
||||
for (i = 0; i < chunk.len; i ++)
|
||||
{
|
||||
str[i*2] = hexdig[(chunk.ptr[i] >> 4) & 0xF];
|
||||
str[i*2+1] = hexdig[(chunk.ptr[i] ) & 0xF];
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
@@ -354,10 +383,8 @@ static int print_bytes(FILE *stream, const struct printf_info *info,
|
||||
|
||||
while (bytes_pos < bytes_roof)
|
||||
{
|
||||
static char hexdig[] = "0123456789ABCDEF";
|
||||
|
||||
*buffer_pos++ = hexdig[(*bytes_pos >> 4) & 0xF];
|
||||
*buffer_pos++ = hexdig[ *bytes_pos & 0xF];
|
||||
*buffer_pos++ = hexdig_upper[(*bytes_pos >> 4) & 0xF];
|
||||
*buffer_pos++ = hexdig_upper[ *bytes_pos & 0xF];
|
||||
|
||||
ascii_buffer[i++] =
|
||||
(*bytes_pos > 31 && *bytes_pos < 127) ? *bytes_pos : '.';
|
||||
|
||||
@@ -83,6 +83,11 @@ void chunk_split(chunk_t chunk, const char *mode, ...);
|
||||
*/
|
||||
bool chunk_write(chunk_t chunk, const char *path, const char *label, mode_t mask, bool force);
|
||||
|
||||
/**
|
||||
* convert a chunk to an allocated hex string
|
||||
*/
|
||||
char *chunk_to_hex(chunk_t chunk, bool uppercase);
|
||||
|
||||
/**
|
||||
* Free contents of a chunk
|
||||
*/
|
||||
|
||||
+19
-1
@@ -25,6 +25,7 @@
|
||||
#include <sqlite3.h>
|
||||
#include <library.h>
|
||||
#include <enumerator.h>
|
||||
#include <crypto/hashers/hasher.h>
|
||||
|
||||
|
||||
typedef struct private_database_t private_database_t;
|
||||
@@ -100,20 +101,37 @@ static enumerator_t* empty_enumerator_create()
|
||||
static int login(private_database_t *this, char *username, char *password)
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
hasher_t *hasher;
|
||||
chunk_t hash, data;
|
||||
size_t username_len, password_len;
|
||||
int uid = 0;
|
||||
char *str;
|
||||
|
||||
/* hash = SHA1( username | password ) */
|
||||
hasher = hasher_create(HASH_SHA1);
|
||||
hash = chunk_alloca(hasher->get_hash_size(hasher));
|
||||
username_len = strlen(username);
|
||||
password_len = strlen(password);
|
||||
data = chunk_alloca(username_len + password_len);
|
||||
memcpy(data.ptr, username, username_len);
|
||||
memcpy(data.ptr + username_len, password, password_len);
|
||||
hasher->get_hash(hasher, data, hash.ptr);
|
||||
hasher->destroy(hasher);
|
||||
str = chunk_to_hex(hash, FALSE);
|
||||
|
||||
if (sqlite3_prepare_v2(this->db,
|
||||
"SELECT oid FROM users WHERE username = ? AND password = ?;",
|
||||
-1, &stmt, NULL) == SQLITE_OK)
|
||||
{
|
||||
if (sqlite3_bind_text(stmt, 1, username, -1, SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 2, password, -1, SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_bind_text(stmt, 2, str, -1, SQLITE_STATIC) == SQLITE_OK &&
|
||||
sqlite3_step(stmt) == SQLITE_ROW)
|
||||
{
|
||||
uid = sqlite3_column_int(stmt, 0);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
free(str);
|
||||
return uid;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,12 +62,12 @@ struct private_request_t {
|
||||
* ClearSilver cgiwrap is not threadsave, so we use a private
|
||||
* context for each thread.
|
||||
*/
|
||||
__thread FCGX_Request *req;
|
||||
static __thread FCGX_Request *req;
|
||||
|
||||
/**
|
||||
* length of param list in req->envp
|
||||
*/
|
||||
__thread int req_env_len;
|
||||
static __thread int req_env_len;
|
||||
|
||||
/**
|
||||
* fcgiwrap read callback
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user