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)
82 if (public_id == NULL) {
86 std::string debased64_token;
87 if (!
Debase64(token, &debased64_token)) {
97 "token_id", JSON_STRING);
101 if (token_id == NULL || blob == NULL) {
105 *public_id = token_id->string_value;
114 std::string *lease_path) {
119 std::string debased64_token;
120 if (!
Debase64(token, &debased64_token)) {
130 "token_id", JSON_STRING);
133 if (token_id == NULL || blob == NULL) {
137 std::string debased64_secret;
138 if (!
Debase64(secret, &debased64_secret)) {
146 std::string encrypted_body;
147 if (!
Debase64(blob->string_value, &encrypted_body)) {
165 if (path == NULL || expiry == NULL) {
172 if (current_time > expiry_time) {
176 *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