diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-09-14 11:10:11 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-09-14 11:10:11 +0000 |
commit | b0a03eeebfdedbb7b0070ef00514f321aafa49db (patch) | |
tree | 06233b8dc0c1bf8ee580367e772c9951a3d7cee6 /src/identity-token/gnunet-identity-token.c | |
parent | 134da182130592c78bdb5d348826825665a2ffab (diff) | |
download | gnunet-b0a03eeebfdedbb7b0070ef00514f321aafa49db.tar.gz gnunet-b0a03eeebfdedbb7b0070ef00514f321aafa49db.zip |
- revert plugin move. Add new identity-token
Diffstat (limited to 'src/identity-token/gnunet-identity-token.c')
-rw-r--r-- | src/identity-token/gnunet-identity-token.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/identity-token/gnunet-identity-token.c b/src/identity-token/gnunet-identity-token.c new file mode 100644 index 000000000..ad4aae78a --- /dev/null +++ b/src/identity-token/gnunet-identity-token.c | |||
@@ -0,0 +1,114 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_util_lib.h" | ||
3 | #include <jansson.h> | ||
4 | #include "gnunet_signatures.h" | ||
5 | |||
6 | /** | ||
7 | * The token | ||
8 | */ | ||
9 | static char* token; | ||
10 | |||
11 | /** | ||
12 | * Weather to print the token | ||
13 | */ | ||
14 | static int print_token; | ||
15 | |||
16 | static void | ||
17 | run (void *cls, | ||
18 | char *const *args, | ||
19 | const char *cfgfile, | ||
20 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
21 | { | ||
22 | char* payload; | ||
23 | char* header; | ||
24 | //Get token parts | ||
25 | char* header_b64 = strtok (token, "."); | ||
26 | char* payload_b64 = strtok(NULL, "."); | ||
27 | char* signature_b32 = strtok(NULL, "."); | ||
28 | const char* keystring; | ||
29 | char* data; | ||
30 | json_t *payload_json; | ||
31 | json_t *keystring_json; | ||
32 | json_error_t error; | ||
33 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | ||
34 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; | ||
35 | struct GNUNET_CRYPTO_EcdsaSignature sig; | ||
36 | //Decode payload | ||
37 | GNUNET_STRINGS_base64_decode (payload_b64, | ||
38 | strlen (payload_b64), | ||
39 | &payload); | ||
40 | //Decode header | ||
41 | GNUNET_STRINGS_base64_decode (header_b64, | ||
42 | strlen (header_b64), | ||
43 | &header); | ||
44 | if (NULL == token) | ||
45 | return; | ||
46 | |||
47 | |||
48 | GNUNET_asprintf(&data, | ||
49 | "%s,%s", | ||
50 | header_b64, | ||
51 | payload_b64); | ||
52 | char *val = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + strlen (data)); | ||
53 | purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose*)val; | ||
54 | purpose->size = htonl(sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + strlen (data)); | ||
55 | purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN); | ||
56 | memcpy (&purpose[1], data, strlen(data)); | ||
57 | |||
58 | |||
59 | payload_json = json_loads (payload, 0, &error); | ||
60 | if ((NULL == payload_json) || !json_is_object (payload_json)) | ||
61 | { | ||
62 | return; | ||
63 | } | ||
64 | keystring_json = json_object_get (payload_json, "iss"); | ||
65 | if (!json_is_string (keystring_json)) | ||
66 | { | ||
67 | return; | ||
68 | } | ||
69 | keystring = json_string_value (keystring_json); | ||
70 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (keystring, | ||
71 | strlen (keystring), | ||
72 | &key)) | ||
73 | { | ||
74 | return; | ||
75 | } | ||
76 | GNUNET_STRINGS_string_to_data (signature_b32, | ||
77 | strlen (signature_b32), | ||
78 | &sig, | ||
79 | sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); | ||
80 | |||
81 | if (print_token) { | ||
82 | printf ("Token:\nHeader:\t\t%s\nPayload:\t%s\nSignature:\t%s\n", header, payload, keystring); | ||
83 | } | ||
84 | |||
85 | if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN, | ||
86 | purpose, | ||
87 | &sig, | ||
88 | &key)) | ||
89 | { | ||
90 | printf("Signature not OK!\n"); | ||
91 | return; | ||
92 | } | ||
93 | printf("Signature OK!\n"); | ||
94 | return; | ||
95 | } | ||
96 | int | ||
97 | main(int argc, char *const argv[]) | ||
98 | { | ||
99 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
100 | {'t', "token", NULL, | ||
101 | gettext_noop ("GNUid token"), 1, | ||
102 | &GNUNET_GETOPT_set_string, &token}, | ||
103 | {'p', "print", NULL, | ||
104 | gettext_noop ("Print token contents"), 0, | ||
105 | &GNUNET_GETOPT_set_one, &print_token}, | ||
106 | |||
107 | GNUNET_GETOPT_OPTION_END | ||
108 | }; | ||
109 | return GNUNET_PROGRAM_run (argc, argv, "ct", | ||
110 | "ct", options, | ||
111 | &run, NULL); | ||
112 | } | ||
113 | |||
114 | |||