|
4 | 4 |
|
5 | 5 | #if defined(LTC_PEM) && defined(LTC_TEST_READDIR) && !defined(LTC_EASY) |
6 | 6 |
|
| 7 | +#ifdef LTC_SSH |
| 8 | + |
| 9 | +static int password_get_ssh(void **p, unsigned long *l, void *u) |
| 10 | +{ |
| 11 | + LTC_UNUSED_PARAM(u); |
| 12 | + *p = strdup("abc123"); |
| 13 | + *l = 6; |
| 14 | + return 0; |
| 15 | +} |
| 16 | +static int s_pem_decode_ssh(const void *in, unsigned long inlen, void *key) |
| 17 | +{ |
| 18 | + password_ctx pw_ctx; |
| 19 | + pw_ctx.callback = password_get_ssh; |
| 20 | + return pem_decode_openssh(in, inlen, key, &pw_ctx); |
| 21 | +} |
| 22 | +static int s_pem_decode_ssh_f(FILE *f, void *key) |
| 23 | +{ |
| 24 | + password_ctx pw_ctx; |
| 25 | + pw_ctx.callback = password_get_ssh; |
| 26 | + return pem_decode_openssh_filehandle(f, key, &pw_ctx); |
| 27 | +} |
| 28 | + |
| 29 | +#endif |
| 30 | + |
7 | 31 | static int password_get(void **p, unsigned long *l, void *u) |
8 | 32 | { |
9 | 33 | LTC_UNUSED_PARAM(u); |
@@ -59,6 +83,17 @@ static int s_pem_decode(const void *in, unsigned long inlen, void *key) |
59 | 83 | return s_key_cmp(key); |
60 | 84 | } |
61 | 85 |
|
| 86 | +static int s_pem_decode_f(FILE *f, void *key) |
| 87 | +{ |
| 88 | + password_ctx pw_ctx; |
| 89 | + int err; |
| 90 | + pw_ctx.callback = password_get; |
| 91 | + if ((err = pem_decode_filehandle(f, key, &pw_ctx)) != CRYPT_OK) { |
| 92 | + return err; |
| 93 | + } |
| 94 | + return s_key_cmp(key); |
| 95 | +} |
| 96 | + |
62 | 97 | static void s_pem_free_key(ltc_pka_key *key) |
63 | 98 | { |
64 | 99 | switch (key->id) { |
@@ -100,8 +135,13 @@ int pem_test(void) |
100 | 135 |
|
101 | 136 |
|
102 | 137 | DO(test_process_dir("tests/pem", &key, s_pem_decode, NULL, (dir_cleanup_cb)s_pem_free_key, "pem_test")); |
| 138 | + DO(test_process_dir("tests/pem", &key, NULL, s_pem_decode_f, (dir_cleanup_cb)s_pem_free_key, "pem_test_filehandle")); |
103 | 139 | DO(test_process_dir("tests/pem-ecc-pkcs8", &key, s_pem_decode, NULL, (dir_cleanup_cb)s_pem_free_key, "pem_test+ecc")); |
| 140 | + DO(test_process_dir("tests/pem-ecc-pkcs8", &key, NULL, s_pem_decode_f, (dir_cleanup_cb)s_pem_free_key, "pem_test_filehandle+ecc")); |
| 141 | +#ifdef LTC_SSH |
104 | 142 | DO(test_process_dir("tests/ssh", &key, s_pem_decode_ssh, NULL, (dir_cleanup_cb)s_pem_free_key, "pem_test+ssh")); |
| 143 | + DO(test_process_dir("tests/ssh", &key, NULL, s_pem_decode_ssh_f, (dir_cleanup_cb)s_pem_free_key, "pem_test_filehandle+ssh")); |
| 144 | +#endif |
105 | 145 |
|
106 | 146 | #if defined(LTC_MDSA) |
107 | 147 | dsa_free(&s_dsa_key_should); |
|
0 commit comments