keycodes work, need some documentation

This commit is contained in:
Kevin Darby committed 2019-06-06 16:40:32 -04:00
1 parent 0da6b2cc3e
commit 8a1d49733e
5 files changed
+31 -10

No files matched your search

+3 -3
View File
@@ -1,8 +1,8 @@
#nusers: 2
#nusers: 1
#expires: 2019-Sep-30 00:00:00 637053984000000000
#generation_time: 2019-Jun-06 17:30:16.234397 5248640408589731874
#generation_time: 2019-Jun-06 19:57:36.339686 5248640496990784764
EncryptedKeyCode {
value {
keycode: "-----BEGIN BTS-----\njkMxNGzarPWcVi0cMbpXa9KkqNKAj3tLVcb5CtACLu78F6RYdpQOJq8Rrt6TQJ4o\nxJdHyAzPwhr/KR/8EMcqWuc5WdailgqoHq+VNhVMD2lVmdMGrIlvLYWzKqgPIvBL\nMgB9hWCMq8vC1JEXmLWgAg9pLcS0LCvE+ydUm3nLdL3kEmfLmbcYfN0FaSBIFieN\n6BQZyL23vmKGGuG5TzJpW9ClRQ8I/iQUGDu3FDTbaEHlVgBrD5NHzQszQ6JKgvGr\ncLMC9gyaI0oaY4AqT/d/img7NMehLdpG4MPsqQXW1iuRxAnI0aJYwXd9WSpCmR+W\nnZynJGKRzWKwlfKspYzXtQ==\n-----END BTS-----\n"
keycode: "JeCTIruFKQ79vsp7EciymRICr+Hl89z53lFT6+KZGkRRFl0+M0NiXwU9xA3pN9wDya1CfLUHIZtJ0vlH3FmJGknD+AzXeRM97teuyjRAEOxiKtoDTU/vVlPTOdsB2vTv4cdkwDn3mKdaz2uxDs8HPNyJGBCJSv30I/BN/IhfuHMNUo7AfNl0tuCduuqu+ZdMyDuKm1cGXKzORMpOWSHH+XgPleL3ms/tndCtk0eMpNS+sxZ7EHaqT6gNbnxwfDGeifDdGxWKHqmO3mPS34+VW/njdre3tXOZMVi90N9dkoAIrToV0wpRk7JPT6BcQL5+Y45bGWqFktWqH3dp2X3doQ=="
}
}
+7 -4
View File
@@ -23,13 +23,15 @@ namespace api {
namespace auth {
const std::string AuthSessionManager::PUBLIC_KEY =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAseguRgLD88QdhK0agy8f"
"-----BEGIN PUBLIC KEY-----\n"
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAseguRgLD88QdhK0agy8f"
"gz3SXp/hmp377+Q+z3OQqGG5kWyKnQfkAQDFeSv8o1iwSQupN0D1QOXyDnV1jmue"
"rqTitasGeq4AwKLhY89O/VuXc+URAO+HZ7EqVWfb3Nv4EOZRiiVsxmVBkld73Rcy"
"UAS4OXh4jDtE8IzOoXB7HhlMPBIAkueqdyy/v9zamzKrxPzWd+IW/IYEdCrUS8ES"
"mxOkeadSHVeH2nlHVREdktE3wKRd3fZ3OkyGaHnUPxBoUW1Ex57BpwdMGUqLZ3W2"
"92yQa/32dsLocoTri4iiImvQ/0JvfhnY9MDTZnmIgb8bPWSvPblQN0RR9OkRDFT9"
"3QIDAQAB";
"3QIDAQAB"
"\n-----END PUBLIC KEY-----\n";
AuthSessionManager::AuthSessionManager() : _map(), _nusers(), _expiration()
{
@@ -63,7 +65,8 @@ bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& t
bool AuthSessionManager::check_session(const api::user::TokenPayload& tok)
{
if(datetime::ll_now() < _expiration)
auto now = datetime::ll_now();
if(datetime::ll_diff_in_us(now, _expiration) > 0)
{
if(tok.wheel())
return true;
@@ -71,7 +74,7 @@ bool AuthSessionManager::check_session(const api::user::TokenPayload& tok)
if(it != _map.end())
{
return google::protobuf::util::MessageDifferencer::Equivalent(tok, it->second.token)
&& (tok.date() < _expiration);
&& datetime::ll_diff_in_us(tok.date(), _expiration) > 0;
}
}
return false;
+1 -1
View File
@@ -19,7 +19,7 @@ bool decrypt_keycode(const bts::crypto::PublicKey& public_key, const bts::config
bts::config::KeyCode* dk)
{
std::stringstream kss, out;
kss << kc.keycode();
kss << "-----BEGIN BTS-----\n" + kc.keycode() + "\n-----END BTS-----\n";
if(public_key.decrypt(kss, out))
{
bts::config::KeyCode kc;
+1
View File
@@ -154,6 +154,7 @@ bool encrypt_decrypt_function(const std::iostream& in_dat, std::iostream& out_da
encrypt_decrypt_init* init_function, encrypt_decrypt* function,
openssl::EVP_PKEY* key, bool encrypt)
{
UNUSED(encrypt);
openssl::EVP_PKEY_CTX* ctx = openssl::EVP_PKEY_CTX_new(key, 0);
bts_assert(ctx);
if(init_function)
+19 -2
View File
@@ -16,6 +16,7 @@
#include <boost/date_time/local_time/local_time.hpp>
#include <boost/tokenizer.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/timestamp.pb.h>
@@ -147,6 +148,17 @@ void write_keycode(const std::string& users, const std::string& expiration, bts:
kc.set_generation_time(now);
}
void eraseAllSubStr(std::string& mainStr, const std::string& toErase)
{
size_t pos = std::string::npos;
// Search for the substring in string in a loop untill nothing is found
while ((pos = mainStr.find(toErase) )!= std::string::npos)
{
// If found then erase it from string
mainStr.erase(pos, toErase.length());
}
}
int encrypt(const std::string& keyfile, const std::string& pass, const std::string& users, const std::string& expiration)
{
@@ -176,7 +188,12 @@ int encrypt(const std::string& keyfile, const std::string& pass, const std::stri
//int ret = openssl::RSA_private_encrypt(sz-1, pay, &buffer[0], key->pkey.rsa, RSA_PKCS1_PADDING);
EncryptedKeyCode ekc;
ekc.set_keycode(encrypted.str());
auto kcstr = encrypted.str();
eraseAllSubStr(kcstr,"-----BEGIN BTS-----\n");
eraseAllSubStr(kcstr, "\n-----END BTS-----\n");
kcstr.erase( std::remove(kcstr.begin(), kcstr.end(), '\n'), kcstr.end() );
//kcstr = boost::replace_all_copy<string>(kcstr, "\n", "\\n");
ekc.set_keycode(kcstr);
std::string pb;
google::protobuf::TextFormat::PrintToString(ekc, &pb);
std::cout << std::endl << std::endl;
@@ -217,7 +234,7 @@ int decode(const std::vector<std::string>& args)
std::fstream fs(source);
//google::protobuf::io::IstreamInputStream pay_stream(&fs);
//google::protobuf::TextFormat::Parse(&pay_stream, &ekc);
std::string str((std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>());
std::string str((std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>());
config::internal::initialize_for_test(str);
ekc = config::get<bts::config::EncryptedKeyCode>();