]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/test-x509v3.c
tests: Use longer timeout in test_ap_wps_er_add_enrollee
[thirdparty/hostap.git] / tests / test-x509v3.c
1 /*
2 * Testing tool for X.509v3 routines
3 * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "includes.h"
10
11 #include "common.h"
12 #include "tls/asn1.h"
13 #include "tls/x509v3.h"
14
15 extern int wpa_debug_level;
16
17
18 int main(int argc, char *argv[])
19 {
20 char *buf;
21 size_t len;
22 struct x509_certificate *certs = NULL, *last = NULL, *cert;
23 int i, reason;
24
25 wpa_debug_level = 0;
26
27 if (argc < 3 || strcmp(argv[1], "-v") != 0) {
28 printf("usage: test_x509v3 -v <cert1.der> <cert2.der> ..\n");
29 return -1;
30 }
31
32 for (i = 2; i < argc; i++) {
33 printf("Reading: %s\n", argv[i]);
34 buf = os_readfile(argv[i], &len);
35 if (buf == NULL) {
36 printf("Failed to read '%s'\n", argv[i]);
37 return -1;
38 }
39
40 cert = x509_certificate_parse((u8 *) buf, len);
41 if (cert == NULL) {
42 printf("Failed to parse X.509 certificate\n");
43 return -1;
44 }
45
46 free(buf);
47
48 if (certs == NULL)
49 certs = cert;
50 else
51 last->next = cert;
52 last = cert;
53 }
54
55 printf("\n\nValidating certificate chain\n");
56 if (x509_certificate_chain_validate(last, certs, &reason, 0) < 0) {
57 printf("\nCertificate chain validation failed: %d\n", reason);
58 return -1;
59 }
60 printf("\nCertificate chain is valid\n");
61
62 return 0;
63 }