]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Refactored windows cert loading
authorAdriaan de Jong <dejong@fox-it.com>
Mon, 27 Jun 2011 12:13:16 +0000 (14:13 +0200)
committerDavid Sommerseth <davids@redhat.com>
Wed, 19 Oct 2011 20:45:01 +0000 (22:45 +0200)
Signed-off-by: Adriaan de Jong <dejong@fox-it.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: David Sommerseth <davids@redhat.com>
ssl.c
ssl_backend.h
ssl_openssl.c

diff --git a/ssl.c b/ssl.c
index 4110004a871e2d3b316cb44184398b6434485493..a308598ec28d3854986cc18029ff0db1bd509e56 100644 (file)
--- a/ssl.c
+++ b/ssl.c
@@ -2003,13 +2003,10 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)
 #ifdef WIN32
   else if (options->cryptoapi_cert)
     {
-         /* Load Certificate and Private Key */
-         if (!SSL_CTX_use_CryptoAPI_certificate (ctx, options->cryptoapi_cert))
-           msg (M_SSLERR, "Cannot load certificate \"%s\" from Microsoft Certificate Store",
-                options->cryptoapi_cert);
+      tls_ctx_load_cryptoapi(new_ctx, options->cryptoapi_cert);
     }
-  else
 #endif
+  else
        {
          X509 *my_cert = NULL;
 
index 027026bf8ca9ff620c7e2438a9340e6603d70822..127647f0957e58ae800626422c3ce18d11b23f78 100644 (file)
@@ -161,6 +161,17 @@ int tls_ctx_load_pkcs11(struct tls_root_ctx *ctx,
     bool pkcs11_id_management, const char *pkcs11_id);
 #endif /* ENABLE_PKCS11 */
 
+/**
+ * Use Windows cryptoapi for key and cert, and add to library-specific TLS
+ * context.
+ *
+ * @param ctx                  TLS context to use
+ * @param crypto_api_cert      String representing the certificate to load.
+ */
+#ifdef WIN32
+void tls_ctx_load_cryptoapi(struct tls_root_ctx *ctx, const char *cryptoapi_cert);
+#endif /* WIN32 */
+
 /**
  * Show the TLS ciphers that are available for us to use in the OpenSSL
  * library.
index 8f5fa98eb39d3af1da23c089d36eb234bb916e1b..e774f56df7779c19311cba594137a6001a9fa1a9 100644 (file)
@@ -330,6 +330,19 @@ tls_ctx_load_pkcs11(struct tls_root_ctx *ctx, bool pkcs11_id_management,
 }
 #endif /* ENABLE_PKCS11 */
 
+#ifdef WIN32
+void
+tls_ctx_load_cryptoapi(struct tls_root_ctx *ctx, const char *cryptoapi_cert)
+{
+  ASSERT(NULL != ctx);
+
+  /* Load Certificate and Private Key */
+  if (!SSL_CTX_use_CryptoAPI_certificate (ctx->ctx, cryptoapi_cert))
+    msg (M_SSLERR, "Cannot load certificate \"%s\" from Microsoft Certificate Store",
+          options->cryptoapi_cert);
+}
+#endif /* WIN32 */
+
 void
 show_available_tls_ciphers ()
 {