View | Details | Raw Unified | Return to bug 3190 | Differences between
and this patch

Collapse All | Expand All

(-)a/sshkey.c (-6 / +9 lines)
Lines 4685-4694 sshkey_parse_pubkey_from_private_fileblob_type(struct sshbuf *blob, int type, Link Here
4685
4685
4686
	if (pubkeyp != NULL)
4686
	if (pubkeyp != NULL)
4687
		*pubkeyp = NULL;
4687
		*pubkeyp = NULL;
4688
	/* only new-format private keys bundle a public key inside */
4688
	/* new-format private keys bundle a public key inside */
4689
	if ((r = sshkey_parse_private2_pubkey(blob, type, pubkeyp)) != 0)
4689
	if ((r = sshkey_parse_private2_pubkey(blob, type, pubkeyp)) == 0)
4690
		return r;
4690
		return 0;
4691
	return 0;
4691
#ifdef WITH_OPENSSL
4692
	/* We can derive public key from unencrypted PEM files too */
4693
	if ((r = sshkey_parse_private_pem_fileblob(blob, type, "", pubkeyp)) == 0)
4694
		return 0;
4695
#endif /* WITH_OPENSSL */
4696
	return r;
4692
}
4697
}
4693
4698
4694
#ifdef WITH_XMSS
4699
#ifdef WITH_XMSS
4695
- 
4696
where possible
4700
where possible
4697
--
4698
regress/unittests/sshkey/test_file.c | 96 ++++++++++++++++++++++++++++
4701
regress/unittests/sshkey/test_file.c | 96 ++++++++++++++++++++++++++++
4699
1 file changed, 96 insertions(+)
4702
1 file changed, 96 insertions(+)
(-)a/regress/unittests/sshkey/test_file.c (-1 / +96 lines)
Lines 73-78 sshkey_file_tests(void) Link Here
73
	BN_free(c);
73
	BN_free(c);
74
	TEST_DONE();
74
	TEST_DONE();
75
75
76
	TEST_START("parse RSA public from private");
77
	buf = load_file("rsa_1");
78
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
79
	    KEY_UNSPEC, &k2), 0);
80
	sshbuf_free(buf);
81
	ASSERT_PTR_NE(k2, NULL);
82
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
83
	sshkey_free(k2);
84
	TEST_DONE();
85
76
	TEST_START("parse RSA from private w/ passphrase");
86
	TEST_START("parse RSA from private w/ passphrase");
77
	buf = load_file("rsa_1_pw");
87
	buf = load_file("rsa_1_pw");
78
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
88
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
Lines 83-88 sshkey_file_tests(void) Link Here
83
	sshkey_free(k2);
93
	sshkey_free(k2);
84
	TEST_DONE();
94
	TEST_DONE();
85
95
96
	TEST_START("parse RSA public from private w/ passphrase should fail");
97
	buf = load_file("rsa_1_pw");
98
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
99
	    KEY_UNSPEC, &k2), SSH_ERR_KEY_WRONG_PASSPHRASE);
100
	sshbuf_free(buf);
101
	ASSERT_PTR_EQ(k2, NULL);
102
	TEST_DONE();
103
86
	TEST_START("parse RSA from new-format");
104
	TEST_START("parse RSA from new-format");
87
	buf = load_file("rsa_n");
105
	buf = load_file("rsa_n");
88
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0);
106
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0);
Lines 92-97 sshkey_file_tests(void) Link Here
92
	sshkey_free(k2);
110
	sshkey_free(k2);
93
	TEST_DONE();
111
	TEST_DONE();
94
112
113
	TEST_START("parse RSA public from private new-format");
114
	buf = load_file("rsa_n");
115
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
116
	    KEY_UNSPEC, &k2), 0);
117
	sshbuf_free(buf);
118
	ASSERT_PTR_NE(k2, NULL);
119
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
120
	sshkey_free(k2);
121
	TEST_DONE();
122
95
	TEST_START("parse RSA from new-format w/ passphrase");
123
	TEST_START("parse RSA from new-format w/ passphrase");
96
	buf = load_file("rsa_n_pw");
124
	buf = load_file("rsa_n_pw");
97
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
125
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
Lines 102-107 sshkey_file_tests(void) Link Here
102
	sshkey_free(k2);
130
	sshkey_free(k2);
103
	TEST_DONE();
131
	TEST_DONE();
104
132
133
	TEST_START("parse RSA public from private new-format w/ passphrase");
134
	buf = load_file("rsa_n_pw");
135
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
136
	    KEY_UNSPEC, &k2), 0);
137
	sshbuf_free(buf);
138
	ASSERT_PTR_NE(k2, NULL);
139
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
140
	sshkey_free(k2);
141
	TEST_DONE();
142
105
	TEST_START("load RSA from public");
143
	TEST_START("load RSA from public");
106
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2,
144
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2,
107
	    NULL), 0);
145
	    NULL), 0);
Lines 280-285 sshkey_file_tests(void) Link Here
280
	BN_free(c);
318
	BN_free(c);
281
	TEST_DONE();
319
	TEST_DONE();
282
320
321
	TEST_START("parse ECDSA public from private");
322
	buf = load_file("ecdsa_1");
323
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
324
	    KEY_UNSPEC, &k2), 0);
325
	sshbuf_free(buf);
326
	ASSERT_PTR_NE(k2, NULL);
327
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
328
	sshkey_free(k2);
329
	TEST_DONE();
330
283
	TEST_START("parse ECDSA from private w/ passphrase");
331
	TEST_START("parse ECDSA from private w/ passphrase");
284
	buf = load_file("ecdsa_1_pw");
332
	buf = load_file("ecdsa_1_pw");
285
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
333
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
Lines 290-295 sshkey_file_tests(void) Link Here
290
	sshkey_free(k2);
338
	sshkey_free(k2);
291
	TEST_DONE();
339
	TEST_DONE();
292
340
341
	TEST_START("parse ECDSA public from private w/ passphrase should fail");
342
	buf = load_file("ecdsa_1_pw");
343
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
344
	    KEY_UNSPEC, &k2), SSH_ERR_KEY_WRONG_PASSPHRASE);
345
	sshbuf_free(buf);
346
	ASSERT_PTR_EQ(k2, NULL);
347
	TEST_DONE();
348
293
	TEST_START("parse ECDSA from new-format");
349
	TEST_START("parse ECDSA from new-format");
294
	buf = load_file("ecdsa_n");
350
	buf = load_file("ecdsa_n");
295
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0);
351
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0);
Lines 299-304 sshkey_file_tests(void) Link Here
299
	sshkey_free(k2);
355
	sshkey_free(k2);
300
	TEST_DONE();
356
	TEST_DONE();
301
357
358
	TEST_START("parse ECDSA public from private new-format");
359
	buf = load_file("ecdsa_n");
360
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
361
	    KEY_UNSPEC, &k2), 0);
362
	sshbuf_free(buf);
363
	ASSERT_PTR_NE(k2, NULL);
364
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
365
	sshkey_free(k2);
366
	TEST_DONE();
367
302
	TEST_START("parse ECDSA from new-format w/ passphrase");
368
	TEST_START("parse ECDSA from new-format w/ passphrase");
303
	buf = load_file("ecdsa_n_pw");
369
	buf = load_file("ecdsa_n_pw");
304
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
370
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
Lines 309-314 sshkey_file_tests(void) Link Here
309
	sshkey_free(k2);
375
	sshkey_free(k2);
310
	TEST_DONE();
376
	TEST_DONE();
311
377
378
	TEST_START("parse ECDSA public from private new-format w/ passphrase");
379
	buf = load_file("ecdsa_n_pw");
380
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
381
	    KEY_UNSPEC, &k2), 0);
382
	sshbuf_free(buf);
383
	ASSERT_PTR_NE(k2, NULL);
384
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
385
	sshkey_free(k2);
386
	TEST_DONE();
387
312
	TEST_START("load ECDSA from public");
388
	TEST_START("load ECDSA from public");
313
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2,
389
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2,
314
	    NULL), 0);
390
	    NULL), 0);
Lines 366-371 sshkey_file_tests(void) Link Here
366
	/* XXX check key contents */
442
	/* XXX check key contents */
367
	TEST_DONE();
443
	TEST_DONE();
368
444
445
	TEST_START("parse Ed25519 pubkey from private");
446
	buf = load_file("ed25519_1");
447
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
448
	    KEY_UNSPEC, &k2), 0);
449
	sshbuf_free(buf);
450
	ASSERT_PTR_NE(k2, NULL);
451
	ASSERT_INT_EQ(k2->type, KEY_ED25519);
452
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
453
	TEST_DONE();
454
369
	TEST_START("parse Ed25519 from private w/ passphrase");
455
	TEST_START("parse Ed25519 from private w/ passphrase");
370
	buf = load_file("ed25519_1_pw");
456
	buf = load_file("ed25519_1_pw");
371
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
457
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
Lines 376-381 sshkey_file_tests(void) Link Here
376
	sshkey_free(k2);
462
	sshkey_free(k2);
377
	TEST_DONE();
463
	TEST_DONE();
378
464
465
	TEST_START("parse Ed25519 pubkey from private w/ passphrase");
466
	buf = load_file("ed25519_1_pw");
467
	ASSERT_INT_EQ(sshkey_parse_pubkey_from_private_fileblob_type(buf,
468
	    KEY_UNSPEC, &k2), 0);
469
	sshbuf_free(buf);
470
	ASSERT_PTR_NE(k2, NULL);
471
	ASSERT_INT_EQ(sshkey_equal_public(k1, k2), 1);
472
	sshkey_free(k2);
473
	TEST_DONE();
474
379
	TEST_START("load Ed25519 from public");
475
	TEST_START("load Ed25519 from public");
380
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2,
476
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2,
381
	    NULL), 0);
477
	    NULL), 0);
382
- 

Return to bug 3190