Merge branch 'upstream' into tizen
[platform/upstream/gnutls.git] / tests / x509cert-tl.c
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
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
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
187 #define NAME "localhost"
188 #define NAME_SIZE (sizeof(NAME)-1)
189 void doit(void)
190 {
191         int ret;
192         const char *path;
193         gnutls_datum_t data;
194         gnutls_x509_crt_t server_crt, ca_crt2;
195         gnutls_x509_trust_list_t tl;
196         unsigned int status;
197         gnutls_typed_vdata_st vdata;
198         gnutls_digest_algorithm_t hash;
199         unsigned int mand;
200
201         /* this must be called once in the program
202          */
203         global_init();
204
205         gnutls_global_set_time_function(mytime);
206         gnutls_global_set_log_function(tls_log_func);
207         if (debug)
208                 gnutls_global_set_log_level(6);
209
210         /* test for gnutls_certificate_get_issuer() */
211         gnutls_x509_trust_list_init(&tl, 0);
212
213         gnutls_x509_crt_init(&server_crt);
214         gnutls_x509_crt_init(&ca_crt2);
215
216         path = getenv("X509CERTDIR");
217         if (!path)
218                 path = "./x509cert-dir";
219
220         ret =
221             gnutls_x509_crt_import(server_crt, &cert, GNUTLS_X509_FMT_PEM);
222         if (ret < 0)
223                 fail("gnutls_x509_crt_import");
224
225         ret = gnutls_x509_crt_get_signature_algorithm(server_crt);
226         if (ret != GNUTLS_SIGN_RSA_SHA1) {
227                 fail("detected wrong algorithm: %s\n", gnutls_sign_get_name(ret));
228                 exit(1);
229         }
230
231         ret = gnutls_x509_crt_get_preferred_hash_algorithm(server_crt, &hash, &mand);
232         if (ret < 0) {
233                 fail("error in gnutls_x509_crt_get_preferred_hash_algorithm: %s\n", gnutls_strerror(ret));
234                 exit(1);
235         }
236
237         if (mand != 0 || hash != GNUTLS_DIG_SHA256) {
238                 fail("gnutls_x509_crt_get_preferred_hash_algorithm returned: %s/%d\n", gnutls_digest_get_name(hash), mand);
239                 exit(1);
240         }
241
242         ret = gnutls_x509_crt_import(ca_crt2, &ca, GNUTLS_X509_FMT_PEM);
243         if (ret < 0)
244                 fail("gnutls_x509_crt_import");
245
246         ret =
247             gnutls_x509_trust_list_add_named_crt(tl, server_crt, NAME,
248                                                  NAME_SIZE, 0);
249         if (ret < 0)
250                 fail("gnutls_x509_trust_list_add_named_crt");
251
252         ret =
253             gnutls_x509_trust_list_verify_named_crt(tl, server_crt, NAME,
254                                                     NAME_SIZE, 0, &status,
255                                                     NULL);
256         if (ret < 0 || status != 0)
257                 fail("gnutls_x509_trust_list_verify_named_crt: %d\n",
258                      __LINE__);
259
260         ret =
261             gnutls_x509_trust_list_verify_named_crt(tl, server_crt, NAME,
262                                                     NAME_SIZE - 1, 0,
263                                                     &status, NULL);
264         if (ret < 0 || status == 0)
265                 fail("gnutls_x509_trust_list_verify_named_crt: %d\n",
266                      __LINE__);
267
268         ret =
269             gnutls_x509_trust_list_verify_named_crt(tl, server_crt,
270                                                     "other", 5, 0, &status,
271                                                     NULL);
272         if (ret < 0 || status == 0)
273                 fail("gnutls_x509_trust_list_verify_named_crt: %d\n",
274                      __LINE__);
275
276         /* check whether the name-only verification works */
277         vdata.type = GNUTLS_DT_DNS_HOSTNAME;
278         vdata.data = (void*)NAME;
279         vdata.size = NAME_SIZE;
280         ret =
281             gnutls_x509_trust_list_verify_crt2(tl, &server_crt, 1, &vdata, 1,
282                                                0, &status, NULL);
283         if (ret < 0 || status != 0)
284                 fail("gnutls_x509_trust_list_verify_crt2 - 1: status: %x\n", status);
285
286         vdata.type = GNUTLS_DT_DNS_HOSTNAME;
287         vdata.data = (void*)NAME;
288         vdata.size = NAME_SIZE-2;
289         ret =
290             gnutls_x509_trust_list_verify_crt2(tl, &server_crt, 1, &vdata, 1,
291                                                0, &status, NULL);
292         if (ret < 0 || status == 0)
293                 fail("gnutls_x509_trust_list_verify_crt2 - 2: status: %x\n", status);
294
295
296         /* check whether the key verification works */
297         ret = gnutls_x509_trust_list_add_trust_dir(tl, path, NULL, GNUTLS_X509_FMT_PEM, 0, 0);
298         if (ret != 1)
299                 fail("gnutls_x509_trust_list_add_trust_dir: %d\n", ret);
300
301         ret =
302             gnutls_x509_trust_list_verify_crt(tl, &server_crt, 1, 0,
303                                               &status, NULL);
304         if (ret < 0 || status != 0)
305                 fail("gnutls_x509_trust_list_verify_crt\n");
306
307
308
309         /* test convenience functions in verify-high2.c */
310         data.data = cert_pem;
311         data.size = strlen((char *) cert_pem);
312         ret =
313             gnutls_x509_trust_list_add_trust_mem(tl, &data, NULL,
314                                                  GNUTLS_X509_FMT_PEM, 0,
315                                                  0);
316         if (ret < 1)
317                 fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
318                      __LINE__, gnutls_strerror(ret));
319
320         ret =
321             gnutls_x509_trust_list_remove_trust_mem(tl, &data,
322                                                     GNUTLS_X509_FMT_PEM);
323         if (ret < 1)
324                 fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
325                      __LINE__, gnutls_strerror(ret));
326
327         data.data = cert_der;
328         data.size = sizeof(cert_der);
329         ret =
330             gnutls_x509_trust_list_add_trust_mem(tl, &data, NULL,
331                                                  GNUTLS_X509_FMT_DER, 0,
332                                                  0);
333         if (ret < 1)
334                 fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
335                      __LINE__, gnutls_strerror(ret));
336
337         ret =
338             gnutls_x509_trust_list_remove_trust_mem(tl, &data,
339                                                     GNUTLS_X509_FMT_DER);
340         if (ret < 1)
341                 fail("gnutls_x509_trust_list_add_trust_mem: %d (%s)\n",
342                      __LINE__, gnutls_strerror(ret));
343
344         ret = gnutls_x509_trust_list_remove_cas(tl, &ca_crt2, 1);
345         if (ret < 1)
346                 fail("gnutls_x509_trust_list_add_cas");
347
348         ret =
349             gnutls_x509_trust_list_verify_crt(tl, &server_crt, 1, 0,
350                                               &status, NULL);
351         if (ret == 0 && status == 0)
352                 fail("gnutls_x509_trust_list_verify_crt\n");
353
354         gnutls_x509_trust_list_deinit(tl, 1);
355         gnutls_x509_crt_deinit(ca_crt2);
356
357         gnutls_global_deinit();
358
359         if (debug)
360                 success("success");
361 }