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