Deleted Added
full compact
test_file.c (294464) test_file.c (296633)
1/* $OpenBSD: test_file.c,v 1.4 2015/07/07 14:53:30 markus Exp $ */
1/* $OpenBSD: test_file.c,v 1.5 2015/10/06 01:20:59 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

--- 39 unchanged lines hidden (view full) ---

49
50 TEST_START("load passphrase");
51 pw = load_text_file("pw");
52 TEST_DONE();
53
54#ifdef WITH_SSH1
55 TEST_START("parse RSA1 from private");
56 buf = load_file("rsa1_1");
2/*
3 * Regress test for sshkey.h key management API
4 *
5 * Placed in the public domain
6 */
7
8#include "includes.h"
9

--- 39 unchanged lines hidden (view full) ---

49
50 TEST_START("load passphrase");
51 pw = load_text_file("pw");
52 TEST_DONE();
53
54#ifdef WITH_SSH1
55 TEST_START("parse RSA1 from private");
56 buf = load_file("rsa1_1");
57 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "rsa1_1",
58 &k1, NULL), 0);
57 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
59 sshbuf_free(buf);
60 ASSERT_PTR_NE(k1, NULL);
61 a = load_bignum("rsa1_1.param.n");
62 ASSERT_BIGNUM_EQ(k1->rsa->n, a);
63 BN_free(a);
64 TEST_DONE();
65
66 TEST_START("parse RSA1 from private w/ passphrase");
67 buf = load_file("rsa1_1_pw");
68 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
58 sshbuf_free(buf);
59 ASSERT_PTR_NE(k1, NULL);
60 a = load_bignum("rsa1_1.param.n");
61 ASSERT_BIGNUM_EQ(k1->rsa->n, a);
62 BN_free(a);
63 TEST_DONE();
64
65 TEST_START("parse RSA1 from private w/ passphrase");
66 buf = load_file("rsa1_1_pw");
67 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
69 (const char *)sshbuf_ptr(pw), "rsa1_1_pw", &k2, NULL), 0);
68 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
70 sshbuf_free(buf);
71 ASSERT_PTR_NE(k2, NULL);
72 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
73 sshkey_free(k2);
74 TEST_DONE();
75
76 TEST_START("load RSA1 from public");
77 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa1_1.pub"), &k2,

--- 21 unchanged lines hidden (view full) ---

99 free(cp);
100 TEST_DONE();
101
102 sshkey_free(k1);
103#endif
104
105 TEST_START("parse RSA from private");
106 buf = load_file("rsa_1");
69 sshbuf_free(buf);
70 ASSERT_PTR_NE(k2, NULL);
71 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
72 sshkey_free(k2);
73 TEST_DONE();
74
75 TEST_START("load RSA1 from public");
76 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa1_1.pub"), &k2,

--- 21 unchanged lines hidden (view full) ---

98 free(cp);
99 TEST_DONE();
100
101 sshkey_free(k1);
102#endif
103
104 TEST_START("parse RSA from private");
105 buf = load_file("rsa_1");
107 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "rsa_1",
108 &k1, NULL), 0);
106 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
109 sshbuf_free(buf);
110 ASSERT_PTR_NE(k1, NULL);
111 a = load_bignum("rsa_1.param.n");
112 b = load_bignum("rsa_1.param.p");
113 c = load_bignum("rsa_1.param.q");
114 ASSERT_BIGNUM_EQ(k1->rsa->n, a);
115 ASSERT_BIGNUM_EQ(k1->rsa->p, b);
116 ASSERT_BIGNUM_EQ(k1->rsa->q, c);
117 BN_free(a);
118 BN_free(b);
119 BN_free(c);
120 TEST_DONE();
121
122 TEST_START("parse RSA from private w/ passphrase");
123 buf = load_file("rsa_1_pw");
124 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
107 sshbuf_free(buf);
108 ASSERT_PTR_NE(k1, NULL);
109 a = load_bignum("rsa_1.param.n");
110 b = load_bignum("rsa_1.param.p");
111 c = load_bignum("rsa_1.param.q");
112 ASSERT_BIGNUM_EQ(k1->rsa->n, a);
113 ASSERT_BIGNUM_EQ(k1->rsa->p, b);
114 ASSERT_BIGNUM_EQ(k1->rsa->q, c);
115 BN_free(a);
116 BN_free(b);
117 BN_free(c);
118 TEST_DONE();
119
120 TEST_START("parse RSA from private w/ passphrase");
121 buf = load_file("rsa_1_pw");
122 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
125 (const char *)sshbuf_ptr(pw), "rsa_1_pw", &k2, NULL), 0);
123 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
126 sshbuf_free(buf);
127 ASSERT_PTR_NE(k2, NULL);
128 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
129 sshkey_free(k2);
130 TEST_DONE();
131
132 TEST_START("parse RSA from new-format");
133 buf = load_file("rsa_n");
124 sshbuf_free(buf);
125 ASSERT_PTR_NE(k2, NULL);
126 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
127 sshkey_free(k2);
128 TEST_DONE();
129
130 TEST_START("parse RSA from new-format");
131 buf = load_file("rsa_n");
134 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
135 "", "rsa_n", &k2, NULL), 0);
132 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0);
136 sshbuf_free(buf);
137 ASSERT_PTR_NE(k2, NULL);
138 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
139 sshkey_free(k2);
140 TEST_DONE();
141
142 TEST_START("parse RSA from new-format w/ passphrase");
143 buf = load_file("rsa_n_pw");
144 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
133 sshbuf_free(buf);
134 ASSERT_PTR_NE(k2, NULL);
135 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
136 sshkey_free(k2);
137 TEST_DONE();
138
139 TEST_START("parse RSA from new-format w/ passphrase");
140 buf = load_file("rsa_n_pw");
141 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
145 (const char *)sshbuf_ptr(pw), "rsa_n_pw", &k2, NULL), 0);
142 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
146 sshbuf_free(buf);
147 ASSERT_PTR_NE(k2, NULL);
148 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
149 sshkey_free(k2);
150 TEST_DONE();
151
152 TEST_START("load RSA from public");
153 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2,

--- 38 unchanged lines hidden (view full) ---

192 sshbuf_free(buf);
193 free(cp);
194 TEST_DONE();
195
196 sshkey_free(k1);
197
198 TEST_START("parse DSA from private");
199 buf = load_file("dsa_1");
143 sshbuf_free(buf);
144 ASSERT_PTR_NE(k2, NULL);
145 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
146 sshkey_free(k2);
147 TEST_DONE();
148
149 TEST_START("load RSA from public");
150 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2,

--- 38 unchanged lines hidden (view full) ---

189 sshbuf_free(buf);
190 free(cp);
191 TEST_DONE();
192
193 sshkey_free(k1);
194
195 TEST_START("parse DSA from private");
196 buf = load_file("dsa_1");
200 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "dsa_1",
201 &k1, NULL), 0);
197 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
202 sshbuf_free(buf);
203 ASSERT_PTR_NE(k1, NULL);
204 a = load_bignum("dsa_1.param.g");
205 b = load_bignum("dsa_1.param.priv");
206 c = load_bignum("dsa_1.param.pub");
207 ASSERT_BIGNUM_EQ(k1->dsa->g, a);
208 ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b);
209 ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c);
210 BN_free(a);
211 BN_free(b);
212 BN_free(c);
213 TEST_DONE();
214
215 TEST_START("parse DSA from private w/ passphrase");
216 buf = load_file("dsa_1_pw");
217 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
198 sshbuf_free(buf);
199 ASSERT_PTR_NE(k1, NULL);
200 a = load_bignum("dsa_1.param.g");
201 b = load_bignum("dsa_1.param.priv");
202 c = load_bignum("dsa_1.param.pub");
203 ASSERT_BIGNUM_EQ(k1->dsa->g, a);
204 ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b);
205 ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c);
206 BN_free(a);
207 BN_free(b);
208 BN_free(c);
209 TEST_DONE();
210
211 TEST_START("parse DSA from private w/ passphrase");
212 buf = load_file("dsa_1_pw");
213 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
218 (const char *)sshbuf_ptr(pw), "dsa_1_pw", &k2, NULL), 0);
214 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
219 sshbuf_free(buf);
220 ASSERT_PTR_NE(k2, NULL);
221 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
222 sshkey_free(k2);
223 TEST_DONE();
224
225 TEST_START("parse DSA from new-format");
226 buf = load_file("dsa_n");
215 sshbuf_free(buf);
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("parse DSA from new-format");
222 buf = load_file("dsa_n");
227 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
228 "", "dsa_n", &k2, NULL), 0);
223 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k2, NULL), 0);
229 sshbuf_free(buf);
230 ASSERT_PTR_NE(k2, NULL);
231 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
232 sshkey_free(k2);
233 TEST_DONE();
234
235 TEST_START("parse DSA from new-format w/ passphrase");
236 buf = load_file("dsa_n_pw");
237 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
224 sshbuf_free(buf);
225 ASSERT_PTR_NE(k2, NULL);
226 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
227 sshkey_free(k2);
228 TEST_DONE();
229
230 TEST_START("parse DSA from new-format w/ passphrase");
231 buf = load_file("dsa_n_pw");
232 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
238 (const char *)sshbuf_ptr(pw), "dsa_n_pw", &k2, NULL), 0);
233 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
239 sshbuf_free(buf);
240 ASSERT_PTR_NE(k2, NULL);
241 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
242 sshkey_free(k2);
243 TEST_DONE();
244
245 TEST_START("load DSA from public");
246 ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_1.pub"), &k2,

--- 39 unchanged lines hidden (view full) ---

286 free(cp);
287 TEST_DONE();
288
289 sshkey_free(k1);
290
291#ifdef OPENSSL_HAS_ECC
292 TEST_START("parse ECDSA from private");
293 buf = load_file("ecdsa_1");
234 sshbuf_free(buf);
235 ASSERT_PTR_NE(k2, NULL);
236 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
237 sshkey_free(k2);
238 TEST_DONE();
239
240 TEST_START("load DSA from public");
241 ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_1.pub"), &k2,

--- 39 unchanged lines hidden (view full) ---

281 free(cp);
282 TEST_DONE();
283
284 sshkey_free(k1);
285
286#ifdef OPENSSL_HAS_ECC
287 TEST_START("parse ECDSA from private");
288 buf = load_file("ecdsa_1");
294 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "ecdsa_1",
295 &k1, NULL), 0);
289 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
296 sshbuf_free(buf);
297 ASSERT_PTR_NE(k1, NULL);
298 buf = load_text_file("ecdsa_1.param.curve");
299 ASSERT_STRING_EQ((const char *)sshbuf_ptr(buf),
300 OBJ_nid2sn(k1->ecdsa_nid));
301 sshbuf_free(buf);
302 a = load_bignum("ecdsa_1.param.priv");
303 b = load_bignum("ecdsa_1.param.pub");

--- 6 unchanged lines hidden (view full) ---

310 BN_free(a);
311 BN_free(b);
312 BN_free(c);
313 TEST_DONE();
314
315 TEST_START("parse ECDSA from private w/ passphrase");
316 buf = load_file("ecdsa_1_pw");
317 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
290 sshbuf_free(buf);
291 ASSERT_PTR_NE(k1, NULL);
292 buf = load_text_file("ecdsa_1.param.curve");
293 ASSERT_STRING_EQ((const char *)sshbuf_ptr(buf),
294 OBJ_nid2sn(k1->ecdsa_nid));
295 sshbuf_free(buf);
296 a = load_bignum("ecdsa_1.param.priv");
297 b = load_bignum("ecdsa_1.param.pub");

--- 6 unchanged lines hidden (view full) ---

304 BN_free(a);
305 BN_free(b);
306 BN_free(c);
307 TEST_DONE();
308
309 TEST_START("parse ECDSA from private w/ passphrase");
310 buf = load_file("ecdsa_1_pw");
311 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
318 (const char *)sshbuf_ptr(pw), "ecdsa_1_pw", &k2, NULL), 0);
312 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
319 sshbuf_free(buf);
320 ASSERT_PTR_NE(k2, NULL);
321 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
322 sshkey_free(k2);
323 TEST_DONE();
324
325 TEST_START("parse ECDSA from new-format");
326 buf = load_file("ecdsa_n");
313 sshbuf_free(buf);
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("parse ECDSA from new-format");
320 buf = load_file("ecdsa_n");
327 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
328 "", "ecdsa_n", &k2, NULL), 0);
321 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &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
335 TEST_START("parse ECDSA from new-format w/ passphrase");
336 buf = load_file("ecdsa_n_pw");
337 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
322 sshbuf_free(buf);
323 ASSERT_PTR_NE(k2, NULL);
324 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
325 sshkey_free(k2);
326 TEST_DONE();
327
328 TEST_START("parse ECDSA from new-format w/ passphrase");
329 buf = load_file("ecdsa_n_pw");
330 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
338 (const char *)sshbuf_ptr(pw), "ecdsa_n_pw", &k2, NULL), 0);
331 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
339 sshbuf_free(buf);
340 ASSERT_PTR_NE(k2, NULL);
341 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
342 sshkey_free(k2);
343 TEST_DONE();
344
345 TEST_START("load ECDSA from public");
346 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2,

--- 39 unchanged lines hidden (view full) ---

386 free(cp);
387 TEST_DONE();
388
389 sshkey_free(k1);
390#endif /* OPENSSL_HAS_ECC */
391
392 TEST_START("parse Ed25519 from private");
393 buf = load_file("ed25519_1");
332 sshbuf_free(buf);
333 ASSERT_PTR_NE(k2, NULL);
334 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
335 sshkey_free(k2);
336 TEST_DONE();
337
338 TEST_START("load ECDSA from public");
339 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_1.pub"), &k2,

--- 39 unchanged lines hidden (view full) ---

379 free(cp);
380 TEST_DONE();
381
382 sshkey_free(k1);
383#endif /* OPENSSL_HAS_ECC */
384
385 TEST_START("parse Ed25519 from private");
386 buf = load_file("ed25519_1");
394 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", "ed25519_1",
395 &k1, NULL), 0);
387 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
396 sshbuf_free(buf);
397 ASSERT_PTR_NE(k1, NULL);
398 ASSERT_INT_EQ(k1->type, KEY_ED25519);
399 /* XXX check key contents */
400 TEST_DONE();
401
402 TEST_START("parse Ed25519 from private w/ passphrase");
403 buf = load_file("ed25519_1_pw");
404 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
388 sshbuf_free(buf);
389 ASSERT_PTR_NE(k1, NULL);
390 ASSERT_INT_EQ(k1->type, KEY_ED25519);
391 /* XXX check key contents */
392 TEST_DONE();
393
394 TEST_START("parse Ed25519 from private w/ passphrase");
395 buf = load_file("ed25519_1_pw");
396 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
405 (const char *)sshbuf_ptr(pw), "ed25519_1_pw", &k2, NULL), 0);
397 (const char *)sshbuf_ptr(pw), &k2, NULL), 0);
406 sshbuf_free(buf);
407 ASSERT_PTR_NE(k2, NULL);
408 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
409 sshkey_free(k2);
410 TEST_DONE();
411
412 TEST_START("load Ed25519 from public");
413 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2,

--- 47 unchanged lines hidden ---
398 sshbuf_free(buf);
399 ASSERT_PTR_NE(k2, NULL);
400 ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
401 sshkey_free(k2);
402 TEST_DONE();
403
404 TEST_START("load Ed25519 from public");
405 ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2,

--- 47 unchanged lines hidden ---