1 /*
2  * Copyright (C) 2011-2012 Free Software Foundation, Inc.
3  *
4  * Author: Nikos Mavrogiannopoulos
5  *
6  * This file is part of GnuTLS.
7  *
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.
12  *
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.
17  *
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
21  */
22 
23 /* Parts copied from GnuTLS example programs. */
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <gnutls/gnutls.h>
35 #include <gnutls/x509.h>
36 
37 #include "utils.h"
38 
39 /* gnutls_trust_list_*().
40  */
41 
tls_log_func(int level,const char * str)42 static void tls_log_func(int level, const char *str)
43 {
44 	fprintf(stderr, "<%d>| %s", level, str);
45 }
46 
47 static unsigned char ca_pem[] =
48     "-----BEGIN CERTIFICATE-----\n"
49     "MIIB5zCCAVKgAwIBAgIERiYdJzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
50     "VExTIHRlc3QgQ0EwHhcNMDcwNDE4MTMyOTExWhcNMDgwNDE3MTMyOTExWjAZMRcw\n"
51     "FQYDVQQDEw5HbnVUTFMgdGVzdCBDQTCBnDALBgkqhkiG9w0BAQEDgYwAMIGIAoGA\n"
52     "vuyYeh1vfmslnuggeEKgZAVmQ5ltSdUY7H25WGSygKMUYZ0KT74v8C780qtcNt9T\n"
53     "7EPH/N6RvB4BprdssgcQLsthR3XKA84jbjjxNCcaGs33lvOz8A1nf8p3hD+cKfRi\n"
54     "kfYSW2JazLrtCC4yRCas/SPOUxu78of+3HiTfFm/oXUCAwEAAaNDMEEwDwYDVR0T\n"
55     "AQH/BAUwAwEB/zAPBgNVHQ8BAf8EBQMDBwQAMB0GA1UdDgQWBBTpPBz7rZJu5gak\n"
56     "Viyi4cBTJ8jylTALBgkqhkiG9w0BAQUDgYEAiaIRqGfp1jPpNeVhABK60SU0KIAy\n"
57     "njuu7kHq5peUgYn8Jd9zNzExBOEp1VOipGsf6G66oQAhDFp2o8zkz7ZH71zR4HEW\n"
58     "KoX6n5Emn6DvcEH/9pAhnGxNHJAoS7czTKv/JDZJhkqHxyrE1fuLsg5Qv25DTw7+\n"
59     "PfqUpIhz5Bbm7J4=\n" "-----END CERTIFICATE-----\n";
60 const gnutls_datum_t ca = { ca_pem, sizeof(ca_pem) };
61 
62 static unsigned char cert_pem[] =
63     "-----BEGIN CERTIFICATE-----\n"
64     "MIICHjCCAYmgAwIBAgIERiYdNzALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
65     "VExTIHRlc3QgQ0EwHhcNMDcwNDE4MTMyOTI3WhcNMDgwNDE3MTMyOTI3WjAdMRsw\n"
66     "GQYDVQQDExJHbnVUTFMgdGVzdCBjbGllbnQwgZwwCwYJKoZIhvcNAQEBA4GMADCB\n"
67     "iAKBgLtmQ/Xyxde2jMzF3/WIO7HJS2oOoa0gUEAIgKFPXKPQ+GzP5jz37AR2ExeL\n"
68     "ZIkiW8DdU3w77XwEu4C5KL6Om8aOoKUSy/VXHqLnu7czSZ/ju0quak1o/8kR4jKN\n"
69     "zj2AC41179gAgY8oBAOgIo1hBAf6tjd9IQdJ0glhaZiQo1ipAgMBAAGjdjB0MAwG\n"
70     "A1UdEwEB/wQCMAAwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDwYDVR0PAQH/BAUDAweg\n"
71     "ADAdBgNVHQ4EFgQUTLkKm/odNON+3svSBxX+odrLaJEwHwYDVR0jBBgwFoAU6Twc\n"
72     "+62SbuYGpFYsouHAUyfI8pUwCwYJKoZIhvcNAQEFA4GBALujmBJVZnvaTXr9cFRJ\n"
73     "jpfc/3X7sLUsMvumcDE01ls/cG5mIatmiyEU9qI3jbgUf82z23ON/acwJf875D3/\n"
74     "U7jyOsBJ44SEQITbin2yUeJMIm1tievvdNXBDfW95AM507ShzP12sfiJkJfjjdhy\n"
75     "dc8Siq5JojruiMizAf0pA7in\n" "-----END CERTIFICATE-----\n";
76 const gnutls_datum_t cert = { cert_pem, sizeof(cert_pem) };
77 
78 static unsigned char key_pem[] =
79     "-----BEGIN RSA PRIVATE KEY-----\n"
80     "MIICXAIBAAKBgQC7ZkP18sXXtozMxd/1iDuxyUtqDqGtIFBACIChT1yj0Phsz+Y8\n"
81     "9+wEdhMXi2SJIlvA3VN8O+18BLuAuSi+jpvGjqClEsv1Vx6i57u3M0mf47tKrmpN\n"
82     "aP/JEeIyjc49gAuNde/YAIGPKAQDoCKNYQQH+rY3fSEHSdIJYWmYkKNYqQIDAQAB\n"
83     "AoGADpmARG5CQxS+AesNkGmpauepiCz1JBF/JwnyiX6vEzUh0Ypd39SZztwrDxvF\n"
84     "PJjQaKVljml1zkJpIDVsqvHdyVdse8M+Qn6hw4x2p5rogdvhhIL1mdWo7jWeVJTF\n"
85     "RKB7zLdMPs3ySdtcIQaF9nUAQ2KJEvldkO3m/bRJFEp54k0CQQDYy+RlTmwRD6hy\n"
86     "7UtMjR0H3CSZJeQ8svMCxHLmOluG9H1UKk55ZBYfRTsXniqUkJBZ5wuV1L+pR9EK\n"
87     "ca89a+1VAkEA3UmBelwEv2u9cAU1QjKjmwju1JgXbrjEohK+3B5y0ESEXPAwNQT9\n"
88     "TrDM1m9AyxYTWLxX93dI5QwNFJtmbtjeBQJARSCWXhsoaDRG8QZrCSjBxfzTCqZD\n"
89     "ZXtl807ymCipgJm60LiAt0JLr4LiucAsMZz6+j+quQbSakbFCACB8SLV1QJBAKZQ\n"
90     "YKf+EPNtnmta/rRKKvySsi3GQZZN+Dt3q0r094XgeTsAqrqujVNfPhTMeP4qEVBX\n"
91     "/iVX2cmMTSh3w3z8MaECQEp0XJWDVKOwcTW6Ajp9SowtmiZ3YDYo1LF9igb4iaLv\n"
92     "sWZGfbnU3ryjvkb6YuFjgtzbZDZHWQCo8/cOtOBmPdk=\n"
93     "-----END RSA PRIVATE KEY-----\n";
94 const gnutls_datum_t key = { key_pem, sizeof(key_pem) };
95 
96 static unsigned char server_cert_pem[] =
97     "-----BEGIN CERTIFICATE-----\n"
98     "MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
99     "VExTIHRlc3QgQ0EwHhcNMDcwNDE4MTMyOTIxWhcNMDgwNDE3MTMyOTIxWjA3MRsw\n"
100     "GQYDVQQKExJHbnVUTFMgdGVzdCBzZXJ2ZXIxGDAWBgNVBAMTD3Rlc3QuZ251dGxz\n"
101     "Lm9yZzCBnDALBgkqhkiG9w0BAQEDgYwAMIGIAoGA17pcr6MM8C6pJ1aqU46o63+B\n"
102     "dUxrmL5K6rce+EvDasTaDQC46kwTHzYWk95y78akXrJutsoKiFV1kJbtple8DDt2\n"
103     "DZcevensf9Op7PuFZKBroEjOd35znDET/z3IrqVgbtm2jFqab7a+n2q9p/CgMyf1\n"
104     "tx2S5Zacc1LWn9bIjrECAwEAAaOBkzCBkDAMBgNVHRMBAf8EAjAAMBoGA1UdEQQT\n"
105     "MBGCD3Rlc3QuZ251dGxzLm9yZzATBgNVHSUEDDAKBggrBgEFBQcDATAPBgNVHQ8B\n"
106     "Af8EBQMDB6AAMB0GA1UdDgQWBBTrx0Vu5fglyoyNgw106YbU3VW0dTAfBgNVHSME\n"
107     "GDAWgBTpPBz7rZJu5gakViyi4cBTJ8jylTALBgkqhkiG9w0BAQUDgYEAaFEPTt+7\n"
108     "bzvBuOf7+QmeQcn29kT6Bsyh1RHJXf8KTk5QRfwp6ogbp94JQWcNQ/S7YDFHglD1\n"
109     "AwUNBRXwd3riUsMnsxgeSDxYBfJYbDLeohNBsqaPDJb7XailWbMQKfAbFQ8cnOxg\n"
110     "rOKLUQRWJ0K3HyXRMhbqjdLIaQiCvQLuizo=\n" "-----END CERTIFICATE-----\n";
111 
112 const gnutls_datum_t server_cert = { server_cert_pem,
113 	sizeof(server_cert_pem)
114 };
115 
116 static unsigned char server_key_pem[] =
117     "-----BEGIN RSA PRIVATE KEY-----\n"
118     "MIICXAIBAAKBgQDXulyvowzwLqknVqpTjqjrf4F1TGuYvkrqtx74S8NqxNoNALjq\n"
119     "TBMfNhaT3nLvxqResm62ygqIVXWQlu2mV7wMO3YNlx696ex/06ns+4VkoGugSM53\n"
120     "fnOcMRP/PciupWBu2baMWppvtr6far2n8KAzJ/W3HZLllpxzUtaf1siOsQIDAQAB\n"
121     "AoGAYAFyKkAYC/PYF8e7+X+tsVCHXppp8AoP8TEZuUqOZz/AArVlle/ROrypg5kl\n"
122     "8YunrvUdzH9R/KZ7saNZlAPLjZyFG9beL/am6Ai7q7Ma5HMqjGU8kTEGwD7K+lbG\n"
123     "iomokKMOl+kkbY/2sI5Czmbm+/PqLXOjtVc5RAsdbgvtmvkCQQDdV5QuU8jap8Hs\n"
124     "Eodv/tLJ2z4+SKCV2k/7FXSKWe0vlrq0cl2qZfoTUYRnKRBcWxc9o92DxK44wgPi\n"
125     "oMQS+O7fAkEA+YG+K9e60sj1K4NYbMPAbYILbZxORDecvP8lcphvwkOVUqbmxOGh\n"
126     "XRmTZUuhBrJhJKKf6u7gf3KWlPl6ShKEbwJASC118cF6nurTjuLf7YKARDjNTEws\n"
127     "qZEeQbdWYINAmCMj0RH2P0mvybrsXSOD5UoDAyO7aWuqkHGcCLv6FGG+qwJAOVqq\n"
128     "tXdUucl6GjOKKw5geIvRRrQMhb/m5scb+5iw8A4LEEHPgGiBaF5NtJZLALgWfo5n\n"
129     "hmC8+G8F0F78znQtPwJBANexu+Tg5KfOnzSILJMo3oXiXhf5PqXIDmbN0BKyCKAQ\n"
130     "LfkcEcUbVfmDaHpvzwY9VEaoMOKVLitETXdNSxVpvWM=\n"
131     "-----END RSA PRIVATE KEY-----\n";
132 
133 static unsigned char cert_der[602] =
134     "\x30\x82\x02\x56\x30\x82\x01\xc1\xa0\x03\x02\x01\x02\x02\x04\x46"
135     "\x26\x1d\x31\x30\x0b\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05"
136     "\x30\x19\x31\x17\x30\x15\x06\x03\x55\x04\x03\x13\x0e\x47\x6e\x75"
137     "\x54\x4c\x53\x20\x74\x65\x73\x74\x20\x43\x41\x30\x1e\x17\x0d\x30"
138     "\x37\x30\x34\x31\x38\x31\x33\x32\x39\x32\x31\x5a\x17\x0d\x30\x38"
139     "\x30\x34\x31\x37\x31\x33\x32\x39\x32\x31\x5a\x30\x37\x31\x1b\x30"
140     "\x19\x06\x03\x55\x04\x0a\x13\x12\x47\x6e\x75\x54\x4c\x53\x20\x74"
141     "\x65\x73\x74\x20\x73\x65\x72\x76\x65\x72\x31\x18\x30\x16\x06\x03"
142     "\x55\x04\x03\x13\x0f\x74\x65\x73\x74\x2e\x67\x6e\x75\x74\x6c\x73"
143     "\x2e\x6f\x72\x67\x30\x81\x9c\x30\x0b\x06\x09\x2a\x86\x48\x86\xf7"
144     "\x0d\x01\x01\x01\x03\x81\x8c\x00\x30\x81\x88\x02\x81\x80\xd7\xba"
145     "\x5c\xaf\xa3\x0c\xf0\x2e\xa9\x27\x56\xaa\x53\x8e\xa8\xeb\x7f\x81"
146     "\x75\x4c\x6b\x98\xbe\x4a\xea\xb7\x1e\xf8\x4b\xc3\x6a\xc4\xda\x0d"
147     "\x00\xb8\xea\x4c\x13\x1f\x36\x16\x93\xde\x72\xef\xc6\xa4\x5e\xb2"
148     "\x6e\xb6\xca\x0a\x88\x55\x75\x90\x96\xed\xa6\x57\xbc\x0c\x3b\x76"
149     "\x0d\x97\x1e\xbd\xe9\xec\x7f\xd3\xa9\xec\xfb\x85\x64\xa0\x6b\xa0"
150     "\x48\xce\x77\x7e\x73\x9c\x31\x13\xff\x3d\xc8\xae\xa5\x60\x6e\xd9"
151     "\xb6\x8c\x5a\x9a\x6f\xb6\xbe\x9f\x6a\xbd\xa7\xf0\xa0\x33\x27\xf5"
152     "\xb7\x1d\x92\xe5\x96\x9c\x73\x52\xd6\x9f\xd6\xc8\x8e\xb1\x02\x03"
153     "\x01\x00\x01\xa3\x81\x93\x30\x81\x90\x30\x0c\x06\x03\x55\x1d\x13"
154     "\x01\x01\xff\x04\x02\x30\x00\x30\x1a\x06\x03\x55\x1d\x11\x04\x13"
155     "\x30\x11\x82\x0f\x74\x65\x73\x74\x2e\x67\x6e\x75\x74\x6c\x73\x2e"
156     "\x6f\x72\x67\x30\x13\x06\x03\x55\x1d\x25\x04\x0c\x30\x0a\x06\x08"
157     "\x2b\x06\x01\x05\x05\x07\x03\x01\x30\x0f\x06\x03\x55\x1d\x0f\x01"
158     "\x01\xff\x04\x05\x03\x03\x07\xa0\x00\x30\x1d\x06\x03\x55\x1d\x0e"
159     "\x04\x16\x04\x14\xeb\xc7\x45\x6e\xe5\xf8\x25\xca\x8c\x8d\x83\x0d"
160     "\x74\xe9\x86\xd4\xdd\x55\xb4\x75\x30\x1f\x06\x03\x55\x1d\x23\x04"
161     "\x18\x30\x16\x80\x14\xe9\x3c\x1c\xfb\xad\x92\x6e\xe6\x06\xa4\x56"
162     "\x2c\xa2\xe1\xc0\x53\x27\xc8\xf2\x95\x30\x0b\x06\x09\x2a\x86\x48"
163     "\x86\xf7\x0d\x01\x01\x05\x03\x81\x81\x00\x68\x51\x0f\x4e\xdf\xbb"
164     "\x6f\x3b\xc1\xb8\xe7\xfb\xf9\x09\x9e\x41\xc9\xf6\xf6\x44\xfa\x06"
165     "\xcc\xa1\xd5\x11\xc9\x5d\xff\x0a\x4e\x4e\x50\x45\xfc\x29\xea\x88"
166     "\x1b\xa7\xde\x09\x41\x67\x0d\x43\xf4\xbb\x60\x31\x47\x82\x50\xf5"
167     "\x03\x05\x0d\x05\x15\xf0\x77\x7a\xe2\x52\xc3\x27\xb3\x18\x1e\x48"
168     "\x3c\x58\x05\xf2\x58\x6c\x32\xde\xa2\x13\x41\xb2\xa6\x8f\x0c\x96"
169     "\xfb\x5d\xa8\xa5\x59\xb3\x10\x29\xf0\x1b\x15\x0f\x1c\x9c\xec\x60"
170     "\xac\xe2\x8b\x51\x04\x56\x27\x42\xb7\x1f\x25\xd1\x32\x16\xea\x8d"
171     "\xd2\xc8\x69\x08\x82\xbd\x02\xee\x8b\x3a";
172 
173 const gnutls_datum_t server_key = { server_key_pem,
174 	sizeof(server_key_pem)
175 };
176 
mytime(time_t * t)177 static time_t mytime(time_t * t)
178 {
179 	time_t then = 1207000800;
180 
181 	if (t)
182 		*t = then;
183 
184 	return then;
185 }
186 
check_stored_algos(gnutls_x509_crt_t server_crt)187 static void check_stored_algos(gnutls_x509_crt_t server_crt)
188 {
189 	int ret;
190 	char oid[256];
191 	size_t oid_size;
192 
193 	oid_size = sizeof(oid);
194 	ret = gnutls_x509_crt_get_signature_oid(server_crt, oid, &oid_size);
195 	if (ret < 0) {
196 		fail("cannot get signature algorithm: %s\n", gnutls_strerror(ret));
197 		exit(1);
198 	}
199 
200 	if (strcmp(oid, "1.2.840.113549.1.1.5") != 0) {
201 		fail("detected wrong algorithm OID: %s\n", oid);
202 		exit(1);
203 	}
204 
205 	ret = gnutls_x509_crt_get_signature_algorithm(server_crt);
206 	if (ret != GNUTLS_SIGN_RSA_SHA1) {
207 		fail("detected wrong algorithm: %s\n", gnutls_sign_get_name(ret));
208 		exit(1);
209 	}
210 
211 	/* PK */
212 	oid_size = sizeof(oid);
213 	ret = gnutls_x509_crt_get_pk_oid(server_crt, oid, &oid_size);
214 	if (ret < 0) {
215 		fail("cannot get PK algorithm: %s\n", gnutls_strerror(ret));
216 		exit(1);
217 	}
218 
219 	if (strcmp(oid, "1.2.840.113549.1.1.1") != 0) {
220 		fail("detected wrong PK algorithm OID: %s\n", oid);
221 		exit(1);
222 	}
223 
224 	ret = gnutls_x509_crt_get_pk_algorithm(server_crt, NULL);
225 	if (ret != GNUTLS_PK_RSA) {
226 		fail("detected wrong PK algorithm: %s\n", gnutls_pk_get_name(ret));
227 		exit(1);
228 	}
229 
230 }
231 
232 #define NAME "localhost"
233 #define NAME_SIZE (sizeof(NAME)-1)
doit(void)234 void doit(void)
235 {
236 	int ret;
237 	const char *path;
238 	gnutls_datum_t data;
239 	gnutls_x509_crt_t server_crt, ca_crt2;
240 	gnutls_x509_trust_list_t tl;
241 	unsigned int status;
242 	gnutls_typed_vdata_st vdata;
243 	gnutls_digest_algorithm_t hash;
244 	unsigned int mand;
245 
246 	/* this must be called once in the program
247 	 */
248 	global_init();
249 
250 	gnutls_global_set_time_function(mytime);
251 	gnutls_global_set_log_function(tls_log_func);
252 	if (debug)
253 		gnutls_global_set_log_level(6);
254 
255 	/* test for gnutls_certificate_get_issuer() */
256 	gnutls_x509_trust_list_init(&tl, 0);
257 
258 	gnutls_x509_crt_init(&server_crt);
259 	gnutls_x509_crt_init(&ca_crt2);
260 
261 	path = getenv("X509CERTDIR");
262 	if (!path)
263 		path = "./x509cert-dir";
264 
265 	ret =
266 	    gnutls_x509_crt_import(server_crt, &cert, GNUTLS_X509_FMT_PEM);
267 	if (ret < 0)
268 		fail("gnutls_x509_crt_import");
269 
270 	check_stored_algos(server_crt);
271 
272 	ret = gnutls_x509_crt_get_preferred_hash_algorithm(server_crt, &hash, &mand);
273 	if (ret < 0) {
274 		fail("error in gnutls_x509_crt_get_preferred_hash_algorithm: %s\n", gnutls_strerror(ret));
275 		exit(1);
276 	}
277 
278 	if (mand != 0 || hash != GNUTLS_DIG_SHA256) {
279 		fail("gnutls_x509_crt_get_preferred_hash_algorithm returned: %s/%d\n", gnutls_digest_get_name(hash), mand);
280 		exit(1);
281 	}
282 
283 	ret = gnutls_x509_crt_import(ca_crt2, &ca, GNUTLS_X509_FMT_PEM);
284 	if (ret < 0)
285 		fail("gnutls_x509_crt_import");
286 
287 	ret =
288 	    gnutls_x509_trust_list_add_named_crt(tl, server_crt, NAME,
289 						 NAME_SIZE, 0);
290 	if (ret < 0)
291 		fail("gnutls_x509_trust_list_add_named_crt");
292 
293 	ret =
294 	    gnutls_x509_trust_list_verify_named_crt(tl, server_crt, NAME,
295 						    NAME_SIZE, 0, &status,
296 						    NULL);
297 	if (ret < 0 || status != 0)
298 		fail("gnutls_x509_trust_list_verify_named_crt: %d\n",
299 		     __LINE__);
300 
301 	ret =
302 	    gnutls_x509_trust_list_verify_named_crt(tl, server_crt, NAME,
303 						    NAME_SIZE - 1, 0,
304 						    &status, NULL);
305 	if (ret < 0 || status == 0)
306 		fail("gnutls_x509_trust_list_verify_named_crt: %d\n",
307 		     __LINE__);
308 
309 	ret =
310 	    gnutls_x509_trust_list_verify_named_crt(tl, server_crt,
311 						    "other", 5, 0, &status,
312 						    NULL);
313 	if (ret < 0 || status == 0)
314 		fail("gnutls_x509_trust_list_verify_named_crt: %d\n",
315 		     __LINE__);
316 
317 	/* check whether the name-only verification works */
318 	vdata.type = GNUTLS_DT_DNS_HOSTNAME;
319 	vdata.data = (void*)NAME;
320 	vdata.size = NAME_SIZE;
321 	ret =
322 	    gnutls_x509_trust_list_verify_crt2(tl, &server_crt, 1, &vdata, 1,
323 						GNUTLS_VERIFY_ALLOW_BROKEN, &status, NULL);
324 	if (ret < 0 || status != 0)
325 		fail("gnutls_x509_trust_list_verify_crt2 - 1: status: %x\n", status);
326 
327 	vdata.type = GNUTLS_DT_DNS_HOSTNAME;
328 	vdata.data = (void*)NAME;
329 	vdata.size = NAME_SIZE-2;
330 	ret =
331 	    gnutls_x509_trust_list_verify_crt2(tl, &server_crt, 1, &vdata, 1,
332 						0, &status, NULL);
333 	if (ret < 0 || status == 0)
334 		fail("gnutls_x509_trust_list_verify_crt2 - 2: status: %x\n", status);
335 
336 
337 	/* check whether the key verification works */
338 	ret = gnutls_x509_trust_list_add_trust_dir(tl, path, NULL, GNUTLS_X509_FMT_PEM, 0, 0);
339 	if (ret != 1)
340 		fail("gnutls_x509_trust_list_add_trust_dir: %d\n", ret);
341 
342 	ret =
343 	    gnutls_x509_trust_list_verify_crt(tl, &server_crt, 1, GNUTLS_VERIFY_ALLOW_BROKEN,
344 					      &status, NULL);
345 	if (ret < 0 || status != 0)
346 		fail("gnutls_x509_trust_list_verify_crt\n");
347 
348 
349 
350 	/* test convenience functions in verify-high2.c */
351 	data.data = cert_pem;
352 	data.size = strlen((char *) cert_pem);
353 	ret =
354 	    gnutls_x509_trust_list_add_trust_mem(tl, &data, NULL,
355 						 GNUTLS_X509_FMT_PEM, 0,
356 						 0);
357 	if (ret < 1)
358 		fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
359 		     __LINE__, gnutls_strerror(ret));
360 
361 	ret =
362 	    gnutls_x509_trust_list_remove_trust_mem(tl, &data,
363 						    GNUTLS_X509_FMT_PEM);
364 	if (ret < 1)
365 		fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
366 		     __LINE__, gnutls_strerror(ret));
367 
368 	data.data = cert_der;
369 	data.size = sizeof(cert_der);
370 	ret =
371 	    gnutls_x509_trust_list_add_trust_mem(tl, &data, NULL,
372 						 GNUTLS_X509_FMT_DER, 0,
373 						 0);
374 	if (ret < 1)
375 		fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
376 		     __LINE__, gnutls_strerror(ret));
377 
378 	ret =
379 	    gnutls_x509_trust_list_remove_trust_mem(tl, &data,
380 						    GNUTLS_X509_FMT_DER);
381 	if (ret < 1)
382 		fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
383 		     __LINE__, gnutls_strerror(ret));
384 
385 	ret = gnutls_x509_trust_list_remove_cas(tl, &ca_crt2, 1);
386 	if (ret < 1)
387 		fail("gnutls_x509_trust_list_add_cas");
388 
389 	ret =
390 	    gnutls_x509_trust_list_verify_crt(tl, &server_crt, 1, 0,
391 					      &status, NULL);
392 	if (ret == 0 && status == 0)
393 		fail("gnutls_x509_trust_list_verify_crt\n");
394 
395 	gnutls_x509_trust_list_deinit(tl, 1);
396 	gnutls_x509_crt_deinit(ca_crt2);
397 
398 	gnutls_global_deinit();
399 
400 	if (debug)
401 		success("success");
402 }
403