1 /* $OpenBSD: test_sshkey.c,v 1.20 2019/11/25 10:32:35 djm Exp $ */
2 /*
3 * Regress test for sshkey.h key management API
4 *
5 * Placed in the public domain
6 */
7
8 #include "includes.h"
9
10 #include <sys/types.h>
11 #include <sys/param.h>
12 #include <stdio.h>
13 #ifdef HAVE_STDINT_H
14 #include <stdint.h>
15 #endif
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include <openssl/bn.h>
20 #include <openssl/rsa.h>
21 #include <openssl/dsa.h>
22 #if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
23 # include <openssl/ec.h>
24 #endif
25
26 #include "../test_helper/test_helper.h"
27
28 #include "ssherr.h"
29 #include "sshbuf.h"
30 #define SSHBUF_INTERNAL 1 /* access internals for testing */
31 #include "sshkey.h"
32
33 #include "authfile.h"
34 #include "common.h"
35 #include "ssh2.h"
36
37 void sshkey_tests(void);
38
39 static void
put_opt(struct sshbuf * b,const char * name,const char * value)40 put_opt(struct sshbuf *b, const char *name, const char *value)
41 {
42 struct sshbuf *sect;
43
44 sect = sshbuf_new();
45 ASSERT_PTR_NE(sect, NULL);
46 ASSERT_INT_EQ(sshbuf_put_cstring(b, name), 0);
47 if (value != NULL)
48 ASSERT_INT_EQ(sshbuf_put_cstring(sect, value), 0);
49 ASSERT_INT_EQ(sshbuf_put_stringb(b, sect), 0);
50 sshbuf_free(sect);
51 }
52
53 #ifdef WITH_OPENSSL
54 static void
build_cert(struct sshbuf * b,struct sshkey * k,const char * type,struct sshkey * sign_key,struct sshkey * ca_key,const char * sig_alg)55 build_cert(struct sshbuf *b, struct sshkey *k, const char *type,
56 struct sshkey *sign_key, struct sshkey *ca_key,
57 const char *sig_alg)
58 {
59 struct sshbuf *ca_buf, *pk, *principals, *critopts, *exts;
60 u_char *sigblob;
61 size_t siglen;
62
63 ca_buf = sshbuf_new();
64 ASSERT_PTR_NE(ca_buf, NULL);
65 ASSERT_INT_EQ(sshkey_putb(ca_key, ca_buf), 0);
66
67 /*
68 * Get the public key serialisation by rendering the key and skipping
69 * the type string. This is a bit of a hack :/
70 */
71 pk = sshbuf_new();
72 ASSERT_PTR_NE(pk, NULL);
73 ASSERT_INT_EQ(sshkey_putb_plain(k, pk), 0);
74 ASSERT_INT_EQ(sshbuf_skip_string(pk), 0);
75
76 principals = sshbuf_new();
77 ASSERT_PTR_NE(principals, NULL);
78 ASSERT_INT_EQ(sshbuf_put_cstring(principals, "gsamsa"), 0);
79 ASSERT_INT_EQ(sshbuf_put_cstring(principals, "gregor"), 0);
80
81 critopts = sshbuf_new();
82 ASSERT_PTR_NE(critopts, NULL);
83 put_opt(critopts, "force-command", "/usr/local/bin/nethack");
84 put_opt(critopts, "source-address", "192.168.0.0/24,127.0.0.1,::1");
85
86 exts = sshbuf_new();
87 ASSERT_PTR_NE(exts, NULL);
88 put_opt(critopts, "permit-X11-forwarding", NULL);
89
90 ASSERT_INT_EQ(sshbuf_put_cstring(b, type), 0);
91 ASSERT_INT_EQ(sshbuf_put_cstring(b, "noncenoncenonce!"), 0); /* nonce */
92 ASSERT_INT_EQ(sshbuf_putb(b, pk), 0); /* public key serialisation */
93 ASSERT_INT_EQ(sshbuf_put_u64(b, 1234), 0); /* serial */
94 ASSERT_INT_EQ(sshbuf_put_u32(b, SSH2_CERT_TYPE_USER), 0); /* type */
95 ASSERT_INT_EQ(sshbuf_put_cstring(b, "gregor"), 0); /* key ID */
96 ASSERT_INT_EQ(sshbuf_put_stringb(b, principals), 0); /* principals */
97 ASSERT_INT_EQ(sshbuf_put_u64(b, 0), 0); /* start */
98 ASSERT_INT_EQ(sshbuf_put_u64(b, 0xffffffffffffffffULL), 0); /* end */
99 ASSERT_INT_EQ(sshbuf_put_stringb(b, critopts), 0); /* options */
100 ASSERT_INT_EQ(sshbuf_put_stringb(b, exts), 0); /* extensions */
101 ASSERT_INT_EQ(sshbuf_put_string(b, NULL, 0), 0); /* reserved */
102 ASSERT_INT_EQ(sshbuf_put_stringb(b, ca_buf), 0); /* signature key */
103 ASSERT_INT_EQ(sshkey_sign(sign_key, &sigblob, &siglen,
104 sshbuf_ptr(b), sshbuf_len(b), sig_alg, NULL, 0), 0);
105 ASSERT_INT_EQ(sshbuf_put_string(b, sigblob, siglen), 0); /* signature */
106
107 free(sigblob);
108 sshbuf_free(ca_buf);
109 sshbuf_free(exts);
110 sshbuf_free(critopts);
111 sshbuf_free(principals);
112 sshbuf_free(pk);
113 }
114 #endif /* WITH_OPENSSL */
115
116 static void
signature_test(struct sshkey * k,struct sshkey * bad,const char * sig_alg,const u_char * d,size_t l)117 signature_test(struct sshkey *k, struct sshkey *bad, const char *sig_alg,
118 const u_char *d, size_t l)
119 {
120 size_t len;
121 u_char *sig;
122
123 ASSERT_INT_EQ(sshkey_sign(k, &sig, &len, d, l, sig_alg, NULL, 0), 0);
124 ASSERT_SIZE_T_GT(len, 8);
125 ASSERT_PTR_NE(sig, NULL);
126 ASSERT_INT_EQ(sshkey_verify(k, sig, len, d, l, NULL, 0, NULL), 0);
127 ASSERT_INT_NE(sshkey_verify(bad, sig, len, d, l, NULL, 0, NULL), 0);
128 /* Fuzz test is more comprehensive, this is just a smoke test */
129 sig[len - 5] ^= 0x10;
130 ASSERT_INT_NE(sshkey_verify(k, sig, len, d, l, NULL, 0, NULL), 0);
131 free(sig);
132 }
133
134 static void
banana(u_char * s,size_t l)135 banana(u_char *s, size_t l)
136 {
137 size_t o;
138 const u_char the_banana[] = { 'b', 'a', 'n', 'a', 'n', 'a' };
139
140 for (o = 0; o < l; o += sizeof(the_banana)) {
141 if (l - o < sizeof(the_banana)) {
142 memcpy(s + o, "nanananana", l - o);
143 break;
144 }
145 memcpy(s + o, banana, sizeof(the_banana));
146 }
147 }
148
149 static void
signature_tests(struct sshkey * k,struct sshkey * bad,const char * sig_alg)150 signature_tests(struct sshkey *k, struct sshkey *bad, const char *sig_alg)
151 {
152 u_char i, buf[2049];
153 size_t lens[] = {
154 1, 2, 7, 8, 9, 15, 16, 17, 31, 32, 33, 127, 128, 129,
155 255, 256, 257, 1023, 1024, 1025, 2047, 2048, 2049
156 };
157
158 for (i = 0; i < (sizeof(lens)/sizeof(lens[0])); i++) {
159 test_subtest_info("%s key, banana length %zu",
160 sshkey_type(k), lens[i]);
161 banana(buf, lens[i]);
162 signature_test(k, bad, sig_alg, buf, lens[i]);
163 }
164 }
165
166 static struct sshkey *
get_private(const char * n)167 get_private(const char *n)
168 {
169 struct sshbuf *b;
170 struct sshkey *ret;
171
172 b = load_file(n);
173 ASSERT_INT_EQ(sshkey_parse_private_fileblob(b, "", &ret, NULL), 0);
174 sshbuf_free(b);
175 return ret;
176 }
177
178 void
sshkey_tests(void)179 sshkey_tests(void)
180 {
181 struct sshkey *k1, *k2, *k3, *kf;
182 #ifdef WITH_OPENSSL
183 struct sshkey *k4, *kr, *kd;
184 #ifdef OPENSSL_HAS_ECC
185 struct sshkey *ke;
186 #endif /* OPENSSL_HAS_ECC */
187 #endif /* WITH_OPENSSL */
188 struct sshbuf *b;
189
190 TEST_START("new invalid");
191 k1 = sshkey_new(-42);
192 ASSERT_PTR_EQ(k1, NULL);
193 TEST_DONE();
194
195 TEST_START("new/free KEY_UNSPEC");
196 k1 = sshkey_new(KEY_UNSPEC);
197 ASSERT_PTR_NE(k1, NULL);
198 sshkey_free(k1);
199 TEST_DONE();
200
201 #ifdef WITH_OPENSSL
202 TEST_START("new/free KEY_RSA");
203 k1 = sshkey_new(KEY_RSA);
204 ASSERT_PTR_NE(k1, NULL);
205 ASSERT_PTR_NE(k1->rsa, NULL);
206 sshkey_free(k1);
207 TEST_DONE();
208
209 TEST_START("new/free KEY_DSA");
210 k1 = sshkey_new(KEY_DSA);
211 ASSERT_PTR_NE(k1, NULL);
212 ASSERT_PTR_NE(k1->dsa, NULL);
213 sshkey_free(k1);
214 TEST_DONE();
215
216 #ifdef OPENSSL_HAS_ECC
217 TEST_START("new/free KEY_ECDSA");
218 k1 = sshkey_new(KEY_ECDSA);
219 ASSERT_PTR_NE(k1, NULL);
220 ASSERT_PTR_EQ(k1->ecdsa, NULL); /* Can't allocate without NID */
221 sshkey_free(k1);
222 TEST_DONE();
223 #endif
224
225 TEST_START("new/free KEY_ED25519");
226 k1 = sshkey_new(KEY_ED25519);
227 ASSERT_PTR_NE(k1, NULL);
228 /* These should be blank until key loaded or generated */
229 ASSERT_PTR_EQ(k1->ed25519_sk, NULL);
230 ASSERT_PTR_EQ(k1->ed25519_pk, NULL);
231 sshkey_free(k1);
232 TEST_DONE();
233
234 TEST_START("generate KEY_RSA too small modulus");
235 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 128, &k1),
236 SSH_ERR_KEY_LENGTH);
237 ASSERT_PTR_EQ(k1, NULL);
238 TEST_DONE();
239
240 TEST_START("generate KEY_RSA too large modulus");
241 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1 << 20, &k1),
242 SSH_ERR_KEY_LENGTH);
243 ASSERT_PTR_EQ(k1, NULL);
244 TEST_DONE();
245
246 TEST_START("generate KEY_DSA wrong bits");
247 ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 2048, &k1),
248 SSH_ERR_KEY_LENGTH);
249 ASSERT_PTR_EQ(k1, NULL);
250 sshkey_free(k1);
251 TEST_DONE();
252
253 #ifdef OPENSSL_HAS_ECC
254 TEST_START("generate KEY_ECDSA wrong bits");
255 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 42, &k1),
256 SSH_ERR_KEY_LENGTH);
257 ASSERT_PTR_EQ(k1, NULL);
258 sshkey_free(k1);
259 TEST_DONE();
260 #endif
261
262 TEST_START("generate KEY_RSA");
263 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 767, &kr),
264 SSH_ERR_KEY_LENGTH);
265 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &kr), 0);
266 ASSERT_PTR_NE(kr, NULL);
267 ASSERT_PTR_NE(kr->rsa, NULL);
268 ASSERT_PTR_NE(rsa_n(kr), NULL);
269 ASSERT_PTR_NE(rsa_e(kr), NULL);
270 ASSERT_PTR_NE(rsa_p(kr), NULL);
271 ASSERT_INT_EQ(BN_num_bits(rsa_n(kr)), 1024);
272 TEST_DONE();
273
274 TEST_START("generate KEY_DSA");
275 ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0);
276 ASSERT_PTR_NE(kd, NULL);
277 ASSERT_PTR_NE(kd->dsa, NULL);
278 ASSERT_PTR_NE(dsa_g(kd), NULL);
279 ASSERT_PTR_NE(dsa_priv_key(kd), NULL);
280 TEST_DONE();
281
282 #ifdef OPENSSL_HAS_ECC
283 TEST_START("generate KEY_ECDSA");
284 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &ke), 0);
285 ASSERT_PTR_NE(ke, NULL);
286 ASSERT_PTR_NE(ke->ecdsa, NULL);
287 ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL);
288 ASSERT_PTR_NE(EC_KEY_get0_private_key(ke->ecdsa), NULL);
289 TEST_DONE();
290 #endif /* OPENSSL_HAS_ECC */
291 #endif /* WITH_OPENSSL */
292
293 TEST_START("generate KEY_ED25519");
294 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &kf), 0);
295 ASSERT_PTR_NE(kf, NULL);
296 ASSERT_INT_EQ(kf->type, KEY_ED25519);
297 ASSERT_PTR_NE(kf->ed25519_pk, NULL);
298 ASSERT_PTR_NE(kf->ed25519_sk, NULL);
299 TEST_DONE();
300
301 #ifdef WITH_OPENSSL
302 TEST_START("demote KEY_RSA");
303 ASSERT_INT_EQ(sshkey_from_private(kr, &k1), 0);
304 ASSERT_PTR_NE(k1, NULL);
305 ASSERT_PTR_NE(kr, k1);
306 ASSERT_INT_EQ(k1->type, KEY_RSA);
307 ASSERT_PTR_NE(k1->rsa, NULL);
308 ASSERT_PTR_NE(rsa_n(k1), NULL);
309 ASSERT_PTR_NE(rsa_e(k1), NULL);
310 ASSERT_PTR_EQ(rsa_p(k1), NULL);
311 TEST_DONE();
312
313 TEST_START("equal KEY_RSA/demoted KEY_RSA");
314 ASSERT_INT_EQ(sshkey_equal(kr, k1), 1);
315 sshkey_free(k1);
316 TEST_DONE();
317
318 TEST_START("demote KEY_DSA");
319 ASSERT_INT_EQ(sshkey_from_private(kd, &k1), 0);
320 ASSERT_PTR_NE(k1, NULL);
321 ASSERT_PTR_NE(kd, k1);
322 ASSERT_INT_EQ(k1->type, KEY_DSA);
323 ASSERT_PTR_NE(k1->dsa, NULL);
324 ASSERT_PTR_NE(dsa_g(k1), NULL);
325 ASSERT_PTR_EQ(dsa_priv_key(k1), NULL);
326 TEST_DONE();
327
328 TEST_START("equal KEY_DSA/demoted KEY_DSA");
329 ASSERT_INT_EQ(sshkey_equal(kd, k1), 1);
330 sshkey_free(k1);
331 TEST_DONE();
332
333 #ifdef OPENSSL_HAS_ECC
334 TEST_START("demote KEY_ECDSA");
335 ASSERT_INT_EQ(sshkey_from_private(ke, &k1), 0);
336 ASSERT_PTR_NE(k1, NULL);
337 ASSERT_PTR_NE(ke, k1);
338 ASSERT_INT_EQ(k1->type, KEY_ECDSA);
339 ASSERT_PTR_NE(k1->ecdsa, NULL);
340 ASSERT_INT_EQ(k1->ecdsa_nid, ke->ecdsa_nid);
341 ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL);
342 ASSERT_PTR_EQ(EC_KEY_get0_private_key(k1->ecdsa), NULL);
343 TEST_DONE();
344
345 TEST_START("equal KEY_ECDSA/demoted KEY_ECDSA");
346 ASSERT_INT_EQ(sshkey_equal(ke, k1), 1);
347 sshkey_free(k1);
348 TEST_DONE();
349 #endif /* OPENSSL_HAS_ECC */
350 #endif /* WITH_OPENSSL */
351
352 TEST_START("demote KEY_ED25519");
353 ASSERT_INT_EQ(sshkey_from_private(kf, &k1), 0);
354 ASSERT_PTR_NE(k1, NULL);
355 ASSERT_PTR_NE(kf, k1);
356 ASSERT_INT_EQ(k1->type, KEY_ED25519);
357 ASSERT_PTR_NE(k1->ed25519_pk, NULL);
358 ASSERT_PTR_EQ(k1->ed25519_sk, NULL);
359 TEST_DONE();
360
361 TEST_START("equal KEY_ED25519/demoted KEY_ED25519");
362 ASSERT_INT_EQ(sshkey_equal(kf, k1), 1);
363 sshkey_free(k1);
364 TEST_DONE();
365
366 #ifdef WITH_OPENSSL
367 TEST_START("equal mismatched key types");
368 ASSERT_INT_EQ(sshkey_equal(kd, kr), 0);
369 #ifdef OPENSSL_HAS_ECC
370 ASSERT_INT_EQ(sshkey_equal(kd, ke), 0);
371 ASSERT_INT_EQ(sshkey_equal(kr, ke), 0);
372 ASSERT_INT_EQ(sshkey_equal(ke, kf), 0);
373 #endif /* OPENSSL_HAS_ECC */
374 ASSERT_INT_EQ(sshkey_equal(kd, kf), 0);
375 TEST_DONE();
376 #endif /* WITH_OPENSSL */
377
378 TEST_START("equal different keys");
379 #ifdef WITH_OPENSSL
380 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0);
381 ASSERT_INT_EQ(sshkey_equal(kr, k1), 0);
382 sshkey_free(k1);
383 ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &k1), 0);
384 ASSERT_INT_EQ(sshkey_equal(kd, k1), 0);
385 sshkey_free(k1);
386 #ifdef OPENSSL_HAS_ECC
387 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0);
388 ASSERT_INT_EQ(sshkey_equal(ke, k1), 0);
389 sshkey_free(k1);
390 #endif /* OPENSSL_HAS_ECC */
391 #endif /* WITH_OPENSSL */
392 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &k1), 0);
393 ASSERT_INT_EQ(sshkey_equal(kf, k1), 0);
394 sshkey_free(k1);
395 TEST_DONE();
396
397 #ifdef WITH_OPENSSL
398 sshkey_free(kr);
399 sshkey_free(kd);
400 #ifdef OPENSSL_HAS_ECC
401 sshkey_free(ke);
402 #endif /* OPENSSL_HAS_ECC */
403 #endif /* WITH_OPENSSL */
404 sshkey_free(kf);
405
406 TEST_START("certify key");
407 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"),
408 &k1, NULL), 0);
409 k2 = get_private("ed25519_2");
410 ASSERT_INT_EQ(sshkey_to_certified(k1), 0);
411 ASSERT_PTR_NE(k1->cert, NULL);
412 k1->cert->type = SSH2_CERT_TYPE_USER;
413 k1->cert->serial = 1234;
414 k1->cert->key_id = strdup("estragon");
415 ASSERT_PTR_NE(k1->cert->key_id, NULL);
416 k1->cert->principals = calloc(4, sizeof(*k1->cert->principals));
417 ASSERT_PTR_NE(k1->cert->principals, NULL);
418 k1->cert->principals[0] = strdup("estragon");
419 k1->cert->principals[1] = strdup("vladimir");
420 k1->cert->principals[2] = strdup("pozzo");
421 k1->cert->principals[3] = strdup("lucky");
422 ASSERT_PTR_NE(k1->cert->principals[0], NULL);
423 ASSERT_PTR_NE(k1->cert->principals[1], NULL);
424 ASSERT_PTR_NE(k1->cert->principals[2], NULL);
425 ASSERT_PTR_NE(k1->cert->principals[3], NULL);
426 k1->cert->nprincipals = 4;
427 k1->cert->valid_after = 0;
428 k1->cert->valid_before = (u_int64_t)-1;
429 sshbuf_free(k1->cert->critical);
430 k1->cert->critical = sshbuf_new();
431 ASSERT_PTR_NE(k1->cert->critical, NULL);
432 sshbuf_free(k1->cert->extensions);
433 k1->cert->extensions = sshbuf_new();
434 ASSERT_PTR_NE(k1->cert->extensions, NULL);
435 put_opt(k1->cert->critical, "force-command", "/usr/bin/true");
436 put_opt(k1->cert->critical, "source-address", "127.0.0.1");
437 put_opt(k1->cert->extensions, "permit-X11-forwarding", NULL);
438 put_opt(k1->cert->extensions, "permit-agent-forwarding", NULL);
439 ASSERT_INT_EQ(sshkey_from_private(k2, &k1->cert->signature_key), 0);
440 ASSERT_INT_EQ(sshkey_certify(k1, k2, NULL, NULL), 0);
441 b = sshbuf_new();
442 ASSERT_PTR_NE(b, NULL);
443 ASSERT_INT_EQ(sshkey_putb(k1, b), 0);
444 ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(b), sshbuf_len(b), &k3), 0);
445
446 sshkey_free(k1);
447 sshkey_free(k2);
448 sshkey_free(k3);
449 sshbuf_reset(b);
450 TEST_DONE();
451
452 #ifdef WITH_OPENSSL
453 TEST_START("sign and verify RSA");
454 k1 = get_private("rsa_1");
455 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2,
456 NULL), 0);
457 signature_tests(k1, k2, "ssh-rsa");
458 sshkey_free(k1);
459 sshkey_free(k2);
460 TEST_DONE();
461
462 TEST_START("sign and verify RSA-SHA256");
463 k1 = get_private("rsa_1");
464 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2,
465 NULL), 0);
466 signature_tests(k1, k2, "rsa-sha2-256");
467 sshkey_free(k1);
468 sshkey_free(k2);
469 TEST_DONE();
470
471 TEST_START("sign and verify RSA-SHA512");
472 k1 = get_private("rsa_1");
473 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2,
474 NULL), 0);
475 signature_tests(k1, k2, "rsa-sha2-512");
476 sshkey_free(k1);
477 sshkey_free(k2);
478 TEST_DONE();
479
480 TEST_START("sign and verify DSA");
481 k1 = get_private("dsa_1");
482 ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_2.pub"), &k2,
483 NULL), 0);
484 signature_tests(k1, k2, NULL);
485 sshkey_free(k1);
486 sshkey_free(k2);
487 TEST_DONE();
488
489 #ifdef OPENSSL_HAS_ECC
490 TEST_START("sign and verify ECDSA");
491 k1 = get_private("ecdsa_1");
492 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_2.pub"), &k2,
493 NULL), 0);
494 signature_tests(k1, k2, NULL);
495 sshkey_free(k1);
496 sshkey_free(k2);
497 TEST_DONE();
498 #endif /* OPENSSL_HAS_ECC */
499 #endif /* WITH_OPENSSL */
500
501 TEST_START("sign and verify ED25519");
502 k1 = get_private("ed25519_1");
503 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_2.pub"), &k2,
504 NULL), 0);
505 signature_tests(k1, k2, NULL);
506 sshkey_free(k1);
507 sshkey_free(k2);
508 TEST_DONE();
509
510 #ifdef WITH_OPENSSL
511 TEST_START("nested certificate");
512 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1"), &k1), 0);
513 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2,
514 NULL), 0);
515 k3 = get_private("rsa_1");
516 build_cert(b, k2, "ssh-rsa-cert-v01@openssh.com", k3, k1, NULL);
517 ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(b), sshbuf_len(b), &k4),
518 SSH_ERR_KEY_CERT_INVALID_SIGN_KEY);
519 ASSERT_PTR_EQ(k4, NULL);
520 sshkey_free(k1);
521 sshkey_free(k2);
522 sshkey_free(k3);
523 sshbuf_free(b);
524 TEST_DONE();
525 #endif /* WITH_OPENSSL */
526 }
527