1 /* $OpenBSD: test_sshkey.c,v 1.23 2023/01/04 22:48:57 tb 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 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 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 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 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 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 * 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 182 sshkey_tests(void) 183 { 184 struct sshkey *k1, *k2, *k3, *kf; 185 #ifdef WITH_OPENSSL 186 struct sshkey *k4, *kr, *kd; 187 #ifdef OPENSSL_HAS_ECC 188 struct sshkey *ke; 189 #endif /* OPENSSL_HAS_ECC */ 190 #endif /* WITH_OPENSSL */ 191 struct sshbuf *b; 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 TEST_START("new/free KEY_DSA"); 213 k1 = sshkey_new(KEY_DSA); 214 ASSERT_PTR_NE(k1, NULL); 215 ASSERT_PTR_NE(k1->dsa, NULL); 216 sshkey_free(k1); 217 TEST_DONE(); 218 219 #ifdef OPENSSL_HAS_ECC 220 TEST_START("new/free KEY_ECDSA"); 221 k1 = sshkey_new(KEY_ECDSA); 222 ASSERT_PTR_NE(k1, NULL); 223 ASSERT_PTR_EQ(k1->ecdsa, NULL); /* Can't allocate without NID */ 224 sshkey_free(k1); 225 TEST_DONE(); 226 #endif 227 228 TEST_START("new/free KEY_ED25519"); 229 k1 = sshkey_new(KEY_ED25519); 230 ASSERT_PTR_NE(k1, NULL); 231 /* These should be blank until key loaded or generated */ 232 ASSERT_PTR_EQ(k1->ed25519_sk, NULL); 233 ASSERT_PTR_EQ(k1->ed25519_pk, NULL); 234 sshkey_free(k1); 235 TEST_DONE(); 236 237 TEST_START("generate KEY_RSA too small modulus"); 238 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 128, &k1), 239 SSH_ERR_KEY_LENGTH); 240 ASSERT_PTR_EQ(k1, NULL); 241 TEST_DONE(); 242 243 TEST_START("generate KEY_RSA too large modulus"); 244 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1 << 20, &k1), 245 SSH_ERR_KEY_LENGTH); 246 ASSERT_PTR_EQ(k1, NULL); 247 TEST_DONE(); 248 249 TEST_START("generate KEY_DSA wrong bits"); 250 ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 2048, &k1), 251 SSH_ERR_KEY_LENGTH); 252 ASSERT_PTR_EQ(k1, NULL); 253 sshkey_free(k1); 254 TEST_DONE(); 255 256 #ifdef OPENSSL_HAS_ECC 257 TEST_START("generate KEY_ECDSA wrong bits"); 258 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 42, &k1), 259 SSH_ERR_KEY_LENGTH); 260 ASSERT_PTR_EQ(k1, NULL); 261 sshkey_free(k1); 262 TEST_DONE(); 263 #endif 264 265 TEST_START("generate KEY_RSA"); 266 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 767, &kr), 267 SSH_ERR_KEY_LENGTH); 268 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &kr), 0); 269 ASSERT_PTR_NE(kr, NULL); 270 ASSERT_PTR_NE(kr->rsa, NULL); 271 ASSERT_PTR_NE(rsa_n(kr), NULL); 272 ASSERT_PTR_NE(rsa_e(kr), NULL); 273 ASSERT_PTR_NE(rsa_p(kr), NULL); 274 ASSERT_INT_EQ(BN_num_bits(rsa_n(kr)), 1024); 275 TEST_DONE(); 276 277 TEST_START("generate KEY_DSA"); 278 ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0); 279 ASSERT_PTR_NE(kd, NULL); 280 ASSERT_PTR_NE(kd->dsa, NULL); 281 ASSERT_PTR_NE(dsa_g(kd), NULL); 282 ASSERT_PTR_NE(dsa_priv_key(kd), NULL); 283 TEST_DONE(); 284 285 #ifdef OPENSSL_HAS_ECC 286 TEST_START("generate KEY_ECDSA"); 287 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &ke), 0); 288 ASSERT_PTR_NE(ke, NULL); 289 ASSERT_PTR_NE(ke->ecdsa, NULL); 290 ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL); 291 ASSERT_PTR_NE(EC_KEY_get0_private_key(ke->ecdsa), NULL); 292 TEST_DONE(); 293 #endif /* OPENSSL_HAS_ECC */ 294 #endif /* WITH_OPENSSL */ 295 296 TEST_START("generate KEY_ED25519"); 297 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &kf), 0); 298 ASSERT_PTR_NE(kf, NULL); 299 ASSERT_INT_EQ(kf->type, KEY_ED25519); 300 ASSERT_PTR_NE(kf->ed25519_pk, NULL); 301 ASSERT_PTR_NE(kf->ed25519_sk, NULL); 302 TEST_DONE(); 303 304 #ifdef WITH_OPENSSL 305 TEST_START("demote KEY_RSA"); 306 ASSERT_INT_EQ(sshkey_from_private(kr, &k1), 0); 307 ASSERT_PTR_NE(k1, NULL); 308 ASSERT_PTR_NE(kr, k1); 309 ASSERT_INT_EQ(k1->type, KEY_RSA); 310 ASSERT_PTR_NE(k1->rsa, NULL); 311 ASSERT_PTR_NE(rsa_n(k1), NULL); 312 ASSERT_PTR_NE(rsa_e(k1), NULL); 313 ASSERT_PTR_EQ(rsa_p(k1), NULL); 314 TEST_DONE(); 315 316 TEST_START("equal KEY_RSA/demoted KEY_RSA"); 317 ASSERT_INT_EQ(sshkey_equal(kr, k1), 1); 318 sshkey_free(k1); 319 TEST_DONE(); 320 321 TEST_START("demote KEY_DSA"); 322 ASSERT_INT_EQ(sshkey_from_private(kd, &k1), 0); 323 ASSERT_PTR_NE(k1, NULL); 324 ASSERT_PTR_NE(kd, k1); 325 ASSERT_INT_EQ(k1->type, KEY_DSA); 326 ASSERT_PTR_NE(k1->dsa, NULL); 327 ASSERT_PTR_NE(dsa_g(k1), NULL); 328 ASSERT_PTR_EQ(dsa_priv_key(k1), NULL); 329 TEST_DONE(); 330 331 TEST_START("equal KEY_DSA/demoted KEY_DSA"); 332 ASSERT_INT_EQ(sshkey_equal(kd, k1), 1); 333 sshkey_free(k1); 334 TEST_DONE(); 335 336 #ifdef OPENSSL_HAS_ECC 337 TEST_START("demote KEY_ECDSA"); 338 ASSERT_INT_EQ(sshkey_from_private(ke, &k1), 0); 339 ASSERT_PTR_NE(k1, NULL); 340 ASSERT_PTR_NE(ke, k1); 341 ASSERT_INT_EQ(k1->type, KEY_ECDSA); 342 ASSERT_PTR_NE(k1->ecdsa, NULL); 343 ASSERT_INT_EQ(k1->ecdsa_nid, ke->ecdsa_nid); 344 ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL); 345 ASSERT_PTR_EQ(EC_KEY_get0_private_key(k1->ecdsa), NULL); 346 TEST_DONE(); 347 348 TEST_START("equal KEY_ECDSA/demoted KEY_ECDSA"); 349 ASSERT_INT_EQ(sshkey_equal(ke, k1), 1); 350 sshkey_free(k1); 351 TEST_DONE(); 352 #endif /* OPENSSL_HAS_ECC */ 353 #endif /* WITH_OPENSSL */ 354 355 TEST_START("demote KEY_ED25519"); 356 ASSERT_INT_EQ(sshkey_from_private(kf, &k1), 0); 357 ASSERT_PTR_NE(k1, NULL); 358 ASSERT_PTR_NE(kf, k1); 359 ASSERT_INT_EQ(k1->type, KEY_ED25519); 360 ASSERT_PTR_NE(k1->ed25519_pk, NULL); 361 ASSERT_PTR_EQ(k1->ed25519_sk, NULL); 362 TEST_DONE(); 363 364 TEST_START("equal KEY_ED25519/demoted KEY_ED25519"); 365 ASSERT_INT_EQ(sshkey_equal(kf, k1), 1); 366 sshkey_free(k1); 367 TEST_DONE(); 368 369 #ifdef WITH_OPENSSL 370 TEST_START("equal mismatched key types"); 371 ASSERT_INT_EQ(sshkey_equal(kd, kr), 0); 372 #ifdef OPENSSL_HAS_ECC 373 ASSERT_INT_EQ(sshkey_equal(kd, ke), 0); 374 ASSERT_INT_EQ(sshkey_equal(kr, ke), 0); 375 ASSERT_INT_EQ(sshkey_equal(ke, kf), 0); 376 #endif /* OPENSSL_HAS_ECC */ 377 ASSERT_INT_EQ(sshkey_equal(kd, kf), 0); 378 TEST_DONE(); 379 #endif /* WITH_OPENSSL */ 380 381 TEST_START("equal different keys"); 382 #ifdef WITH_OPENSSL 383 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0); 384 ASSERT_INT_EQ(sshkey_equal(kr, k1), 0); 385 sshkey_free(k1); 386 ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &k1), 0); 387 ASSERT_INT_EQ(sshkey_equal(kd, k1), 0); 388 sshkey_free(k1); 389 #ifdef OPENSSL_HAS_ECC 390 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0); 391 ASSERT_INT_EQ(sshkey_equal(ke, k1), 0); 392 sshkey_free(k1); 393 #endif /* OPENSSL_HAS_ECC */ 394 #endif /* WITH_OPENSSL */ 395 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &k1), 0); 396 ASSERT_INT_EQ(sshkey_equal(kf, k1), 0); 397 sshkey_free(k1); 398 TEST_DONE(); 399 400 #ifdef WITH_OPENSSL 401 sshkey_free(kr); 402 sshkey_free(kd); 403 #ifdef OPENSSL_HAS_ECC 404 sshkey_free(ke); 405 #endif /* OPENSSL_HAS_ECC */ 406 #endif /* WITH_OPENSSL */ 407 sshkey_free(kf); 408 409 TEST_START("certify key"); 410 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), 411 &k1, NULL), 0); 412 k2 = get_private("ed25519_2"); 413 ASSERT_INT_EQ(sshkey_to_certified(k1), 0); 414 ASSERT_PTR_NE(k1->cert, NULL); 415 k1->cert->type = SSH2_CERT_TYPE_USER; 416 k1->cert->serial = 1234; 417 k1->cert->key_id = strdup("estragon"); 418 ASSERT_PTR_NE(k1->cert->key_id, NULL); 419 k1->cert->principals = calloc(4, sizeof(*k1->cert->principals)); 420 ASSERT_PTR_NE(k1->cert->principals, NULL); 421 k1->cert->principals[0] = strdup("estragon"); 422 k1->cert->principals[1] = strdup("vladimir"); 423 k1->cert->principals[2] = strdup("pozzo"); 424 k1->cert->principals[3] = strdup("lucky"); 425 ASSERT_PTR_NE(k1->cert->principals[0], NULL); 426 ASSERT_PTR_NE(k1->cert->principals[1], NULL); 427 ASSERT_PTR_NE(k1->cert->principals[2], NULL); 428 ASSERT_PTR_NE(k1->cert->principals[3], NULL); 429 k1->cert->nprincipals = 4; 430 k1->cert->valid_after = 0; 431 k1->cert->valid_before = (u_int64_t)-1; 432 sshbuf_free(k1->cert->critical); 433 k1->cert->critical = sshbuf_new(); 434 ASSERT_PTR_NE(k1->cert->critical, NULL); 435 sshbuf_free(k1->cert->extensions); 436 k1->cert->extensions = sshbuf_new(); 437 ASSERT_PTR_NE(k1->cert->extensions, NULL); 438 put_opt(k1->cert->critical, "force-command", "/usr/bin/true"); 439 put_opt(k1->cert->critical, "source-address", "127.0.0.1"); 440 put_opt(k1->cert->extensions, "permit-X11-forwarding", NULL); 441 put_opt(k1->cert->extensions, "permit-agent-forwarding", NULL); 442 ASSERT_INT_EQ(sshkey_from_private(k2, &k1->cert->signature_key), 0); 443 ASSERT_INT_EQ(sshkey_certify(k1, k2, NULL, NULL, NULL), 0); 444 b = sshbuf_new(); 445 ASSERT_PTR_NE(b, NULL); 446 ASSERT_INT_EQ(sshkey_putb(k1, b), 0); 447 ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(b), sshbuf_len(b), &k3), 0); 448 449 sshkey_free(k1); 450 sshkey_free(k2); 451 sshkey_free(k3); 452 sshbuf_reset(b); 453 TEST_DONE(); 454 455 #ifdef WITH_OPENSSL 456 TEST_START("sign and verify RSA"); 457 k1 = get_private("rsa_1"); 458 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2, 459 NULL), 0); 460 signature_tests(k1, k2, "ssh-rsa"); 461 sshkey_free(k1); 462 sshkey_free(k2); 463 TEST_DONE(); 464 465 TEST_START("sign and verify RSA-SHA256"); 466 k1 = get_private("rsa_1"); 467 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2, 468 NULL), 0); 469 signature_tests(k1, k2, "rsa-sha2-256"); 470 sshkey_free(k1); 471 sshkey_free(k2); 472 TEST_DONE(); 473 474 TEST_START("sign and verify RSA-SHA512"); 475 k1 = get_private("rsa_1"); 476 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2, 477 NULL), 0); 478 signature_tests(k1, k2, "rsa-sha2-512"); 479 sshkey_free(k1); 480 sshkey_free(k2); 481 TEST_DONE(); 482 483 TEST_START("sign and verify DSA"); 484 k1 = get_private("dsa_1"); 485 ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_2.pub"), &k2, 486 NULL), 0); 487 signature_tests(k1, k2, NULL); 488 sshkey_free(k1); 489 sshkey_free(k2); 490 TEST_DONE(); 491 492 #ifdef OPENSSL_HAS_ECC 493 TEST_START("sign and verify ECDSA"); 494 k1 = get_private("ecdsa_1"); 495 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_2.pub"), &k2, 496 NULL), 0); 497 signature_tests(k1, k2, NULL); 498 sshkey_free(k1); 499 sshkey_free(k2); 500 TEST_DONE(); 501 #endif /* OPENSSL_HAS_ECC */ 502 #endif /* WITH_OPENSSL */ 503 504 TEST_START("sign and verify ED25519"); 505 k1 = get_private("ed25519_1"); 506 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_2.pub"), &k2, 507 NULL), 0); 508 signature_tests(k1, k2, NULL); 509 sshkey_free(k1); 510 sshkey_free(k2); 511 TEST_DONE(); 512 513 #ifdef WITH_OPENSSL 514 TEST_START("nested certificate"); 515 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1"), &k1), 0); 516 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2, 517 NULL), 0); 518 k3 = get_private("rsa_1"); 519 build_cert(b, k2, "ssh-rsa-cert-v01@openssh.com", k3, k1, NULL); 520 ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(b), sshbuf_len(b), &k4), 521 SSH_ERR_KEY_CERT_INVALID_SIGN_KEY); 522 ASSERT_PTR_EQ(k4, NULL); 523 sshkey_free(k1); 524 sshkey_free(k2); 525 sshkey_free(k3); 526 sshbuf_free(b); 527 TEST_DONE(); 528 #endif /* WITH_OPENSSL */ 529 } 530