1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <gnutls/gnutls.h>
22#include <gnutls/x509.h>
23
24#include <gnutls/gnutls.h>
25#include <gnutls/x509.h>
26
27#if !(defined WIN32) && \
28 defined(CONFIG_TASN1) && \
29 defined(LIBGNUTLS_VERSION_NUMBER) && \
30 (LIBGNUTLS_VERSION_NUMBER >= 0x020600)
31# define QCRYPTO_HAVE_TLS_TEST_SUPPORT
32#endif
33
34#ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
35# include <libtasn1.h>
36
37# include "qemu-common.h"
38
39
40
41
42
43typedef struct QCryptoTLSTestCertReq QCryptoTLSTestCertReq;
44struct QCryptoTLSTestCertReq {
45 gnutls_x509_crt_t crt;
46
47 const char *filename;
48
49
50 const char *country;
51 const char *cn;
52 const char *altname1;
53 const char *altname2;
54 const char *ipaddr1;
55 const char *ipaddr2;
56
57
58 bool basicConstraintsEnable;
59 bool basicConstraintsCritical;
60 bool basicConstraintsIsCA;
61
62
63 bool keyUsageEnable;
64 bool keyUsageCritical;
65 int keyUsageValue;
66
67
68 bool keyPurposeEnable;
69 bool keyPurposeCritical;
70 const char *keyPurposeOID1;
71 const char *keyPurposeOID2;
72
73
74 int start_offset;
75
76 int expire_offset;
77};
78
79void test_tls_generate_cert(QCryptoTLSTestCertReq *req,
80 gnutls_x509_crt_t ca);
81void test_tls_write_cert_chain(const char *filename,
82 gnutls_x509_crt_t *certs,
83 size_t ncerts);
84void test_tls_discard_cert(QCryptoTLSTestCertReq *req);
85
86void test_tls_init(const char *keyfile);
87void test_tls_cleanup(const char *keyfile);
88
89# define TLS_CERT_REQ(varname, cavarname, \
90 country, commonname, \
91 altname1, altname2, \
92 ipaddr1, ipaddr2, \
93 basicconsenable, basicconscritical, basicconsca, \
94 keyusageenable, keyusagecritical, keyusagevalue, \
95 keypurposeenable, keypurposecritical, \
96 keypurposeoid1, keypurposeoid2, \
97 startoffset, endoffset) \
98 static QCryptoTLSTestCertReq varname = { \
99 NULL, WORKDIR #varname "-ctx.pem", \
100 country, commonname, altname1, altname2, \
101 ipaddr1, ipaddr2, \
102 basicconsenable, basicconscritical, basicconsca, \
103 keyusageenable, keyusagecritical, keyusagevalue, \
104 keypurposeenable, keypurposecritical, \
105 keypurposeoid1, keypurposeoid2, \
106 startoffset, endoffset \
107 }; \
108 test_tls_generate_cert(&varname, cavarname.crt)
109
110# define TLS_ROOT_REQ(varname, \
111 country, commonname, \
112 altname1, altname2, \
113 ipaddr1, ipaddr2, \
114 basicconsenable, basicconscritical, basicconsca, \
115 keyusageenable, keyusagecritical, keyusagevalue, \
116 keypurposeenable, keypurposecritical, \
117 keypurposeoid1, keypurposeoid2, \
118 startoffset, endoffset) \
119 static QCryptoTLSTestCertReq varname = { \
120 NULL, WORKDIR #varname "-ctx.pem", \
121 country, commonname, altname1, altname2, \
122 ipaddr1, ipaddr2, \
123 basicconsenable, basicconscritical, basicconsca, \
124 keyusageenable, keyusagecritical, keyusagevalue, \
125 keypurposeenable, keypurposecritical, \
126 keypurposeoid1, keypurposeoid2, \
127 startoffset, endoffset \
128 }; \
129 test_tls_generate_cert(&varname, NULL)
130
131extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
132
133#endif
134