1/*	$Id: test-geofeed.c,v 1.6 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
33int outformats;
34int verbose;
35int filemode;
36int experimental;
37
38int
39main(int argc, char *argv[])
40{
41	int		 c, i, ppem = 0, verb = 0;
42	X509		*xp = NULL;
43	struct geofeed	*p;
44	unsigned char	*buf;
45	size_t		 len;
46
47
48	ERR_load_crypto_strings();
49	OpenSSL_add_all_ciphers();
50	OpenSSL_add_all_digests();
51	x509_init_oid();
52
53	while ((c = getopt(argc, argv, "pv")) != -1)
54		switch (c) {
55		case 'p':
56			if (ppem)
57				break;
58			ppem = 1;
59			break;
60		case 'v':
61			verb++;
62			break;
63		default:
64			errx(1, "bad argument %c", c);
65		}
66
67	argv += optind;
68	argc -= optind;
69
70	if (argc == 0)
71		errx(1, "argument missing");
72
73	for (i = 0; i < argc; i++) {
74		buf = load_file(argv[i], &len);
75		if ((p = geofeed_parse(&xp, argv[i], -1, buf, len)) == NULL) {
76			free(buf);
77			break;
78		}
79		if (verb)
80			geofeed_print(xp, p);
81		if (ppem) {
82			if (!PEM_write_X509(stdout, xp))
83				errx(1, "PEM_write_X509: unable to write cert");
84		}
85		free(buf);
86		geofeed_free(p);
87		X509_free(xp);
88	}
89
90	EVP_cleanup();
91	CRYPTO_cleanup_all_ex_data();
92	ERR_free_strings();
93
94	if (i < argc)
95		errx(1, "test failed for %s", argv[i]);
96
97	printf("OK\n");
98	return 0;
99}
100
101time_t
102get_current_time(void)
103{
104	return time(NULL);
105}
106