Added a warning message and facility to allow concurrent logins in a keycode
This commit is contained in:
1 parent
589476eb02
commit
c09ef31061
12 files changed
+59
-25
No files matched your search
@@ -48,7 +48,7 @@ std::string KeyCode::helpstr ()
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "\n"
|
||||
<< "ENCODE -keyfile:[keyfile] -pass:password -users:<nusers> -expiration:<2020-05-18> [-ip:<ip_address>] [-port:<spark_port>]\n "
|
||||
<< "ENCODE -keyfile:[keyfile] -pass:password -users:<nusers> -expiration:<2020-05-18> [-ip:<ip_address>] [-port:<spark_port>] [-allow_concurrent]\n "
|
||||
<< "DECODE -keyfile:[keyfile] -pass:password -source:[file] \n "
|
||||
<< "KEYGEN -keyfile:[keyfile_prefix]\n "
|
||||
<< "CHECKIPS \n ";
|
||||
@@ -73,7 +73,7 @@ std::string parse_date (std::string const &date)
|
||||
|
||||
void get_cmd(const std::vector<std::string>& args, std::string& keyfile, std::string& pass,
|
||||
std::string& users, std::string& expiration, std::string* source = nullptr,
|
||||
std::string* ip = nullptr, std::string* port = nullptr)
|
||||
std::string* ip = nullptr, std::string* port = nullptr, bool* allow_concurrent = nullptr)
|
||||
{
|
||||
for(size_t i = 1; i < args.size(); i++)
|
||||
{
|
||||
@@ -103,7 +103,11 @@ void get_cmd(const std::vector<std::string>& args, std::string& keyfile, std::st
|
||||
|
||||
size_t p_pos = args[i].find("-port:");
|
||||
if(port && p_pos != args[i].npos)
|
||||
*port = args[i].substr(p_pos+6);
|
||||
*port = args[i].substr(p_pos+6);
|
||||
|
||||
size_t c_pos = args[i].find("-allow_concurrent");
|
||||
if(allow_concurrent && c_pos != args[i].npos)
|
||||
*allow_concurrent = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +163,7 @@ int keygen(const std::vector<std::string>& args)
|
||||
// }
|
||||
|
||||
void write_keycode(const std::string& users, const std::string& expiration,
|
||||
const std::string& ip, const std::string& port, bts::config::KeyCode& kc)
|
||||
const std::string& ip, const std::string& port, bool concurrent, bts::config::KeyCode& kc)
|
||||
{
|
||||
std::ostringstream out_stream;
|
||||
|
||||
@@ -174,6 +178,7 @@ void write_keycode(const std::string& users, const std::string& expiration,
|
||||
bts_assert_msg(ip != "127.0.0.1", "you can't generate a keycode for loopback, just leave the parameter blank");
|
||||
kc.set_ip(ip);
|
||||
kc.set_port(port);
|
||||
kc.set_allow_concurrent(concurrent);
|
||||
}
|
||||
|
||||
void eraseAllSubStr(std::string& mainStr, const std::string& toErase)
|
||||
@@ -189,7 +194,7 @@ void eraseAllSubStr(std::string& mainStr, const std::string& toErase)
|
||||
}
|
||||
|
||||
int encrypt(const std::string& keyfile, const std::string& pass, const std::string& users,
|
||||
const std::string& expiration, const std::string& ip, const std::string& port)
|
||||
const std::string& expiration, const std::string& ip, const std::string& port, bool concurrent)
|
||||
{
|
||||
std::string protobuf;
|
||||
|
||||
@@ -206,7 +211,7 @@ int encrypt(const std::string& keyfile, const std::string& pass, const std::stri
|
||||
PrivateKeyPtr key = PrivateKey::read_file(keyfile, &cache);
|
||||
|
||||
bts::config::KeyCode kc;
|
||||
write_keycode(users, expiration, ip, port, kc);
|
||||
write_keycode(users, expiration, ip, port, concurrent, kc);
|
||||
if(google::protobuf::TextFormat::PrintToString(kc, &kc_string))
|
||||
{
|
||||
oss << kc_string;
|
||||
@@ -227,7 +232,8 @@ int encrypt(const std::string& keyfile, const std::string& pass, const std::stri
|
||||
google::protobuf::TextFormat::PrintToString(ekc, &pb);
|
||||
std::cout << std::endl << std::endl;
|
||||
std::cout << "#nusers: " << users << std::endl;
|
||||
std::cout << "#expires: " << datetime::simple_date_time_string(datetime::ll_to_ptime(kc.expiration())) << " " << std::to_string(kc.expiration()) << std::endl;
|
||||
std::cout << "#allow concurrent : " << (kc.allow_concurrent() ? "true" : "false") << std::endl;
|
||||
std::cout << "#expires: " << datetime::simple_date_time_string(datetime::ll_to_ptime(kc.expiration())) << " " << std::to_string(kc.expiration()) << std::endl;
|
||||
std::cout << "#generation_time: " << datetime::simple_date_time_string(datetime::ll_to_ptime(kc.generation_time())) << " " << std::to_string(kc.generation_time()) << std::endl;
|
||||
std::cout << "EncryptedKeyCode {" << std::endl;
|
||||
std::cout << " value {" << std::endl;
|
||||
@@ -242,10 +248,10 @@ int encrypt(const std::string& keyfile, const std::string& pass, const std::stri
|
||||
|
||||
int encode(const std::vector<std::string>& args)
|
||||
{
|
||||
std::string keyfile, pass, users, expiration, ip, port;
|
||||
get_cmd(args, keyfile, pass, users, expiration, nullptr, &ip, &port);
|
||||
std::string keyfile, pass, users, expiration, ip, port; bool concurrent = false;
|
||||
get_cmd(args, keyfile, pass, users, expiration, nullptr, &ip, &port, &concurrent);
|
||||
|
||||
return encrypt(keyfile, pass, users, expiration, ip, port);
|
||||
return encrypt(keyfile, pass, users, expiration, ip, port, concurrent);
|
||||
}
|
||||
|
||||
int decode(const std::vector<std::string>& args)
|
||||
|
||||
Reference in new issue
Block a user