Patch: PKCS #12 support
Here we go...
Attached is a patch which enables PKCS #12 support i OpenVPN 2.0 beta7. It adds the option --pkcs12 filename, where filename should be a .p12 file contain the private key, certificate and CA cert.
I've tested on Linux both as Server and Client.
You can build this .p12 file from your PEM fiels with:
openssl pkcs12 -export -inkey $1.key -in $1.crt -certfile ca.crt \
-out $1.p12
Enjoy!
Signature · 4 lines
_____________________________________________________________ Mathias Sundman (^) ASCII Ribbon Campaign SunGard Availability Services X NO HTML/RTF in e-mail Tel: +46-(0)8-666 32 28 / \ NO Word docs in e-mail
init.c +1 -0
@@ -891,6 +891,7 @@ options->dh_file, options->cert_file, options->priv_key_file, + options->pkcs12_file, options->cipher_list);/* Get cipher & hash algorithms */
options.c +25 -3
@@ -312,6 +312,8 @@"--cert file : Local certificate in .pem format -- must be signed\n" " by a Certificate Authority in --ca file.\n" "--key file : Local private key in .pem format.\n" +"--pkcs12 file : PKCS#12 file containing local private key, local certificate\n" +" and root CA certificate.\n" "--tls-cipher l : A list l of allowable TLS ciphers separated by : (optional).\n" " : Use --show-tls to see a list of supported TLS ciphers.\n" "--tls-timeout n : Packet retransmit timeout on TLS control channel\n"
@@ -838,6 +840,7 @@SHOW_STR (dh_file);SHOW_STR (cert_file);SHOW_STR (priv_key_file); +SHOW_STR (pkcs12_file);SHOW_STR (cipher_list);SHOW_STR (tls_verify);SHOW_STR (tls_remote);
@@ -1160,9 +1163,21 @@ }if (options->tls_server || options->tls_client) { -notnull (options->ca_file,"CA file (--ca)" ); -notnull (options->cert_file,"certificate file (--cert)" ); -notnull (options->priv_key_file,"private key file (--key)" ); +if (options->pkcs12_file) + { +if (options->ca_file) +msg (M_USAGE ,"Options error: Parameter --ca can not be used when --pkcs12 is also specified." ); +if (options->cert_file) +msg (M_USAGE ,"Options error: Parameter --cert can not be used when --pkcs12 is also specified." ); +if (options->priv_key_file) +msg (M_USAGE ,"Options error: Parameter --key can not be used when --pkcs12 is also specified." ); + } +else + { +notnull (options->ca_file,"CA file (--ca) or PKCS#12 file (--pkcs12)" ); +notnull (options->cert_file,"certificate file (--cert) or PKCS#12 file (--pkcs12)" ); +notnull (options->priv_key_file,"private key file (--key) or PKCS#12 file (--pkcs12)" ); + }if (first_time && options->askpass)pem_password_callback (NULL ,0 ,0 ,NULL ); }
@@ -1181,6 +1196,7 @@MUST_BE_UNDEF (dh_file);MUST_BE_UNDEF (cert_file);MUST_BE_UNDEF (priv_key_file); +MUST_BE_UNDEF (pkcs12_file);MUST_BE_UNDEF (cipher_list);MUST_BE_UNDEF (tls_verify);MUST_BE_UNDEF (tls_remote);
@@ -3025,6 +3041,12 @@VERIFY_PERMISSION (OPT_P_GENERAL ); options->priv_key_file = p[1 ]; } +else if (streq (p[0 ],"pkcs12" ) && p[1 ]) + { + ++i; +VERIFY_PERMISSION (OPT_P_GENERAL ); + options->pkcs12_file = p[1 ]; + }else if (streq (p[0 ],"askpass" )) {VERIFY_PERMISSION (OPT_P_GENERAL );
options.h +1 -0
@@ -272,6 +272,7 @@const char *dh_file;const char *cert_file;const char *priv_key_file; +const char *pkcs12_file;const char *cipher_list;const char *tls_verify;const char *tls_remote;
ssl.c +89 -27
130 lines not on this page · raw message
ssl.h +2 -0
@@ -32,6 +32,7 @@#include <openssl/bio.h> #include <openssl/rand.h> #include <openssl/err.h> +#include <openssl/pkcs12.h> #include "basic.h" #include "crypto.h"
@@ -436,6 +437,7 @@const char *ca_file, const char *dh_file, const char *cert_file, + const char *pkcs12_file, const char *priv_key_file, const char *cipher_list);struct tls_multi *tls_multi_init (struct tls_options *tls_options);