1 /* Copyright (c) 2007-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
9 #include "trunnel/ed25519_cert.h"
10 #include "lib/cc/torint.h" /* TOR_PRIdSZ */
11 #include "lib/crypt_ops/crypto_format.h"
12 #include "lib/malloc/malloc.h"
13 #include "lib/encoding/time_fmt.h"
16 main(int argc
, char **argv
)
18 ed25519_cert_t
*cert
= NULL
;
19 char rfc1123_buf
[RFC1123_TIME_LEN
+1] = "";
22 fprintf(stderr
, "Usage:\n");
23 fprintf(stderr
, "%s <path to ed25519_signing_cert file>\n", argv
[0]);
27 const char *filepath
= argv
[1];
31 ssize_t cert_body_len
= crypto_read_tagged_contents_from_file(
32 filepath
, "ed25519v1-cert",
33 &got_tag
, certbuf
, sizeof(certbuf
));
35 if (cert_body_len
<= 0) {
36 fprintf(stderr
, "crypto_read_tagged_contents_from_file failed with "
37 "error: %s\n", strerror(errno
));
42 fprintf(stderr
, "Found no tag\n");
46 if (strcmp(got_tag
, "type4") != 0) {
47 fprintf(stderr
, "Wrong tag: %s\n", got_tag
);
53 ssize_t parsed
= ed25519_cert_parse(&cert
, certbuf
, cert_body_len
);
55 fprintf(stderr
, "ed25519_cert_parse failed with return value %" TOR_PRIdSZ
60 time_t expires_at
= (time_t)cert
->exp_field
* 60 * 60;
62 printf("Expires at: %s", ctime(&expires_at
));
64 format_rfc1123_time(rfc1123_buf
, expires_at
);
65 printf("RFC 1123 timestamp: %s\n", rfc1123_buf
);
67 printf("UNIX timestamp: %ld\n", (long int)expires_at
);
69 ed25519_cert_free(cert
);