keycodes. boost stil can't handle dates
This commit is contained in:
1 parent
7d75d87e6b
commit
8a965d41ff
24 files changed
+747
-132
No files matched your search
+28
-14
@@ -5,6 +5,8 @@
|
||||
#include "datetime.h"
|
||||
#include "base64.hpp"
|
||||
|
||||
#include "AuthSessionManager.h"
|
||||
|
||||
// cryptopp
|
||||
#include <cryptopp/osrng.h>//temp
|
||||
#include <cryptopp/cryptlib.h>
|
||||
@@ -13,6 +15,7 @@
|
||||
#include <cryptopp/twofish.h>
|
||||
#include <cryptopp/eax.h>
|
||||
#include <cryptopp/secblock.h>
|
||||
#include <map>
|
||||
|
||||
namespace bts {
|
||||
namespace api {
|
||||
@@ -42,45 +45,56 @@ std::string decrypt(const std::string& buffer) {
|
||||
return result;
|
||||
}
|
||||
|
||||
AuthToken generate_token(const admin::BTSUser& user) {
|
||||
AuthSessionManager& session_manager()
|
||||
{
|
||||
static AuthSessionManager mgr;
|
||||
return mgr;
|
||||
}
|
||||
|
||||
AuthToken generate_token(const admin::BTSUser& user)
|
||||
{
|
||||
api::user::TokenPayload payload;
|
||||
payload.set_date(datetime::ll_now());
|
||||
payload.set_id(user.id());
|
||||
if(user.name() == "bts") {
|
||||
if(user.name() == "bts")
|
||||
payload.set_wheel(true);
|
||||
}
|
||||
session_manager().add_or_replace_session(payload);
|
||||
auto token = encrypt(payload.SerializeAsString());
|
||||
bts_assert_d(token.size() < 255-8);
|
||||
AuthToken result;
|
||||
result.set_token(token);
|
||||
return result;
|
||||
}
|
||||
AuthToken generate_wheel_token() {
|
||||
|
||||
AuthToken generate_wheel_token()
|
||||
{
|
||||
api::user::TokenPayload payload;
|
||||
payload.set_date(datetime::ll_now());
|
||||
payload.set_id(99999);
|
||||
payload.set_wheel(true);
|
||||
session_manager().add_or_replace_session(payload);
|
||||
auto token = encrypt(payload.SerializeAsString());
|
||||
AuthToken result;
|
||||
result.set_token(token);
|
||||
return result;
|
||||
}
|
||||
bool decode_token(const api::AuthToken& token, user::TokenPayload* payload) {
|
||||
if (token.token().empty()) return false;
|
||||
|
||||
bool decode_token(const api::AuthToken& token, user::TokenPayload* payload)
|
||||
{
|
||||
if (token.token().empty())
|
||||
return false;
|
||||
std::string temp = decrypt(token.token());
|
||||
if (payload) {
|
||||
return payload->ParseFromString(temp) && !is_expired(*payload);
|
||||
if(payload)
|
||||
{
|
||||
return payload->ParseFromString(temp) && session_manager().check_session(*payload);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// validate the token but don't return it
|
||||
user::TokenPayload payload;
|
||||
return payload.ParseFromString(temp) && !is_expired(payload);
|
||||
return payload.ParseFromString(temp) && session_manager().check_session(payload);
|
||||
}
|
||||
}
|
||||
bool is_expired(const user::TokenPayload&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
namespace bts {
|
||||
|
||||
Reference in new issue
Block a user