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