version 1.2, 2015/04/20 18:10:09
|
version 1.3, 2015/04/20 18:19:49
|
|
|
| |
#include "credcache.h" | #include "credcache.h" |
#include "log.h" | #include "log.h" |
#include <base/time.h> |
#include <pal/sleep.h> |
| |
#if defined (CONFIG_POSIX) | #if defined (CONFIG_POSIX) |
# include <openssl/evp.h> | # include <openssl/evp.h> |
|
|
/* Initialize salt */ | /* Initialize salt */ |
if (0 == RAND_load_file("/dev/urandom", 1024)) | if (0 == RAND_load_file("/dev/urandom", 1024)) |
{ | { |
LOGW_CHAR(("failed to load /dev/urandom")); |
trace_FailedLoadDevUrandom(); |
return -1; | return -1; |
} | } |
| |
if (0 == RAND_bytes(s_salt, sizeof(s_salt))) | if (0 == RAND_bytes(s_salt, sizeof(s_salt))) |
{ | { |
LOGW_CHAR(("failed to init salt")); |
trace_FailedInitSalt(); |
return -1; | return -1; |
} | } |
| |
|
|
!(s_md = EVP_get_digestbyname("sha224")) && | !(s_md = EVP_get_digestbyname("sha224")) && |
!(s_md = EVP_get_digestbyname("sha1"))) | !(s_md = EVP_get_digestbyname("sha1"))) |
{ | { |
LOGW_CHAR(("no digest available")); |
trace_NoDigestAvailable(); |
return -1; | return -1; |
} | } |
| |
|
|
pos = _FindUserEmptyOldest(user); | pos = _FindUserEmptyOldest(user); |
| |
/* timestamp */ | /* timestamp */ |
if (MI_RESULT_OK != Time_Now(&s_cache[pos].timestamp)) |
if (PAL_TRUE != PAL_Time(&s_cache[pos].timestamp)) |
return; | return; |
| |
/* user name */ | /* user name */ |
|
|
return -1; | return -1; |
| |
/* Is it expired? */ | /* Is it expired? */ |
if (MI_RESULT_OK != Time_Now(&now)) |
if (PAL_TRUE != PAL_Time(&now)) |
return -1; | return -1; |
| |
if (s_cache[pos].timestamp + s_expirationTime_us < now) | if (s_cache[pos].timestamp + s_expirationTime_us < now) |
|
|
| |
if (0 == RAND_bytes((unsigned char*)buf, size)) | if (0 == RAND_bytes((unsigned char*)buf, size)) |
{ | { |
LOGW_CHAR(("failed to produce random data")); |
trace_FailedToProduceRandomData(); |
return -1; | return -1; |
} | } |
| |