1 /* $OpenBSD: test_file.c,v 1.10 2021/12/14 21:25:27 deraadt 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/stat.h> 12 #include <fcntl.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 #include <unistd.h> 20 21 #ifdef WITH_OPENSSL 22 #include <openssl/bn.h> 23 #include <openssl/rsa.h> 24 #include <openssl/dsa.h> 25 #include <openssl/objects.h> 26 #ifdef OPENSSL_HAS_NISTP256 27 # include <openssl/ec.h> 28 #endif /* OPENSSL_HAS_NISTP256 */ 29 #endif /* WITH_OPENSSL */ 30 31 #include "../test_helper/test_helper.h" 32 33 #include "ssherr.h" 34 #include "authfile.h" 35 #include "sshkey.h" 36 #include "sshbuf.h" 37 #include "digest.h" 38 39 #include "common.h" 40 41 void sshkey_file_tests(void); 42 43 void 44 sshkey_file_tests(void) 45 { 46 struct sshkey *k1, *k2; 47 struct sshbuf *buf, *pw; 48 #ifdef WITH_OPENSSL 49 BIGNUM *a, *b, *c; 50 #endif 51 char *cp; 52 53 TEST_START("load passphrase"); 54 pw = load_text_file("pw"); 55 TEST_DONE(); 56 57 58 #ifdef WITH_OPENSSL 59 TEST_START("parse RSA from private"); 60 buf = load_file("rsa_1"); 61 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 62 sshbuf_free(buf); 63 ASSERT_PTR_NE(k1, NULL); 64 a = load_bignum("rsa_1.param.n"); 65 b = load_bignum("rsa_1.param.p"); 66 c = load_bignum("rsa_1.param.q"); 67 ASSERT_BIGNUM_EQ(rsa_n(k1), a); 68 ASSERT_BIGNUM_EQ(rsa_p(k1), b); 69 ASSERT_BIGNUM_EQ(rsa_q(k1), c); 70 BN_free(a); 71 BN_free(b); 72 BN_free(c); 73 TEST_DONE(); 74 75 TEST_START("parse RSA from private w/ passphrase"); 76 buf = load_file("rsa_1_pw"); 77 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 78 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 79 sshbuf_free(buf); 80 ASSERT_PTR_NE(k2, NULL); 81 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 82 sshkey_free(k2); 83 TEST_DONE(); 84 85 TEST_START("parse RSA from new-format"); 86 buf = load_file("rsa_n"); 87 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0); 88 sshbuf_free(buf); 89 ASSERT_PTR_NE(k2, NULL); 90 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 91 sshkey_free(k2); 92 TEST_DONE(); 93 94 TEST_START("parse RSA from new-format w/ passphrase"); 95 buf = load_file("rsa_n_pw"); 96 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 97 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 98 sshbuf_free(buf); 99 ASSERT_PTR_NE(k2, NULL); 100 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 101 sshkey_free(k2); 102 TEST_DONE(); 103 104 TEST_START("load RSA from public"); 105 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2, 106 NULL), 0); 107 ASSERT_PTR_NE(k2, NULL); 108 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 109 sshkey_free(k2); 110 TEST_DONE(); 111 112 TEST_START("load RSA cert with SHA1 signature"); 113 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1_sha1"), &k2), 0); 114 ASSERT_PTR_NE(k2, NULL); 115 ASSERT_INT_EQ(k2->type, KEY_RSA_CERT); 116 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 117 ASSERT_STRING_EQ(k2->cert->signature_type, "ssh-rsa"); 118 sshkey_free(k2); 119 TEST_DONE(); 120 121 TEST_START("load RSA cert with SHA512 signature"); 122 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1_sha512"), &k2), 0); 123 ASSERT_PTR_NE(k2, NULL); 124 ASSERT_INT_EQ(k2->type, KEY_RSA_CERT); 125 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 126 ASSERT_STRING_EQ(k2->cert->signature_type, "rsa-sha2-512"); 127 sshkey_free(k2); 128 TEST_DONE(); 129 130 TEST_START("load RSA cert"); 131 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1"), &k2), 0); 132 ASSERT_PTR_NE(k2, NULL); 133 ASSERT_INT_EQ(k2->type, KEY_RSA_CERT); 134 ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); 135 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 136 TEST_DONE(); 137 138 TEST_START("RSA key hex fingerprint"); 139 buf = load_text_file("rsa_1.fp"); 140 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA256, SSH_FP_BASE64); 141 ASSERT_PTR_NE(cp, NULL); 142 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 143 sshbuf_free(buf); 144 free(cp); 145 TEST_DONE(); 146 147 TEST_START("RSA cert hex fingerprint"); 148 buf = load_text_file("rsa_1-cert.fp"); 149 cp = sshkey_fingerprint(k2, SSH_DIGEST_SHA256, SSH_FP_BASE64); 150 ASSERT_PTR_NE(cp, NULL); 151 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 152 sshbuf_free(buf); 153 free(cp); 154 sshkey_free(k2); 155 TEST_DONE(); 156 157 TEST_START("RSA key bubblebabble fingerprint"); 158 buf = load_text_file("rsa_1.fp.bb"); 159 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); 160 ASSERT_PTR_NE(cp, NULL); 161 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 162 sshbuf_free(buf); 163 free(cp); 164 TEST_DONE(); 165 166 sshkey_free(k1); 167 168 TEST_START("parse DSA from private"); 169 buf = load_file("dsa_1"); 170 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 171 sshbuf_free(buf); 172 ASSERT_PTR_NE(k1, NULL); 173 a = load_bignum("dsa_1.param.g"); 174 b = load_bignum("dsa_1.param.priv"); 175 c = load_bignum("dsa_1.param.pub"); 176 ASSERT_BIGNUM_EQ(dsa_g(k1), a); 177 ASSERT_BIGNUM_EQ(dsa_priv_key(k1), b); 178 ASSERT_BIGNUM_EQ(dsa_pub_key(k1), c); 179 BN_free(a); 180 BN_free(b); 181 BN_free(c); 182 TEST_DONE(); 183 184 TEST_START("parse DSA from private w/ passphrase"); 185 buf = load_file("dsa_1_pw"); 186 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 187 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 188 sshbuf_free(buf); 189 ASSERT_PTR_NE(k2, NULL); 190 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 191 sshkey_free(k2); 192 TEST_DONE(); 193 194 TEST_START("parse DSA from new-format"); 195 buf = load_file("dsa_n"); 196 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0); 197 sshbuf_free(buf); 198 ASSERT_PTR_NE(k2, NULL); 199 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 200 sshkey_free(k2); 201 TEST_DONE(); 202 203 TEST_START("parse DSA from new-format w/ passphrase"); 204 buf = load_file("dsa_n_pw"); 205 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 206 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 207 sshbuf_free(buf); 208 ASSERT_PTR_NE(k2, NULL); 209 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 210 sshkey_free(k2); 211 TEST_DONE(); 212 213 TEST_START("load DSA from public"); 214 ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_1.pub"), &k2, 215 NULL), 0); 216 ASSERT_PTR_NE(k2, NULL); 217 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 218 sshkey_free(k2); 219 TEST_DONE(); 220 221 TEST_START("load DSA cert"); 222 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("dsa_1"), &k2), 0); 223 ASSERT_PTR_NE(k2, NULL); 224 ASSERT_INT_EQ(k2->type, KEY_DSA_CERT); 225 ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); 226 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 227 TEST_DONE(); 228 229 TEST_START("DSA key hex fingerprint"); 230 buf = load_text_file("dsa_1.fp"); 231 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA256, SSH_FP_BASE64); 232 ASSERT_PTR_NE(cp, NULL); 233 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 234 sshbuf_free(buf); 235 free(cp); 236 TEST_DONE(); 237 238 TEST_START("DSA cert hex fingerprint"); 239 buf = load_text_file("dsa_1-cert.fp"); 240 cp = sshkey_fingerprint(k2, SSH_DIGEST_SHA256, SSH_FP_BASE64); 241 ASSERT_PTR_NE(cp, NULL); 242 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 243 sshbuf_free(buf); 244 free(cp); 245 sshkey_free(k2); 246 TEST_DONE(); 247 248 TEST_START("DSA key bubblebabble fingerprint"); 249 buf = load_text_file("dsa_1.fp.bb"); 250 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); 251 ASSERT_PTR_NE(cp, NULL); 252 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 253 sshbuf_free(buf); 254 free(cp); 255 TEST_DONE(); 256 257 sshkey_free(k1); 258 259 #ifdef OPENSSL_HAS_ECC 260 TEST_START("parse ECDSA from private"); 261 buf = load_file("ecdsa_1"); 262 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 263 sshbuf_free(buf); 264 ASSERT_PTR_NE(k1, NULL); 265 buf = load_text_file("ecdsa_1.param.curve"); 266 ASSERT_STRING_EQ((const char *)sshbuf_ptr(buf), 267 OBJ_nid2sn(k1->ecdsa_nid)); 268 sshbuf_free(buf); 269 a = load_bignum("ecdsa_1.param.priv"); 270 b = load_bignum("ecdsa_1.param.pub"); 271 c = EC_POINT_point2bn(EC_KEY_get0_group(k1->ecdsa), 272 EC_KEY_get0_public_key(k1->ecdsa), POINT_CONVERSION_UNCOMPRESSED, 273 NULL, NULL); 274 ASSERT_PTR_NE(c, NULL); 275 ASSERT_BIGNUM_EQ(EC_KEY_get0_private_key(k1->ecdsa), a); 276 ASSERT_BIGNUM_EQ(b, c); 277 BN_free(a); 278 BN_free(b); 279 BN_free(c); 280 TEST_DONE(); 281 282 TEST_START("parse ECDSA from private w/ passphrase"); 283 buf = load_file("ecdsa_1_pw"); 284 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 285 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 286 sshbuf_free(buf); 287 ASSERT_PTR_NE(k2, NULL); 288 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 289 sshkey_free(k2); 290 TEST_DONE(); 291 292 TEST_START("parse ECDSA from new-format"); 293 buf = load_file("ecdsa_n"); 294 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0); 295 sshbuf_free(buf); 296 ASSERT_PTR_NE(k2, NULL); 297 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 298 sshkey_free(k2); 299 TEST_DONE(); 300 301 TEST_START("parse ECDSA from new-format w/ passphrase"); 302 buf = load_file("ecdsa_n_pw"); 303 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 304 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 305 sshbuf_free(buf); 306 ASSERT_PTR_NE(k2, NULL); 307 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 308 sshkey_free(k2); 309 TEST_DONE(); 310 311 TEST_START("load ECDSA from public"); 312 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2, 313 NULL), 0); 314 ASSERT_PTR_NE(k2, NULL); 315 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 316 sshkey_free(k2); 317 TEST_DONE(); 318 319 TEST_START("load ECDSA cert"); 320 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("ecdsa_1"), &k2), 0); 321 ASSERT_PTR_NE(k2, NULL); 322 ASSERT_INT_EQ(k2->type, KEY_ECDSA_CERT); 323 ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); 324 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 325 TEST_DONE(); 326 327 TEST_START("ECDSA key hex fingerprint"); 328 buf = load_text_file("ecdsa_1.fp"); 329 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA256, SSH_FP_BASE64); 330 ASSERT_PTR_NE(cp, NULL); 331 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 332 sshbuf_free(buf); 333 free(cp); 334 TEST_DONE(); 335 336 TEST_START("ECDSA cert hex fingerprint"); 337 buf = load_text_file("ecdsa_1-cert.fp"); 338 cp = sshkey_fingerprint(k2, SSH_DIGEST_SHA256, SSH_FP_BASE64); 339 ASSERT_PTR_NE(cp, NULL); 340 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 341 sshbuf_free(buf); 342 free(cp); 343 sshkey_free(k2); 344 TEST_DONE(); 345 346 TEST_START("ECDSA key bubblebabble fingerprint"); 347 buf = load_text_file("ecdsa_1.fp.bb"); 348 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); 349 ASSERT_PTR_NE(cp, NULL); 350 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 351 sshbuf_free(buf); 352 free(cp); 353 TEST_DONE(); 354 355 sshkey_free(k1); 356 #endif /* OPENSSL_HAS_ECC */ 357 #endif /* WITH_OPENSSL */ 358 359 TEST_START("parse Ed25519 from private"); 360 buf = load_file("ed25519_1"); 361 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 362 sshbuf_free(buf); 363 ASSERT_PTR_NE(k1, NULL); 364 ASSERT_INT_EQ(k1->type, KEY_ED25519); 365 /* XXX check key contents */ 366 TEST_DONE(); 367 368 TEST_START("parse Ed25519 from private w/ passphrase"); 369 buf = load_file("ed25519_1_pw"); 370 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 371 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 372 sshbuf_free(buf); 373 ASSERT_PTR_NE(k2, NULL); 374 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 375 sshkey_free(k2); 376 TEST_DONE(); 377 378 TEST_START("load Ed25519 from public"); 379 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2, 380 NULL), 0); 381 ASSERT_PTR_NE(k2, NULL); 382 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 383 sshkey_free(k2); 384 TEST_DONE(); 385 386 TEST_START("load Ed25519 cert"); 387 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("ed25519_1"), &k2), 0); 388 ASSERT_PTR_NE(k2, NULL); 389 ASSERT_INT_EQ(k2->type, KEY_ED25519_CERT); 390 ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); 391 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 392 TEST_DONE(); 393 394 TEST_START("Ed25519 key hex fingerprint"); 395 buf = load_text_file("ed25519_1.fp"); 396 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA256, SSH_FP_BASE64); 397 ASSERT_PTR_NE(cp, NULL); 398 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 399 sshbuf_free(buf); 400 free(cp); 401 TEST_DONE(); 402 403 TEST_START("Ed25519 cert hex fingerprint"); 404 buf = load_text_file("ed25519_1-cert.fp"); 405 cp = sshkey_fingerprint(k2, SSH_DIGEST_SHA256, SSH_FP_BASE64); 406 ASSERT_PTR_NE(cp, NULL); 407 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 408 sshbuf_free(buf); 409 free(cp); 410 sshkey_free(k2); 411 TEST_DONE(); 412 413 TEST_START("Ed25519 key bubblebabble fingerprint"); 414 buf = load_text_file("ed25519_1.fp.bb"); 415 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); 416 ASSERT_PTR_NE(cp, NULL); 417 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 418 sshbuf_free(buf); 419 free(cp); 420 TEST_DONE(); 421 422 sshkey_free(k1); 423 424 #ifdef ENABLE_SK 425 #if defined(WITH_OPENSSL) && defined(OPENSSL_HAS_ECC) 426 TEST_START("parse ECDSA-SK from private"); 427 buf = load_file("ecdsa_sk1"); 428 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 429 sshbuf_free(buf); 430 ASSERT_PTR_NE(k1, NULL); 431 ASSERT_INT_EQ(k1->type, KEY_ECDSA_SK); 432 TEST_DONE(); 433 434 TEST_START("parse ECDSA-SK from private w/ passphrase"); 435 buf = load_file("ecdsa_sk1_pw"); 436 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 437 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 438 sshbuf_free(buf); 439 ASSERT_PTR_NE(k2, NULL); 440 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 441 sshkey_free(k2); 442 TEST_DONE(); 443 444 TEST_START("load ECDSA-SK from public"); 445 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_sk1.pub"), &k2, 446 NULL), 0); 447 ASSERT_PTR_NE(k2, NULL); 448 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 449 sshkey_free(k2); 450 TEST_DONE(); 451 452 TEST_START("load ECDSA-SK cert"); 453 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("ecdsa_sk1"), &k2), 0); 454 ASSERT_PTR_NE(k2, NULL); 455 ASSERT_INT_EQ(k2->type, KEY_ECDSA_SK_CERT); 456 ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); 457 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 458 TEST_DONE(); 459 460 TEST_START("ECDSA-SK key hex fingerprint"); 461 buf = load_text_file("ecdsa_sk1.fp"); 462 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA256, SSH_FP_BASE64); 463 ASSERT_PTR_NE(cp, NULL); 464 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 465 sshbuf_free(buf); 466 free(cp); 467 TEST_DONE(); 468 469 TEST_START("ECDSA-SK cert hex fingerprint"); 470 buf = load_text_file("ecdsa_sk1-cert.fp"); 471 cp = sshkey_fingerprint(k2, SSH_DIGEST_SHA256, SSH_FP_BASE64); 472 ASSERT_PTR_NE(cp, NULL); 473 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 474 sshbuf_free(buf); 475 free(cp); 476 sshkey_free(k2); 477 TEST_DONE(); 478 479 TEST_START("ECDSA-SK key bubblebabble fingerprint"); 480 buf = load_text_file("ecdsa_sk1.fp.bb"); 481 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); 482 ASSERT_PTR_NE(cp, NULL); 483 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 484 sshbuf_free(buf); 485 free(cp); 486 TEST_DONE(); 487 488 sshkey_free(k1); 489 #endif 490 491 TEST_START("parse Ed25519-SK from private"); 492 buf = load_file("ed25519_sk1"); 493 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 494 sshbuf_free(buf); 495 ASSERT_PTR_NE(k1, NULL); 496 ASSERT_INT_EQ(k1->type, KEY_ED25519_SK); 497 /* XXX check key contents */ 498 TEST_DONE(); 499 500 TEST_START("parse Ed25519-SK from private w/ passphrase"); 501 buf = load_file("ed25519_sk1_pw"); 502 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, 503 (const char *)sshbuf_ptr(pw), &k2, NULL), 0); 504 sshbuf_free(buf); 505 ASSERT_PTR_NE(k2, NULL); 506 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 507 sshkey_free(k2); 508 TEST_DONE(); 509 510 TEST_START("load Ed25519-SK from public"); 511 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_sk1.pub"), 512 &k2, NULL), 0); 513 ASSERT_PTR_NE(k2, NULL); 514 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1); 515 sshkey_free(k2); 516 TEST_DONE(); 517 518 TEST_START("load Ed25519-SK cert"); 519 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("ed25519_sk1"), &k2), 0); 520 ASSERT_PTR_NE(k2, NULL); 521 ASSERT_INT_EQ(k2->type, KEY_ED25519_SK_CERT); 522 ASSERT_INT_EQ(sshkey_equal(k1, k2), 0); 523 ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1); 524 TEST_DONE(); 525 526 TEST_START("Ed25519-SK key hex fingerprint"); 527 buf = load_text_file("ed25519_sk1.fp"); 528 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA256, SSH_FP_BASE64); 529 ASSERT_PTR_NE(cp, NULL); 530 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 531 sshbuf_free(buf); 532 free(cp); 533 TEST_DONE(); 534 535 TEST_START("Ed25519-SK cert hex fingerprint"); 536 buf = load_text_file("ed25519_sk1-cert.fp"); 537 cp = sshkey_fingerprint(k2, SSH_DIGEST_SHA256, SSH_FP_BASE64); 538 ASSERT_PTR_NE(cp, NULL); 539 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 540 sshbuf_free(buf); 541 free(cp); 542 sshkey_free(k2); 543 TEST_DONE(); 544 545 TEST_START("Ed25519-SK key bubblebabble fingerprint"); 546 buf = load_text_file("ed25519_sk1.fp.bb"); 547 cp = sshkey_fingerprint(k1, SSH_DIGEST_SHA1, SSH_FP_BUBBLEBABBLE); 548 ASSERT_PTR_NE(cp, NULL); 549 ASSERT_STRING_EQ(cp, (const char *)sshbuf_ptr(buf)); 550 sshbuf_free(buf); 551 free(cp); 552 TEST_DONE(); 553 554 sshkey_free(k1); 555 #endif /* ENABLE_SK */ 556 557 sshbuf_free(pw); 558 559 } 560