Skip to content

Commit 5a35728

Browse files
committed
Add a tool_verify
1 parent 81bc436 commit 5a35728

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tool/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,37 @@ static int tool_sign(int argc, const char *argv[])
132132
return EXIT_SUCCESS;
133133
}
134134

135+
static int tool_verify(int argc, const char *argv[])
136+
{
137+
libecdsaauth_key_t *key;
138+
char inbuf[1024];
139+
size_t inlen;
140+
bool verify;
141+
142+
if (argc < 4)
143+
{
144+
fprintf(stderr, "usage: ecdsatool verify privatekey.pem base64challenge base64signature\n");
145+
return EXIT_FAILURE;
146+
}
147+
148+
key = libecdsaauth_key_load(argv[1]);
149+
if (key == NULL)
150+
{
151+
fprintf(stderr, "loading key failed\n");
152+
return EXIT_FAILURE;
153+
}
154+
155+
inlen = base64_decode(argv[2], inbuf, sizeof inbuf);
156+
157+
verify = libecdsaauth_verify_base64(key, inbuf, inlen, argv[3]);
158+
159+
libecdsaauth_key_free(key);
160+
161+
printf("verified: %s\n", verify ? "true" : "false");
162+
163+
return EXIT_SUCCESS;
164+
}
165+
135166
static tool_applet_t tool_applets[];
136167

137168
static int tool_usage(int argc, const char *argv[])
@@ -156,6 +187,7 @@ static tool_applet_t tool_applets[] = {
156187
{"pubkey", tool_pubkey},
157188
{"keyinfo", tool_keyinfo},
158189
{"sign", tool_sign},
190+
{"verify", tool_verify},
159191
{"usage", tool_usage},
160192
{NULL, NULL}
161193
};

0 commit comments

Comments
 (0)