|
20 | 20 |
|
21 | 21 | #include <stdio.h> |
22 | 22 | #include <stdlib.h> |
| 23 | +#include <string.h> |
23 | 24 |
|
24 | 25 | #include "libecdsaauth/keypair.h" |
| 26 | +#include "libecdsaauth/op.h" |
25 | 27 | #include "tool-applet.h" |
26 | 28 |
|
27 | 29 | static int tool_keygen(int argc, const char *argv[]) |
@@ -92,12 +94,61 @@ static int tool_keyinfo(int argc, const char *argv[]) |
92 | 94 | return EXIT_SUCCESS; |
93 | 95 | } |
94 | 96 |
|
| 97 | +static int tool_sign(int argc, const char *argv[]) |
| 98 | +{ |
| 99 | + libecdsaauth_key_t *key; |
| 100 | + char *signature = NULL; |
| 101 | + char *in = strdup(argv[2]); |
| 102 | + size_t siglen; |
| 103 | + |
| 104 | + if (argv[1] == NULL) |
| 105 | + { |
| 106 | + fprintf(stderr, "usage: ecdsatool sign privatekey.pem base64challenge\n"); |
| 107 | + return EXIT_FAILURE; |
| 108 | + } |
| 109 | + |
| 110 | + key = libecdsaauth_key_load(argv[1]); |
| 111 | + libecdsaauth_sign_base64(key, in, strlen(in) + 1, &signature, &siglen); |
| 112 | + libecdsaauth_key_free(key); |
| 113 | + |
| 114 | + if (signature != NULL) |
| 115 | + { |
| 116 | + printf("%s\n", signature); |
| 117 | + free(signature); |
| 118 | + } |
| 119 | + else |
| 120 | + fprintf(stderr, "signing failed\n"); |
| 121 | + |
| 122 | + free(in); |
| 123 | + |
| 124 | + return EXIT_SUCCESS; |
| 125 | +} |
| 126 | + |
| 127 | +static tool_applet_t tool_applets[]; |
| 128 | + |
| 129 | +static int tool_usage(int argc, const char *argv[]) |
| 130 | +{ |
| 131 | + tool_applet_t *applet; |
| 132 | + |
| 133 | + printf("usage: ecdsatool applet [options]\n"); |
| 134 | + printf("\nthe following applets are available: "); |
| 135 | + |
| 136 | + for (applet = tool_applets; applet->name != NULL; applet++) |
| 137 | + printf("%s ", applet->name); |
| 138 | + |
| 139 | + printf("\n"); |
| 140 | + |
| 141 | + return EXIT_FAILURE; |
| 142 | +} |
| 143 | + |
95 | 144 | /**************************************************************************************/ |
96 | 145 |
|
97 | 146 | static tool_applet_t tool_applets[] = { |
98 | 147 | {"keygen", tool_keygen}, |
99 | 148 | {"pubkey", tool_pubkey}, |
100 | 149 | {"keyinfo", tool_keyinfo}, |
| 150 | + {"sign", tool_sign}, |
| 151 | + {"usage", tool_usage}, |
101 | 152 | {NULL, NULL} |
102 | 153 | }; |
103 | 154 |
|
|
0 commit comments