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