31 uint64_t max_lease_time, std::string* session_token,
32 std::string* public_token_id,
33 std::string* token_secret) {
34 if (session_token == NULL || public_token_id == NULL ||
35 token_secret == NULL) {
39 if (key_id.empty() && path.empty()) {
53 *public_token_id = key_id + path;
57 if (std::numeric_limits<uint64_t>::max() - max_lease_time < current_time) {
61 const std::string expiry(
StringifyUint(current_time + max_lease_time));
63 std::string encrypted_body;
65 "{\"path\" : \"" + path +
"\", \"expiry\" : \"" + expiry +
"\"}",
66 *secret, &encrypted_body)) {
70 *session_token =
Base64(
"{\"token_id\" : \"" + *public_token_id +
71 "\", \"blob\" : \"" +
Base64(encrypted_body) +
"\"}");
81 if (public_id == NULL) {
85 std::string debased64_token;
86 if (!
Debase64(token, &debased64_token)) {
95 const JSON* token_id =
100 if (token_id == NULL || blob == NULL) {
104 *public_id = token_id->string_value;
113 std::string* lease_path) {
118 std::string debased64_token;
119 if (!
Debase64(token, &debased64_token)) {
128 const JSON* token_id =
132 if (token_id == NULL || blob == NULL) {
136 std::string debased64_secret;
137 if (!
Debase64(secret, &debased64_secret)) {
145 std::string encrypted_body;
146 if (!
Debase64(blob->string_value, &encrypted_body)) {
164 if (path == NULL || expiry == NULL) {
171 if (current_time > expiry_time) {
175 *lease_path = path->string_value;
static bool Decrypt(const std::string &ciphertext, const Key &key, std::string *plaintext)
static JSON * SearchInObject(const JSON *json_object, const std::string &name, const json_type type)
static Cipher * Create(const Algorithms a)
std::string ToBase64() const
bool GenerateSessionToken(const std::string &key_id, const std::string &path, uint64_t max_lease_time, std::string *session_token, std::string *public_token_id, std::string *token_secret)
static Key * CreateRandomly(const unsigned size)
std::string StringifyUint(const uint64_t value)
bool Debase64(const string &data, string *decoded)
static JsonDocument * Create(const std::string &text)
bool GetTokenPublicId(const std::string &token, std::string *public_id)
TokenCheckResult CheckToken(const std::string &token, const std::string &secret, std::string *lease_path)
string Base64(const string &data)
bool Encrypt(const std::string &plaintext, const Key &key, std::string *ciphertext)
uint64_t String2Uint64(const string &value)
static Key * CreateFromString(const std::string &key)
const JSON * root() const