1 /* $Id: test-roa.c,v 1.26 2024/04/22 05:54:01 claudio Exp $ */
2 /*
3 * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <assert.h>
19 #include <err.h>
20 #include <inttypes.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include <openssl/err.h>
27 #include <openssl/evp.h>
28 #include <openssl/pem.h>
29 #include <openssl/x509v3.h>
30
31 #include "extern.h"
32
33 int outformats;
34 int verbose;
35 int filemode = 1;
36 int experimental;
37
38 int
main(int argc,char * argv[])39 main(int argc, char *argv[])
40 {
41 int c, i, ppem = 0, verb = 0;
42 X509 *xp = NULL;
43 struct roa *p;
44 unsigned char *buf;
45 size_t len;
46
47 ERR_load_crypto_strings();
48 OpenSSL_add_all_ciphers();
49 OpenSSL_add_all_digests();
50 x509_init_oid();
51
52 while ((c = getopt(argc, argv, "pv")) != -1)
53 switch (c) {
54 case 'p':
55 if (ppem)
56 break;
57 ppem = 1;
58 break;
59 case 'v':
60 verb++;
61 break;
62 default:
63 errx(1, "bad argument %c", c);
64 }
65
66 argv += optind;
67 argc -= optind;
68
69 if (argc == 0)
70 errx(1, "argument missing");
71
72 for (i = 0; i < argc; i++) {
73 buf = load_file(argv[i], &len);
74 if ((p = roa_parse(&xp, argv[i], -1, buf, len)) == NULL) {
75 free(buf);
76 break;
77 }
78 if (verb)
79 roa_print(xp, p);
80 if (ppem) {
81 if (!PEM_write_X509(stdout, xp))
82 errx(1, "PEM_write_X509: unable to write cert");
83 }
84 free(buf);
85 roa_free(p);
86 X509_free(xp);
87 }
88
89 EVP_cleanup();
90 CRYPTO_cleanup_all_ex_data();
91 ERR_free_strings();
92
93 if (i < argc)
94 errx(1, "test failed for %s", argv[i]);
95
96 printf("OK\n");
97 return 0;
98 }
99
100 time_t
get_current_time(void)101 get_current_time(void)
102 {
103 return time(NULL);
104 }
105