[pkg-opensc-commit] [libp11] 07/51: Gracefully handle alien RSA keys
Eric Dorland
eric at moszumanska.debian.org
Wed Dec 7 17:51:30 UTC 2016
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit f160e2fce640a577597b90fd9c647fc268b00867
Author: Michał Trojnara <Michal.Trojnara at stunnel.org>
Date: Fri Sep 30 03:22:37 2016 +0200
Gracefully handle alien RSA keys
EC keys will be handled in a separate commit
---
src/p11_rsa.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/src/p11_rsa.c b/src/p11_rsa.c
index 6748746..ca81975 100644
--- a/src/p11_rsa.c
+++ b/src/p11_rsa.c
@@ -310,13 +310,33 @@ int pkcs11_get_key_size(PKCS11_KEY *key)
return RSA_size(rsa);
}
+#if OPENSSL_VERSION_NUMBER < 0x10100005L
+
+int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
+ (int flen, const unsigned char *from,
+ unsigned char *to, RSA *rsa, int padding)
+{
+ return meth->rsa_priv_enc;
+}
+
+int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
+ (int flen, const unsigned char *from,
+ unsigned char *to, RSA *rsa, int padding)
+{
+ return meth->rsa_priv_dec;
+}
+
+#endif
+
static int pkcs11_rsa_priv_dec_method(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
PKCS11_KEY *key = RSA_get_ex_data(rsa, rsa_ex_index);
+ int (*priv_dec) (int flen, const unsigned char *from,
+ unsigned char *to, RSA *rsa, int padding);
if (key == NULL) {
- PKCS11err(PKCS11_F_PKCS11_RSA_DECRYPT, PKCS11_ALIEN_KEY);
- return -1;
+ priv_dec = RSA_meth_get_priv_dec(RSA_get_default_method());
+ return priv_dec(flen, from, to, rsa, padding);
}
return PKCS11_private_decrypt(flen, from, to, key, padding);
}
@@ -325,9 +345,11 @@ static int pkcs11_rsa_priv_enc_method(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
PKCS11_KEY *key = RSA_get_ex_data(rsa, rsa_ex_index);
+ int (*priv_enc) (int flen, const unsigned char *from,
+ unsigned char *to, RSA *rsa, int padding);
if (key == NULL) {
- PKCS11err(PKCS11_F_PKCS11_RSA_ENCRYPT, PKCS11_ALIEN_KEY);
- return -1;
+ priv_enc = RSA_meth_get_priv_enc(RSA_get_default_method());
+ return priv_enc(flen, from, to, rsa, padding);
}
return PKCS11_private_encrypt(flen, from, to, key, padding);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list