Skip to content

Commit af926a5

Browse files
committed
tool: implement sign and usage applets
1 parent 8ef3bcb commit af926a5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tool/main.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
#include <stdio.h>
2222
#include <stdlib.h>
23+
#include <string.h>
2324

2425
#include "libecdsaauth/keypair.h"
26+
#include "libecdsaauth/op.h"
2527
#include "tool-applet.h"
2628

2729
static int tool_keygen(int argc, const char *argv[])
@@ -92,12 +94,61 @@ static int tool_keyinfo(int argc, const char *argv[])
9294
return EXIT_SUCCESS;
9395
}
9496

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+
95144
/**************************************************************************************/
96145

97146
static tool_applet_t tool_applets[] = {
98147
{"keygen", tool_keygen},
99148
{"pubkey", tool_pubkey},
100149
{"keyinfo", tool_keyinfo},
150+
{"sign", tool_sign},
151+
{"usage", tool_usage},
101152
{NULL, NULL}
102153
};
103154

0 commit comments

Comments
 (0)