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()) {
54 *public_token_id = key_id + path;
58 if (std::numeric_limits<uint64_t>::max() - max_lease_time < current_time) {
62 const std::string expiry(
StringifyUint(current_time + max_lease_time));
64 std::string encrypted_body;
66 "{\"path\" : \"" + path +
"\", \"expiry\" : \"" + expiry +
"\"}",
67 *secret, &encrypted_body)) {
71 *session_token =
Base64(
"{\"token_id\" : \"" + *public_token_id
72 +
"\", \"blob\" : \"" +
Base64(encrypted_body)
83 if (public_id == NULL) {
87 std::string debased64_token;
88 if (!
Debase64(token, &debased64_token)) {
99 "token_id", JSON_STRING);
103 if (token_id == NULL || blob == NULL) {
107 *public_id = token_id->string_value;
116 std::string *lease_path) {
121 std::string debased64_token;
122 if (!
Debase64(token, &debased64_token)) {
133 "token_id", JSON_STRING);
136 if (token_id == NULL || blob == NULL) {
140 std::string debased64_secret;
141 if (!
Debase64(secret, &debased64_secret)) {
150 std::string encrypted_body;
151 if (!
Debase64(blob->string_value, &encrypted_body)) {
169 if (path == NULL || expiry == NULL) {
174 const uint64_t expiry_time =
String2Uint64(expiry->string_value);
176 if (current_time > expiry_time) {
180 *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