PolarSSL 1.3
PATCH 1/1 PolarSSL 1.3
Hi,
The attached patches add support for PolarSSL 1.3. These patches are for master only, as they drop support for PolarSSL 1.2. Supporting both versions would require a lot of #ifdef's, so I opted for dropping 1.2.
Along with PolarSSL 1.3 comes support for AES-NI and elliptic curve crypto. PolarSSL requires no specific initialization for EC crypto; everything just works out-of-the-box.
Regards,
-Steffan
PATCH 1/2 Upgrade to PolarSSL 1.3
From: Steffan Karger <[email protected]...>
This removes support for PolarSSL 1.2. The mimimum version of PolarSSL required is now 1.3.3. The upgrade brings OpenVPN-with-PolarSSL:
* Support for EC-crypto in TLS (but not yet for external pkcs11/management keys)
* Support for AES-NI (if PolarSSL is compiled with AES-NI support)
--- configure.ac | 4 +- src/openvpn/crypto_polarssl.c | 7 +- src/openvpn/pkcs11_polarssl.c | 13 +-- src/openvpn/ssl_polarssl.c | 182 ++++++++++++++++++-------------------- src/openvpn/ssl_polarssl.h | 7 +- src/openvpn/ssl_verify.c | 6 +- src/openvpn/ssl_verify_backend.h | 4 +- src/openvpn/ssl_verify_openssl.c | 4 +- src/openvpn/ssl_verify_polarssl.c | 109 +++++++---------------- src/openvpn/ssl_verify_polarssl.h | 6 +- 10 files changed, 147 insertions(+), 195 deletions(-)
configure.ac +2 -2
@@ -826,13 +826,13 @@ if test "${with_crypto_library}" = "polarssl" ; then #include <polarssl/version.h> ]], [[ -#if POLARSSL_VERSION_NUMBER < 0x01020A00 || POLARSSL_VERSION_NUMBER >= 0x01030000 +#if POLARSSL_VERSION_NUMBER < 0x01030300 || POLARSSL_VERSION_NUMBER >= 0x01040000 #error invalid version #endif ]] )], [AC_MSG_RESULT([ok])], - [AC_MSG_ERROR([PolarSSL 1.2.x required and must be 1.2.10 or later])] + [AC_MSG_ERROR([PolarSSL 1.3.x required and must be 1.3.3 or later])] ) polarssl_with_pkcs11="no"
src/openvpn/crypto_polarssl.c +6 -1
@@ -466,7 +466,12 @@ int cipher_ctx_mode (const cipher_context_t *ctx)int cipher_ctx_reset (cipher_context_t *ctx,uint8_t *iv_buf) { -return 0 ==cipher_reset (ctx, iv_buf); +int retval =cipher_reset (ctx); + +if (0 == retval) + retval =cipher_set_iv (ctx, iv_buf, ctx->cipher_info->iv_size); + +return 0 == retval; } int cipher_ctx_update (cipher_context_t *ctx, uint8_t *dst, int *dst_len,
src/openvpn/pkcs11_polarssl.c +7 -6
@@ -40,6 +40,7 @@#include "errlevel.h" #include "pkcs11_backend.h" #include <polarssl/pkcs11.h> +#include <polarssl/x509.h> int pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
@@ -78,14 +79,14 @@ pkcs11_certificate_dn (pkcs11h_certificate_t cert, struct gc_arena *gc)char *ret =NULL ;char dn[1024 ] = {0 }; -x509_cert polar_cert = {0 }; +x509_crt polar_cert = {0 };if (pkcs11_x509_cert_init (&polar_cert, cert)) {msg (M_FATAL ,"PKCS#11: Cannot retrieve PolarSSL certificate object" ); goto cleanup; } -if (-1 ==x509parse_dn_gets (dn,sizeof (dn), &polar_cert.subject)) { +if (-1 ==x509_dn_gets (dn,sizeof (dn), &polar_cert.subject)) {msg (M_FATAL ,"PKCS#11: PolarSSL cannot parse subject" ); goto cleanup; }
@@ -93,7 +94,7 @@ pkcs11_certificate_dn (pkcs11h_certificate_t cert, struct gc_arena *gc) ret =string_alloc (dn, gc); cleanup: -x509_free (&polar_cert); +x509_crt_free (&polar_cert);return ret; }
@@ -104,14 +105,14 @@ pkcs11_certificate_serial (pkcs11h_certificate_t cert, char *serial, {int ret =1 ; -x509_cert polar_cert = {0 }; +x509_crt polar_cert = {0 };if (pkcs11_x509_cert_init (&polar_cert, cert)) {msg (M_FATAL ,"PKCS#11: Cannot retrieve PolarSSL certificate object" ); goto cleanup; } -if (-1 ==x509parse_serial_gets (serial, serial_len, &polar_cert.serial)) { +if (-1 ==x509_serial_gets (serial, serial_len, &polar_cert.serial)) {msg (M_FATAL ,"PKCS#11: PolarSSL cannot parse serial" ); goto cleanup; }
@@ -119,7 +120,7 @@ pkcs11_certificate_serial (pkcs11h_certificate_t cert, char *serial, ret =0 ; cleanup: -x509_free (&polar_cert); +x509_crt_free (&polar_cert);return ret; }
src/openvpn/ssl_polarssl.c +84 -98
333 lines not on this page · raw message
src/openvpn/ssl_polarssl.h +4 -3
@@ -33,6 +33,7 @@#include "syshead.h" #include <polarssl/ssl.h> +#include <polarssl/x509_crt.h> #if defined(ENABLE_PKCS11 )#include <polarssl/pkcs11.h>
@@ -64,9 +65,9 @@ struct tls_root_ctx {int endpoint;/**< Whether or not this is a server or a client */ dhm_context *dhm_ctx;/**< Diffie-Helmann-Merkle context */ -x509_cert *crt_chain;/**< Local Certificate chain */ -x509_cert *ca_chain;/**< CA chain for remote verification */ -rsa_context *priv_key;/**< Local private key */ +x509_crt *crt_chain;/**< Local Certificate chain */ +x509_crt *ca_chain;/**< CA chain for remote verification */ +pk_context *priv_key;/**< Local private key */ #if defined(ENABLE_PKCS11 )pkcs11_context *priv_key_pkcs11;/**< PKCS11 private key */ #endif
src/openvpn/ssl_verify.c +3 -3
@@ -435,7 +435,7 @@ verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert }/* export serial number as environmental variable */ - serial =x509_get_serial (peer_cert, &gc); + serial =backend_x509_get_serial (peer_cert, &gc);openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);
@@ -562,7 +562,7 @@ verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert)int fd =-1 ;struct gc_arena gc =gc_new (); -char *serial =x509_get_serial (cert, &gc); +char *serial =backend_x509_get_serial (cert, &gc);if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,OS_SPECIFIC_DIRSEP , serial)) {
@@ -614,7 +614,7 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depstring_replace_leading (subject,'-' ,'_' );/* extract the username (default is CN) */ -if (SUCCESS !=x509_get_username (common_name,TLS_USERNAME_LEN , +if (SUCCESS !=backend_x509_get_username (common_name,TLS_USERNAME_LEN , opt->x509_username_field, cert)) {if (!cert_depth)
src/openvpn/ssl_verify_backend.h +2 -2
@@ -109,7 +109,7 @@ unsigned char *x509_get_sha1_hash (openvpn_x509_cert_t *cert, struct gc_arena *g* * @return \c FAILURE, \c or SUCCESS */ -result_t x509_get_username (char *common_name,int cn_len, +result_t backend_x509_get_username (char *common_name,int cn_len,char * x509_username_field,openvpn_x509_cert_t *peer_cert);/*
@@ -122,7 +122,7 @@ result_t x509_get_username (char *common_name, int cn_len,* * @return The certificate's serial number. */ -char *x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc); +char *backend_x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc);/* * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_openssl.c +2 -2
@@ -202,7 +202,7 @@ extract_x509_field_ssl (X509_NAME *x509, const char *field_name, char *out, }result_t -x509_get_username (char *common_name,int cn_len, +backend_x509_get_username (char *common_name,int cn_len,char * x509_username_field,X509 *peer_cert) {#ifdef ENABLE_X509ALTUSERNAME
@@ -220,7 +220,7 @@ x509_get_username (char *common_name, int cn_len, }char * -x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc) +backend_x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc) {ASN1_INTEGER *asn1_i;BIGNUM *bignum;
src/openvpn/ssl_verify_polarssl.c +34 -75
213 lines not on this page · raw message
src/openvpn/ssl_verify_polarssl.h +3 -3
@@ -33,11 +33,11 @@#include "syshead.h" #include "misc.h" #include "manage.h" -#include <polarssl/x509.h> +#include <polarssl/x509_crt.h> #ifndef __OPENVPN_X509_CERT_T_DECLARED#define __OPENVPN_X509_CERT_T_DECLARED -typedef x509_cert openvpn_x509_cert_t ; +typedef x509_crt openvpn_x509_cert_t ;#endif /** @name Function for authenticating a new connection from a remote OpenVPN peer
@@ -72,7 +72,7 @@ typedef x509_cert openvpn_x509_cert_t;* * @return The return value is 0 unless a fatal error occurred. */ -int verify_callback (void *session_obj,x509_cert *cert,int cert_depth, +int verify_callback (void *session_obj,x509_crt *cert,int cert_depth,int *flags);/** @} name Function for authenticating a new connection from a remote OpenVPN peer */
Signature · 1 line
1.8.3.2
PATCH 2/2 Improve error reporting during key/cert loading with PolarSSL.
In reply to [email protected]...From: Steffan Karger <[email protected]...>
--- src/openvpn/ssl_polarssl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
src/openvpn/ssl_polarssl.c +14 -4
@@ -261,8 +261,13 @@ tls_ctx_load_cert_file (struct tls_root_ctx *ctx, const char *cert_file, }else { -if (0 !=x509_crt_parse_file (ctx->crt_chain, cert_file)) -msg (M_FATAL ,"Cannot load certificate file %s" , cert_file); +int retval =x509_crt_parse_file (ctx->crt_chain, cert_file); +if (0 != retval) + { +char errstr[128 ]; +polarssl_strerror (retval, errstr,sizeof (errstr)); +msg (M_FATAL ,"Cannot load certificate file %s (%s)" , cert_file, errstr); + } } }
@@ -475,8 +480,13 @@ void tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,else {/* Load CA file for verifying peer supplied certificate */ -if (0 !=x509_crt_parse_file (ctx->ca_chain, ca_file)) -msg (M_FATAL ,"Cannot load CA certificate file %s" , ca_file); +int retval =x509_crt_parse_file (ctx->ca_chain, ca_file); +if (0 != retval) + { +char errstr[128 ]; +polarssl_strerror (retval, errstr,sizeof (errstr)); +msg (M_FATAL ,"Cannot load CA certificate file %s (%s)" , ca_file, errstr); + } } }
Signature · 1 line
1.8.3.2
Quoted 9 lines · On 27/02/2014 12:40, [email protected]... wrote:
Hi,
The attached patches add support for PolarSSL 1.3. These patches are for master only, as they drop support for PolarSSL 1.2. Supporting both versions would require a lot of #ifdef's, so I opted for dropping 1.2.
Along with PolarSSL 1.3 comes support for AES-NI and elliptic curve crypto. PolarSSL requires no specific initialization for EC crypto; everything just works out-of-the-box.
Just tested this on server side -- works great so far.
But I scanned the patch and noticed this:
sig_len = ctx->signature_length;
if ( (SIZE_MAX - hashlen) > asn_len || (hashlen + asn_len) > sig_len )
return POLARSSL_ERR_RSA_BAD_INPUT_DATA;I'm not sure I understand the (SIZE_MAX - hashlen) > asn_len part. Wouldn't this always be true for reasonable values of hashlen and asn_len?
And the *p++ lines below, I assume that the buffer's size is ctx->signature_length? Maybe add some comments about buffer-sizing assumptions?
James
Hi James,
Quoted 11 lines · James Yonan
Quoted 7 lines · On 27/02/2014 12:40, [email protected]... wrote:
The attached patches add support for PolarSSL 1.3. These patches are for master only, as they drop support for PolarSSL 1.2. Supporting both versions would require a lot of #ifdef's, so I opted for dropping 1.2.
Along with PolarSSL 1.3 comes support for AES-NI and elliptic curve crypto. PolarSSL requires no specific initialization for EC crypto; everything just works out-of-the-box.
Just tested this on server side -- works great so far.
Quoted 8 lines
But I scanned the patch and noticed this:
sig_len = ctx->signature_length; if ( (SIZE_MAX - hashlen) > asn_len || (hashlen + asn_len) > sig_len ) return POLARSSL_ERR_RSA_BAD_INPUT_DATA;I'm not sure I understand the (
SIZE_MAX- hashlen) >asn_lenpart. Wouldn't this always be true for reasonable values of hashlen andasn_len?
This should indeed always be true for reasonable input. However, it is guarding against size_t overflow attacks. In case of a raw signature we use 'hashlen' supplied by the user. This check prevents an attacker from causing a buffer overflow using integer overflow of hashlen + asnlen (if that is larger than SIZE_MAX, the second check would possibly not catch the overflow). I don't think this can actually happen in the current codebase, but the check is cheap and 'better be safe then sorry'.
Quoted 3 lines
And the *p++ lines below, I assume that the buffer's size is
ctx->signature_length? Maybe add some comments about buffer-sizing assumptions?
Correct. I agree that this was a bit too much "left as an exercise to the reader", so I added some doxygen for this function.
Attached are the updated patches, also rebased on the current master. If you're comfortable with the code, could you perhaps give it an ACK / NACK?
Regards,
-Steffan
From 10bd3bcbfbb8927ed975a573f073490919a8d4cd Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Tue, 4 Feb 2014 13:57:15 +0100
Subject: [PATCH 1/2] Upgrade to PolarSSL 1.3
This removes support for PolarSSL 1.2. The mimimum version of PolarSSL required is now 1.3.3. The upgrade brings OpenVPN-with-PolarSSL:
* Support for EC-crypto in TLS (but not yet for external pkcs11/management keys)
* Support for AES-NI (if PolarSSL is compiled with AES-NI support)
--- configure.ac | 4 +- src/openvpn/crypto_polarssl.c | 7 +- src/openvpn/pkcs11_polarssl.c | 13 +-- src/openvpn/ssl_polarssl.c | 202 ++++++++++++++++++++------------------ src/openvpn/ssl_polarssl.h | 7 +- src/openvpn/ssl_verify.c | 6 +- src/openvpn/ssl_verify_backend.h | 4 +- src/openvpn/ssl_verify_openssl.c | 4 +- src/openvpn/ssl_verify_polarssl.c | 109 +++++++------------- src/openvpn/ssl_verify_polarssl.h | 6 +- 10 files changed, 167 insertions(+), 195 deletions(-)
configure.ac +2 -2
@@ -844,13 +844,13 @@ if test "${with_crypto_library}" = "polarssl" ; then #include <polarssl/version.h> ]], [[ -#if POLARSSL_VERSION_NUMBER < 0x01020A00 || POLARSSL_VERSION_NUMBER >= 0x01030000 +#if POLARSSL_VERSION_NUMBER < 0x01030300 || POLARSSL_VERSION_NUMBER >= 0x01040000 #error invalid version #endif ]] )], [AC_MSG_RESULT([ok])], - [AC_MSG_ERROR([PolarSSL 1.2.x required and must be 1.2.10 or later])] + [AC_MSG_ERROR([PolarSSL 1.3.x required and must be 1.3.3 or later])] ) polarssl_with_pkcs11="no"
src/openvpn/crypto_polarssl.c +6 -1
@@ -466,7 +466,12 @@ int cipher_ctx_mode (const cipher_context_t *ctx)int cipher_ctx_reset (cipher_context_t *ctx,uint8_t *iv_buf) { -return 0 ==cipher_reset (ctx, iv_buf); +int retval =cipher_reset (ctx); + +if (0 == retval) + retval =cipher_set_iv (ctx, iv_buf, ctx->cipher_info->iv_size); + +return 0 == retval; } int cipher_ctx_update (cipher_context_t *ctx, uint8_t *dst, int *dst_len,
src/openvpn/pkcs11_polarssl.c +7 -6
@@ -40,6 +40,7 @@#include "errlevel.h" #include "pkcs11_backend.h" #include <polarssl/pkcs11.h> +#include <polarssl/x509.h> int pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
@@ -78,14 +79,14 @@ pkcs11_certificate_dn (pkcs11h_certificate_t cert, struct gc_arena *gc)char *ret =NULL ;char dn[1024 ] = {0 }; -x509_cert polar_cert = {0 }; +x509_crt polar_cert = {0 };if (pkcs11_x509_cert_init (&polar_cert, cert)) {msg (M_FATAL ,"PKCS#11: Cannot retrieve PolarSSL certificate object" ); goto cleanup; } -if (-1 ==x509parse_dn_gets (dn,sizeof (dn), &polar_cert.subject)) { +if (-1 ==x509_dn_gets (dn,sizeof (dn), &polar_cert.subject)) {msg (M_FATAL ,"PKCS#11: PolarSSL cannot parse subject" ); goto cleanup; }
@@ -93,7 +94,7 @@ pkcs11_certificate_dn (pkcs11h_certificate_t cert, struct gc_arena *gc) ret =string_alloc (dn, gc); cleanup: -x509_free (&polar_cert); +x509_crt_free (&polar_cert);return ret; }
@@ -104,14 +105,14 @@ pkcs11_certificate_serial (pkcs11h_certificate_t cert, char *serial, {int ret =1 ; -x509_cert polar_cert = {0 }; +x509_crt polar_cert = {0 };if (pkcs11_x509_cert_init (&polar_cert, cert)) {msg (M_FATAL ,"PKCS#11: Cannot retrieve PolarSSL certificate object" ); goto cleanup; } -if (-1 ==x509parse_serial_gets (serial, serial_len, &polar_cert.serial)) { +if (-1 ==x509_serial_gets (serial, serial_len, &polar_cert.serial)) {msg (M_FATAL ,"PKCS#11: PolarSSL cannot parse serial" ); goto cleanup; }
@@ -119,7 +120,7 @@ pkcs11_certificate_serial (pkcs11h_certificate_t cert, char *serial, ret =0 ; cleanup: -x509_free (&polar_cert); +x509_crt_free (&polar_cert);return ret; }
src/openvpn/ssl_polarssl.c +104 -98
355 lines not on this page · raw message
src/openvpn/ssl_polarssl.h +4 -3
@@ -33,6 +33,7 @@#include "syshead.h" #include <polarssl/ssl.h> +#include <polarssl/x509_crt.h> #if defined(ENABLE_PKCS11 )#include <polarssl/pkcs11.h>
@@ -64,9 +65,9 @@ struct tls_root_ctx {int endpoint;/**< Whether or not this is a server or a client */ dhm_context *dhm_ctx;/**< Diffie-Helmann-Merkle context */ -x509_cert *crt_chain;/**< Local Certificate chain */ -x509_cert *ca_chain;/**< CA chain for remote verification */ -rsa_context *priv_key;/**< Local private key */ +x509_crt *crt_chain;/**< Local Certificate chain */ +x509_crt *ca_chain;/**< CA chain for remote verification */ +pk_context *priv_key;/**< Local private key */ #if defined(ENABLE_PKCS11 )pkcs11_context *priv_key_pkcs11;/**< PKCS11 private key */ #endif
src/openvpn/ssl_verify.c +3 -3
@@ -431,7 +431,7 @@ verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert }/* export serial number as environmental variable */ - serial =x509_get_serial (peer_cert, &gc); + serial =backend_x509_get_serial (peer_cert, &gc);openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);
@@ -558,7 +558,7 @@ verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert)int fd =-1 ;struct gc_arena gc =gc_new (); -char *serial =x509_get_serial (cert, &gc); +char *serial =backend_x509_get_serial (cert, &gc);if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,OS_SPECIFIC_DIRSEP , serial)) {
@@ -610,7 +610,7 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depstring_replace_leading (subject,'-' ,'_' );/* extract the username (default is CN) */ -if (SUCCESS !=x509_get_username (common_name,TLS_USERNAME_LEN , +if (SUCCESS !=backend_x509_get_username (common_name,TLS_USERNAME_LEN , opt->x509_username_field, cert)) {if (!cert_depth)
src/openvpn/ssl_verify_backend.h +2 -2
@@ -109,7 +109,7 @@ unsigned char *x509_get_sha1_hash (openvpn_x509_cert_t *cert, struct gc_arena *g* * @return \c FAILURE, \c or SUCCESS */ -result_t x509_get_username (char *common_name,int cn_len, +result_t backend_x509_get_username (char *common_name,int cn_len,char * x509_username_field,openvpn_x509_cert_t *peer_cert);/*
@@ -122,7 +122,7 @@ result_t x509_get_username (char *common_name, int cn_len,* * @return The certificate's serial number. */ -char *x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc); +char *backend_x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc);/* * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_openssl.c +2 -2
@@ -202,7 +202,7 @@ extract_x509_field_ssl (X509_NAME *x509, const char *field_name, char *out, }result_t -x509_get_username (char *common_name,int cn_len, +backend_x509_get_username (char *common_name,int cn_len,char * x509_username_field,X509 *peer_cert) {#ifdef ENABLE_X509ALTUSERNAME
@@ -220,7 +220,7 @@ x509_get_username (char *common_name, int cn_len, }char * -x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc) +backend_x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc) {ASN1_INTEGER *asn1_i;BIGNUM *bignum;
src/openvpn/ssl_verify_polarssl.c +34 -75
213 lines not on this page · raw message
src/openvpn/ssl_verify_polarssl.h +3 -3
@@ -33,11 +33,11 @@#include "syshead.h" #include "misc.h" #include "manage.h" -#include <polarssl/x509.h> +#include <polarssl/x509_crt.h> #ifndef __OPENVPN_X509_CERT_T_DECLARED#define __OPENVPN_X509_CERT_T_DECLARED -typedef x509_cert openvpn_x509_cert_t ; +typedef x509_crt openvpn_x509_cert_t ;#endif /** @name Function for authenticating a new connection from a remote OpenVPN peer
@@ -72,7 +72,7 @@ typedef x509_cert openvpn_x509_cert_t;* * @return The return value is 0 unless a fatal error occurred. */ -int verify_callback (void *session_obj,x509_cert *cert,int cert_depth, +int verify_callback (void *session_obj,x509_crt *cert,int cert_depth,int *flags);/** @} name Function for authenticating a new connection from a remote OpenVPN peer */
Signature · 1 line
1.8.3.2
From 773200816a73c0f356418fbe98d380be6559b477 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Tue, 4 Feb 2014 13:58:05 +0100
Subject: [PATCH 2/2] Improve error reporting during key/cert loading with
PolarSSL.
--- src/openvpn/ssl_polarssl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
src/openvpn/ssl_polarssl.c +14 -4
@@ -261,8 +261,13 @@ tls_ctx_load_cert_file (struct tls_root_ctx *ctx, const char *cert_file, }else { -if (0 !=x509_crt_parse_file (ctx->crt_chain, cert_file)) -msg (M_FATAL ,"Cannot load certificate file %s" , cert_file); +int retval =x509_crt_parse_file (ctx->crt_chain, cert_file); +if (0 != retval) + { +char errstr[128 ]; +polarssl_strerror (retval, errstr,sizeof (errstr)); +msg (M_FATAL ,"Cannot load certificate file %s (%s)" , cert_file, errstr); + } } }
@@ -495,8 +500,13 @@ void tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,else {/* Load CA file for verifying peer supplied certificate */ -if (0 !=x509_crt_parse_file (ctx->ca_chain, ca_file)) -msg (M_FATAL ,"Cannot load CA certificate file %s" , ca_file); +int retval =x509_crt_parse_file (ctx->ca_chain, ca_file); +if (0 != retval) + { +char errstr[128 ]; +polarssl_strerror (retval, errstr,sizeof (errstr)); +msg (M_FATAL ,"Cannot load CA certificate file %s (%s)" , ca_file, errstr); + } } }
Signature · 1 line
1.8.3.2
Hi,
Quoted 5 lines · Steffan Karger
Quoted 2 lines · James Yonan
I'm not sure I understand the (
SIZE_MAX- hashlen) >asn_lenpart. Wouldn't this always be true for reasonable values of hashlen andasn_len?This should indeed always be true for reasonable input.
Ouch, James was totally right. This would always be true, but should always be *false* for reasonable input; the check has to be the other way around. Attached the same two patches, except for that single character...
On the positive side: I've added my management-external-key test to my vanilla-openvpn tests too, so I should catch regressions more easily now.
-Steffan
From 4fa6fbfd1e1d2937b7aae689bccb24e59279416b Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Tue, 4 Feb 2014 13:57:15 +0100
Subject: [PATCH 1/2] Upgrade to PolarSSL 1.3
This removes support for PolarSSL 1.2. The mimimum version of PolarSSL required is now 1.3.3. The upgrade brings OpenVPN-with-PolarSSL:
* Support for EC-crypto in TLS (but not yet for external pkcs11/management keys)
* Support for AES-NI (if PolarSSL is compiled with AES-NI support)
--- configure.ac | 4 +- src/openvpn/crypto_polarssl.c | 7 +- src/openvpn/pkcs11_polarssl.c | 13 +-- src/openvpn/ssl_polarssl.c | 202 ++++++++++++++++++++------------------ src/openvpn/ssl_polarssl.h | 7 +- src/openvpn/ssl_verify.c | 6 +- src/openvpn/ssl_verify_backend.h | 4 +- src/openvpn/ssl_verify_openssl.c | 4 +- src/openvpn/ssl_verify_polarssl.c | 109 +++++++------------- src/openvpn/ssl_verify_polarssl.h | 6 +- 10 files changed, 167 insertions(+), 195 deletions(-)
configure.ac +2 -2
@@ -844,13 +844,13 @@ if test "${with_crypto_library}" = "polarssl" ; then #include <polarssl/version.h> ]], [[ -#if POLARSSL_VERSION_NUMBER < 0x01020A00 || POLARSSL_VERSION_NUMBER >= 0x01030000 +#if POLARSSL_VERSION_NUMBER < 0x01030300 || POLARSSL_VERSION_NUMBER >= 0x01040000 #error invalid version #endif ]] )], [AC_MSG_RESULT([ok])], - [AC_MSG_ERROR([PolarSSL 1.2.x required and must be 1.2.10 or later])] + [AC_MSG_ERROR([PolarSSL 1.3.x required and must be 1.3.3 or later])] ) polarssl_with_pkcs11="no"
src/openvpn/crypto_polarssl.c +6 -1
@@ -466,7 +466,12 @@ int cipher_ctx_mode (const cipher_context_t *ctx)int cipher_ctx_reset (cipher_context_t *ctx,uint8_t *iv_buf) { -return 0 ==cipher_reset (ctx, iv_buf); +int retval =cipher_reset (ctx); + +if (0 == retval) + retval =cipher_set_iv (ctx, iv_buf, ctx->cipher_info->iv_size); + +return 0 == retval; } int cipher_ctx_update (cipher_context_t *ctx, uint8_t *dst, int *dst_len,
src/openvpn/pkcs11_polarssl.c +7 -6
@@ -40,6 +40,7 @@#include "errlevel.h" #include "pkcs11_backend.h" #include <polarssl/pkcs11.h> +#include <polarssl/x509.h> int pkcs11_init_tls_session(pkcs11h_certificate_t certificate,
@@ -78,14 +79,14 @@ pkcs11_certificate_dn (pkcs11h_certificate_t cert, struct gc_arena *gc)char *ret =NULL ;char dn[1024 ] = {0 }; -x509_cert polar_cert = {0 }; +x509_crt polar_cert = {0 };if (pkcs11_x509_cert_init (&polar_cert, cert)) {msg (M_FATAL ,"PKCS#11: Cannot retrieve PolarSSL certificate object" ); goto cleanup; } -if (-1 ==x509parse_dn_gets (dn,sizeof (dn), &polar_cert.subject)) { +if (-1 ==x509_dn_gets (dn,sizeof (dn), &polar_cert.subject)) {msg (M_FATAL ,"PKCS#11: PolarSSL cannot parse subject" ); goto cleanup; }
@@ -93,7 +94,7 @@ pkcs11_certificate_dn (pkcs11h_certificate_t cert, struct gc_arena *gc) ret =string_alloc (dn, gc); cleanup: -x509_free (&polar_cert); +x509_crt_free (&polar_cert);return ret; }
@@ -104,14 +105,14 @@ pkcs11_certificate_serial (pkcs11h_certificate_t cert, char *serial, {int ret =1 ; -x509_cert polar_cert = {0 }; +x509_crt polar_cert = {0 };if (pkcs11_x509_cert_init (&polar_cert, cert)) {msg (M_FATAL ,"PKCS#11: Cannot retrieve PolarSSL certificate object" ); goto cleanup; } -if (-1 ==x509parse_serial_gets (serial, serial_len, &polar_cert.serial)) { +if (-1 ==x509_serial_gets (serial, serial_len, &polar_cert.serial)) {msg (M_FATAL ,"PKCS#11: PolarSSL cannot parse serial" ); goto cleanup; }
@@ -119,7 +120,7 @@ pkcs11_certificate_serial (pkcs11h_certificate_t cert, char *serial, ret =0 ; cleanup: -x509_free (&polar_cert); +x509_crt_free (&polar_cert);return ret; }
src/openvpn/ssl_polarssl.c +104 -98
355 lines not on this page · raw message
src/openvpn/ssl_polarssl.h +4 -3
@@ -33,6 +33,7 @@#include "syshead.h" #include <polarssl/ssl.h> +#include <polarssl/x509_crt.h> #if defined(ENABLE_PKCS11 )#include <polarssl/pkcs11.h>
@@ -64,9 +65,9 @@ struct tls_root_ctx {int endpoint;/**< Whether or not this is a server or a client */ dhm_context *dhm_ctx;/**< Diffie-Helmann-Merkle context */ -x509_cert *crt_chain;/**< Local Certificate chain */ -x509_cert *ca_chain;/**< CA chain for remote verification */ -rsa_context *priv_key;/**< Local private key */ +x509_crt *crt_chain;/**< Local Certificate chain */ +x509_crt *ca_chain;/**< CA chain for remote verification */ +pk_context *priv_key;/**< Local private key */ #if defined(ENABLE_PKCS11 )pkcs11_context *priv_key_pkcs11;/**< PKCS11 private key */ #endif
src/openvpn/ssl_verify.c +3 -3
@@ -431,7 +431,7 @@ verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, int cert }/* export serial number as environmental variable */ - serial =x509_get_serial (peer_cert, &gc); + serial =backend_x509_get_serial (peer_cert, &gc);openvpn_snprintf (envname,sizeof (envname),"tls_serial_%d" , cert_depth);setenv_str (es, envname, serial);
@@ -558,7 +558,7 @@ verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert)int fd =-1 ;struct gc_arena gc =gc_new (); -char *serial =x509_get_serial (cert, &gc); +char *serial =backend_x509_get_serial (cert, &gc);if (!openvpn_snprintf (fn,sizeof (fn),"%s%c%s" , crl_dir,OS_SPECIFIC_DIRSEP , serial)) {
@@ -610,7 +610,7 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depstring_replace_leading (subject,'-' ,'_' );/* extract the username (default is CN) */ -if (SUCCESS !=x509_get_username (common_name,TLS_USERNAME_LEN , +if (SUCCESS !=backend_x509_get_username (common_name,TLS_USERNAME_LEN , opt->x509_username_field, cert)) {if (!cert_depth)
src/openvpn/ssl_verify_backend.h +2 -2
@@ -109,7 +109,7 @@ unsigned char *x509_get_sha1_hash (openvpn_x509_cert_t *cert, struct gc_arena *g* * @return \c FAILURE, \c or SUCCESS */ -result_t x509_get_username (char *common_name,int cn_len, +result_t backend_x509_get_username (char *common_name,int cn_len,char * x509_username_field,openvpn_x509_cert_t *peer_cert);/*
@@ -122,7 +122,7 @@ result_t x509_get_username (char *common_name, int cn_len,* * @return The certificate's serial number. */ -char *x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc); +char *backend_x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc);/* * Save X509 fields to environment, using the naming convention:
src/openvpn/ssl_verify_openssl.c +2 -2
@@ -202,7 +202,7 @@ extract_x509_field_ssl (X509_NAME *x509, const char *field_name, char *out, }result_t -x509_get_username (char *common_name,int cn_len, +backend_x509_get_username (char *common_name,int cn_len,char * x509_username_field,X509 *peer_cert) {#ifdef ENABLE_X509ALTUSERNAME
@@ -220,7 +220,7 @@ x509_get_username (char *common_name, int cn_len, }char * -x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc) +backend_x509_get_serial (openvpn_x509_cert_t *cert,struct gc_arena *gc) {ASN1_INTEGER *asn1_i;BIGNUM *bignum;
src/openvpn/ssl_verify_polarssl.c +34 -75
213 lines not on this page · raw message
src/openvpn/ssl_verify_polarssl.h +3 -3
@@ -33,11 +33,11 @@#include "syshead.h" #include "misc.h" #include "manage.h" -#include <polarssl/x509.h> +#include <polarssl/x509_crt.h> #ifndef __OPENVPN_X509_CERT_T_DECLARED#define __OPENVPN_X509_CERT_T_DECLARED -typedef x509_cert openvpn_x509_cert_t ; +typedef x509_crt openvpn_x509_cert_t ;#endif /** @name Function for authenticating a new connection from a remote OpenVPN peer
@@ -72,7 +72,7 @@ typedef x509_cert openvpn_x509_cert_t;* * @return The return value is 0 unless a fatal error occurred. */ -int verify_callback (void *session_obj,x509_cert *cert,int cert_depth, +int verify_callback (void *session_obj,x509_crt *cert,int cert_depth,int *flags);/** @} name Function for authenticating a new connection from a remote OpenVPN peer */
Signature · 1 line
1.8.3.2
From 6a09fd63d84e867e9dae7b9af9133c9b07e9e0f6 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Tue, 4 Feb 2014 13:58:05 +0100
Subject: [PATCH 2/2] Improve error reporting during key/cert loading with
PolarSSL.
--- src/openvpn/ssl_polarssl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
src/openvpn/ssl_polarssl.c +14 -4
@@ -261,8 +261,13 @@ tls_ctx_load_cert_file (struct tls_root_ctx *ctx, const char *cert_file, }else { -if (0 !=x509_crt_parse_file (ctx->crt_chain, cert_file)) -msg (M_FATAL ,"Cannot load certificate file %s" , cert_file); +int retval =x509_crt_parse_file (ctx->crt_chain, cert_file); +if (0 != retval) + { +char errstr[128 ]; +polarssl_strerror (retval, errstr,sizeof (errstr)); +msg (M_FATAL ,"Cannot load certificate file %s (%s)" , cert_file, errstr); + } } }
@@ -495,8 +500,13 @@ void tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,else {/* Load CA file for verifying peer supplied certificate */ -if (0 !=x509_crt_parse_file (ctx->ca_chain, ca_file)) -msg (M_FATAL ,"Cannot load CA certificate file %s" , ca_file); +int retval =x509_crt_parse_file (ctx->ca_chain, ca_file); +if (0 != retval) + { +char errstr[128 ]; +polarssl_strerror (retval, errstr,sizeof (errstr)); +msg (M_FATAL ,"Cannot load CA certificate file %s (%s)" , ca_file, errstr); + } } }
Signature · 1 line
1.8.3.2
Quoted 9 lines · Steffan Karger
Hi,
Quoted 5 lines · Steffan Karger
Quoted 2 lines · James Yonan
I'm not sure I understand the (
SIZE_MAX- hashlen) >asn_lenpart. Wouldn't this always be true for reasonable values of hashlen andasn_len?This should indeed always be true for reasonable input.
Quoted 7 lines
Ouch, James was totally right. This would always be true, but should always be *false* for reasonable input; the check has to be the other way around. Attached the same two patches, except for that single character...
On the positive side: I've added my management-external-key test to my vanilla-openvpn tests too, so I should catch regressions more easily now.
ACK for the revised patches (0001-Upgrade-to-PolarSSL-1.3.patch and 0002-Improve-error-reporting-during-key-cert-loading-with.patch).
James
Hi,
Quoted 4 lines · Steffan Karger
Ouch, James was totally right. This would always be true, but should always be *false* for reasonable input; the check has to be the other way around. Attached the same two patches, except for that single character...
Merged both, will push soon.
When test-building, it seems that there is a patch missing to the plugin API bits...
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../../../openvpn/src/plugins/auth-pam -I../../.. -I../../../../openvpn/include -g -O2 -MT auth-pam.lo -MD -MP -MF .deps/auth-pam.Tpo -c ../../../../openvpn/src/plugins/auth-pam/auth-pam.c -fPIC -DPIC -o .libs/auth-pam.o In file included from ../../../../openvpn/src/plugins/auth-pam/auth-pam.c:51:0:../../../../openvpn/include/openvpn-plugin.h:35:1: error: unknown type name 'x509_cert'
make[4]: *** [auth-pam.lo] Fehler 1
(basic "./configure --with-crypto-library=polarssl && make" on Linux)
Could you...?
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]...Hi,
Quoted 2 lines · Gert Doering
When test-building, it seems that there is a patch missing to the plugin API bits...
Ah, right, I usually compile polar builds without the plugin api. Attached a patch that should fix this. It compiles and passes client_t tests, but I don't have plugin tests to really verify everything works...
-Steffan
From 491fd5e253a62940caafd973377019be1e3164f3 Mon Sep 17 00:00:00 2001
From: Steffan Karger <[email protected]...>
Date: Mon, 21 Apr 2014 11:52:51 +0200
Subject: [PATCH] Update openvpn-plugin.h for PolarSSL 1.3.
--- include/openvpn-plugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/openvpn-plugin.h +2 -2
@@ -29,10 +29,10 @@#ifdef ENABLE_SSL #ifdef ENABLE_CRYPTO_POLARSSL -#include <polarssl/x509.h> +#include <polarssl/x509_crt.h> #ifndef __OPENVPN_X509_CERT_T_DECLARED#define __OPENVPN_X509_CERT_T_DECLARED -typedef x509_cert openvpn_x509_cert_t ; +typedef x509_crt openvpn_x509_cert_t ;#endif #else #include <openssl/x509.h>
Signature · 1 line
1.8.3.2
[Openvpn-devel] [PATCH applied] Re: Update openvpn-plugin.h for PolarSSL 1.3.
ACK (as in "fixes the build for me". None of the default plugins will actually *use* this, and any plugin using x509 stuff would have to be adapted to the 1.3 API - yes, this is the way it is)
Your patch has been applied to the master branch.
commit cc1cee74c683ce92e56bb6a6170988fb6520b803
Author: Steffan Karger Date: Mon Apr 21 11:52:51 2014 +0200
Update openvpn-plugin.h for PolarSSL 1.3.
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8567
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Upgrade to PolarSSL 1.3
In reply to Steffan KargerYour patch has been applied to the master branch.
commit 03df3a990f71b3d02653eba364ac89f8400611c3
Author: Steffan Karger Date: Tue Feb 4 13:57:15 2014 +0100
Upgrade to PolarSSL 1.3
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: James Yonan <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8555
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Improve error reporting during key/cert loading with PolarSSL.
In reply to Steffan KargerYour patch has been applied to the master branch.
commit 5e0112d9c60c488d3951491052d1aec8ef793023
Author: Steffan Karger Date: Tue Feb 4 13:58:05 2014 +0100
Improve error reporting during key/cert loading with PolarSSL.
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: James Yonan <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8555
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering