SPARK-959 SecureLogon - only consider non-expired keys
This commit is contained in:
1 parent
005073060a
commit
a008bac794
1 file changed
+19
-4
@@ -1,6 +1,7 @@
|
||||
#ifndef _WIN32
|
||||
#include "SecureLogon.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/system.pb.h"
|
||||
@@ -19,12 +20,24 @@
|
||||
#include <tuple>
|
||||
|
||||
using namespace CryptoPP;
|
||||
using namespace boost;
|
||||
using std::string;
|
||||
|
||||
namespace glbx {
|
||||
|
||||
bool is_expired(const string& expiration) {
|
||||
char_separator<char> sep("-\\");
|
||||
tokenizer<char_separator<char>> tokens(expiration, sep);
|
||||
auto t = tokens.begin();
|
||||
int year = std::stoi(*t);
|
||||
int month = std::stoi(*(++t));
|
||||
int day = std::stoi(*(++t));
|
||||
bts::datetime::Date dtexp(year, month, day);
|
||||
auto today = bts::datetime::today();
|
||||
return dtexp < today;
|
||||
}
|
||||
|
||||
std::tuple<string, string> load_session_keys(const string& session) {
|
||||
using namespace boost;
|
||||
using namespace boost::filesystem;
|
||||
auto path = bts::config::get<bts::config::System>().data_path() + "glbx_logon/";
|
||||
if (is_directory(path)) {
|
||||
@@ -42,7 +55,11 @@ std::tuple<string, string> load_session_keys(const string& session) {
|
||||
if (t != tokens.end() && *t == session) {
|
||||
auto id = *(++t);
|
||||
auto secret = *(++t);
|
||||
return {id,secret};
|
||||
auto create_date = *(++t);
|
||||
auto expiration_date = *(++t);
|
||||
if (!is_expired(expiration_date)) {
|
||||
return {id,secret};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +129,6 @@ LogonData calculate_hmac(
|
||||
bts_assert(false);
|
||||
}
|
||||
|
||||
|
||||
// TEST_CASE("LoadSessionKeys", "") {
|
||||
// std::string session_id = "1U7";
|
||||
// string secret_key, access_id;
|
||||
@@ -122,5 +138,4 @@ LogonData calculate_hmac(
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user