corrected makefile
[gnutls.git] / tests / hostname-check.c
blob50c87f32692d3c1770ef52a215d9d5f8e318c615
1 /*
2 * Copyright (C) 2007-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 <string.h>
28 #include <gnutls/gnutls.h>
29 #include <gnutls/x509.h>
30 #ifdef ENABLE_OPENPGP
31 #include <gnutls/openpgp.h>
32 #endif
34 #include "utils.h"
37 A self-test of the RFC 2818 hostname matching algorithm. Used to
38 detect regressions of the bug reported in:
39 http://lists.gnupg.org/pipermail/gnutls-dev/2007-February/001385.html
42 /* Certificate with no SAN nor CN. */
43 char pem1[] =
44 "X.509 Certificate Information:\n"
45 " Version: 3\n"
46 " Serial Number (hex): 00\n"
47 " Issuer: O=GnuTLS hostname check test CA\n"
48 " Validity:\n"
49 " Not Before: Fri Feb 16 12:59:09 UTC 2007\n"
50 " Not After: Fri Mar 30 12:59:13 UTC 2007\n"
51 " Subject: O=GnuTLS hostname check test CA\n"
52 " Subject Public Key Algorithm: RSA\n"
53 " Modulus (bits 1024):\n"
54 " be:ec:98:7a:1d:6f:7e:6b:25:9e:e8:20:78:42:a0:64\n"
55 " 05:66:43:99:6d:49:d5:18:ec:7d:b9:58:64:b2:80:a3\n"
56 " 14:61:9d:0a:4f:be:2f:f0:2e:fc:d2:ab:5c:36:df:53\n"
57 " ec:43:c7:fc:de:91:bc:1e:01:a6:b7:6c:b2:07:10:2e\n"
58 " cb:61:47:75:ca:03:ce:23:6e:38:f1:34:27:1a:1a:cd\n"
59 " f7:96:f3:b3:f0:0d:67:7f:ca:77:84:3f:9c:29:f4:62\n"
60 " 91:f6:12:5b:62:5a:cc:ba:ed:08:2e:32:44:26:ac:fd\n"
61 " 23:ce:53:1b:bb:f2:87:fe:dc:78:93:7c:59:bf:a1:75\n"
62 " Exponent:\n"
63 " 01:00:01\n"
64 " Extensions:\n"
65 " Basic Constraints (critical):\n"
66 " Certificate Authority (CA): TRUE\n"
67 " Subject Key Identifier (not critical):\n"
68 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
69 " Signature Algorithm: RSA-SHA\n"
70 " Signature:\n"
71 " 7b:e8:11:6c:15:3f:f9:01:a0:f1:28:0c:62:50:58:f8\n"
72 " 92:44:fb:bf:ab:20:8a:3b:81:ca:e5:68:60:71:df:2b\n"
73 " e8:50:58:82:32:ef:fb:6e:4a:72:2c:c9:37:4f:88:1d\n"
74 " d7:1b:68:5b:db:83:1b:1a:f3:b4:8e:e0:88:03:e2:43\n"
75 " 91:be:d8:b1:ca:f2:62:ec:a1:fd:1a:c8:41:8c:fe:53\n"
76 " 1b:be:03:c9:a1:3d:f4:ae:57:fc:44:a6:34:bb:2c:2e\n"
77 " a7:56:14:1f:89:e9:3a:ec:1f:a3:da:d7:a1:94:3b:72\n"
78 " 1d:12:71:b9:65:a1:85:a2:4c:3a:d1:2c:e9:e9:ea:1c\n"
79 "Other Information:\n"
80 " MD5 fingerprint:\n"
81 " fd845ded8c28ba5e78d6c1844ceafd24\n"
82 " SHA-1 fingerprint:\n"
83 " 0bae431dda3cae76012b82276e4cd92ad7961798\n"
84 " Public Key Id:\n"
85 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
86 "\n"
87 "-----BEGIN CERTIFICATE-----\n"
88 "MIIB8TCCAVygAwIBAgIBADALBgkqhkiG9w0BAQUwKDEmMCQGA1UEChMdR251VExT\n"
89 "IGhvc3RuYW1lIGNoZWNrIHRlc3QgQ0EwHhcNMDcwMjE2MTI1OTA5WhcNMDcwMzMw\n"
90 "MTI1OTEzWjAoMSYwJAYDVQQKEx1HbnVUTFMgaG9zdG5hbWUgY2hlY2sgdGVzdCBD\n"
91 "QTCBnDALBgkqhkiG9w0BAQEDgYwAMIGIAoGAvuyYeh1vfmslnuggeEKgZAVmQ5lt\n"
92 "SdUY7H25WGSygKMUYZ0KT74v8C780qtcNt9T7EPH/N6RvB4BprdssgcQLsthR3XK\n"
93 "A84jbjjxNCcaGs33lvOz8A1nf8p3hD+cKfRikfYSW2JazLrtCC4yRCas/SPOUxu7\n"
94 "8of+3HiTfFm/oXUCAwEAAaMyMDAwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU\n"
95 "6Twc+62SbuYGpFYsouHAUyfI8pUwCwYJKoZIhvcNAQEFA4GBAHvoEWwVP/kBoPEo\n"
96 "DGJQWPiSRPu/qyCKO4HK5Whgcd8r6FBYgjLv+25KcizJN0+IHdcbaFvbgxsa87SO\n"
97 "4IgD4kORvtixyvJi7KH9GshBjP5TG74DyaE99K5X/ESmNLssLqdWFB+J6TrsH6Pa\n"
98 "16GUO3IdEnG5ZaGFokw60Szp6eoc\n" "-----END CERTIFICATE-----\n";
100 /* Certificate with CN but no SAN. */
101 char pem2[] =
102 "X.509 Certificate Information:\n"
103 " Version: 3\n"
104 " Serial Number (hex): 00\n"
105 " Issuer: CN=www.example.org\n"
106 " Validity:\n"
107 " Not Before: Fri Feb 16 13:30:30 UTC 2007\n"
108 " Not After: Fri Mar 30 13:30:32 UTC 2007\n"
109 " Subject: CN=www.example.org\n"
110 " Subject Public Key Algorithm: RSA\n"
111 " Modulus (bits 1024):\n"
112 " be:ec:98:7a:1d:6f:7e:6b:25:9e:e8:20:78:42:a0:64\n"
113 " 05:66:43:99:6d:49:d5:18:ec:7d:b9:58:64:b2:80:a3\n"
114 " 14:61:9d:0a:4f:be:2f:f0:2e:fc:d2:ab:5c:36:df:53\n"
115 " ec:43:c7:fc:de:91:bc:1e:01:a6:b7:6c:b2:07:10:2e\n"
116 " cb:61:47:75:ca:03:ce:23:6e:38:f1:34:27:1a:1a:cd\n"
117 " f7:96:f3:b3:f0:0d:67:7f:ca:77:84:3f:9c:29:f4:62\n"
118 " 91:f6:12:5b:62:5a:cc:ba:ed:08:2e:32:44:26:ac:fd\n"
119 " 23:ce:53:1b:bb:f2:87:fe:dc:78:93:7c:59:bf:a1:75\n"
120 " Exponent:\n"
121 " 01:00:01\n"
122 " Extensions:\n"
123 " Basic Constraints (critical):\n"
124 " Certificate Authority (CA): TRUE\n"
125 " Subject Key Identifier (not critical):\n"
126 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
127 " Signature Algorithm: RSA-SHA\n"
128 " Signature:\n"
129 " b0:4e:ac:fb:89:12:36:27:f3:72:b8:1a:57:dc:bf:f3\n"
130 " a9:27:de:15:75:94:4f:65:cc:3a:59:12:4b:91:0e:28\n"
131 " b9:8d:d3:6e:ac:5d:a8:3e:b9:35:81:0c:8f:c7:95:72\n"
132 " d9:51:61:06:00:c6:aa:68:54:c8:52:3f:b6:1f:21:92\n"
133 " c8:fd:15:50:15:ac:d4:18:29:a1:ff:c9:25:5a:ce:5e\n"
134 " 11:7f:82:b2:94:8c:44:3c:3f:de:d7:3b:ff:1c:da:9c\n"
135 " 81:fa:63:e1:a7:67:ee:aa:fa:d0:c9:2f:66:1b:5e:af\n"
136 " 46:8c:f9:53:55:e7:80:7e:74:95:98:d4:2d:5f:94:ab\n"
137 "Other Information:\n"
138 " MD5 fingerprint:\n"
139 " 30cda7de4f0360892547974f45111ac1\n"
140 " SHA-1 fingerprint:\n"
141 " 39e3f8fec6a8d842390b6536998a957c1a6b7322\n"
142 " Public Key Id:\n"
143 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
144 "\n"
145 "-----BEGIN CERTIFICATE-----\n"
146 "MIIB1TCCAUCgAwIBAgIBADALBgkqhkiG9w0BAQUwGjEYMBYGA1UEAxMPd3d3LmV4\n"
147 "YW1wbGUub3JnMB4XDTA3MDIxNjEzMzAzMFoXDTA3MDMzMDEzMzAzMlowGjEYMBYG\n"
148 "A1UEAxMPd3d3LmV4YW1wbGUub3JnMIGcMAsGCSqGSIb3DQEBAQOBjAAwgYgCgYC+\n"
149 "7Jh6HW9+ayWe6CB4QqBkBWZDmW1J1RjsfblYZLKAoxRhnQpPvi/wLvzSq1w231Ps\n"
150 "Q8f83pG8HgGmt2yyBxAuy2FHdcoDziNuOPE0JxoazfeW87PwDWd/yneEP5wp9GKR\n"
151 "9hJbYlrMuu0ILjJEJqz9I85TG7vyh/7ceJN8Wb+hdQIDAQABozIwMDAPBgNVHRMB\n"
152 "Af8EBTADAQH/MB0GA1UdDgQWBBTpPBz7rZJu5gakViyi4cBTJ8jylTALBgkqhkiG\n"
153 "9w0BAQUDgYEAsE6s+4kSNifzcrgaV9y/86kn3hV1lE9lzDpZEkuRDii5jdNurF2o\n"
154 "Prk1gQyPx5Vy2VFhBgDGqmhUyFI/th8hksj9FVAVrNQYKaH/ySVazl4Rf4KylIxE\n"
155 "PD/e1zv/HNqcgfpj4adn7qr60MkvZhter0aM+VNV54B+dJWY1C1flKs=\n"
156 "-----END CERTIFICATE-----\n";
158 /* Certificate with SAN but no CN. */
159 char pem3[] =
160 "X.509 Certificate Information:"
161 " Version: 3\n"
162 " Serial Number (hex): 00\n"
163 " Issuer: O=GnuTLS hostname check test CA\n"
164 " Validity:\n"
165 " Not Before: Fri Feb 16 13:36:27 UTC 2007\n"
166 " Not After: Fri Mar 30 13:36:29 UTC 2007\n"
167 " Subject: O=GnuTLS hostname check test CA\n"
168 " Subject Public Key Algorithm: RSA\n"
169 " Modulus (bits 1024):\n"
170 " be:ec:98:7a:1d:6f:7e:6b:25:9e:e8:20:78:42:a0:64\n"
171 " 05:66:43:99:6d:49:d5:18:ec:7d:b9:58:64:b2:80:a3\n"
172 " 14:61:9d:0a:4f:be:2f:f0:2e:fc:d2:ab:5c:36:df:53\n"
173 " ec:43:c7:fc:de:91:bc:1e:01:a6:b7:6c:b2:07:10:2e\n"
174 " cb:61:47:75:ca:03:ce:23:6e:38:f1:34:27:1a:1a:cd\n"
175 " f7:96:f3:b3:f0:0d:67:7f:ca:77:84:3f:9c:29:f4:62\n"
176 " 91:f6:12:5b:62:5a:cc:ba:ed:08:2e:32:44:26:ac:fd\n"
177 " 23:ce:53:1b:bb:f2:87:fe:dc:78:93:7c:59:bf:a1:75\n"
178 " Exponent:\n"
179 " 01:00:01\n"
180 " Extensions:\n"
181 " Basic Constraints (critical):\n"
182 " Certificate Authority (CA): TRUE\n"
183 " Subject Alternative Name (not critical):\n"
184 " DNSname: www.example.org\n"
185 " Key Purpose (not critical):\n"
186 " TLS WWW Server.\n"
187 " Subject Key Identifier (not critical):\n"
188 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
189 " Signature Algorithm: RSA-SHA\n"
190 " Signature:\n"
191 " a1:30:bc:01:b3:0f:98:7f:8e:76:7d:23:87:34:15:7f\n"
192 " a6:ae:a1:fb:87:75:e3:e8:1a:e5:5e:03:5d:bf:44:75\n"
193 " 46:4f:d2:a1:28:50:84:49:6d:3b:e0:bc:4e:de:79:85\n"
194 " fa:e1:07:b7:6e:0c:14:04:4a:82:b9:f3:22:6a:bc:99\n"
195 " 14:20:3b:49:1f:e4:97:d9:ea:eb:73:9a:83:a6:cc:b8\n"
196 " 55:fb:52:8e:5f:86:7c:9d:fa:af:03:76:ae:97:e0:64\n"
197 " 50:59:73:22:99:55:cf:da:59:31:0a:e8:6d:a0:53:bc\n"
198 " 39:63:2e:ac:92:4a:e9:8b:1e:d0:03:df:33:bb:4e:88\n"
199 "Other Information:\n"
200 " MD5 fingerprint:\n"
201 " df3f57d00c8149bd826b177d6ea4f369\n"
202 " SHA-1 fingerprint:\n"
203 " e95e56e2acac305f72ea6f698c11624663a595bd\n"
204 " Public Key Id:\n"
205 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
206 "\n"
207 "-----BEGIN CERTIFICATE-----\n"
208 "MIICIjCCAY2gAwIBAgIBADALBgkqhkiG9w0BAQUwKDEmMCQGA1UEChMdR251VExT\n"
209 "IGhvc3RuYW1lIGNoZWNrIHRlc3QgQ0EwHhcNMDcwMjE2MTMzNjI3WhcNMDcwMzMw\n"
210 "MTMzNjI5WjAoMSYwJAYDVQQKEx1HbnVUTFMgaG9zdG5hbWUgY2hlY2sgdGVzdCBD\n"
211 "QTCBnDALBgkqhkiG9w0BAQEDgYwAMIGIAoGAvuyYeh1vfmslnuggeEKgZAVmQ5lt\n"
212 "SdUY7H25WGSygKMUYZ0KT74v8C780qtcNt9T7EPH/N6RvB4BprdssgcQLsthR3XK\n"
213 "A84jbjjxNCcaGs33lvOz8A1nf8p3hD+cKfRikfYSW2JazLrtCC4yRCas/SPOUxu7\n"
214 "8of+3HiTfFm/oXUCAwEAAaNjMGEwDwYDVR0TAQH/BAUwAwEB/zAaBgNVHREEEzAR\n"
215 "gg93d3cuZXhhbXBsZS5vcmcwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHQYDVR0OBBYE\n"
216 "FOk8HPutkm7mBqRWLKLhwFMnyPKVMAsGCSqGSIb3DQEBBQOBgQChMLwBsw+Yf452\n"
217 "fSOHNBV/pq6h+4d14+ga5V4DXb9EdUZP0qEoUIRJbTvgvE7eeYX64Qe3bgwUBEqC\n"
218 "ufMiaryZFCA7SR/kl9nq63Oag6bMuFX7Uo5fhnyd+q8Ddq6X4GRQWXMimVXP2lkx\n"
219 "CuhtoFO8OWMurJJK6Yse0APfM7tOiA==\n" "-----END CERTIFICATE-----\n";
221 /* Certificate with wildcard SAN but no CN. */
222 char pem4[] =
223 "X.509 Certificate Information:\n"
224 " Version: 3\n"
225 " Serial Number (hex): 00\n"
226 " Issuer:\n"
227 " Validity:\n"
228 " Not Before: Fri Feb 16 13:40:10 UTC 2007\n"
229 " Not After: Fri Mar 30 13:40:12 UTC 2007\n"
230 " Subject:\n"
231 " Subject Public Key Algorithm: RSA\n"
232 " Modulus (bits 1024):\n"
233 " be:ec:98:7a:1d:6f:7e:6b:25:9e:e8:20:78:42:a0:64\n"
234 " 05:66:43:99:6d:49:d5:18:ec:7d:b9:58:64:b2:80:a3\n"
235 " 14:61:9d:0a:4f:be:2f:f0:2e:fc:d2:ab:5c:36:df:53\n"
236 " ec:43:c7:fc:de:91:bc:1e:01:a6:b7:6c:b2:07:10:2e\n"
237 " cb:61:47:75:ca:03:ce:23:6e:38:f1:34:27:1a:1a:cd\n"
238 " f7:96:f3:b3:f0:0d:67:7f:ca:77:84:3f:9c:29:f4:62\n"
239 " 91:f6:12:5b:62:5a:cc:ba:ed:08:2e:32:44:26:ac:fd\n"
240 " 23:ce:53:1b:bb:f2:87:fe:dc:78:93:7c:59:bf:a1:75\n"
241 " Exponent:\n"
242 " 01:00:01\n"
243 " Extensions:\n"
244 " Basic Constraints (critical):\n"
245 " Certificate Authority (CA): TRUE\n"
246 " Subject Alternative Name (not critical):\n"
247 " DNSname: *.example.org\n"
248 " Key Purpose (not critical):\n"
249 " TLS WWW Server.\n"
250 " Subject Key Identifier (not critical):\n"
251 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
252 " Signature Algorithm: RSA-SHA\n"
253 " Signature:\n"
254 " b1:62:e5:e3:0b:a5:99:58:b0:1c:5c:f5:d1:3f:7c:bb\n"
255 " 67:e1:43:c5:d7:a2:5c:db:f2:5a:f3:03:fc:76:e4:4d\n"
256 " c1:a0:89:36:24:82:a4:a1:ad:f5:83:e3:96:75:f4:c4\n"
257 " f3:eb:ff:3a:9b:da:d2:2c:58:d4:10:37:50:33:d1:39\n"
258 " 53:71:9e:48:2d:b2:5b:27:ce:1e:d9:d5:36:59:ac:17\n"
259 " 3a:83:cc:59:6b:8f:6a:24:b8:9f:f0:e6:14:03:23:5a\n"
260 " 87:e7:33:10:32:11:58:a2:bb:f1:e5:5a:88:87:bb:80\n"
261 " 1b:b6:bb:12:18:cb:15:d5:3a:fc:99:e4:42:5a:ba:45\n"
262 "Other Information:\n"
263 " MD5 fingerprint:\n"
264 " a411da7b0fa064d214116d5f94e06c24\n"
265 " SHA-1 fingerprint:\n"
266 " 3596e796c73ed096d762ab3d440a9ab55a386b3b\n"
267 " Public Key Id:\n"
268 " e93c1cfbad926ee606a4562ca2e1c05327c8f295\n"
269 "\n"
270 "-----BEGIN CERTIFICATE-----\n"
271 "MIIB0DCCATugAwIBAgIBADALBgkqhkiG9w0BAQUwADAeFw0wNzAyMTYxMzQwMTBa\n"
272 "Fw0wNzAzMzAxMzQwMTJaMAAwgZwwCwYJKoZIhvcNAQEBA4GMADCBiAKBgL7smHod\n"
273 "b35rJZ7oIHhCoGQFZkOZbUnVGOx9uVhksoCjFGGdCk++L/Au/NKrXDbfU+xDx/ze\n"
274 "kbweAaa3bLIHEC7LYUd1ygPOI2448TQnGhrN95bzs/ANZ3/Kd4Q/nCn0YpH2Elti\n"
275 "Wsy67QguMkQmrP0jzlMbu/KH/tx4k3xZv6F1AgMBAAGjYTBfMA8GA1UdEwEB/wQF\n"
276 "MAMBAf8wGAYDVR0RBBEwD4INKi5leGFtcGxlLm9yZzATBgNVHSUEDDAKBggrBgEF\n"
277 "BQcDATAdBgNVHQ4EFgQU6Twc+62SbuYGpFYsouHAUyfI8pUwCwYJKoZIhvcNAQEF\n"
278 "A4GBALFi5eMLpZlYsBxc9dE/fLtn4UPF16Jc2/Ja8wP8duRNwaCJNiSCpKGt9YPj\n"
279 "lnX0xPPr/zqb2tIsWNQQN1Az0TlTcZ5ILbJbJ84e2dU2WawXOoPMWWuPaiS4n/Dm\n"
280 "FAMjWofnMxAyEViiu/HlWoiHu4AbtrsSGMsV1Tr8meRCWrpF\n"
281 "-----END CERTIFICATE-----\n";
283 /* Certificate with multiple wildcards SAN but no CN. */
284 char pem6[] =
285 "X.509 Certificate Information:\n"
286 " Version: 3\n"
287 " Serial Number (hex): 00\n"
288 " Validity:\n"
289 " Not Before: Sat May 3 11:00:51 UTC 2008\n"
290 " Not After: Sat May 17 11:00:54 UTC 2008\n"
291 " Subject: O=GnuTLS hostname check test CA\n"
292 " Subject Public Key Algorithm: RSA\n"
293 " Modulus (bits 1024):\n"
294 " d2:05:c1:65:cb:bd:1e:2e:eb:7b:87:07:94:4c:93:33\n"
295 " f3:81:83:7d:32:1b:71:4e:4e:7f:c7:bc:bf:4b:2f:f2\n"
296 " 49:b5:cf:bf:c0:b8:e8:29:cc:f3:61:bd:2e:1d:e4:e8\n"
297 " 19:dd:c5:bd:2e:f0:35:b1:fd:30:d7:f5:a8:7c:83:9a\n"
298 " 13:9e:bf:25:ed:08:a6:05:9e:7b:4e:23:59:c3:0e:5a\n"
299 " f3:bf:54:c7:dc:d4:13:57:a1:0f:a2:9e:c8:ab:75:66\n"
300 " de:07:84:8d:68:ad:71:04:e0:9c:bd:cb:f6:08:7a:97\n"
301 " 42:f8:10:94:29:01:4a:7e:61:d7:04:21:05:4c:f1:07\n"
302 " Exponent:\n"
303 " 01:00:01\n"
304 " Extensions:\n"
305 " Basic Constraints (critical):\n"
306 " Certificate Authority (CA): TRUE\n"
307 " Subject Alternative Name (not critical):\n"
308 " DNSname: *.*.example.org\n"
309 " Key Purpose (not critical):\n"
310 " TLS WWW Server.\n"
311 " Subject Key Identifier (not critical):\n"
312 " 5493e6599b283b4529378818aef9a4abbf4d9918\n"
313 "Other Information:\n"
314 " Public Key Id:\n"
315 " 5493e6599b283b4529378818aef9a4abbf4d9918\n"
316 "\n"
317 "-----BEGIN CERTIFICATE-----\n"
318 "MIICIjCCAY2gAwIBAgIBADALBgkqhkiG9w0BAQUwKDEmMCQGA1UEChMdR251VExT\n"
319 "IGhvc3RuYW1lIGNoZWNrIHRlc3QgQ0EwHhcNMDgwNTAzMTEwMDUxWhcNMDgwNTE3\n"
320 "MTEwMDU0WjAoMSYwJAYDVQQKEx1HbnVUTFMgaG9zdG5hbWUgY2hlY2sgdGVzdCBD\n"
321 "QTCBnDALBgkqhkiG9w0BAQEDgYwAMIGIAoGA0gXBZcu9Hi7re4cHlEyTM/OBg30y\n"
322 "G3FOTn/HvL9LL/JJtc+/wLjoKczzYb0uHeToGd3FvS7wNbH9MNf1qHyDmhOevyXt\n"
323 "CKYFnntOI1nDDlrzv1TH3NQTV6EPop7Iq3Vm3geEjWitcQTgnL3L9gh6l0L4EJQp\n"
324 "AUp+YdcEIQVM8QcCAwEAAaNjMGEwDwYDVR0TAQH/BAUwAwEB/zAaBgNVHREEEzAR\n"
325 "gg8qLiouZXhhbXBsZS5vcmcwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHQYDVR0OBBYE\n"
326 "FFST5lmbKDtFKTeIGK75pKu/TZkYMAsGCSqGSIb3DQEBBQOBgQAQ9PStleVvfmlK\n"
327 "wRs8RE/oOO+ouC3qLdnumNEITMRFh8Q12/X4yMLD3CH0aQ/hvHcP26PxAWzpNutk\n"
328 "swNx7AzsCu6pN1t1aI3jLgo8e4/zZi57e8QcRuXZPDJxtJxVhJZX/C4pSz802WhS\n"
329 "64NgtpHEMu9JUHFhtRwPcvVGYqPUUA==\n" "-----END CERTIFICATE-----\n";
331 /* Certificate with prefixed and suffixed wildcard SAN but no CN. */
332 char pem7[] =
333 "X.509 Certificate Information:\n"
334 " Version: 3\n"
335 " Serial Number (hex): 00\n"
336 " Validity:\n"
337 " Not Before: Sat May 3 11:02:43 UTC 2008\n"
338 " Not After: Sat May 17 11:02:45 UTC 2008\n"
339 " Subject: O=GnuTLS hostname check test CA\n"
340 " Subject Public Key Algorithm: RSA\n"
341 " Modulus (bits 1024):\n"
342 " d2:05:c1:65:cb:bd:1e:2e:eb:7b:87:07:94:4c:93:33\n"
343 " f3:81:83:7d:32:1b:71:4e:4e:7f:c7:bc:bf:4b:2f:f2\n"
344 " 49:b5:cf:bf:c0:b8:e8:29:cc:f3:61:bd:2e:1d:e4:e8\n"
345 " 19:dd:c5:bd:2e:f0:35:b1:fd:30:d7:f5:a8:7c:83:9a\n"
346 " 13:9e:bf:25:ed:08:a6:05:9e:7b:4e:23:59:c3:0e:5a\n"
347 " f3:bf:54:c7:dc:d4:13:57:a1:0f:a2:9e:c8:ab:75:66\n"
348 " de:07:84:8d:68:ad:71:04:e0:9c:bd:cb:f6:08:7a:97\n"
349 " 42:f8:10:94:29:01:4a:7e:61:d7:04:21:05:4c:f1:07\n"
350 " Exponent:\n"
351 " 01:00:01\n"
352 " Extensions:\n"
353 " Basic Constraints (critical):\n"
354 " Certificate Authority (CA): TRUE\n"
355 " Subject Alternative Name (not critical):\n"
356 " DNSname: foo*bar.example.org\n"
357 " Key Purpose (not critical):\n"
358 " TLS WWW Server.\n"
359 " Subject Key Identifier (not critical):\n"
360 " 5493e6599b283b4529378818aef9a4abbf4d9918\n"
361 "Other Information:\n"
362 " Public Key Id:\n"
363 " 5493e6599b283b4529378818aef9a4abbf4d9918\n"
364 "\n"
365 "-----BEGIN CERTIFICATE-----\n"
366 "MIICJjCCAZGgAwIBAgIBADALBgkqhkiG9w0BAQUwKDEmMCQGA1UEChMdR251VExT\n"
367 "IGhvc3RuYW1lIGNoZWNrIHRlc3QgQ0EwHhcNMDgwNTAzMTEwMjQzWhcNMDgwNTE3\n"
368 "MTEwMjQ1WjAoMSYwJAYDVQQKEx1HbnVUTFMgaG9zdG5hbWUgY2hlY2sgdGVzdCBD\n"
369 "QTCBnDALBgkqhkiG9w0BAQEDgYwAMIGIAoGA0gXBZcu9Hi7re4cHlEyTM/OBg30y\n"
370 "G3FOTn/HvL9LL/JJtc+/wLjoKczzYb0uHeToGd3FvS7wNbH9MNf1qHyDmhOevyXt\n"
371 "CKYFnntOI1nDDlrzv1TH3NQTV6EPop7Iq3Vm3geEjWitcQTgnL3L9gh6l0L4EJQp\n"
372 "AUp+YdcEIQVM8QcCAwEAAaNnMGUwDwYDVR0TAQH/BAUwAwEB/zAeBgNVHREEFzAV\n"
373 "ghNmb28qYmFyLmV4YW1wbGUub3JnMBMGA1UdJQQMMAoGCCsGAQUFBwMBMB0GA1Ud\n"
374 "DgQWBBRUk+ZZmyg7RSk3iBiu+aSrv02ZGDALBgkqhkiG9w0BAQUDgYEAPPNe38jc\n"
375 "8NsZQVKKLYc1Y4y8LRPhvnxkSnlcGa1RzYZY1s12BZ6OVIfyxD1Z9BcNdqRSq7bQ\n"
376 "kEicsGp5ugGQTNq6aSlzYOUD9/fUP3jDsH7HVb36aCF3waGCQWj+pLqK0LYcW2p/\n"
377 "xnr5+z4YevFBhn7l/fMhg8TzKejxYm7TECg=\n" "-----END CERTIFICATE-----\n";
379 /* Certificate with ending wildcard SAN but no CN. */
380 char pem8[] =
381 "X.509 Certificate Information:\n"
382 " Version: 3\n"
383 " Serial Number (hex): 00\n"
384 " Validity:\n"
385 " Not Before: Sat May 3 11:24:38 UTC 2008\n"
386 " Not After: Sat May 17 11:24:40 UTC 2008\n"
387 " Subject: O=GnuTLS hostname check test CA\n"
388 " Subject Public Key Algorithm: RSA\n"
389 " Modulus (bits 1024):\n"
390 " d2:05:c1:65:cb:bd:1e:2e:eb:7b:87:07:94:4c:93:33\n"
391 " f3:81:83:7d:32:1b:71:4e:4e:7f:c7:bc:bf:4b:2f:f2\n"
392 " 49:b5:cf:bf:c0:b8:e8:29:cc:f3:61:bd:2e:1d:e4:e8\n"
393 " 19:dd:c5:bd:2e:f0:35:b1:fd:30:d7:f5:a8:7c:83:9a\n"
394 " 13:9e:bf:25:ed:08:a6:05:9e:7b:4e:23:59:c3:0e:5a\n"
395 " f3:bf:54:c7:dc:d4:13:57:a1:0f:a2:9e:c8:ab:75:66\n"
396 " de:07:84:8d:68:ad:71:04:e0:9c:bd:cb:f6:08:7a:97\n"
397 " 42:f8:10:94:29:01:4a:7e:61:d7:04:21:05:4c:f1:07\n"
398 " Exponent:\n"
399 " 01:00:01\n"
400 " Extensions:\n"
401 " Basic Constraints (critical):\n"
402 " Certificate Authority (CA): TRUE\n"
403 " Subject Alternative Name (not critical):\n"
404 " DNSname: www.example.*\n"
405 " Key Purpose (not critical):\n"
406 " TLS WWW Server.\n"
407 " Subject Key Identifier (not critical):\n"
408 " 5493e6599b283b4529378818aef9a4abbf4d9918\n"
409 "Other Information:\n"
410 " Public Key Id:\n"
411 " 5493e6599b283b4529378818aef9a4abbf4d9918\n"
412 "\n"
413 "-----BEGIN CERTIFICATE-----\n"
414 "MIICIDCCAYugAwIBAgIBADALBgkqhkiG9w0BAQUwKDEmMCQGA1UEChMdR251VExT\n"
415 "IGhvc3RuYW1lIGNoZWNrIHRlc3QgQ0EwHhcNMDgwNTAzMTEyNDM4WhcNMDgwNTE3\n"
416 "MTEyNDQwWjAoMSYwJAYDVQQKEx1HbnVUTFMgaG9zdG5hbWUgY2hlY2sgdGVzdCBD\n"
417 "QTCBnDALBgkqhkiG9w0BAQEDgYwAMIGIAoGA0gXBZcu9Hi7re4cHlEyTM/OBg30y\n"
418 "G3FOTn/HvL9LL/JJtc+/wLjoKczzYb0uHeToGd3FvS7wNbH9MNf1qHyDmhOevyXt\n"
419 "CKYFnntOI1nDDlrzv1TH3NQTV6EPop7Iq3Vm3geEjWitcQTgnL3L9gh6l0L4EJQp\n"
420 "AUp+YdcEIQVM8QcCAwEAAaNhMF8wDwYDVR0TAQH/BAUwAwEB/zAYBgNVHREEETAP\n"
421 "gg13d3cuZXhhbXBsZS4qMBMGA1UdJQQMMAoGCCsGAQUFBwMBMB0GA1UdDgQWBBRU\n"
422 "k+ZZmyg7RSk3iBiu+aSrv02ZGDALBgkqhkiG9w0BAQUDgYEAZ7gLXtXwFW61dSAM\n"
423 "0Qt6IN68WBH7LCzetSF8ofG1WVUImCUU3pqXhXYtPGTrswOh2AavWTRbzVTtrFvf\n"
424 "WJg09Z7H6I70RPvAYGsK9t9qJ/4TPoYTGYQgsTbVpkv13O54O6jzemd8Zws/xMH5\n"
425 "7/q6C7P5OUmGOtfVe7UVDY0taQM=\n" "-----END CERTIFICATE-----\n";
427 /* Certificate with SAN and CN but for different names. */
428 char pem9[] =
429 "X.509 Certificate Information:\n"
430 " Version: 3\n"
431 " Serial Number (hex): 4a827d5c\n"
432 " Issuer: O=GnuTLS hostname check test CA,CN=foo.example.org\n"
433 " Validity:\n"
434 " Not Before: Wed Aug 12 08:29:17 UTC 2009\n"
435 " Not After: Thu Aug 13 08:29:23 UTC 2009\n"
436 " Subject: O=GnuTLS hostname check test CA,CN=foo.example.org\n"
437 " Subject Public Key Algorithm: RSA\n"
438 " Modulus (bits 1024):\n"
439 " bb:66:43:f5:f2:c5:d7:b6:8c:cc:c5:df:f5:88:3b:b1\n"
440 " c9:4b:6a:0e:a1:ad:20:50:40:08:80:a1:4f:5c:a3:d0\n"
441 " f8:6c:cf:e6:3c:f7:ec:04:76:13:17:8b:64:89:22:5b\n"
442 " c0:dd:53:7c:3b:ed:7c:04:bb:80:b9:28:be:8e:9b:c6\n"
443 " 8e:a0:a5:12:cb:f5:57:1e:a2:e7:bb:b7:33:49:9f:e3\n"
444 " bb:4a:ae:6a:4d:68:ff:c9:11:e2:32:8d:ce:3d:80:0b\n"
445 " 8d:75:ef:d8:00:81:8f:28:04:03:a0:22:8d:61:04:07\n"
446 " fa:b6:37:7d:21:07:49:d2:09:61:69:98:90:a3:58:a9\n"
447 " Exponent (bits 24):\n"
448 " 01:00:01\n"
449 " Extensions:\n"
450 " Basic Constraints (critical):\n"
451 " Certificate Authority (CA): TRUE\n"
452 " Subject Alternative Name (not critical):\n"
453 " DNSname: bar.example.org\n"
454 " Key Purpose (not critical):\n"
455 " TLS WWW Server.\n"
456 " Subject Key Identifier (not critical):\n"
457 " 4cb90a9bfa1d34e37edecbd20715fea1dacb6891\n"
458 " Signature Algorithm: RSA-SHA\n"
459 " Signature:\n"
460 " a2:1f:d2:90:5f:c9:1c:6f:92:1d:c5:0b:ac:b0:17:23\n"
461 " c5:67:46:94:6f:0f:62:7d:66:4c:28:ff:b7:10:73:60\n"
462 " ae:0e:a2:47:82:83:bb:89:0d:f1:16:5e:f9:5b:35:4b\n"
463 " ce:ee:5e:d0:ad:b5:8b:cc:37:b3:ac:4d:1b:58:c2:4f\n"
464 " 1c:7f:c6:ac:3d:25:18:67:37:f0:27:11:9b:2c:20:b6\n"
465 " 78:24:21:a6:77:44:e7:1a:e5:f6:bf:45:84:32:81:67\n"
466 " af:8d:96:26:f7:39:31:6b:63:c5:15:9d:e0:a0:9a:1e\n"
467 " 96:12:cb:ad:85:cb:a7:d4:86:ac:d8:f5:e9:a4:2b:20\n"
468 "Other Information:\n"
469 " MD5 fingerprint:\n"
470 " f27b18092c7497f206e70f504eee0f8e\n"
471 " SHA-1 fingerprint:\n"
472 " bebdac9d0dd54e8f044642e0f065fae5d75ca6e5\n"
473 " Public Key Id:\n"
474 " 4cb90a9bfa1d34e37edecbd20715fea1dacb6891\n"
475 "\n"
476 "-----BEGIN CERTIFICATE-----\n"
477 "MIICWTCCAcSgAwIBAgIESoJ9XDALBgkqhkiG9w0BAQUwQjEmMCQGA1UEChMdR251\n"
478 "VExTIGhvc3RuYW1lIGNoZWNrIHRlc3QgQ0ExGDAWBgNVBAMTD2Zvby5leGFtcGxl\n"
479 "Lm9yZzAeFw0wOTA4MTIwODI5MTdaFw0wOTA4MTMwODI5MjNaMEIxJjAkBgNVBAoT\n"
480 "HUdudVRMUyBob3N0bmFtZSBjaGVjayB0ZXN0IENBMRgwFgYDVQQDEw9mb28uZXhh\n"
481 "bXBsZS5vcmcwgZwwCwYJKoZIhvcNAQEBA4GMADCBiAKBgLtmQ/Xyxde2jMzF3/WI\n"
482 "O7HJS2oOoa0gUEAIgKFPXKPQ+GzP5jz37AR2ExeLZIkiW8DdU3w77XwEu4C5KL6O\n"
483 "m8aOoKUSy/VXHqLnu7czSZ/ju0quak1o/8kR4jKNzj2AC41179gAgY8oBAOgIo1h\n"
484 "BAf6tjd9IQdJ0glhaZiQo1ipAgMBAAGjYzBhMA8GA1UdEwEB/wQFMAMBAf8wGgYD\n"
485 "VR0RBBMwEYIPYmFyLmV4YW1wbGUub3JnMBMGA1UdJQQMMAoGCCsGAQUFBwMBMB0G\n"
486 "A1UdDgQWBBRMuQqb+h00437ey9IHFf6h2stokTALBgkqhkiG9w0BAQUDgYEAoh/S\n"
487 "kF/JHG+SHcULrLAXI8VnRpRvD2J9Zkwo/7cQc2CuDqJHgoO7iQ3xFl75WzVLzu5e\n"
488 "0K21i8w3s6xNG1jCTxx/xqw9JRhnN/AnEZssILZ4JCGmd0TnGuX2v0WEMoFnr42W\n"
489 "Jvc5MWtjxRWd4KCaHpYSy62Fy6fUhqzY9emkKyA=\n" "-----END CERTIFICATE-----\n";
491 /* Certificate with SAN and CN that match iff you truncate the SAN to
492 the embedded NUL.
493 See <http://thread.gmane.org/gmane.network.gnutls.general/1735>. */
494 char pem10[] =
495 "X.509 Certificate Information:\n"
496 " Version: 3\n"
497 " Serial Number (hex): 0b5d0a870d09\n"
498 " Issuer: C=NN,O=Edel Curl Arctic Illudium Research Cloud,CN=Nothern Nowhere Trust Anchor\n"
499 " Validity:\n"
500 " Not Before: Tue Aug 04 22:07:33 UTC 2009\n"
501 " Not After: Sat Oct 21 22:07:33 UTC 2017\n"
502 " Subject: C=NN,O=Edel Curl Arctic Illudium Research Cloud,CN=localhost\n"
503 " Subject Public Key Algorithm: RSA\n"
504 " Modulus (bits 1024):\n"
505 " be:67:3b:b4:ea:c0:85:b4:c3:56:c1:a4:96:23:36:f5\n"
506 " c6:77:aa:ad:e5:c1:dd:ce:c1:9a:97:07:dd:16:90:eb\n"
507 " f0:38:b5:95:6b:a6:0f:b9:73:4e:7d:82:57:ab:5f:b5\n"
508 " ba:5c:a0:48:8c:82:77:fd:67:d8:53:44:61:86:a5:06\n"
509 " 19:bf:73:51:68:2e:1a:0a:c5:05:39:ca:3d:ca:83:ed\n"
510 " 07:fe:ae:b7:73:1d:60:dd:ab:9e:0e:7e:02:f3:68:42\n"
511 " 93:27:c8:5f:c5:fa:cb:a9:84:06:2f:f3:66:bd:de:7d\n"
512 " 29:82:57:47:e4:a9:df:bf:8b:bc:c0:46:33:5a:7b:87\n"
513 " Exponent (bits 24):\n"
514 " 01:00:01\n"
515 " Extensions:\n"
516 " Subject Alternative Name (not critical):\n"
517 "warning: SAN contains an embedded NUL, replacing with '!'\n"
518 " DNSname: localhost!h\n"
519 " Key Usage (not critical):\n"
520 " Key encipherment.\n"
521 " Key Purpose (not critical):\n"
522 " TLS WWW Server.\n"
523 " Subject Key Identifier (not critical):\n"
524 " 0c37a3db0f73b3388a69d36eb3a7d6d8774eda67\n"
525 " Authority Key Identifier (not critical):\n"
526 " 126b24d24a68b7a1b01ccdbfd64ccc405b7fe040\n"
527 " Basic Constraints (critical):\n"
528 " Certificate Authority (CA): FALSE\n"
529 " Signature Algorithm: RSA-SHA\n"
530 " Signature:\n"
531 " 88:a0:17:77:77:bf:c1:8a:18:4e:a3:94:6e:45:18:31\n"
532 " fa:2f:7b:1f:ee:95:20:d1:cd:40:df:ee:f0:45:2e:e9\n"
533 " e6:cf:c8:77:bd:85:16:d7:9f:18:52:78:3f:ea:9c:86\n"
534 " 62:6e:db:90:b0:cd:f1:c1:6f:2d:87:4a:a0:be:b3:dc\n"
535 " 6d:e4:6b:d1:da:b9:10:25:7e:35:1f:1b:aa:a7:09:2f\n"
536 " 84:77:27:b0:48:a8:6d:54:57:38:35:22:34:03:0f:d4\n"
537 " 5d:ab:1c:72:15:b1:d9:89:56:10:12:fb:7d:0d:18:12\n"
538 " a9:0a:38:dc:93:cf:69:ff:75:86:9e:e3:6b:eb:92:6c\n"
539 " 55:16:d5:65:8b:d7:9c:5e:4b:82:c8:92:6c:8b:e6:18\n"
540 " a2:f8:8c:65:aa:b6:eb:23:ed:cb:99:db:fc:8b:8e:1d\n"
541 " 7a:39:c9:f5:7b:7f:58:7b:ed:01:6c:3c:40:ec:e3:a9\n"
542 " 5f:c4:3d:cb:81:17:03:6d:2d:d7:bd:00:5f:c4:79:f2\n"
543 " fb:ab:c6:0e:a2:01:8b:a1:42:73:de:96:29:3e:bf:d7\n"
544 " d9:51:a7:d4:98:07:7f:f0:f4:cd:00:a1:e1:ac:6c:05\n"
545 " ac:ab:93:1b:b0:5c:2c:13:ad:ff:27:dc:80:99:34:66\n"
546 " bd:e3:31:54:d5:b6:3f:ce:d4:08:a3:52:28:61:5e:bd\n"
547 "Other Information:\n"
548 " MD5 fingerprint:\n"
549 " 0b4d6d944200cdd1639008b24dc0fe0a\n"
550 " SHA-1 fingerprint:\n"
551 " ce85660f5451b0cc12f525577f0eb9411a20c76b\n"
552 " Public Key Id:\n"
553 " a1d18c15e65c7c4935512eeea7ca5d3e6baad4e1\n"
554 "\n"
555 "-----BEGIN CERTIFICATE-----\n"
556 "MIIDQzCCAiugAwIBAgIGC10Khw0JMA0GCSqGSIb3DQEBBQUAMGcxCzAJBgNVBAYT\n"
557 "Ak5OMTEwLwYDVQQKDChFZGVsIEN1cmwgQXJjdGljIElsbHVkaXVtIFJlc2VhcmNo\n"
558 "IENsb3VkMSUwIwYDVQQDDBxOb3RoZXJuIE5vd2hlcmUgVHJ1c3QgQW5jaG9yMB4X\n"
559 "DTA5MDgwNDIyMDczM1oXDTE3MTAyMTIyMDczM1owVDELMAkGA1UEBhMCTk4xMTAv\n"
560 "BgNVBAoMKEVkZWwgQ3VybCBBcmN0aWMgSWxsdWRpdW0gUmVzZWFyY2ggQ2xvdWQx\n"
561 "EjAQBgNVBAMMCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA\n"
562 "vmc7tOrAhbTDVsGkliM29cZ3qq3lwd3OwZqXB90WkOvwOLWVa6YPuXNOfYJXq1+1\n"
563 "ulygSIyCd/1n2FNEYYalBhm/c1FoLhoKxQU5yj3Kg+0H/q63cx1g3aueDn4C82hC\n"
564 "kyfIX8X6y6mEBi/zZr3efSmCV0fkqd+/i7zARjNae4cCAwEAAaOBizCBiDAWBgNV\n"
565 "HREEDzANggtsb2NhbGhvc3QAaDALBgNVHQ8EBAMCBSAwEwYDVR0lBAwwCgYIKwYB\n"
566 "BQUHAwEwHQYDVR0OBBYEFAw3o9sPc7M4imnTbrOn1th3TtpnMB8GA1UdIwQYMBaA\n"
567 "FBJrJNJKaLehsBzNv9ZMzEBbf+BAMAwGA1UdEwEB/wQCMAAwDQYJKoZIhvcNAQEF\n"
568 "BQADggEBAIigF3d3v8GKGE6jlG5FGDH6L3sf7pUg0c1A3+7wRS7p5s/Id72FFtef\n"
569 "GFJ4P+qchmJu25CwzfHBby2HSqC+s9xt5GvR2rkQJX41HxuqpwkvhHcnsEiobVRX\n"
570 "ODUiNAMP1F2rHHIVsdmJVhAS+30NGBKpCjjck89p/3WGnuNr65JsVRbVZYvXnF5L\n"
571 "gsiSbIvmGKL4jGWqtusj7cuZ2/yLjh16Ocn1e39Ye+0BbDxA7OOpX8Q9y4EXA20t\n"
572 "170AX8R58vurxg6iAYuhQnPelik+v9fZUafUmAd/8PTNAKHhrGwFrKuTG7BcLBOt\n"
573 "/yfcgJk0Zr3jMVTVtj/O1AijUihhXr0=\n" "-----END CERTIFICATE-----\n";
575 char pem_too_many[] = "\n"
576 " Subject: C=BE,CN=******************.gnutls.org\n"
577 "\n"
578 "-----BEGIN CERTIFICATE-----\n"
579 "MIIDljCCAk6gAwIBAgIETcMNdjANBgkqhkiG9w0BAQsFADA6MQswCQYDVQQGEwJC\n"
580 "RTErMCkGA1UEAxMiKioqKioqKioqKioqKioqKioqKioqKiouZ251dGxzLm9yZzAe\n"
581 "Fw0xMTA1MDUyMDQ5NTlaFw02NDAxMTUyMDUwMDJaMDoxCzAJBgNVBAYTAkJFMSsw\n"
582 "KQYDVQQDEyIqKioqKioqKioqKioqKioqKioqKioqKi5nbnV0bHMub3JnMIIBUjAN\n"
583 "BgkqhkiG9w0BAQEFAAOCAT8AMIIBOgKCATEA3c+X0qUdld2GGNjEua2mDLSdttz6\n"
584 "3CHhOmI0B+gzsuiX7ixB0hLxX+3kdv9lJh4Mx0EVaV8N+a2JFI3q1xZSmkfBuwAC\n"
585 "5IhFc3ikrts4w8YH0mQOh+10jGvEwAJQfE6m0Vjp5RMJqdta6usPBoBcCe+UyOn7\n"
586 "Ny514ayTrZs3E0tmOnYz2MTXTPthyJIhB/zfqYhU5KOpR9JsuOM5iRGIOC2i3D5e\n"
587 "SqmkjtUfstDdQTzaEGieRxtlAqLFKHMCgwMJ/fUpfpfcKk5LqnlGRnCGG5u49oq+\n"
588 "KYd9X9qll2vvyEMJQ+IfihZ+HVBd9doC7vLDKkjmazDqAtfvrIsMuMGF2L98hage\n"
589 "g75cJi55e0f1Sj9mYpL9QSC2LADwUsomBi18z3pQfQ/L3ZcgyG/k4FD04wIDAQAB\n"
590 "o0QwQjAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMB0GA1UdDgQW\n"
591 "BBSSU9ZxufhoqrNT9o31OUVmnKflMTANBgkqhkiG9w0BAQsFAAOCATEAUMK435LP\n"
592 "0XpmpWLBBuC6VLLIsAGmXRv7odw8sG9fOctalsbK3zd9pDOaoFI/128GOmlTp1aC\n"
593 "n4a/pZ9G5wTKRvdxVqecdYkozDtAS35uwCSQPU/P12Oug6kA4NNJDxF3FGm5eov6\n"
594 "SnZDL0Qlhat9y0yOakaOkVNwESAwgUEYClZeR45htvH5oP48XEgwqHQ9jPS2MXAe\n"
595 "QLBjqqeYzIvWqwT4z14tIkN0VWWqqVo/dzV+lfNwQy0UL8iWVYnks8wKs2SBkVHx\n"
596 "41wBR3uCgCDwlYGDLIG1cm0n7mXrnE7KNcrwQKXL8WGNRAVvx5MVO1vDoWPyQ1Y4\n"
597 "sDdnQiVER9ee/KxO6IgCTGh+nCBTSSYgLX2E/m789quPvzyi9Hf/go28he6E3dSK\n"
598 "q7/LRSxaZenB/Q==\n"
599 "-----END CERTIFICATE-----\n";
601 #ifdef ENABLE_OPENPGP
602 /* Check basic OpenPGP comparison too.
603 <http://thread.gmane.org/gmane.comp.encryption.gpg.gnutls.devel/3812>. */
604 char pem11[] =
605 "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
606 "Version: GnuPG v1.4.6 (GNU/Linux)\n"
607 "\n"
608 "mQGiBEXInlgRBAD0teb6ohIlchkHcFlmmvtVW1KXexlDfXExf8T+fOz5z354GPOX\n"
609 "sDq98ztCEE3hnPEOFj4NT0X3nEtrvLkhmZqrDHSbuJACB4qxeHwEbGFx7OIDW8+u\n"
610 "4sKxpaza1GVf1NQ7VIaQiXaGHy8Esn9SW7oNhK6z5l4TIRlm3OBt3cxU3wCgjnnO\n"
611 "jpGJeeo0OnZzSH+xsNLJQEcEAOmUc+7N9OhpT/gqddIgzYRr/FD0Ad6HBfABol6Q\n"
612 "wWCapzIxggnZJ9i+lHujpcA8idtrBU/DGhkGtW95QaHwQ8d5SvetM7Wc/xoHEP3o\n"
613 "HGvSGoXtfqlofastcC7eso39EBD10cpIB+gUmhe1MpaXm7A6m+KJO+2CkqE1vMkc\n"
614 "tmKHBACzDRrWgkV+AtGWKl3ge9RkYHKxAPc0FBrpzDrvmvvNMaIme2u/+WP/xa4T\n"
615 "nTjgys+pfeplHVfCO/n6nKWrVepMPE0+ZeNWzY6CsfhL7VjSN99vm7qzNHswBiJS\n"
616 "gCSwJXRmQcJcS9hxqLciUyVEB32zPqX24QHnsyPYaSCzEBgOnLQPdGVzdC5nbnV0\n"
617 "bHMub3JniF8EExECACAFAkXInlgCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAK\n"
618 "CRCuX60+XR0U2FcfAJ9eZDmhk5a9k4K/zu+a5xFwb9SWsgCXTkDnOIQmueZPHg5U\n"
619 "VgKnazckK7kCDQRFyJ51EAgAozi9Vk9R5I2AtRcqV4jLfpzh3eiBYSUt4U3ZLxff\n"
620 "LAyvGMUXA7OATGGhuKphNQLux17AGpRN4nugnIWMLE9akyrxXqg/165UFKbwwVsl\n"
621 "po7KzPvEXHmOYDgVEqS0sZNWmkJeMPdCVsD2wifPkocufUu2Ux8CmrvT1nEgoiVu\n"
622 "kUjplJOralQBdsPkIEk8LMVtF3IW2aHCEET0yrJ2Y2q0i/u1K4bxSUi5ESrN0UNa\n"
623 "WT7wtCegdwWlObwJEgwcu/8YtjMnfBI855gXVdJiRLdOJvkU+65I/jnPQG5QEIQM\n"
624 "weLty/+GHkXVN2xw5OGUIryIPUHi8+EDGOGqoxqNUMTzvwADBQf/bTPc0z3oHp+X\n"
625 "hsj3JP/AMCSQV87peKqFYEnRIubsN4Y4tTwVjEkRA3s5u+qTNvdypE1tvAEmdspa\n"
626 "CL/EKfMCEltcW3WUwqUIULQ2Z0t9tBuVfMEH1Z1jjb68IOVwTJYz+iBtmbq5Wxoq\n"
627 "lc5woOCDVL9qaKR6hOuAukTl6L3wQL+5zGBE4k5UfLf8UVJEa4ZTqsoMi3iyQAFO\n"
628 "/h7WzqUATH3aQSz9tpilJ760wadDhc+Sdt2a0W6cC+SBmJaU/ym9seTd26nyWHG+\n"
629 "03G+ynCHf5pBAXHhfCNhA0lMv5h3eJECNElcCh0sYGmo19jOzbnlRSGKRqrflOtO\n"
630 "YwhQXK9y/ohJBBgRAgAJBQJFyJ51AhsMAAoJEK5frT5dHRTYDDgAn2bLaS5n3Xy8\n"
631 "Z/V2Me1st/9pqPfZAJ4+9YBnyjCq/0vosIoZabi+s92m7g==\n"
632 "=NkXV\n" "-----END PGP PUBLIC KEY BLOCK-----\n";
633 #endif
635 void
636 doit (void)
638 gnutls_x509_crt_t x509;
639 #ifdef ENABLE_OPENPGP
640 gnutls_openpgp_crt_t pgp;
641 #endif
642 gnutls_datum_t data;
643 int ret;
645 ret = gnutls_global_init ();
646 if (ret < 0)
647 fail ("gnutls_global_init: %d\n", ret);
649 ret = gnutls_x509_crt_init (&x509);
650 if (ret < 0)
651 fail ("gnutls_x509_crt_init: %d\n", ret);
653 #ifdef ENABLE_OPENPGP
654 ret = gnutls_openpgp_crt_init (&pgp);
655 if (ret < 0)
656 fail ("gnutls_openpgp_crt_init: %d\n", ret);
657 #endif
659 if (debug)
660 success ("Testing pem1...\n");
661 data.data = (unsigned char*)pem1;
662 data.size = strlen (pem1);
664 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
665 if (ret < 0)
666 fail ("gnutls_x509_crt_import: %d\n", ret);
668 ret = gnutls_x509_crt_check_hostname (x509, "foo");
669 if (ret)
670 fail ("Hostname incorrectly matches (%d)\n", ret);
672 if (debug)
673 success ("Testing pem2...\n");
674 data.data = (unsigned char*)pem2;
675 data.size = strlen (pem2);
677 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
678 if (ret < 0)
679 fail ("gnutls_x509_crt_import: %d\n", ret);
681 ret = gnutls_x509_crt_check_hostname (x509, "foo");
682 if (ret)
683 fail ("Hostname incorrectly matches (%d)\n", ret);
685 ret = gnutls_x509_crt_check_hostname (x509, "www.example.org");
686 if (!ret)
687 fail ("Hostname incorrectly does not match (%d)\n", ret);
689 ret = gnutls_x509_crt_check_hostname (x509, "*.example.org");
690 if (ret)
691 fail ("Hostname incorrectly matches (%d)\n", ret);
693 if (debug)
694 success ("Testing pem3...\n");
695 data.data = (unsigned char*)pem3;
696 data.size = strlen (pem3);
698 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
699 if (ret < 0)
700 fail ("gnutls_x509_crt_import: %d\n", ret);
702 ret = gnutls_x509_crt_check_hostname (x509, "foo");
703 if (ret)
704 fail ("Hostname incorrectly matches (%d)\n", ret);
706 ret = gnutls_x509_crt_check_hostname (x509, "www.example.org");
707 if (!ret)
708 fail ("Hostname incorrectly does not match (%d)\n", ret);
710 ret = gnutls_x509_crt_check_hostname (x509, "*.example.org");
711 if (ret)
712 fail ("Hostname incorrectly matches (%d)\n", ret);
714 if (debug)
715 success ("Testing pem4...\n");
716 data.data = (unsigned char*)pem4;
717 data.size = strlen (pem4);
719 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
720 if (ret < 0)
721 fail ("gnutls_x509_crt_import: %d\n", ret);
723 ret = gnutls_x509_crt_check_hostname (x509, "foo");
724 if (ret)
725 fail ("Hostname incorrectly matches (%d)\n", ret);
727 ret = gnutls_x509_crt_check_hostname (x509, "www.example.org");
728 if (!ret)
729 fail ("Hostname incorrectly does not match (%d)\n", ret);
731 ret = gnutls_x509_crt_check_hostname (x509, "foo.example.org");
732 if (!ret)
733 fail ("Hostname incorrectly does not match (%d)\n", ret);
735 ret = gnutls_x509_crt_check_hostname (x509, "foo.example.com");
736 if (ret)
737 fail ("Hostname incorrectly matches (%d)\n", ret);
739 if (debug)
740 success ("Testing pem6...\n");
741 data.data = (unsigned char*)pem6;
742 data.size = strlen (pem6);
744 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
745 if (ret < 0)
746 fail ("gnutls_x509_crt_import: %d\n", ret);
748 ret = gnutls_x509_crt_check_hostname (x509, "foo.example.org");
749 if (ret)
750 fail ("Hostname incorrectly matches (%d)\n", ret);
752 ret = gnutls_x509_crt_check_hostname (x509, "bar.foo.example.org");
753 if (!ret)
754 fail ("Hostname incorrectly does not match (%d)\n", ret);
756 if (debug)
757 success ("Testing pem7...\n");
758 data.data = (unsigned char*)pem7;
759 data.size = strlen (pem7);
761 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
762 if (ret < 0)
763 fail ("gnutls_x509_crt_import: %d\n", ret);
765 ret = gnutls_x509_crt_check_hostname (x509, "foo.bar.example.org");
766 if (ret)
767 fail ("Hostname incorrectly matches (%d)\n", ret);
769 ret = gnutls_x509_crt_check_hostname (x509, "foobar.bar.example.org");
770 if (ret)
771 fail ("Hostname incorrectly matches (%d)\n", ret);
773 ret = gnutls_x509_crt_check_hostname (x509, "foobar.example.org");
774 if (!ret)
775 fail ("Hostname incorrectly does not match (%d)\n", ret);
777 ret = gnutls_x509_crt_check_hostname (x509, "foobazbar.example.org");
778 if (!ret)
779 fail ("Hostname incorrectly does not match (%d)\n", ret);
781 if (debug)
782 success ("Testing pem8...\n");
783 data.data = (unsigned char*)pem8;
784 data.size = strlen (pem8);
786 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
787 if (ret < 0)
788 fail ("gnutls_x509_crt_import: %d\n", ret);
790 ret = gnutls_x509_crt_check_hostname (x509, "www.example.org");
791 if (!ret)
792 fail ("Hostname incorrectly does not match (%d)\n", ret);
794 ret = gnutls_x509_crt_check_hostname (x509, "www.example.");
795 if (!ret)
796 fail ("Hostname incorrectly does not match (%d)\n", ret);
798 ret = gnutls_x509_crt_check_hostname (x509, "www.example.com");
799 if (!ret)
800 fail ("Hostname incorrectly does not match (%d)\n", ret);
802 ret = gnutls_x509_crt_check_hostname (x509, "www.example.foo.com");
803 if (ret)
804 fail ("Hostname incorrectly matches (%d)\n", ret);
806 if (debug)
807 success ("Testing pem9...\n");
808 data.data = (unsigned char*)pem9;
809 data.size = strlen (pem9);
811 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
812 if (ret < 0)
813 fail ("gnutls_x509_crt_import: %d\n", ret);
815 ret = gnutls_x509_crt_check_hostname (x509, "foo.example.org");
816 if (ret)
817 fail ("Hostname incorrectly matches (%d)\n", ret);
819 ret = gnutls_x509_crt_check_hostname (x509, "bar.example.org");
820 if (!ret)
821 fail ("Hostname incorrectly does not match (%d)\n", ret);
823 if (debug)
824 success ("Testing pem10...\n");
825 data.data = (unsigned char*)pem10;
826 data.size = strlen (pem10);
828 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
829 if (ret < 0)
830 fail ("gnutls_x509_crt_import: %d\n", ret);
832 ret = gnutls_x509_crt_check_hostname (x509, "localhost");
833 if (ret)
834 fail ("Hostname incorrectly matches (%d)\n", ret);
836 if (debug)
837 success ("Testing pem_too_many...\n");
838 data.data = (unsigned char*)pem_too_many;
839 data.size = strlen (pem_too_many);
841 ret = gnutls_x509_crt_import (x509, &data, GNUTLS_X509_FMT_PEM);
842 if (ret < 0)
843 fail ("gnutls_x509_crt_import: %d\n", ret);
845 ret = gnutls_x509_crt_check_hostname (x509, "localhost.gnutls.gnutls.org");
846 if (ret)
847 fail ("Hostname verification should have failed (too many wildcards)\n");
849 #ifdef ENABLE_OPENPGP
850 if (debug)
851 success ("Testing pem11...\n");
852 data.data = (unsigned char*)pem11;
853 data.size = strlen (pem11);
855 ret = gnutls_openpgp_crt_import (pgp, &data, GNUTLS_OPENPGP_FMT_BASE64);
856 if (ret < 0)
857 fail ("gnutls_openpgp_crt_import: %d\n", ret);
859 ret = gnutls_openpgp_crt_check_hostname (pgp, "test.gnutls.org");
860 if (!ret)
861 fail ("Hostname incorrectly does not match (%d)\n", ret);
863 gnutls_openpgp_crt_deinit (pgp);
864 #endif
865 gnutls_x509_crt_deinit (x509);
867 gnutls_global_deinit ();