--management-external-key for polarssl
Hi,
These three patches add --management-external-key support for polarssl builds. The code was originally written by Joachim Schipper for OpenVPN-NL, which is why he is mentioned as the author of the patches. I reworked it a bit to match the regular OpenVPN codebase better.
Patch 1/3 is just a bit of preparation for patch 2/3.
Patch 2/2 adds the --management-external-key functionality.
Patch 3/3 enables TLSv1.2 signatures. This adds (GPL) code from polarssl's pkcs11.c to the ssl_polarssl.c file to do the signature selection.
These patches should apply cleanly to the master and 2.3 branches. I suggest adding them to both branches as these 'fix a missing functionality issue' for polarssl builds.
-Steffan
PATCH 1/3 Refactor tls_ctx_use_external_private_key()
From: Joachim Schipper <[email protected]...>
OpenSSL's tls_ctx_load_cert_file() had a parameter in which a copy of the context's certificate chain was stored on return, used by tls_ctx_use_external_private_key() only and free()d immediately thereafter.
PolarSSL also supported this output parameter, but returned a pointer to the context's certificate chain (rather than to a copy of the certificate, as OpenSSL does) - which meant that we would have to #ifdef the free().
PolarSSL cannot make a copy of a certificate chain, and OpenSSL cannot store a pointer to (instead of a copy of) the cert.
So remove the output parameter from tls_ctx_load_cert_file() and incorporate the needed functionality directly into tls_ctx_use_external_private_key() (which is straightforward for both OpenSSL and PolarSSL, as long as you don't try to support both at once.)
--- src/openvpn/ssl.c | 10 +++------- src/openvpn/ssl_backend.h | 26 +++++++------------------- src/openvpn/ssl_openssl.c | 23 +++++++++++++++++++---- src/openvpn/ssl_polarssl.c | 20 ++++---------------- 4 files changed, 33 insertions(+), 46 deletions(-)
src/openvpn/ssl.c +3 -7
@@ -513,12 +513,8 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)#ifdef MANAGMENT_EXTERNAL_KEY else if ((options->management_flags & MF_EXTERNAL_KEY) && options->cert_file) { -openvpn_x509_cert_t *my_cert =NULL ; -tls_ctx_load_cert_file (new_ctx, options->cert_file, options->cert_file_inline, - &my_cert); -tls_ctx_use_external_private_key (new_ctx, my_cert); - -tls_ctx_free_cert_file (my_cert); +tls_ctx_use_external_private_key (new_ctx, options->cert_file, + options->cert_file_inline); }#endif else
@@ -526,7 +522,7 @@ init_ssl (const struct options *options, struct tls_root_ctx *new_ctx)/* Load Certificate */ if (options->cert_file) { -tls_ctx_load_cert_file (new_ctx, options->cert_file, options->cert_file_inline,NULL ); +tls_ctx_load_cert_file (new_ctx, options->cert_file, options->cert_file_inline); }/* Load Private Key */
src/openvpn/ssl_backend.h +7 -19
@@ -215,27 +215,13 @@ void tls_ctx_load_cryptoapi(struct tls_root_ctx *ctx, const char *cryptoapi_cert* Load certificate file into the given TLS context. If the given certificate * file contains a certificate chain, load the whole chain. * -* If the x509 parameter is not NULL, the certificate will be returned in it. -* * @param ctx TLS context to use * @param cert_file The file name to load the certificate from, or * "[[INLINE]]" in the case of inline files. * @param cert_file_inline A string containing the certificate -* @param x509 An optional certificate, if x509 is NULL, -* do nothing, if x509 is not NULL, *x509 will be -* allocated and filled with the loaded certificate. -* *x509 must be NULL. */ void tls_ctx_load_cert_file (struct tls_root_ctx *ctx,const char *cert_file, -const char *cert_file_inline,openvpn_x509_cert_t **x509 - ); - -/** -* Free the given certificate -* -* @param x509 certificate to free -*/ -void tls_ctx_free_cert_file (openvpn_x509_cert_t *x509); +const char *cert_file_inline);/** * Load private key file into the given TLS context.
@@ -255,17 +241,19 @@ int tls_ctx_load_priv_file (struct tls_root_ctx *ctx, const char *priv_key_file,#ifdef MANAGMENT_EXTERNAL_KEY /** -* Tell the management interface to load the external private key matching -* the given certificate. +* Tell the management interface to load the given certificate and the external +* private key matching the given certificate. * * @param ctx TLS context to use -* @param cert The certificate file to load the private key for +* @param cert_file The file name to load the certificate from, or * "[[INLINE]]" in the case of inline files. +* @param cert_file_inline A string containing the certificate * * @return 1 if an error occurred, 0 if parsing was * successful. */ -int tls_ctx_use_external_private_key (struct tls_root_ctx *ctx,openvpn_x509_cert_t *cert); +int tls_ctx_use_external_private_key (struct tls_root_ctx *ctx, +const char *cert_file,const char *cert_file_inline);#endif
src/openvpn/ssl_openssl.c +19 -4
@@ -456,9 +456,10 @@ tls_ctx_add_extra_certs (struct tls_root_ctx *ctx, BIO *bio) } } -void -tls_ctx_load_cert_file (struct tls_root_ctx *ctx,const char *cert_file, -const char *cert_file_inline,X509 **x509 +/* Like tls_ctx_load_cert, but returns a copy of the certificate in **X509 */ +static void +tls_ctx_load_cert_file_and_copy (struct tls_root_ctx *ctx, +const char *cert_file,const char *cert_file_inline,X509 **x509 ) {BIO *in =NULL ;
@@ -513,6 +514,13 @@ end: }void +tls_ctx_load_cert_file (struct tls_root_ctx *ctx,const char *cert_file, +const char *cert_file_inline) +{ +tls_ctx_load_cert_file_ext (ctx, cert_file, cert_file_inline,NULL ); +} + +void tls_ctx_free_cert_file (X509 *x509) {X509_free (x509);
@@ -648,15 +656,19 @@ rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, i }int -tls_ctx_use_external_private_key (struct tls_root_ctx *ctx,X509 *cert) +tls_ctx_use_external_private_key (struct tls_root_ctx *ctx, +const char *cert_file,const char *cert_file_inline) {RSA *rsa =NULL ;RSA *pub_rsa;RSA_METHOD *rsa_meth; +X509 *cert =NULL ;ASSERT (NULL != ctx);ASSERT (NULL != cert); +tls_ctx_load_cert_file_ext (ctx, cert_file, cert_file_inline, &cert); +/* allocate custom RSA method object */ ALLOC_OBJ_CLEAR (rsa_meth,RSA_METHOD ); rsa_meth->name ="OpenVPN external private key RSA Method" ;
@@ -691,10 +703,13 @@ tls_ctx_use_external_private_key (struct tls_root_ctx *ctx, X509 *cert)if (!SSL_CTX_use_RSAPrivateKey (ctx->ctx, rsa)) goto err; +X509_free (cert);RSA_free (rsa);/* doesn't necessarily free, just decrements refcount */ return 1 ; err: +if (cert) +X509_free (cert);if (rsa)RSA_free (rsa);else
src/openvpn/ssl_polarssl.c +4 -16
@@ -237,13 +237,10 @@ tls_ctx_load_cryptoapi(struct tls_root_ctx *ctx, const char *cryptoapi_cert)void tls_ctx_load_cert_file (struct tls_root_ctx *ctx,const char *cert_file, -const char *cert_file_inline, -openvpn_x509_cert_t **x509 +const char *cert_file_inline ) {ASSERT (NULL != ctx); -if (NULL != x509) -ASSERT (NULL == *x509);if (!strcmp (cert_file,INLINE_FILE_TAG ) && cert_file_inline) {
@@ -256,16 +253,6 @@ tls_ctx_load_cert_file (struct tls_root_ctx *ctx, const char *cert_file,if (0 !=x509parse_crtfile (ctx->crt_chain, cert_file))msg (M_FATAL ,"Cannot load certificate file %s" , cert_file); } -if (x509) - { - *x509 = ctx->crt_chain; - } -} - -void -tls_ctx_free_cert_file (openvpn_x509_cert_t *x509) -{ -x509_free (x509); }int
@@ -322,8 +309,9 @@ tls_ctx_load_priv_file (struct tls_root_ctx *ctx, const char *priv_key_file,#ifdef MANAGMENT_EXTERNAL_KEY -int -tls_ctx_use_external_private_key (struct tls_root_ctx *ctx,openvpn_x509_cert_t *cert) +tls_ctx_use_external_private_key (struct tls_root_ctx *ctx, + const char *cert_file, const char *cert_file_inline + ) { msg(M_FATAL, "Use of management external keys not yet supported for PolarSSL.");return false;
Signature · 1 line
1.7.9.5
Re: [Openvpn-devel] [PATCH 1/3] Refactor tls_ctx_use_external_private_key()
Am 19.09.13 12:47, schrieb [email protected]...:
Quoted 10 lines
From: Joachim Schipper <[email protected]...>
OpenSSL's
tls_ctx_load_cert_file()had a parameter in which a copy of the context's certificate chain was stored on return, used bytls_ctx_use_external_private_key()only and free()d immediately thereafter.PolarSSL also supported this output parameter, but returned a pointer to the context's certificate chain (rather than to a copy of the certificate, as OpenSSL does) - which meant that we would have to #ifdef the
free().
Quoted 9 lines
PolarSSL cannot make a copy of a certificate chain, and OpenSSL cannot store a pointer to (instead of a copy of) the cert.
So remove the output parameter from
tls_ctx_load_cert_file()and incorporate the needed functionality directly intotls_ctx_use_external_private_key()(which is straightforward for both OpenSSL and PolarSSL, as long as you don't try to support both at once.)
ACK. This "only" refactoring.
Arne
[Openvpn-devel] [PATCH applied] Re: Refactor tls_ctx_use_external_private_key()
In reply to [email protected]...Your patch has been applied to the master and release/2.3 branches.
commit c3b2d487bc5089c8c0cf65df8e6cc2232d84b05b (master) commit a1e2e7699ca265e911ea8068eadffe1b5a7d24bf (release/2.3)
Author: Joachim Schipper Date: Thu Sep 19 12:47:27 2013 +0200
Refactor tls_ctx_use_external_private_key()
Signed-off-by: Joachim Schipper <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/7888
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH 1/3] Refactor tls_ctx_use_external_private_key()
In reply to [email protected]...Hi,
Quoted 10 lines · On Thu, Sep 19, 2013 at 12:47:27PM +0200, [email protected]... wrote:
From: Joachim Schipper <[email protected]...>
OpenSSL's
tls_ctx_load_cert_file()had a parameter in which a copy of the context's certificate chain was stored on return, used bytls_ctx_use_external_private_key()only and free()d immediately thereafter.PolarSSL also supported this output parameter, but returned a pointer to the context's certificate chain (rather than to a copy of the certificate, as OpenSSL does) - which meant that we would have to #ifdef the
free().
Quoted 7 lines
PolarSSL cannot make a copy of a certificate chain, and OpenSSL cannot store a pointer to (instead of a copy of) the cert.
So remove the output parameter from
tls_ctx_load_cert_file()and incorporate the needed functionality directly intotls_ctx_use_external_private_key()(which is straightforward for both OpenSSL and PolarSSL, as long as you don't try to support both at once.)
While I'm sure this works all nice and dandy for PolarSSL builds, it blows up for me for OpenSSL builds (in master)...
ssl_openssl.o: In function tls_ctx_load_cert_file': /rhome/gert/src/openvpn-maint/test-build-master/src/openvpn/../../../openvpn/src/openvpn/ssl_openssl.c:537: undefined reference to tls_ctx_load_cert_file_ext' ssl_openssl.o: In function tls_ctx_use_external_private_key': /rhome/gert/src/openvpn-maint/test-build-master/src/openvpn/../../../openvpn/src/openvpn/ssl_openssl.c:687: undefined reference to tls_ctx_load_cert_file_ext'
collect2: ld returned 1 exit status
This is on a gentoo installation with openssl 1.0.1c - does it need a more recent version? Is this based on other patches that we've not seen yet?
(I'd NAK it, but since it's in and pushed - should have done a test-build myself, instead of just relying on the buildslaves - could you please send a fix?)
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...PATCH 1/1 Fix compile error in ssl_openssl introduced by polar external-management patch
--- src/openvpn/ssl_openssl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +2 -2
@@ -534,7 +534,7 @@ void tls_ctx_load_cert_file (struct tls_root_ctx *ctx, const char *cert_file, const char *cert_file_inline) { -tls_ctx_load_cert_file_ext (ctx, cert_file, cert_file_inline, NULL); +tls_ctx_load_cert_file_and_copy (ctx, cert_file, cert_file_inline, NULL); }void
@@ -684,7 +684,7 @@ tls_ctx_use_external_private_key (struct tls_root_ctx *ctx,ASSERT (NULL != ctx);ASSERT (NULL != cert); -tls_ctx_load_cert_file_ext (ctx, cert_file, cert_file_inline, &cert); +tls_ctx_load_cert_file_and_copy (ctx, cert_file, cert_file_inline, &cert);/* allocate custom RSA method object */ ALLOC_OBJ_CLEAR (rsa_meth,RSA_METHOD );
Signature · 1 line
1.8.3.4 (Apple Git-47)
Re: [Openvpn-devel] [PATCH] Fix compile error in ssl_openssl introduced by polar external-management patch
Argh, this must have slipped in while rewriting my git history to extract these patches from my own try. Sorry!
ACK to Arne's quick fix, thanks for acting quickly.
-Steffan
Quoted 46 lines · Arne Schwabe
--- src/openvpn/ssl_openssl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)src/openvpn/ssl_openssl.c +1
-1@@ -534,7 +534,7 @@ void tls_ctx_load_cert_file (struct tls_root_ctx *ctx, const char *cert_file, const char *cert_file_inline) { -tls_ctx_load_cert_file_ext (ctx, cert_file, cert_file_inline, NULL); +tls_ctx_load_cert_file_and_copy (ctx, cert_file, cert_file_inline, NULL); }void
src/openvpn/ssl_openssl.c +1
-1@@ -684,7 +684,7 @@ tls_ctx_use_external_private_key (struct tls_root_ctx *ctx,ASSERT (NULL != ctx);ASSERT (NULL != cert); -tls_ctx_load_cert_file_ext (ctx, cert_file, cert_file_inline, &cert); +tls_ctx_load_cert_file_and_copy (ctx, cert_file, cert_file_inline, &cert);/* allocate custom RSA method object */ ALLOC_OBJ_CLEAR (rsa_meth, RSA_METHOD);--
1.8.3.4 (Apple Git-47)------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH 1/1 Move ASSERT so external-key with OpenSSL works again
--- src/openvpn/ssl_openssl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpn/ssl_openssl.c +2 -1
@@ -682,10 +682,11 @@ tls_ctx_use_external_private_key (struct tls_root_ctx *ctx,X509 *cert =NULL ;ASSERT (NULL != ctx); -ASSERT (NULL != cert);tls_ctx_load_cert_file_and_copy (ctx, cert_file, cert_file_inline, &cert); +ASSERT (NULL != cert); +/* allocate custom RSA method object */ ALLOC_OBJ_CLEAR (rsa_meth,RSA_METHOD ); rsa_meth->name ="OpenVPN external private key RSA Method" ;
Signature · 1 line
1.8.3.4 (Apple Git-47)
Re: [Openvpn-devel] [PATCH] Move ASSERT so external-key with OpenSSL works again
ACK
-Steffan
Quoted 48 lines
-----Original Message-----
From: Arne Schwabe [mailto:[email protected]...]
Sent: vrijdag 29 november 2013 13:33
To: [email protected]
Subject: [Openvpn-devel] [PATCH] Move ASSERT so external-key with OpenSSL works again--- src/openvpn/ssl_openssl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)src/openvpn/ssl_openssl.c +2
-1@@ -682,10 +682,11 @@ tls_ctx_use_external_private_key (struct tls_root_ctx *ctx,X509 *cert =NULL ;ASSERT (NULL != ctx); -ASSERT (NULL != cert);tls_ctx_load_cert_file_and_copy (ctx, cert_file, cert_file_inline, &cert); +ASSERT (NULL != cert); +/* allocate custom RSA method object */ ALLOC_OBJ_CLEAR (rsa_meth, RSA_METHOD); rsa_meth->name = "OpenVPN external private key RSA Method";--
1.8.3.4 (Apple Git-47)-----------------------------------------------------------------------
-------
Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.cl
ktrk
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
[Openvpn-devel] [PATCH applied] Re: Move ASSERT so external-key with OpenSSL works again
In reply to Arne SchwabeYour patch has been applied to the master branch.
commit 68793f40e1d04409264d21dd24453d959828a306
Author: Arne Schwabe Date: Fri Nov 29 13:32:40 2013 +0100
Move ASSERT so external-key with OpenSSL works again
Acked-by: Steffan Karger <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8069
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: Move ASSERT so external-key with OpenSSL works again
Hi,
Quoted 6 lines · Gert Doering
Your patch has been applied to the master branch.
commit
68793f40e1d04409264d21dd24453d959828a306Author: Arne Schwabe Date: Fri Nov 29 13:32:40 2013 +0100
Quoted 6 lines
Move ASSERT so external-key with OpenSSL works again
Acked-by: Steffan Karger <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8069
Signed-off-by: Gert Doering <[email protected]...>And as discussed today, and in trac#693, also applied to release/2.3 (bugfix)
commit 5f3d28b374d4058a08753d06c675cbc589675e24
Author: Arne Schwabe <[email protected]...> Date: Fri Nov 29 13:32:40 2013 +0100
Move ASSERT so external-key with OpenSSL works again
Acked-by: Steffan Karger <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8069
trac #693
Signed-off-by: Gert Doering <[email protected]...>
(cherry picked from commit 68793f40e1d04409264d21dd24453d959828a306)(got an Ack from Steffan in the ticket)
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...[Openvpn-devel] [PATCH applied] Re: Fix compile error in ssl_openssl introduced by polar external-management patch
In reply to Arne SchwabeThanks. ACKed on #openvpn-devel and on the list (and this time, actually compile-tested locally before pushing).
Patch has been applied to the master and release/2.3 branches.
commit 20fe5561dfe7a6f1da3aac07b38d0773c2758e5e (master) commit 816ccf2666a2de6b7098c4b28d931ea378c278ea (release/2.3)
Author: Arne Schwabe Date: Sat Nov 23 13:40:34 2013 +0100
Fix compile error in ssl_openssl introduced by polar external-management patch
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8039
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 2/3 --management-external-key for PolarSSL
In reply to [email protected]...From: Joachim Schipper <[email protected]...>
Add --management-external-key support, compatible with the OpenSSL implementation. Needs the flexibility of ssl_set_own_cert_alt(), which is new in PolarSSL-1.2.
--- src/openvpn/ssl_polarssl.c | 100 ++++++++++++++++++++++++++++++++++++++++++-- src/openvpn/ssl_polarssl.h | 5 +++ src/openvpn/syshead.h | 2 +- 3 files changed, 102 insertions(+), 5 deletions(-)
src/openvpn/ssl_polarssl.c +96 -4
@@ -121,6 +121,10 @@ tls_ctx_free(struct tls_root_ctx *ctx) free(ctx->priv_key_pkcs11); }#endif +#if defined(MANAGMENT_EXTERNAL_KEY ) +if (ctx->external_key !=NULL ) +free (ctx->external_key); +#endif if (ctx->allowed_ciphers)free (ctx->allowed_ciphers);
@@ -309,14 +313,95 @@ tls_ctx_load_priv_file (struct tls_root_ctx *ctx, const char *priv_key_file,#ifdef MANAGMENT_EXTERNAL_KEY + +struct external_context { +size_t signature_length; +}; + +int tls_ctx_use_external_private_key (struct tls_root_ctx *ctx, - const char *cert_file, const char *cert_file_inline - ) +const char *cert_file,const char *cert_file_inline) { - msg(M_FATAL, "Use of management external keys not yet supported for PolarSSL."); -return false; +ASSERT (NULL != ctx); + +tls_ctx_load_cert_file (ctx, cert_file, cert_file_inline); + +if (ctx->crt_chain ==NULL ) +return 0 ; + +/* Most of the initialization happens in key_state_ssl_init() */ + ALLOC_OBJ_CLEAR (ctx->external_key, struct external_context); + ctx->external_key->signature_length = ctx->crt_chain->rsa.len; + +return 1 ; } +static inline int external_pkcs1_sign (void *ctx_voidptr, +int (*f_rng)(void *,unsigned char *,size_t ),void *p_rng,int mode, +int hash_id,unsigned int hashlen,const unsigned char *hash, +unsigned char *sig ) +{ +struct external_context *const ctx = ctx_voidptr; +char *in_b64 =NULL ; +char *out_b64 =NULL ; +int rv; + +ASSERT (NULL != ctx); + +if (RSA_PRIVATE != mode) + { + rv =POLARSSL_ERR_RSA_BAD_INPUT_DATA ; + goto done; + } + +/* +* Normally (i.e. rsa_pkcs1_sign()), the padding is set in the context, and +* we have padding-specific code to handle various hash_id's here. Since the +* management client will RSA-sign the bytes we present without further +* processing, we only support SIG_RSA_RAW (PolarSSL's equivalent of +* OpenSSL's NID_md5_sha1). +*/ +ASSERT (hash_id ==SIG_RSA_RAW ); +/* convert 'from' to base64 */ +if (openvpn_base64_encode (hash, hashlen, &in_b64) <=0 ) + { + rv =POLARSSL_ERR_RSA_BAD_INPUT_DATA ; + goto done; + } + +/* call MI for signature */ +if (management) + out_b64 =management_query_rsa_sig (management, in_b64); +if (!out_b64) + { + rv =POLARSSL_ERR_RSA_PRIVATE_FAILED ; + goto done; + } + +/* decode base64 signature to binary and verify length */ +if (openvpn_base64_decode (out_b64, sig, ctx->signature_length) != + ctx->signature_length ) + { + rv =POLARSSL_ERR_RSA_PRIVATE_FAILED ; + goto done; + } + + rv =0 ; + + done: +if (in_b64) +free (in_b64); +if (out_b64) +free (out_b64); +return rv; +} + +static inline size_t external_key_len (void *vctx) +{ +struct external_context *const ctx = vctx; + +return ctx->signature_length; +}#endif void tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,
@@ -530,6 +615,13 @@ void key_state_ssl_init(struct key_state_ssl *ks_ssl, ssl_pkcs11_key_len ); else#endif +#if defined(MANAGMENT_EXTERNAL_KEY ) +if (ssl_ctx->external_key !=NULL ) +ssl_set_own_cert_alt ( ks_ssl->ctx, ssl_ctx->crt_chain, + ssl_ctx->external_key,NULL , external_pkcs1_sign, + external_key_len ); + else +#endif ssl_set_own_cert ( ks_ssl->ctx, ssl_ctx->crt_chain, ssl_ctx->priv_key );/* Initialise SSL verification */
src/openvpn/ssl_polarssl.h +5 -0
@@ -30,6 +30,8 @@#ifndef SSL_POLARSSL_H_ #define SSL_POLARSSL_H_ +#include "syshead.h" +#include <polarssl/ssl.h> #if defined(ENABLE_PKCS11 )
@@ -68,6 +70,9 @@ struct tls_root_ctx {#if defined(ENABLE_PKCS11 )pkcs11_context *priv_key_pkcs11;/**< PKCS11 private key */ #endif +#ifdef MANAGMENT_EXTERNAL_KEY +struct external_context *external_key;/**< Management external key */ +#endif int * allowed_ciphers;/**< List of allowed ciphers for this connection */ };
src/openvpn/syshead.h +1 -1
@@ -539,7 +539,7 @@ socket_defined (const socket_descriptor_t sd)/* * Enable external private key */ -#if defined(ENABLE_MANAGEMENT ) && defined(ENABLE_SSL ) && !defined(ENABLE_CRYPTO_POLARSSL ) +#if defined(ENABLE_MANAGEMENT ) && defined(ENABLE_SSL )#define MANAGMENT_EXTERNAL_KEY #endif
Signature · 1 line
1.7.9.5
Re: [Openvpn-devel] [PATCH 2/3] --management-external-key for PolarSSL
Am 19.09.13 12:47, schrieb [email protected]...:
Quoted 6 lines
From: Joachim Schipper <[email protected]...>
Add --management-external-key support, compatible with the OpenSSL implementation. Needs the flexibility of
ssl_set_own_cert_alt(), which is new in PolarSSL-1.2.
ACK. Also works on Android :)
Arne
[Openvpn-devel] [PATCH applied] Re: --management-external-key for PolarSSL
In reply to [email protected]...Your patch has been applied to the master and release/2.3 branches.
commit 38ace48c6820c611e689bc69b0cf5380bf7a8891 (master) commit 5269096bde5350d7afb51694b0c38b560c32b5f4 (release/2.3)
Author: Joachim Schipper Date: Thu Sep 19 12:47:28 2013 +0200
--management-external-key for PolarSSL
Signed-off-by: Joachim Schipper <[email protected]...>
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/7886
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 3/3 external_pkcs1_sign: Support non-RSA_SIG_RAW hash_ids
In reply to [email protected]...From: Joachim Schipper <[email protected]...>
For TLSv1.2, we need to support various hashes. (GPL) code taken from PolarSSL pkcs11_sign().
--- src/openvpn/ssl_polarssl.c | 76 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 7 deletions(-)
src/openvpn/ssl_polarssl.c +69 -7
@@ -7,6 +7,7 @@* * Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <[email protected]...> * Copyright (C) 2010 Fox Crypto B.V. <[email protected]...> +* Copyright (C) 2006-2010, Brainspark B.V. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2
@@ -345,6 +346,8 @@ static inline int external_pkcs1_sign( void *ctx_voidptr,char *in_b64 =NULL ;char *out_b64 =NULL ;int rv; +unsigned char *const p = sig; +size_t asn_len;ASSERT (NULL != ctx);
@@ -355,15 +358,74 @@ static inline int external_pkcs1_sign( void *ctx_voidptr, }/* -* Normally (i.e. rsa_pkcs1_sign()), the padding is set in the context, and -* we have padding-specific code to handle various hash_id's here. Since the -* management client will RSA-sign the bytes we present without further -* processing, we only support SIG_RSA_RAW (PolarSSL's equivalent of -* OpenSSL's NID_md5_sha1). +* Support a wide range of hashes. TLSv1.1 and before only need SIG_RSA_RAW, +* but TLSv1.2 needs the full suite of hashes. +* +* This code has been taken from PolarSSL pkcs11_sign(), under the GPLv2.0+. */ -ASSERT (hash_id ==SIG_RSA_RAW ); +switch ( hash_id ) + { +case SIG_RSA_RAW : + asn_len =0 ; +memcpy ( p, hash, hashlen ); +break ; + +case SIG_RSA_MD2 : + asn_len =OID_SIZE (ASN1_HASH_MDX ); +memcpy ( p,ASN1_HASH_MDX , asn_len ); +memcpy ( p + asn_len, hash, hashlen ); + p[13 ] =2 ;break ; + +case SIG_RSA_MD4 : + asn_len =OID_SIZE (ASN1_HASH_MDX ); +memcpy ( p,ASN1_HASH_MDX , asn_len ); +memcpy ( p + asn_len, hash, hashlen ); + p[13 ] =4 ;break ; + +case SIG_RSA_MD5 : + asn_len =OID_SIZE (ASN1_HASH_MDX ); +memcpy ( p,ASN1_HASH_MDX , asn_len ); +memcpy ( p + asn_len, hash, hashlen ); + p[13 ] =5 ;break ; + +case SIG_RSA_SHA1 : + asn_len =OID_SIZE (ASN1_HASH_SHA1 ); +memcpy ( p,ASN1_HASH_SHA1 , asn_len ); +memcpy ( p +15 , hash, hashlen ); +break ; + +case SIG_RSA_SHA224 : + asn_len =OID_SIZE (ASN1_HASH_SHA2X ); +memcpy ( p,ASN1_HASH_SHA2X , asn_len ); +memcpy ( p + asn_len, hash, hashlen ); + p[1 ] += hashlen; p[14 ] =4 ; p[18 ] += hashlen;break ; + +case SIG_RSA_SHA256 : + asn_len =OID_SIZE (ASN1_HASH_SHA2X ); +memcpy ( p,ASN1_HASH_SHA2X , asn_len ); +memcpy ( p + asn_len, hash, hashlen ); + p[1 ] += hashlen; p[14 ] =1 ; p[18 ] += hashlen;break ; + +case SIG_RSA_SHA384 : + asn_len =OID_SIZE (ASN1_HASH_SHA2X ); +memcpy ( p,ASN1_HASH_SHA2X , asn_len ); +memcpy ( p + asn_len, hash, hashlen ); + p[1 ] += hashlen; p[14 ] =2 ; p[18 ] += hashlen;break ; + +case SIG_RSA_SHA512 : + asn_len =OID_SIZE (ASN1_HASH_SHA2X ); +memcpy ( p,ASN1_HASH_SHA2X , asn_len ); +memcpy ( p + asn_len, hash, hashlen ); + p[1 ] += hashlen; p[14 ] =3 ; p[18 ] += hashlen;break ; + +/* End of copy */ +default : + rv =POLARSSL_ERR_RSA_BAD_INPUT_DATA ; + goto done; + } +/* convert 'from' to base64 */ -if (openvpn_base64_encode (hash, hashlen, &in_b64) <=0 ) +if (openvpn_base64_encode (sig, asn_len + hashlen, &in_b64) <=0 ) { rv =POLARSSL_ERR_RSA_BAD_INPUT_DATA ; goto done;
Signature · 1 line
1.7.9.5
Re: [Openvpn-devel] [PATCH 3/3] external_pkcs1_sign: Support non-RSA_SIG_RAW hash_ids
Am 19.09.13 12:47, schrieb [email protected]...:
Quoted 6 lines
From: Joachim Schipper <[email protected]...>
For TLSv1.2, we need to support various hashes. (GPL) code taken from PolarSSL
pkcs11_sign().
ACK
[Openvpn-devel] [PATCH applied] Re: external_pkcs1_sign: Support non-RSA_SIG_RAW hash_ids
In reply to [email protected]...Your patch has been applied to the master and release/2.3 branches.
commit 32f07c8e5b0f6ec66cfa8566cb8e97b4a6238037 (master) commit d81e29fe89976e4553ce2f491732611416d76fee (release/2.3)
Author: Joachim Schipper Date: Thu Sep 19 12:47:29 2013 +0200
external_pkcs1_sign: Support non-RSA_SIG_RAW hash_ids
Signed-off-by: Joachim Schipper <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/7887
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering