diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-05-24 09:40:06 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-05-24 09:40:06 -0400 |
commit | 3f3739c6e064fd5e1c2ac89bfd49fed7a622ac68 (patch) | |
tree | 91b743747d7531e4f036f8c96732cf8e45e18d43 /src/test/test_crypto.c | |
parent | 8340f641c30f8e529b513732be2c931e128227e2 (diff) | |
parent | f48fb8a720c7cca79249248f92e3bc99cee3414d (diff) | |
download | tor-3f3739c6e064fd5e1c2ac89bfd49fed7a622ac68.tar.gz tor-3f3739c6e064fd5e1c2ac89bfd49fed7a622ac68.zip |
Merge branch 'maint-0.3.1' into maint-0.3.2
Diffstat (limited to 'src/test/test_crypto.c')
-rw-r--r-- | src/test/test_crypto.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c index c8443fd3bb..83d97f2867 100644 --- a/src/test/test_crypto.c +++ b/src/test/test_crypto.c @@ -1362,6 +1362,46 @@ test_crypto_pk_base64(void *arg) tor_free(encoded); } +static void +test_crypto_pk_pem_encrypted(void *arg) +{ + crypto_pk_t *pk = NULL; + (void)arg; + + pk = crypto_pk_new(); + /* we need to make sure that we won't stall if somebody gives us a key + that's encrypted with a password. */ + { + const char *s = + "-----BEGIN RSA PRIVATE KEY-----\n" + "Proc-Type: 4,ENCRYPTED\n" + "DEK-Info: AES-128-CBC,EFA86BB9D2AB11E80B4E3DCD97782B16\n" + "\n" + "Z2Je4m0cFepc6coQkVbGcvNCHxTf941N2XYEVE6kn0CqWqoUH4tlwV6for5D91np\n" + "5NiEFTkWj31EhrvrYcuiJtQ/iEbABxZULFWFeJ058rb+1izBz5rScqnEacIS/3Go\n" + "YntnROBDwiKmUnue6PJVYg==\n" + "-----END RSA PRIVATE KEY-----\n"; + tt_int_op(-1, OP_EQ, + crypto_pk_read_private_key_from_string(pk, s, strlen(s))); + } + /* For fun, make sure we aren't hit by OpenSSL issue + https://github.com/openssl/openssl/issues/6347 , where we get in trouble + if a cipher doesn't use an IV. + */ + { + const char *s = + "-----BEGIN RSA PUBLIC KEY-----\n" + "Proc-Type:4,ENCRYPTED\n" + "DEK-Info:des-ede -\n" + "\n" + "iRqK\n" + "-----END RSA PUBLIC KEY-----\n"; + tt_int_op(-1, OP_EQ, + crypto_pk_read_public_key_from_string(pk, s, strlen(s))); + } + done: + crypto_pk_free(pk); +} #ifdef HAVE_TRUNCATE #define do_truncate truncate #else @@ -2990,6 +3030,7 @@ struct testcase_t crypto_tests[] = { CRYPTO_LEGACY(pk), { "pk_fingerprints", test_crypto_pk_fingerprints, TT_FORK, NULL, NULL }, { "pk_base64", test_crypto_pk_base64, TT_FORK, NULL, NULL }, + { "pk_pem_encrypted", test_crypto_pk_pem_encrypted, TT_FORK, NULL, NULL }, CRYPTO_LEGACY(digests), { "digest_names", test_crypto_digest_names, 0, NULL, NULL }, { "sha3", test_crypto_sha3, TT_FORK, NULL, NULL}, |