diff options
Diffstat (limited to 'auth.c')
| -rw-r--r-- | auth.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 200809L + #include "auth.h" #include "crealpath.h" #include "hex.h" @@ -13,6 +15,7 @@ #include <stdint.h> #include <stdio.h> #include <string.h> +#include <time.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> @@ -171,8 +174,24 @@ static int generate_cookie(const char *const name, const char *const key, unsigned char dkey[KEYLEN]; int ret = -1; char *jwt = NULL; + time_t t = time(NULL); + + if (t == (time_t)-1) + { + fprintf(stderr, "%s: time(3): %s\n", __func__, strerror(errno)); + goto end; + } - if (hex_decode(key, dkey, sizeof dkey)) + t += 365 * 24 * 60 * 60; + + struct tm tm; + + if (!localtime_r(&t, &tm)) + { + fprintf(stderr, "%s: localtime_r(3): %s\n", __func__, strerror(errno)); + goto end; + } + else if (hex_decode(key, dkey, sizeof dkey)) { fprintf(stderr, "%s: hex_decode failed\n", __func__); goto end; @@ -182,7 +201,7 @@ static int generate_cookie(const char *const name, const char *const key, fprintf(stderr, "%s: jwt_encode failed\n", __func__); goto end; } - else if (!(*cookie = http_cookie_create(name, jwt))) + else if (!(*cookie = http_cookie_create(name, jwt, &tm))) { fprintf(stderr, "%s: http_cookie_create failed\n", __func__); goto end; |
