test_file.c 16 KB

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