2 * Copyright (C) 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
18 * Author: Daniel P. Berrange <berrange@redhat.com>
21 #ifndef TESTS_CRYPTO_TLS_X509_HELPERS_H
22 #define TESTS_CRYPTO_TLS_X509_HELPERS_H
24 #include <gnutls/gnutls.h>
25 #include <gnutls/x509.h>
30 * This contains parameter about how to generate
33 typedef struct QCryptoTLSTestCertReq QCryptoTLSTestCertReq
;
34 struct QCryptoTLSTestCertReq
{
35 gnutls_x509_crt_t crt
;
39 /* Identifying information */
47 /* Basic constraints */
48 bool basicConstraintsEnable
;
49 bool basicConstraintsCritical
;
50 bool basicConstraintsIsCA
;
54 bool keyUsageCritical
;
57 /* Key purpose (aka Extended key usage) */
58 bool keyPurposeEnable
;
59 bool keyPurposeCritical
;
60 const char *keyPurposeOID1
;
61 const char *keyPurposeOID2
;
63 /* zero for current time, or non-zero for hours from now */
65 /* zero for 24 hours from now, or non-zero for hours from now */
69 void test_tls_generate_cert(QCryptoTLSTestCertReq
*req
,
70 gnutls_x509_crt_t ca
);
71 void test_tls_write_cert_chain(const char *filename
,
72 gnutls_x509_crt_t
*certs
,
74 void test_tls_discard_cert(QCryptoTLSTestCertReq
*req
);
76 void test_tls_init(const char *keyfile
);
77 void test_tls_cleanup(const char *keyfile
);
79 # define TLS_CERT_REQ(varname, cavarname, \
80 country, commonname, \
83 basicconsenable, basicconscritical, basicconsca, \
84 keyusageenable, keyusagecritical, keyusagevalue, \
85 keypurposeenable, keypurposecritical, \
86 keypurposeoid1, keypurposeoid2, \
87 startoffset, endoffset) \
88 static QCryptoTLSTestCertReq varname = { \
89 NULL, WORKDIR #varname "-ctx.pem", \
90 country, commonname, altname1, altname2, \
92 basicconsenable, basicconscritical, basicconsca, \
93 keyusageenable, keyusagecritical, keyusagevalue, \
94 keypurposeenable, keypurposecritical, \
95 keypurposeoid1, keypurposeoid2, \
96 startoffset, endoffset \
98 test_tls_generate_cert(&varname, cavarname.crt)
100 # define TLS_ROOT_REQ(varname, \
101 country, commonname, \
102 altname1, altname2, \
104 basicconsenable, basicconscritical, basicconsca, \
105 keyusageenable, keyusagecritical, keyusagevalue, \
106 keypurposeenable, keypurposecritical, \
107 keypurposeoid1, keypurposeoid2, \
108 startoffset, endoffset) \
109 static QCryptoTLSTestCertReq varname = { \
110 NULL, WORKDIR #varname "-ctx.pem", \
111 country, commonname, altname1, altname2, \
113 basicconsenable, basicconscritical, basicconsca, \
114 keyusageenable, keyusagecritical, keyusagevalue, \
115 keypurposeenable, keypurposecritical, \
116 keypurposeoid1, keypurposeoid2, \
117 startoffset, endoffset \
119 test_tls_generate_cert(&varname, NULL)
121 extern const asn1_static_node pkix_asn1_tab
[];