This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathleak.c
72 lines (51 loc) · 1.69 KB
/
leak.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "config.h"
#include <jansson.h>
#include <string.h>
#include <stdlib.h>
#include <argp.h>
#include <assert.h>
#include "../libjosec.h"
#include "../src/soft_crypto.h"
#include "jwt.h"
#include <mcheck.h>
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic push
#endif
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Winitializer-overrides"
#pragma GCC diagnostic ignored "-Woverride-init"
#pragma GCC diagnostic ignored "-Wcast-qual"
int
main (void)
{
jose_context_t ctx;
char *hmac_key = "secret";
char *jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9";
json_t *header, *claims;
int rc;
mtrace();
rc = jwt_split (jwt, &header, &claims);
assert (0 == jose_create_context (&ctx, NULL, NULL, NULL));
assert (ctx.cookie == NULL);
assert ((void *)ctx.verify_func == (void *)jose_soft_verify);
assert ((void *)ctx.sign_func == (void *)jose_soft_sign);
assert (ctx.key_container[HS256].key == NULL);
jose_key_t key;
key.alg_type = HS256;
key.key = (uint8_t *)hmac_key;
key.k_len = strlen (hmac_key);
assert (0 == jose_add_key (&ctx, key));
char *result = jwt_encode(&ctx, claims, HS256);
assert(NULL != result);
printf ("jwt: %s\n", result);
assert (0 == jwt_verify_sig (&ctx, result, HS256));
printf ("verified\n");
free (result);
json_decref (header);
json_decref (claims);
muntrace();
}
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#pragma GCC diagnostic pop
#endif