the new makeinfo sets the FLOAT_NAME by default.
[gnutls.git] / tests / infoaccess.c
blob910e1dd783ca828adb4fd4cc4987b56c0e4437e3
1 /*
2 * Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 * Author: Simon Josefsson
6 * This file is part of GnuTLS.
8 * GnuTLS is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GnuTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GnuTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <gnutls/gnutls.h>
31 #include <gnutls/x509.h>
33 #include "utils.h"
35 static char cert_with_aia_data[] =
36 "-----BEGIN CERTIFICATE-----\n"
37 "MIIF0DCCBLigAwIBAgIEOrZQizANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJC\n"
38 "TTEZMBcGA1UEChMQUXVvVmFkaXMgTGltaXRlZDElMCMGA1UECxMcUm9vdCBDZXJ0\n"
39 "aWZpY2F0aW9uIEF1dGhvcml0eTEuMCwGA1UEAxMlUXVvVmFkaXMgUm9vdCBDZXJ0\n"
40 "aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wMTAzMTkxODMzMzNaFw0yMTAzMTcxODMz\n"
41 "MzNaMH8xCzAJBgNVBAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBMaW1pdGVkMSUw\n"
42 "IwYDVQQLExxSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MS4wLAYDVQQDEyVR\n"
43 "dW9WYWRpcyBSb290IENlcnRpZmljYXRpb24gQ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OAFItLbe3TKbkGGew5Oanwl4Rq\n"
59 "y+/foYGEpIGBMH8xCzAJBgNVBAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBMaW1p\n"
60 "dGVkMSUwIwYDVQQLExxSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MS4wLAYD\n"
61 "VQQDEyVRdW9WYWRpcyBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggQ6tlCL\n"
62 "MA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQUFAAOCAQEAitQUtf70mpKnGdSk\n"
63 "fnIYj9lofFIk3WdvOXrEql494liwTXCYhGHoG+NpGA7O+0dQoE7/8CQfvbLO9Sf8\n"
64 "7C9TqnN7Az10buYWnuulLsS/VidQK2K6vkscPFVcQR0kvoIgR13VRH56FmjffU1R\n"
65 "cHhXHTMe/QKZnAzNCgVPx7uOpHX6Sm2xgI4JVrmcGmD+XcHXetwReNDWXcG31a0y\n"
66 "mQM6isxUJTkxgXsTIlG6Rmyhu576BGxJJnSP0nPrzDCi5upZIof4l/UO/erMkqQW\n"
67 "xFIY6iHOsfHmhIHluqmGKPJDWl0Snawe2ajlCmqnf6CHKc/yiU3U7MXi5nrQNiOK\n"
68 "SnQ2+Q==\n"
69 "-----END CERTIFICATE-----\n";
71 const gnutls_datum_t cert_with_aia = {
72 (void*)cert_with_aia_data, sizeof (cert_with_aia_data)
75 void
76 doit (void)
78 gnutls_x509_crt_t crt;
79 int ret;
80 gnutls_datum_t data;
81 unsigned int critical;
83 ret = gnutls_global_init ();
84 if (ret < 0)
86 fail ("gnutls_global_init\n");
87 exit (1);
90 ret = gnutls_x509_crt_init (&crt);
91 if (ret != 0)
93 fail ("gnutls_x509_crt_init\n");
94 exit (1);
97 ret = gnutls_x509_crt_import (crt, &cert_with_aia, GNUTLS_X509_FMT_PEM);
98 if (ret < 0)
100 fail ("gnutls_x509_crt_import\n");
101 exit (1);
104 /* test null input */
105 ret = gnutls_x509_crt_get_authority_info_access (NULL, 0, 0, NULL, NULL);
106 if (ret != GNUTLS_E_INVALID_REQUEST)
108 fail ("gnutls_x509_crt_get_authority_info_access null input\n");
109 exit (1);
112 /* test unused enum */
113 ret = gnutls_x509_crt_get_authority_info_access (crt, 0, 44, NULL, NULL);
114 if (ret != GNUTLS_E_INVALID_REQUEST)
116 fail ("gnutls_x509_crt_get_authority_info_access insane input\n");
117 exit (1);
120 /* test basic query with null output */
121 ret = gnutls_x509_crt_get_authority_info_access
122 (crt, 0, GNUTLS_IA_ACCESSMETHOD_OID, NULL, NULL);
123 if (ret < 0)
125 fail ("gnutls_x509_crt_get_authority_info_access "
126 "GNUTLS_IA_ACCESSMETHOD_OID null output critical\n");
127 exit (1);
130 /* test same as previous but also check that critical flag is
131 correct */
132 ret = gnutls_x509_crt_get_authority_info_access
133 (crt, 0, GNUTLS_IA_ACCESSMETHOD_OID, NULL, &critical);
134 if (ret < 0)
136 fail ("gnutls_x509_crt_get_authority_info_access "
137 "GNUTLS_IA_ACCESSMETHOD_OID null output\n");
138 exit (1);
141 if (critical != 0)
143 fail ("gnutls_x509_crt_get_authority_info_access "
144 "critical failed: %d\n", critical);
145 exit (1);
148 /* basic query of another type */
149 ret = gnutls_x509_crt_get_authority_info_access
150 (crt, 0, GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE, NULL, NULL);
151 if (ret < 0)
153 fail ("gnutls_x509_crt_get_authority_info_access "
154 "GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE null output\n");
155 exit (1);
158 /* basic query of another type, with out-of-bound sequence */
159 ret = gnutls_x509_crt_get_authority_info_access
160 (crt, 1, GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE, NULL, NULL);
161 if (ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
163 fail ("gnutls_x509_crt_get_authority_info_access "
164 "GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE out-of-bounds\n");
165 exit (1);
168 /* basic query and check output value */
169 ret = gnutls_x509_crt_get_authority_info_access
170 (crt, 0, GNUTLS_IA_ACCESSMETHOD_OID, &data, NULL);
171 if (ret < 0)
173 fail ("gnutls_x509_crt_get_authority_info_access "
174 "GNUTLS_IA_ACCESSMETHOD_OID\n");
175 exit (1);
178 if (memcmp ("1.3.6.1.5.5.7.48.1", data.data, data.size) != 0)
180 fail ("memcmp OCSP OID failed\n");
181 exit (1);
183 gnutls_free (data.data);
185 /* basic query of another type and check output value */
186 ret = gnutls_x509_crt_get_authority_info_access
187 (crt, 0, GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE, &data, NULL);
188 if (ret < 0)
190 fail ("gnutls_x509_crt_get_authority_info_access "
191 "GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE\n");
192 exit (1);
195 if (memcmp ("uniformResourceIdentifier", data.data, data.size) != 0)
197 fail ("memcmp URI failed\n");
198 exit (1);
200 gnutls_free (data.data);
202 /* specific query */
203 ret = gnutls_x509_crt_get_authority_info_access
204 (crt, 0, GNUTLS_IA_URI, &data, NULL);
205 if (ret < 0)
207 fail ("gnutls_x509_crt_get_authority_info_access GNUTLS_IA_URI\n");
208 exit (1);
211 if (memcmp ("https://ocsp.quovadisoffshore.com", data.data, data.size) != 0)
213 fail ("memcmp URI value failed\n");
214 exit (1);
216 gnutls_free (data.data);
218 /* even more specific query */
219 ret = gnutls_x509_crt_get_authority_info_access
220 (crt, 0, GNUTLS_IA_OCSP_URI, &data, NULL);
221 if (ret < 0)
223 fail ("gnutls_x509_crt_get_authority_info_access GNUTLS_IA_OCSP_URI\n");
224 exit (1);
227 if (memcmp ("https://ocsp.quovadisoffshore.com", data.data, data.size) != 0)
229 fail ("memcmp URI value failed\n");
230 exit (1);
232 gnutls_free (data.data);
234 gnutls_x509_crt_deinit (crt);
236 gnutls_global_deinit ();