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