diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-19 20:13:08 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-19 20:13:08 +0800 |
commit | e594d063888db9f36a4682bc31348cea952eadaa (patch) | |
tree | b899fa56ce1f2a05b0cafb59b868e5fc406d7e39 /sessiontoken.h | |
parent | 69ff68be8fa52ac741146789f7be024ada28a4ad (diff) |
First attempt to validate session token
Function & variable names are changed for consistency & conventions.
Tries to print out shop name from referer header, and the session token
details.
Diffstat (limited to 'sessiontoken.h')
-rw-r--r-- | sessiontoken.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sessiontoken.h b/sessiontoken.h new file mode 100644 index 0000000..ec7a462 --- /dev/null +++ b/sessiontoken.h @@ -0,0 +1,22 @@ +#include <jwt.h> + +static inline bool sessiontoken_isvalid(const char *token, const char *secret) +{ + const size_t key_len = strlen(secret) / 2; + unsigned char key[key_len]; + for (size_t i = 0; i < key_len; i++) { + char hex[3] = { [2] = '\0' }; + strncpy(hex, &secret[i], 2); + key[i] = strtol(hex, NULL, 16); + } + jwt_t *jwt = NULL; + jwt_decode(&jwt, token, key, key_len); + printf("exp: %s\n", jwt_get_grant(jwt, "exp")); + printf("nbf: %s\n", jwt_get_grant(jwt, "nbf")); + printf("iss: %s\n", jwt_get_grant(jwt, "iss")); + printf("dest: %s\n", jwt_get_grant(jwt, "dest")); + printf("aud: %s\n", jwt_get_grant(jwt, "aud")); + printf("sub: %s\n", jwt_get_grant(jwt, "sub")); + jwt_free(jwt); + return false; +} |