summaryrefslogtreecommitdiff
path: root/tests/infoaccess.c
blob: 71189ed51f1e538b4c9991a51ea44f775123d3b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
 * Copyright (C) 2011-2012 Free Software Foundation, Inc.
 *
 * Author: Simon Josefsson
 *
 * This file is part of GnuTLS.
 *
 * GnuTLS is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * GnuTLS is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GnuTLS; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>

#include "utils.h"

static char cert_with_aia_data[] =
    "-----BEGIN CERTIFICATE-----\n"
    "MIIF0DCCBLigAwIBAgIEOrZQizANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJC\n"
    "TTEZMBcGA1UEChMQUXVvVmFkaXMgTGltaXRlZDElMCMGA1UECxMcUm9vdCBDZXJ0\n"
    "aWZpY2F0aW9uIEF1dGhvcml0eTEuMCwGA1UEAxMlUXVvVmFkaXMgUm9vdCBDZXJ0\n"
    "aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wMTAzMTkxODMzMzNaFw0yMTAzMTcxODMz\n"
    "MzNaMH8xCzAJBgNVBAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBMaW1pdGVkMSUw\n"
    "IwYDVQQLExxSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MS4wLAYDVQQDEyVR\n"
    "dW9WYWRpcyBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIIBIjANBgkqhkiG\n"
    "9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv2G1lVO6V/z68mcLOhrfEYBklbTRvM16z/Yp\n"
    "li4kVEAkOPcahdxYTMukJ0KX0J+DisPkBgNbAKVRHnAEdOLB1Dqr1607BxgFjv2D\n"
    "rOpm2RgbaIr1VxqYuvXtdj182d6UajtLF8HVj71lODqV0D1VNk7feVcxKh7YWWVJ\n"
    "WCCYfqtffp/p1k3sg3Spx2zY7ilKhSoGFPlU5tPaZQeLYzcS19Dsw3sgQUSj7cug\n"
    "F+FxZc4dZjH3dgEZyH0DWLaVSR2mEiboxgx24ONmy+pdpibu5cxfvWenAScOospU\n"
    "xbF6lR1xHkopigPcakXBpBlebzbNw6Kwt/5cOOJSvPhEQ+aQuwIDAQABo4ICUjCC\n"
    "Ak4wPQYIKwYBBQUHAQEEMTAvMC0GCCsGAQUFBzABhiFodHRwczovL29jc3AucXVv\n"
    "dmFkaXNvZmZzaG9yZS5jb20wDwYDVR0TAQH/BAUwAwEB/zCCARoGA1UdIASCAREw\n"
    "ggENMIIBCQYJKwYBBAG+WAABMIH7MIHUBggr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Xi5nrQNiOK\n"
    "SnQ2+Q==\n" "-----END CERTIFICATE-----\n";

const gnutls_datum_t cert_with_aia = {
	(void *) cert_with_aia_data, sizeof(cert_with_aia_data)
};

void doit(void)
{
	gnutls_x509_crt_t crt;
	int ret;
	gnutls_datum_t data;
	unsigned int critical;

	ret = global_init();
	if (ret < 0) {
		fail("global_init\n");
		exit(1);
	}

	ret = gnutls_x509_crt_init(&crt);
	if (ret != 0) {
		fail("gnutls_x509_crt_init\n");
		exit(1);
	}

	ret =
	    gnutls_x509_crt_import(crt, &cert_with_aia,
				   GNUTLS_X509_FMT_PEM);
	if (ret < 0) {
		fail("gnutls_x509_crt_import\n");
		exit(1);
	}

	/* test null input */
	ret =
	    gnutls_x509_crt_get_authority_info_access(NULL, 0, 0, NULL,
						      NULL);
	if (ret != GNUTLS_E_INVALID_REQUEST) {
		fail("gnutls_x509_crt_get_authority_info_access null input\n");
		exit(1);
	}

	/* test unused enum */
	ret =
	    gnutls_x509_crt_get_authority_info_access(crt, 0, 44, NULL,
						      NULL);
	if (ret != GNUTLS_E_INVALID_REQUEST) {
		fail("gnutls_x509_crt_get_authority_info_access insane input\n");
		exit(1);
	}

	/* test basic query with null output */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 0, GNUTLS_IA_ACCESSMETHOD_OID, NULL, NULL);
	if (ret < 0) {
		fail("gnutls_x509_crt_get_authority_info_access "
		     "GNUTLS_IA_ACCESSMETHOD_OID null output critical\n");
		exit(1);
	}

	/* test same as previous but also check that critical flag is
	   correct */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 0, GNUTLS_IA_ACCESSMETHOD_OID, NULL, &critical);
	if (ret < 0) {
		fail("gnutls_x509_crt_get_authority_info_access "
		     "GNUTLS_IA_ACCESSMETHOD_OID null output\n");
		exit(1);
	}

	if (critical != 0) {
		fail("gnutls_x509_crt_get_authority_info_access "
		     "critical failed: %d\n", critical);
		exit(1);
	}

	/* basic query of another type */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 0, GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE, NULL,
	     NULL);
	if (ret < 0) {
		fail("gnutls_x509_crt_get_authority_info_access "
		     "GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE null output\n");
		exit(1);
	}

	/* basic query of another type, with out-of-bound sequence */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 1, GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE, NULL,
	     NULL);
	if (ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) {
		fail("gnutls_x509_crt_get_authority_info_access "
		     "GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE out-of-bounds\n");
		exit(1);
	}

	/* basic query and check output value */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 0, GNUTLS_IA_ACCESSMETHOD_OID, &data, NULL);
	if (ret < 0) {
		fail("gnutls_x509_crt_get_authority_info_access "
		     "GNUTLS_IA_ACCESSMETHOD_OID\n");
		exit(1);
	}

	if (memcmp("1.3.6.1.5.5.7.48.1", data.data, data.size) != 0) {
		fail("memcmp OCSP OID failed\n");
		exit(1);
	}
	gnutls_free(data.data);

	/* basic query of another type and check output value */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 0, GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE, &data,
	     NULL);
	if (ret < 0) {
		fail("gnutls_x509_crt_get_authority_info_access "
		     "GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE\n");
		exit(1);
	}

	if (memcmp("uniformResourceIdentifier", data.data, data.size) != 0) {
		fail("memcmp URI failed\n");
		exit(1);
	}
	gnutls_free(data.data);

	/* specific query */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 0, GNUTLS_IA_URI, &data, NULL);
	if (ret < 0) {
		fail("gnutls_x509_crt_get_authority_info_access GNUTLS_IA_URI\n");
		exit(1);
	}

	if (memcmp
	    ("https://ocsp.quovadisoffshore.com", data.data,
	     data.size) != 0) {
		fail("memcmp URI value failed\n");
		exit(1);
	}
	gnutls_free(data.data);

	/* even more specific query */
	ret = gnutls_x509_crt_get_authority_info_access
	    (crt, 0, GNUTLS_IA_OCSP_URI, &data, NULL);
	if (ret < 0) {
		fail("gnutls_x509_crt_get_authority_info_access GNUTLS_IA_OCSP_URI\n");
		exit(1);
	}

	if (memcmp
	    ("https://ocsp.quovadisoffshore.com", data.data,
	     data.size) != 0) {
		fail("memcmp URI value failed\n");
		exit(1);
	}
	gnutls_free(data.data);

	gnutls_x509_crt_deinit(crt);

	gnutls_global_deinit();

}