Skip to contentSkip to conversation

pkcs11: use generic evp key instead of rsa

PATCH In review Alon Bar-Lev 3 participants 3 messages Nov 11, 2013 – Dec 16, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pkcs11: use generic evp key instead of rsa

Enables DSA, ECDSA key usages with newer pkcs11-helper.

---
 configure.ac                 |  2 +-
 src/openvpn/pkcs11_openssl.c | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)
configure.ac +1 -1
index 5fad0af..0635149 100644
@@ -725,7 +725,7 @@ esac
 
 PKG_CHECK_MODULES(
 	[PKCS11_HELPER],
-	[libpkcs11-helper-1 >= 1.02],
+	[libpkcs11-helper-1 >= 1.11],
 	[have_pkcs11_helper="yes"],
 	[]
 )
src/openvpn/pkcs11_openssl.c +7 -7
index af843b7..87eb166 100644
@@ -49,7 +49,7 @@ pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
   int ret = 1;
 
   X509 *x509 = NULL;
-  RSA *rsa = NULL;
+  EVP_PKEY *evp = NULL;
   pkcs11h_openssl_session_t openssl_session = NULL;
 
   if ((openssl_session = pkcs11h_openssl_createSession (certificate)) == NULL)
@@ -63,9 +63,9 @@ pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
    */
   certificate = NULL;
 
-  if ((rsa = pkcs11h_openssl_session_getRSA (openssl_session)) == NULL)
+  if ((evp = pkcs11h_openssl_session_getEVP (openssl_session)) == NULL)
     {
-      msg (M_WARN, "PKCS#11: Unable get rsa object");
+      msg (M_WARN, "PKCS#11: Unable get evp object");
       goto cleanup;
     }
 
@@ -75,7 +75,7 @@ pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
       goto cleanup;
     }
 
-  if (!SSL_CTX_use_RSAPrivateKey (ssl_ctx->ctx, rsa))
+  if (!SSL_CTX_use_PrivateKey (ssl_ctx->ctx, evp))
     {
       msg (M_WARN, "PKCS#11: Cannot set private key for openssl");
       goto cleanup;
@@ -108,10 +108,10 @@ cleanup:
       x509 = NULL;
     }
 
-  if (rsa != NULL)
+  if (evp != NULL)
     {
-      RSA_free (rsa);
-      rsa = NULL;
+      EVP_PKEY_free (evp);
+      evp = NULL;
     }
 
   if (openssl_session != NULL)
Signature · 1 line
1.8.3.2
#1 lore raw

ACK. Code looks good, compiles and passes my local pkcs11-test.

-Steffan

Quoted 71 lines · Alon Bar-Lev

Enables DSA, ECDSA key usages with newer pkcs11-helper.

---
 configure.ac                 |  2 +-
 src/openvpn/pkcs11_openssl.c | 14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)
configure.ac +1 -1
index 5fad0af..0635149 100644
@@ -725,7 +725,7 @@ esac
 
 PKG_CHECK_MODULES(
 	[PKCS11_HELPER],
-	[libpkcs11-helper-1 >= 1.02],
+	[libpkcs11-helper-1 >= 1.11],
 	[have_pkcs11_helper="yes"],
 	[]
 )
src/openvpn/pkcs11_openssl.c +7 -7
index af843b7..87eb166 100644
@@ -49,7 +49,7 @@ pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
   int ret = 1;
 
   X509 *x509 = NULL;
-  RSA *rsa = NULL;
+  EVP_PKEY *evp = NULL;
   pkcs11h_openssl_session_t openssl_session = NULL;
 
   if ((openssl_session = pkcs11h_openssl_createSession (certificate)) == NULL)
@@ -63,9 +63,9 @@ pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
    */
   certificate = NULL;
 
-  if ((rsa = pkcs11h_openssl_session_getRSA (openssl_session)) == NULL)
+  if ((evp = pkcs11h_openssl_session_getEVP (openssl_session)) == NULL)
     {
-      msg (M_WARN, "PKCS#11: Unable get rsa object");
+      msg (M_WARN, "PKCS#11: Unable get evp object");
       goto cleanup;
     }
 
@@ -75,7 +75,7 @@ pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
       goto cleanup;
     }
 
-  if (!SSL_CTX_use_RSAPrivateKey (ssl_ctx->ctx, rsa))
+  if (!SSL_CTX_use_PrivateKey (ssl_ctx->ctx, evp))
     {
       msg (M_WARN, "PKCS#11: Cannot set private key for openssl");
       goto cleanup;
@@ -108,10 +108,10 @@ cleanup:
       x509 = NULL;
     }
 
-  if (rsa != NULL)
+  if (evp != NULL)
     {
-      RSA_free (rsa);
-      rsa = NULL;
+      EVP_PKEY_free (evp);
+      evp = NULL;
     }
 
   if (openssl_session != NULL)
#2 lore raw
In reply to Alon Bar-Lev

Your patch has been applied to the master and release/2.3 branch.

(I have not actually tested that it *works* - my gentoo system only installs pkcs11-helper 1.10, which isn't sufficient for --enable-pkcs11 with this patch. So I just tested that it doesn't break default compiles)

commit 6575ad483702dd53c0f683093b5f26a87518c6a8 (master) commit f8b590d5a6692324a8cb8522ddc598358a215ac5 (release/2.3)

Author: Alon Bar-Lev
Date:   Tue Nov 12 00:36:06 2013 +0200
     pkcs11: use generic evp key instead of rsa

     Signed-off-by: Alon Bar-Lev <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/7960
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering