Allow setting up OpenVPN in TLS mode without CA
cover Allow setting up OpenVPN in TLS mode without CA
Setting up a CA even with the help of easy-tls and similar tools is difficult/tiresome. For small setups self-signed certificates are sufficient enough and restarting the server to add another client is generally not a big problem (when you need that capability a CA is better suited).
This patch set allows setting up OpenVPN with verification of peer certificates and without a CA certificate. Instead of verifying certificates through a CA, it allows to verify a certificate just by it fingerprint. This is usually called certificate pinning. (If you wonder if this secure, it is as secure as normal CA operation as certificate signature also only sign the finerprinter of a certificate and not the whole cert.)
The commit themselves have examples.
The main difference of this patch set to Jason's V1 version is that it does not rely on an external script on the server side and instead relys on an a inlined <peer-fingerprint> section. The downside is that this requires a server restart on adding a client but the upside is that no script-security or external scripts are necessary and server/client setup become symmetric.
Arne Schwabe (3):
Extend verify-hash to allow multiple hashes
Implement peer-fingerprint to check fingerprint of peer certificate Document the simple self-signed certificate setup in examples
Jason A. Donenfeld (1):
Support fingerprint authentication without CA certificate
Changes.rst | 12 +++ doc/man-sections/examples.rst | 46 ++++++---- doc/man-sections/inline-files.rst | 4 +- doc/man-sections/tls-options.rst | 36 +++++++- src/openvpn/init.c | 3 + src/openvpn/options.c | 145 +++++++++++++++++++++++++----- src/openvpn/options.h | 13 ++- src/openvpn/ssl.c | 2 +- src/openvpn/ssl_common.h | 4 +- src/openvpn/ssl_verify.c | 30 +++++-- src/openvpn/ssl_verify_mbedtls.c | 17 ++++ src/openvpn/ssl_verify_openssl.c | 2 +- 12 files changed, 263 insertions(+), 51 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/4 Extend verify-hash to allow multiple hashes
For a new syntax introduced now it does not make much sense to support deprecated and old hashes, so support only SHA-256.
Also give a warning about SHA1 hash being deprecated to verify certificates as it is now "industry standard".
--- doc/man-sections/inline-files.rst | 4 +- doc/man-sections/tls-options.rst | 10 ++++ src/openvpn/options.c | 91 +++++++++++++++++++++++++++---- src/openvpn/options.h | 11 +++- src/openvpn/ssl_common.h | 2 +- src/openvpn/ssl_verify.c | 17 +++++- 6 files changed, 119 insertions(+), 16 deletions(-)
doc/man-sections/inline-files.rst +2 -2
@@ -4,8 +4,8 @@ INLINE FILE SUPPORT OpenVPN allows including files in the main configuration for the ``--ca``, ``--cert``, ``--dh``, ``--extra-certs``, ``--key``, ``--pkcs12``, ``--secret``, ``--crl-verify``, ``--http-proxy-user-pass``, ``--tls-auth``, -``--auth-gen-token-secret``, ``--tls-crypt`` and ``--tls-crypt-v2`` -options. +``--auth-gen-token-secret``, ``--tls-crypt``, ``--tls-crypt-v2`` and +``--verify-hash`` options. Each inline file started by the line ``<option>`` and ended by the line ``</option>``
doc/man-sections/tls-options.rst +10 -0
@@ -579,6 +579,16 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa The ``algo`` flag can be either :code:`SHA1` or :code:`SHA256`. If not provided, it defaults to :code:`SHA1`. + This option can also be inlined + :: + + <verify-hash> + 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff + 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 + </verify-hash> + +If the option is inlined, ``algo`` is always :code:`SHA256`. + --verify-x509-name args Accept connections only if a host's X.509 name is equal to **name.** The remote host must also pass all other tests of verification.
src/openvpn/options.c +81 -10
132 lines not on this page · raw message
src/openvpn/options.h +10 -1
@@ -191,6 +191,15 @@ enum genkey_type {GENKEY_AUTH_TOKEN }; +struct verify_hash_list +{ +/* Currently we only support SHA256 for longer lists, for a one item +* list with SHA1 we ignore the 12 byte memory wasted */ +uint8_t hash[32 ]; +struct verify_hash_list *next; + +}; +/* Command line options */ struct options {
@@ -553,7 +562,7 @@ struct optionsint ns_cert_type;/* set to 0, NS_CERT_CHECK_SERVER, or NS_CERT_CHECK_CLIENT */ unsigned remote_cert_ku[MAX_PARMS ];const char *remote_cert_eku; -uint8_t *verify_hash; +struct verify_hash_list *verify_hash;hash_algo_type verify_hash_algo;unsigned int ssl_flags;/* set to SSLF_x flags from ssl.h */
src/openvpn/ssl_common.h +1 -1
@@ -282,7 +282,7 @@ struct tls_optionsint ns_cert_type;unsigned remote_cert_ku[MAX_PARMS ];const char *remote_cert_eku; -uint8_t *verify_hash; +struct verify_hash_list *verify_hash;hash_algo_type verify_hash_algo;char *x509_username_field;
src/openvpn/ssl_verify.c +15 -2
@@ -720,9 +720,22 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep goto cleanup; } -if (memcmp (BPTR (&ca_hash), opt->verify_hash,BLEN (&ca_hash))) +struct verify_hash_list *current_hash = opt->verify_hash; +bool hash_matched = false; + +while (current_hash) + { +if (memcmp_constant_time (BPTR (&ca_hash), current_hash->hash, +BLEN (&ca_hash)) ==0 ) + { + hash_matched = true; + } + current_hash = current_hash->next; + } + +if (!hash_matched) { -msg (D_TLS_ERRORS ,"TLS Error: level-1 certificate hash verification failed" ); +msg (D_TLS_ERRORS ,"TLS Error: --tls-verify certificate hash verification failed" ); goto cleanup; } }
Signature · 1 line
2.26.2
PATCH 2/4 Implement peer-fingerprint to check fingerprint of peer certificate
In reply to Arne SchwabeThis options allows to pin a certificate or a number of certificate. It also prepares for doing TLS authentication without a CA and just self-signed certificates.
--- Changes.rst | 7 ++++++ doc/man-sections/inline-files.rst | 4 ++-- doc/man-sections/tls-options.rst | 22 ++++++++++++++++- src/openvpn/init.c | 1 + src/openvpn/options.c | 40 ++++++++++++++++++++++--------- src/openvpn/options.h | 1 + src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 19 ++++++++------- 8 files changed, 73 insertions(+), 22 deletions(-)
Changes.rst +7 -0
@@ -1,5 +1,12 @@ Overview of changes in 2.5 ========================== +New features in 2.5.1 +--------------------- +Certificate pinning/verify peer fingerprint + The ``--peer-fingerprint`` option has been introduced to give users a + easy to use alternative to the ``tls-verify`` for matching the + fingerprint of the peer. The option has use a number of + SHA256 fingerprints. New features ------------
doc/man-sections/inline-files.rst +2 -2
@@ -4,8 +4,8 @@ INLINE FILE SUPPORT OpenVPN allows including files in the main configuration for the ``--ca``, ``--cert``, ``--dh``, ``--extra-certs``, ``--key``, ``--pkcs12``, ``--secret``, ``--crl-verify``, ``--http-proxy-user-pass``, ``--tls-auth``, -``--auth-gen-token-secret``, ``--tls-crypt``, ``--tls-crypt-v2`` and -``--verify-hash`` options. +``--auth-gen-token-secret``, ``--peer-fingerprint``, ``--tls-crypt``, +``--tls-crypt-v2`` and ``--verify-hash`` options. Each inline file started by the line ``<option>`` and ended by the line ``</option>``
doc/man-sections/tls-options.rst +21 -1
@@ -268,7 +268,8 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa man-in-the-middle attack where an authorized client attempts to connect to another client by impersonating the server. The attack is easily prevented by having clients verify the server certificate using any one - of ``--remote-cert-tls``, ``--verify-x509-name``, or ``--tls-verify``. + of ``--remote-cert-tls``, ``--verify-x509-name``, ``--peer-fingerprint`` + or ``--tls-verify``. --tls-auth args Add an additional layer of HMAC authentication on top of the TLS control
@@ -589,6 +590,25 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa If the option is inlined, ``algo`` is always :code:`SHA256`. +--peer-fingerprint args + Specify a SHA256 fingerprint or list of SHA256 fingerprints to verify + the peer certificate against. The peer certificate must match one of the + fingerprint or certificate verification will fail. The option can also + be inlined + + Valid syntax: + :: + + peer-fingerprint AD:B0:95:D8:09:... + + or inline: + :: + + <peer-fingerprint> + 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff + 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 + </peer-fingerprint> + --verify-x509-name args Accept connections only if a host's X.509 name is equal to **name.** The remote host must also pass all other tests of verification.
src/openvpn/init.c +1 -0
@@ -2909,6 +2909,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.remote_cert_eku = options->remote_cert_eku; to.verify_hash = options->verify_hash; to.verify_hash_algo = options->verify_hash_algo; + to.verify_hash_depth = options->verify_hash_depth;#ifdef ENABLE_X509ALTUSERNAME to.x509_username_field = (char *) options->x509_username_field;#else
src/openvpn/options.c +29 -11
@@ -8192,26 +8192,44 @@ add_option(struct options *options, options->extra_certs_file = p[1 ]; options->extra_certs_file_inline = is_inline; } -else if (streq (p[0 ],"verify-hash" ) && p[1 ] && !p[3 ]) +else if ((streq (p[0 ],"verify-hash" ) && p[1 ] && !p[3 ]) + || (streq (p[0 ],"peer-fingerprint" ) && p[1 ] && !p[2 ])) {VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_INLINE ); + + options->verify_hash_depth =0 ; options->verify_hash_algo =MD_SHA256 ;int digest_len =SHA256_DIGEST_LENGTH ; -if (!p[2 ] || (p[2 ] &&streq (p[2 ],"SHA1" ))) +if (options->verify_hash) { - options->verify_hash_algo =MD_SHA1 ; -msg (M_WARN ,"DEPRECATED FEATURE: Usage of SHA1 fingerprints for " -"verify-hash is deprecated. You should switch to the " -"SHA256." ); - options->verify_hash_algo =MD_SHA1 ; - digest_len =SHA_DIGEST_LENGTH ; +msg (msglevel,"ERROR: Setting %s not allowed. Option to verify " +"fingerprint of certificate of peer certificate " +"(--verify-hash or --peer-fingerprint) already set." , + p[0 ]); + goto err; } -else if (p[2 ] && !streq (p[2 ],"SHA256" )) + +if (streq (p[0 ],"verify-hash" )) { -msg (msglevel,"invalid or unsupported hashing algorithm: %s (only SHA1 and SHA256 are valid)" , p[2 ]); - goto err; +/* verify level 1 cert, i.e. the CA that signed the leaf cert */ + options->verify_hash_depth =1 ; + +if (!p[2 ] || (p[2 ] &&streq (p[2 ],"SHA1" ))) + { + options->verify_hash_algo =MD_SHA1 ; +msg (M_WARN ,"DEPRECATED FEATURE: Usage of SHA1 fingerprints for " +"verify-hash is deprecated. You should switch to the " +"SHA256." ); + options->verify_hash_algo =SHA_DIGEST_LENGTH ; + digest_len =SHA_DIGEST_LENGTH ; + } +else if (p[2 ] && !streq (p[2 ],"SHA256" )) + { +msg (msglevel,"invalid or unsupported hashing algorithm: %s (only SHA1 and SHA256 are valid)" , p[2 ]); + goto err; + } }if (is_inline)
src/openvpn/options.h +1 -0
@@ -564,6 +564,7 @@ struct optionsconst char *remote_cert_eku;struct verify_hash_list *verify_hash;hash_algo_type verify_hash_algo; +int verify_hash_depth;unsigned int ssl_flags;/* set to SSLF_x flags from ssl.h */ #ifdef ENABLE_PKCS11
src/openvpn/ssl_common.h +1 -0
@@ -283,6 +283,7 @@ struct tls_optionsunsigned remote_cert_ku[MAX_PARMS ];const char *remote_cert_eku;struct verify_hash_list *verify_hash; +int verify_hash_depth;hash_algo_type verify_hash_algo;char *x509_username_field;
src/openvpn/ssl_verify.c +11 -8
@@ -693,19 +693,18 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep goto cleanup;/* Reject connection */ } -/* verify level 1 cert, i.e. the CA that signed our leaf cert */ -if (cert_depth ==1 && opt->verify_hash) +if (cert_depth == opt->verify_hash_depth && opt->verify_hash) { -struct buffer ca_hash = {0 }; +struct buffer cert_fp = {0 };switch (opt->verify_hash_algo) {case MD_SHA1 : - ca_hash =x509_get_sha1_fingerprint (cert, &gc); + cert_fp =x509_get_sha1_fingerprint (cert, &gc);break ;case MD_SHA256 : - ca_hash =x509_get_sha256_fingerprint (cert, &gc); + cert_fp =x509_get_sha256_fingerprint (cert, &gc);break ;default :
@@ -725,8 +724,8 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depwhile (current_hash) { -if (memcmp_constant_time (BPTR (&ca_hash), current_hash->hash, -BLEN (&ca_hash)) ==0 ) +if (memcmp_constant_time (BPTR (&cert_fp), current_hash->hash, +BLEN (&cert_fp)) ==0 ) { hash_matched = true; }
@@ -735,7 +734,11 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depif (!hash_matched) { -msg (D_TLS_ERRORS ,"TLS Error: --tls-verify certificate hash verification failed" ); +const char *hex_fp =format_hex_ex (BPTR (&cert_fp),BLEN (&cert_fp), +0 ,1 ,":" , &gc); +msg (D_TLS_ERRORS ,"TLS Error: --tls-verify/--peer-fingerprint" +"certificate hash verification failed. (got " +"fingerprint: %s" , hex_fp); goto cleanup; } }
Signature · 1 line
2.26.2
PATCH 3/4 Support fingerprint authentication without CA certificate
In reply to Arne SchwabeFrom: "Jason A. Donenfeld" <[email protected]...>
OpenVPN traditionally works around CAs. However many TLS-based protocols also allow an alternative simpler mode in which rather than verify certificates against CAs, the certificate itself is hashed and compared against a pre-known set of acceptable hashes. This is usually referred to as "fingerprint verification". It's popular across SMTP servers, IRC servers, XMPP servers, and even in the context of HTTP with pinning.
* Allow not specifying the --ca parameter, to specify that certificates should not be checked against a CA.
I've included some instructions on how to use all of this.
Server side:
============
Make self-signed cert:
$ openssl req -x509 -newkey ec:<(openssl ecparam -name secp384r1) -keyout serverkey.pem -out servercert.pem -nodes -sha256 -days 3650 -subj '/CN=server'
Record our fingerprint in an environment variable for the client to use later:
$ server_fingerprint="$(openssl x509 -in servercert.pem -noout -sha256 -fingerprint | sed 's/.*=//;s/\(.*\)/\1/')"
Client side:
============
Make self-signed cert:
$ openssl req -x509 -newkey ec:<(openssl ecparam -name secp384r1) -keyout clientkey.pem -out clientcert.pem -nodes -sha256 -days 3650 -subj '/CN=client'
Record our fingerprint in an environment variable for the server to use later:
$ client_fingerprint="$(openssl x509 -in clientcert.pem -noout -sha256 -fingerprint | sed 's/.*=//;s/\(.*\)/\1/')"
Start server/client
===================
Start openvpn with peer fingerprint verification:
$ sudo openvpn --server 10.66.0.0 255.255.255.0 --dev tun --dh none --cert servercert.pem --key serverkey.pem --peer-fingerprint "$client_fingerprint"
$ sudo openvpn --client --remote 127.0.0.1 --dev tun --cert clientcert.pem --key clientkey.pem --peer-fingerprint "$server_fingerprint" --nobind
Patch V2: Changes in V2 (by Arne Schwabe):
- Only check peer certificates, not all cert levels, if you need multiple levels of certificate you should use a real CA
- Use peer-fingerprint instead tls-verify on server side in example.
- rename variable ca_file_none to verify_hash_no_ca
- do no require --ca none but allow --ca simply
to be absent when --peer-fingprint is present
- adjust warnings/errors messages to also point to peer-fingerprint as valid verification method.
- Fix mbed TLS version of not requiring CA
not working
--- src/openvpn/init.c | 2 ++ src/openvpn/options.c | 30 +++++++++++++++++++++++------- src/openvpn/options.h | 1 + src/openvpn/ssl.c | 2 +- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify_mbedtls.c | 17 +++++++++++++++++ src/openvpn/ssl_verify_openssl.c | 2 +- 7 files changed, 46 insertions(+), 9 deletions(-)
src/openvpn/init.c +2 -0
@@ -2910,6 +2910,8 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.verify_hash = options->verify_hash; to.verify_hash_algo = options->verify_hash_algo; to.verify_hash_depth = options->verify_hash_depth; + to.verify_hash_no_ca = options->verify_hash_no_ca; +#ifdef ENABLE_X509ALTUSERNAME to.x509_username_field = (char *) options->x509_username_field;#else
src/openvpn/options.c +23 -7
@@ -2721,18 +2721,23 @@ options_postprocess_verify_ce(const struct options *options, const struct connecelse {#ifdef ENABLE_CRYPTO_MBEDTLS -if (!(options->ca_file)) +if (!(options->ca_file || options->verify_hash_no_ca)) { -msg (M_USAGE ,"You must define CA file (--ca)" ); +msg (M_USAGE ,"You must define CA file (--ca) and/or " +"peer fingeprint verification " +"(--peer-fingerprint)" ); }if (options->ca_path) {msg (M_USAGE ,"Parameter --capath cannot be used with the mbed TLS version version of OpenVPN." ); }#else /* ifdef ENABLE_CRYPTO_MBEDTLS */ -if ((!(options->ca_file)) && (!(options->ca_path))) +if ((!(options->ca_file)) && (!(options->ca_path)) + && (!(options->verify_hash_no_ca))) { -msg (M_USAGE ,"You must define CA file (--ca) or CA path (--capath)" ); +msg (M_USAGE ,"You must define CA file (--ca) or CA path " +"(--capath) and/or peer fingeprint verification " +"(--peer-fingerprint)" ); }#endif if (pull)
@@ -2751,7 +2756,8 @@ options_postprocess_verify_ce(const struct options *options, const struct connec#if P2MP if (!options->auth_user_pass_file)#endif -msg (M_USAGE ,"No client-side authentication method is specified. You must use either --cert/--key, --pkcs12, or --auth-user-pass" ); +msg (M_USAGE ,"No client-side authentication method is specified. You must use either --cert/--key," +" --pkcs12, or --auth-user-pass" ); }else if (sum ==2 ) {
@@ -3241,6 +3247,13 @@ options_postprocess_mutate(struct options *o) options_postprocess_http_proxy_override(o); }#endif +if (!o->ca_file && !o->ca_path && o->verify_hash + && o->verify_hash_depth ==0 ) + { +msg (M_INFO ,"Using certificate fingerprint to verify peer (no CA " +"option set). " ); + o->verify_hash_no_ca = true; + }#if P2MP /*
@@ -3476,8 +3489,11 @@ options_postprocess_filechecks(struct options *options) errs |=check_file_access_inline (options->dh_file_inline,CHKACC_FILE , options->dh_file,R_OK ,"--dh" ); - errs |=check_file_access_inline (options->ca_file_inline,CHKACC_FILE , - options->ca_file,R_OK ,"--ca" ); +if (!options->verify_hash_no_ca) + { + errs |=check_file_access_inline (options->ca_file_inline,CHKACC_FILE , + options->ca_file,R_OK ,"--ca" ); + } errs |=check_file_access_chroot (options->chroot_dir,CHKACC_FILE , options->ca_path,R_OK ,"--capath" );
src/openvpn/options.h +1 -0
@@ -565,6 +565,7 @@ struct optionsstruct verify_hash_list *verify_hash;hash_algo_type verify_hash_algo;int verify_hash_depth; +bool verify_hash_no_ca;unsigned int ssl_flags;/* set to SSLF_x flags from ssl.h */ #ifdef ENABLE_PKCS11
src/openvpn/ssl.c +1 -1
@@ -684,7 +684,7 @@ init_ssl(const struct options *options, struct tls_root_ctx *new_ctx) }#endif -if (options->ca_file || options->ca_path) +if ((!options->verify_hash_no_ca && options->ca_file) || options->ca_path) {tls_ctx_load_ca (new_ctx, options->ca_file, options->ca_file_inline, options->ca_path, options->tls_server);
src/openvpn/ssl_common.h +1 -0
@@ -284,6 +284,7 @@ struct tls_optionsconst char *remote_cert_eku;struct verify_hash_list *verify_hash;int verify_hash_depth; +bool verify_hash_no_ca;hash_algo_type verify_hash_algo;char *x509_username_field;
src/openvpn/ssl_verify_mbedtls.c +17 -0
@@ -62,6 +62,23 @@ verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth,struct buffer cert_fingerprint =x509_get_sha256_fingerprint (cert, &gc);cert_hash_remember (session, cert_depth, &cert_fingerprint); + +if (session->opt->verify_hash_no_ca) + { +/* +* If we decide to verify the peer certificate based on the fingerprint +* we ignore wrong dates and the certificate not being trusted. +* Any other problem with the certificate (wrong key, bad cert,...) +* will still trigger an error. +* Clearing these flags relies on verify_cert will later rejecting a +* certificate that has no matching fingerprint. +*/ +uint32_t flags_ignore =MBEDTLS_X509_BADCERT_NOT_TRUSTED + |MBEDTLS_X509_BADCERT_EXPIRED + |MBEDTLS_X509_BADCERT_FUTURE ; + *flags = *flags & ~flags_ignore; + } +/* did peer present cert which was signed by our root cert? */ if (*flags !=0 ) {
src/openvpn/ssl_verify_openssl.c +1 -1
@@ -67,7 +67,7 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx)cert_hash_remember (session,X509_STORE_CTX_get_error_depth (ctx), &cert_hash);/* did peer present cert which was signed by our root cert? */ -if (!preverify_ok) +if (!preverify_ok && !session->opt->verify_hash_no_ca) {/* get the X509 name */ char *subject =x509_get_subject (current_cert, &gc);
Signature · 1 line
2.26.2
PATCH 4/4 Document the simple self-signed certificate setup in examples
In reply to Arne SchwabeAlso remove the static key setup example as it is less secure and we want to avoid it for new setups as we want to slowly deprecate these.
--- Changes.rst | 5 ++++ doc/man-sections/examples.rst | 46 ++++++++++++++++++++------------ doc/man-sections/tls-options.rst | 4 +++ 3 files changed, 38 insertions(+), 17 deletions(-)
Changes.rst +5 -0
@@ -8,6 +8,11 @@ Certificate pinning/verify peer fingerprint fingerprint of the peer. The option has use a number of SHA256 fingerprints. +TLS mode with self-signed certificates + When ``--peer-fingerprint`` is used, the ``--ca`` and ``--capath`` option + become optional. This allows for small OpenVPN setups without setting up + a PKI with Easy-RSA or similar software. + New features ------------ Client-specific tls-crypt keys (``--tls-crypt-v2``)
doc/man-sections/examples.rst +29 -17
77 lines not on this page · raw message
doc/man-sections/tls-options.rst +4 -0
@@ -609,6 +609,10 @@ If the option is inlined, ``algo`` is always :code:`SHA256`. 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 </peer-fingerprint> + When the ``--peer-fingerprint`` option is used, specifying a CA with ``--ca`` or ``--capath`` is + optional. This allows the he ``--peer-fingerprint`` to be used as alternative to a PKI with + self-signed certificates for small setups. See the examples section for such a setup. + --verify-x509-name args Accept connections only if a host's X.509 name is equal to **name.** The remote host must also pass all other tests of verification.
Signature · 1 line
2.26.2
Quoted 5 lines · Arne Schwabe
The main difference of this patch set to Jason's V1 version is that it does not rely on an external script on the server side and instead relys on an a inlined <peer-fingerprint> section. The downside is that this requires a server restart on adding a client but the upside is that no script-security or external scripts are necessary and server/client setup become symmetric.
One of the nice features of Jason's patch was that also for big(ger) deployments you could get rid of the CA if you have another channel to establish trust between client and server.
I guess it won't be possible to use --tls-verify (on the server) with your patch and verify the fingerprint(s) there? For the client it is enough to have a (fixed) list of trusted fingerprints. Would it be possible to add this (again)?
Regards,
François
Quoted 3 lines
One of the nice features of Jason's patch was that also for big(ger) deployments you could get rid of the CA if you have another channel to establish trust between client and server.
I really wonder which large deployment want to do that instead of a CA. I really understand the need for small and simple deployments. But for larger deployments a CA + CRL seems more useful for everything that I can come up with.
Quoted 1 line
I guess it won't be possible to use --tls-verify (on the server) with your patch and verify the fingerprint(s) there?
No. Currently not.
Arne
Quoted 4 lines · Arne Schwabe
I really wonder which large deployment want to do that instead of a CA. I really understand the need for small and simple deployments. But for larger deployments a CA + CRL seems more useful for everything that I can come up with.
It would be more for the situation where you already have a "parallel trust", e.g. through an OAuth API where a CA would be redundant. Just having an API to register fingerprints (which would act as a CRL at the same time by simply removing fingerprints) is easier than having a complete CA with CRL.
Of course, all of this can also be done by using a CA, and something can be said that if you operate on that scale you can also handle the extra "cost" of a CA...
Thanks,
François
Am 09.09.20 um 10:04 schrieb François Kooman:
Quoted 12 lines · Arne Schwabe
Quoted 4 lines
I really wonder which large deployment want to do that instead of a CA. I really understand the need for small and simple deployments. But for larger deployments a CA + CRL seems more useful for everything that I can come up with.
It would be more for the situation where you already have a "parallel trust", e.g. through an OAuth API where a CA would be redundant. Just having an API to register fingerprints (which would act as a CRL at the same time by simply removing fingerprints) is easier than having a complete CA with CRL.
Quoted 3 lines
Of course, all of this can also be done by using a CA, and something can be said that if you operate on that scale you can also handle the extra "cost" of a CA...
I am happy to review a patch that adds a allow_no_ca or similar flag to the tls-verify option that allows this but I don't have a real motivation to implement it myself.
Just allowing ca not set with tls-verify script being set is a bit too dangerous for my taste.
Arne
Quoted 17 lines · Arne Schwabe
Am 09.09.20 um 10:04 schrieb François Kooman:
Quoted 12 lines · Arne Schwabe
Quoted 4 lines
I really wonder which large deployment want to do that instead of a CA. I really understand the need for small and simple deployments. But for larger deployments a CA + CRL seems more useful for everything that I can come up with.
It would be more for the situation where you already have a "parallel trust", e.g. through an OAuth API where a CA would be redundant. Just having an API to register fingerprints (which would act as a CRL at the same time by simply removing fingerprints) is easier than having a complete CA with CRL.
Quoted 3 lines
Of course, all of this can also be done by using a CA, and something can be said that if you operate on that scale you can also handle the extra "cost" of a CA...
Quoted 7 lines
I am happy to review a patch that adds a
allow_no_caor similar flag to the tls-verify option that allows this but I don't have a real motivation to implement it myself.Just allowing ca not set with tls-verify script being set is a bit too dangerous for my taste.
I too would like to see an external list of fingerprints be made available.
https://community.openvpn.net/openvpn/ticket/1323#ticket
Am 09.09.20 um 20:23 schrieb tincanteksup:
Quoted 24 lines · Arne Schwabe
Quoted 21 lines
Am 09.09.20 um 10:04 schrieb François Kooman:
Quoted 12 lines · Arne Schwabe
Quoted 4 lines
I really wonder which large deployment want to do that instead of a CA. I really understand the need for small and simple deployments. But for larger deployments a CA + CRL seems more useful for everything that I can come up with.
It would be more for the situation where you already have a "parallel trust", e.g. through an OAuth API where a CA would be redundant. Just having an API to register fingerprints (which would act as a CRL at the same time by simply removing fingerprints) is easier than having a complete CA with CRL.
Quoted 3 lines
Of course, all of this can also be done by using a CA, and something can be said that if you operate on that scale you can also handle the extra "cost" of a CA...
I am happy to review a patch that adds a
allow_no_caor similar flag to the tls-verify option that allows this but I don't have a real motivation to implement it myself.
Quoted 6 lines
Quoted 3 lines
Just allowing ca not set with tls-verify script being set is a bit too dangerous for my taste.
I too would like to see an external list of fingerprints be made available.
https://community.openvpn.net/openvpn/ticket/1323#ticket
Yes it would be nicer but this is for small setups and reconnects and quick and cheap. I don't want this feature to evolve into a second PKI infrastructure just worse.
Arne
Re: [Openvpn-devel] [PATCH 1/4] Extend verify-hash to allow multiple hashes
In reply to Arne SchwabeHi,
This patch conflicts a bit with current master, but can be applied using "git am -3".
Intro: it's not easy to understand what "verify-hash" was really meant for, but I am happy to see it being restructured to actually become useful :-)
Quoted 5 lines · Arne Schwabe
For a new syntax introduced now it does not make much sense to support deprecated and old hashes, so support only SHA-256.
Also give a warning about SHA1 hash being deprecated to verify certificates as it is now "industry standard".
I would reword the commit as follows:
---
This patch introduces support for verify-hash inlining.
When inlined, this options now allows to specify multiple fingerprints, one per line.
Since this is a new syntax, there is no backwards compatibility to take care of, therefore we can drop support for SHA1. Inlined fingerprints are assumed be to SHA-256 only.
Also print a warning about SHA1 hash being deprecated to verify certificates as it is not "industry standard" anymore.
---
More comments below:
Quoted 52 lines
Signed-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/inline-files.rst | 4 +- doc/man-sections/tls-options.rst | 10 ++++ src/openvpn/options.c | 91 +++++++++++++++++++++++++++---- src/openvpn/options.h | 11 +++- src/openvpn/ssl_common.h | 2 +- src/openvpn/ssl_verify.c | 17 +++++- 6 files changed, 119 insertions(+), 16 deletions(-)doc/man-sections/inline-files.rst +2
-2@@ -4,8 +4,8 @@ INLINE FILE SUPPORT OpenVPN allows including files in the main configuration for the ``--ca``, ``--cert``, ``--dh``, ``--extra-certs``, ``--key``, ``--pkcs12``, ``--secret``, ``--crl-verify``, ``--http-proxy-user-pass``, ``--tls-auth``, -``--auth-gen-token-secret``, ``--tls-crypt`` and ``--tls-crypt-v2`` -options. +``--auth-gen-token-secret``, ``--tls-crypt``, ``--tls-crypt-v2`` and +``--verify-hash`` options. Each inline file started by the line ``<option>`` and ended by the line ``</option>``doc/man-sections/tls-options.rst +10
-0@@ -579,6 +579,16 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa The ``algo`` flag can be either :code:`SHA1` or :code:`SHA256`. If not provided, it defaults to :code:`SHA1`. + This option can also be inlined + :: + + <verify-hash> + 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff + 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 + </verify-hash> + +If the option is inlined, ``algo`` is always :code:`SHA256`. + --verify-x509-name args Accept connections only if a host's X.509 name is equal to **name.** The remote host must also pass all other tests of verification.src/openvpn/options.c +0
-0
src/openvpn/options.c string_substitute(const char *src, int from, int to, struct gc_arena *gc) · line 1087
Quoted 7 lines
src/openvpn/options.c +3
-1@@ -1082,12 +1082,24 @@ string_substitute(const char *src, int from, int to, struct gc_arena *gc)return ret; } -static uint8_t * +/** +* Parses a hexstring and checks if the string has the correct length. Return +* a verify_hash_list of the parsed string.
"a verify_hash_list object containing the parsed string."
src/openvpn/options.c string_substitute(const char *src, int from, int to, struct gc_arena *gc) · line 1092
Quoted 5 lines
src/openvpn/options.c +5
-0+* +* @param str String to check/parse +* @param nbytes Number of bytes expected in the hexstr (e.g. 20 for SHA1) +* @param msglevel message level to use when printing warnings/errors +* @param gc The returned string will be allocated in this gc.
returned string -> returned object
We never put the period at the end of doxygen strings. it should be removed
Quoted 26 lines
src/openvpn/options.c +7
-2+*/ +static struct verify_hash_list *parse_hash_fingerprint (const char *str,int nbytes,int msglevel,struct gc_arena *gc) {int i;const char *cp = str; -uint8_t *ret = (uint8_t *)gc_malloc (nbytes, true, gc); + +struct verify_hash_list *ret; + ALLOC_OBJ_CLEAR_GC(ret, struct verify_hash_list, gc); +char term =1 ;int byte;char bs[3 ];@@ -1106,7 +1118,7 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren {msg (msglevel,"format error in hash fingerprint hex byte: %s" , str); } - ret[i] = (uint8_t )byte; + ret->hash[i] = (uint8_t )byte; term = *cp++;if (term !=':' && term !=0 ) {@@ -1120,10 +1132,54 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_arenif (term !=0 || i != nbytes-1 ) {
src/openvpn/options.c parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren · line 1143
Quoted 10 lines
src/openvpn/options.c +5
-0msg (msglevel,"hash fingerprint is different length than expected (%d bytes): %s" , nbytes, str); +return NULL ; }return ret; } +/** +* Parses a string consisting of multiple lines of hexstrings and checks if each +* string has the correct length. Lines that are empty are ignored. Returns +* a verify_hash_list.
a linked list of (possibly) multiple verify_hash_list objects.
src/openvpn/options.c string_substitute(const char *src, int from, int to, struct gc_arena *gc) · line 1090
Quoted 3 lines
src/openvpn/options.c +3
-0+* +* @param str String to check/parse +* @param nbytes Number of bytes expected in the hexstr (e.g. 20 for SHA1)
in the hexstr -> in each hexstring
src/openvpn/options.c parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren · line 1148
Quoted 2 lines
src/openvpn/options.c +2
-0+* @param msglevel message level to use when printing warnings/errors +* @param gc The returned string will be allocated in this gc.
returned string -> returned list
no dot at the end.
Quoted 15 lines
src/openvpn/options.c +15
-0+*/ +static struct verify_hash_list * +parse_hash_fingerprint_multiline (const char *str,int nbytes,int msglevel, +struct gc_arena *gc) +{ +struct gc_arena gc_temp =gc_new (); +char *lines =string_alloc (str, &gc_temp); + +struct verify_hash_list *ret =NULL ; + +const char *line; +while ((line =strsep (&lines,"\n" ))) + { +/* skip empty lines */ +if (strlen (line) ==0 )
src/openvpn/options.c parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren · line 1173
Quoted 10 lines
src/openvpn/options.c +10
-0+ { +continue ; + } + +struct verify_hash_list *hash =parse_hash_fingerprint (line, nbytes, + msglevel, gc); + +if (!hash) + { +return NULL ;
I believe we are leaking gc_temp here.
It is allocated on the stack of this function, therefore it should be free'd before the return.
Quoted 13 lines
src/openvpn/options.c +9
-0+ } + + hash->next = ret; + ret = hash; + } +gc_free (&gc_temp); + +return ret; +}#ifdef _WIN32#ifndef ENABLE_SMALL
src/openvpn/options.c add_option(struct options *options, · line 8202
Quoted 10 lines
src/openvpn/options.c +4
-1@@ -8138,22 +8194,37 @@ add_option(struct options *options, }else if (streq (p[0 ],"verify-hash" ) && p[1 ] && !p[3 ]) { -VERIFY_PERMISSION (OPT_P_GENERAL ); +VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_INLINE ); + options->verify_hash_algo =MD_SHA256 ; + +int digest_len =SHA256_DIGEST_LENGTH ;if (!p[2 ] || (p[2 ] &&streq (p[2 ],"SHA1" )))
This condition has to be modified.
p[2] is NULL when this option is inlined, therefore this condition is evaluated to true in that case.
Maybe you should change it to: if (!is_inline && (...)) ?
I tested and I indeed get the following with an inlined verify-hash:
DEPRECATED FEATURE: Usage of SHA1 fingerprints for verify-hash is deprecated. You should switch to the SHA256.
Quoted 12 lines
src/openvpn/options.c +6
-2{ - options->verify_hash =parse_hash_fingerprint (p[1 ],SHA_DIGEST_LENGTH , msglevel, &options->gc); options->verify_hash_algo =MD_SHA1 ; +msg (M_WARN ,"DEPRECATED FEATURE: Usage of SHA1 fingerprints for " +"verify-hash is deprecated. You should switch to the " +"SHA256." ); + options->verify_hash_algo =MD_SHA1 ; + digest_len =SHA_DIGEST_LENGTH ; } - else if (p[2] && streq(p[2], "SHA256")) + else if (p[2] && !streq(p[2], "SHA256")) {
src/openvpn/options.c add_option(struct options *options, · line 8220
Quoted 10 lines
src/openvpn/options.c +8
-2- options->verify_hash =parse_hash_fingerprint (p[1 ],SHA256_DIGEST_LENGTH , msglevel, &options->gc); - options->verify_hash_algo =MD_SHA256 ; +msg (msglevel,"invalid or unsupported hashing algorithm: %s (only SHA1 and SHA256 are valid)" , p[2 ]); + goto err; + } + +if (is_inline) + { +/* We do not have a inline flag in options struct as it is either +* a one line or multiline string */
I am not sure what this comment is telling us. Is it trying to explain some decision about how to call the following function? If so, which decision?
To me the code makes sense also without the comment.
Quoted 17 lines
src/openvpn/options.c +4
-2+ options->verify_hash =parse_hash_fingerprint_multiline (p[1 ], digest_len, msglevel, + &options->gc); }else { -msg (msglevel,"invalid or unsupported hashing algorithm: %s (only SHA1 and SHA256 are valid)" , p[2 ]); - goto err; + options->verify_hash =parse_hash_fingerprint (p[1 ], digest_len, msglevel, + &options->gc); } }#ifdef ENABLE_CRYPTOAPI src/openvpn/options.h +0
-0
src/openvpn/options.h enum genkey_type { · line 197
Quoted 7 lines
src/openvpn/options.h +4
-0@@ -191,6 +191,15 @@ enum genkey_type {GENKEY_AUTH_TOKEN }; +struct verify_hash_list +{ +/* Currently we only support SHA256 for longer lists, for a one item +* list with SHA1 we ignore the 12 byte memory wasted */
This comment explains how we are solving something, without telling what that something is.
My guess is that you are referring to SHA1 having 20bytes long hash, while for SHA256 it is 32bytes long. Is that right?
Maybe it could reworded a little bit, because these numbers are not obvious to everybody.
src/openvpn/options.h enum genkey_type { · line 200
Quoted 3 lines
src/openvpn/options.h +3
-0+uint8_t hash[32 ]; +struct verify_hash_list *next; +
no need for an empty line here.
Quoted 32 lines
src/openvpn/options.h +3
-1+}; +/* Command line options */ struct options {@@ -553,7 +562,7 @@ struct optionsint ns_cert_type;/* set to 0, NS_CERT_CHECK_SERVER, or NS_CERT_CHECK_CLIENT */ unsigned remote_cert_ku[MAX_PARMS ];const char *remote_cert_eku; -uint8_t *verify_hash; +struct verify_hash_list *verify_hash;hash_algo_type verify_hash_algo;unsigned int ssl_flags;/* set to SSLF_x flags from ssl.h */ src/openvpn/ssl_common.h +1
-1@@ -282,7 +282,7 @@ struct tls_optionsint ns_cert_type;unsigned remote_cert_ku[MAX_PARMS ];const char *remote_cert_eku; -uint8_t *verify_hash; +struct verify_hash_list *verify_hash;hash_algo_type verify_hash_algo;char *x509_username_field;src/openvpn/ssl_verify.c +0
-0
src/openvpn/ssl_verify.c verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep · line 724
Quoted 6 lines
src/openvpn/ssl_verify.c +2
-1@@ -720,9 +720,22 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep goto cleanup; } -if (memcmp (BPTR (&ca_hash), opt->verify_hash,BLEN (&ca_hash))) +struct verify_hash_list *current_hash = opt->verify_hash; +bool hash_matched = false;
we don't really need this extra variable here. see below:
src/openvpn/ssl_verify.c verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep · line 731
Quoted 7 lines
src/openvpn/ssl_verify.c +7
-0+ +while (current_hash) + { +if (memcmp_constant_time (BPTR (&ca_hash), current_hash->hash, +BLEN (&ca_hash)) ==0 ) + { + hash_matched = true;
.. you can just break here ..
src/openvpn/ssl_verify.c verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep · line 736
Quoted 5 lines
src/openvpn/ssl_verify.c +5
-0+ } + current_hash = current_hash->next; + } + +if (!hash_matched)
.. and change this to if (!current_hash) << it implies we reached the end of the list without a match.
src/openvpn/ssl_verify.c verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep · line 741
Quoted 7 lines
src/openvpn/ssl_verify.c +1
-1{ -msg (D_TLS_ERRORS ,"TLS Error: level-1 certificate hash verification failed" ); +msg (D_TLS_ERRORS ,"TLS Error: --tls-verify certificate hash verification failed" ); goto cleanup; } }
I believe the comments are all somewhat minor. The change is sound and well implemented.
I'd ACK but I think it's better if Arne sends a new patch with some code changes, rather than having Gert change the patch on the fly.
Cheers,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH 2/4] Implement peer-fingerprint to check fingerprint of peer certificate
In reply to Arne SchwabeHi,
This patch currently only applies with "git am -3"
We currently have "verify-hash" that accepts fingerprints as argument. For consistency I would suggest to either:
1) rename this option to peer-hash; or
2) add an alias for "verify-hash" named "verify-fingerprint", so that we can then get rid of the former at some point.
I am more incline to option 2.
Quoted 1 line · Arne Schwabe
This options allows to pin a certificate or a number of certificate.
How about:
"This option allows to pin one more more peer certificates"
Quoted 20 lines
It also prepares for doing TLS authentication without a CA and just self-signed certificates.
Signed-off-by Arne Schwabe <[email protected]...>--- Changes.rst | 7 ++++++ doc/man-sections/inline-files.rst | 4 ++-- doc/man-sections/tls-options.rst | 22 ++++++++++++++++- src/openvpn/init.c | 1 + src/openvpn/options.c | 40 ++++++++++++++++++++++--------- src/openvpn/options.h | 1 + src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 19 ++++++++------- 8 files changed, 73 insertions(+), 22 deletions(-)Changes.rst +0
-0
Changes.rst line 9
Quoted 9 lines
Changes.rst +7
-0@@ -1,5 +1,12 @@ Overview of changes in 2.5 ========================== +New features in 2.5.1 +--------------------- +Certificate pinning/verify peer fingerprint + The ``--peer-fingerprint`` option has been introduced to give users a + easy to use alternative to the ``tls-verify`` for matching the + fingerprint of the peer. The option has use a number of + SHA256 fingerprints.
"has use" ? maybe "can list" ?
Quoted 93 lines
Changes.rst +0
-0New features ------------doc/man-sections/inline-files.rst +2
-2@@ -4,8 +4,8 @@ INLINE FILE SUPPORT OpenVPN allows including files in the main configuration for the ``--ca``, ``--cert``, ``--dh``, ``--extra-certs``, ``--key``, ``--pkcs12``, ``--secret``, ``--crl-verify``, ``--http-proxy-user-pass``, ``--tls-auth``, -``--auth-gen-token-secret``, ``--tls-crypt``, ``--tls-crypt-v2`` and -``--verify-hash`` options. +``--auth-gen-token-secret``, ``--peer-fingerprint``, ``--tls-crypt``, +``--tls-crypt-v2`` and ``--verify-hash`` options. Each inline file started by the line ``<option>`` and ended by the line ``</option>``doc/man-sections/tls-options.rst +21
-1@@ -268,7 +268,8 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa man-in-the-middle attack where an authorized client attempts to connect to another client by impersonating the server. The attack is easily prevented by having clients verify the server certificate using any one - of ``--remote-cert-tls``, ``--verify-x509-name``, or ``--tls-verify``. + of ``--remote-cert-tls``, ``--verify-x509-name``, ``--peer-fingerprint`` + or ``--tls-verify``. --tls-auth args Add an additional layer of HMAC authentication on top of the TLS control@@ -589,6 +590,25 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa If the option is inlined, ``algo`` is always :code:`SHA256`. +--peer-fingerprint args + Specify a SHA256 fingerprint or list of SHA256 fingerprints to verify + the peer certificate against. The peer certificate must match one of the + fingerprint or certificate verification will fail. The option can also + be inlined + + Valid syntax: + :: + + peer-fingerprint AD:B0:95:D8:09:... + + or inline: + :: + + <peer-fingerprint> + 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff + 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 + </peer-fingerprint> + --verify-x509-name args Accept connections only if a host's X.509 name is equal to **name.** The remote host must also pass all other tests of verification.src/openvpn/init.c +1
-0@@ -2909,6 +2909,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.remote_cert_eku = options->remote_cert_eku; to.verify_hash = options->verify_hash; to.verify_hash_algo = options->verify_hash_algo; + to.verify_hash_depth = options->verify_hash_depth;#ifdef ENABLE_X509ALTUSERNAME to.x509_username_field = (char *) options->x509_username_field;#else src/openvpn/options.c +5
-3@@ -8192,26 +8192,44 @@ add_option(struct options *options, options->extra_certs_file = p[1 ]; options->extra_certs_file_inline = is_inline; } -else if (streq (p[0 ],"verify-hash" ) && p[1 ] && !p[3 ]) +else if ((streq (p[0 ],"verify-hash" ) && p[1 ] && !p[3 ]) + || (streq (p[0 ],"peer-fingerprint" ) && p[1 ] && !p[2 ])) {VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_INLINE ); + + options->verify_hash_depth =0 ; options->verify_hash_algo =MD_SHA256 ;int digest_len =SHA256_DIGEST_LENGTH ; -if (!p[2 ] || (p[2 ] &&streq (p[2 ],"SHA1" ))) +if (options->verify_hash) { - options->verify_hash_algo =MD_SHA1 ;
src/openvpn/options.c add_option(struct options *options, · line 8211
Quoted 10 lines
src/openvpn/options.c +5
-5-msg (M_WARN ,"DEPRECATED FEATURE: Usage of SHA1 fingerprints for " -"verify-hash is deprecated. You should switch to the " -"SHA256." ); - options->verify_hash_algo =MD_SHA1 ; - digest_len =SHA_DIGEST_LENGTH ; +msg (msglevel,"ERROR: Setting %s not allowed. Option to verify " +"fingerprint of certificate of peer certificate " +"(--verify-hash or --peer-fingerprint) already set." , + p[0 ]); + goto err;
This will error out also when listing peer-fingerprint (or verify-hash) twice.
It would be the first option in openvpn to behave this way. Do we really want that?
It may be better to have some flag and complain when the two options are used together.
In any case, why not allowing to use these two options together? If the peer cert is not self-signed, we could still be willing to check the CA *and* also filter which peer-certificate we accept.
src/openvpn/options.c add_option(struct options *options, · line 8219
Quoted 11 lines
src/openvpn/options.c +6
-3} -else if (p[2 ] && !streq (p[2 ],"SHA256" )) + +if (streq (p[0 ],"verify-hash" )) { -msg (msglevel,"invalid or unsupported hashing algorithm: %s (only SHA1 and SHA256 are valid)" , p[2 ]); - goto err; +/* verify level 1 cert, i.e. the CA that signed the leaf cert */ + options->verify_hash_depth =1 ; + +if (!p[2 ] || (p[2 ] &&streq (p[2 ],"SHA1" )))
(this may need rebasing on top of a - possibly - modified patch 1.)
Quoted 83 lines
src/openvpn/options.c +13
-0+ { + options->verify_hash_algo =MD_SHA1 ; +msg (M_WARN ,"DEPRECATED FEATURE: Usage of SHA1 fingerprints for " +"verify-hash is deprecated. You should switch to the " +"SHA256." ); + options->verify_hash_algo =SHA_DIGEST_LENGTH ; + digest_len =SHA_DIGEST_LENGTH ; + } + else if (p[2] && !streq(p[2], "SHA256")) + { +msg (msglevel,"invalid or unsupported hashing algorithm: %s (only SHA1 and SHA256 are valid)" , p[2 ]); + goto err; + } }if (is_inline)src/openvpn/options.h +1
-0@@ -564,6 +564,7 @@ struct optionsconst char *remote_cert_eku;struct verify_hash_list *verify_hash;hash_algo_type verify_hash_algo; +int verify_hash_depth;unsigned int ssl_flags;/* set to SSLF_x flags from ssl.h */ #ifdef ENABLE_PKCS11 src/openvpn/ssl_common.h +1
-0@@ -283,6 +283,7 @@ struct tls_optionsunsigned remote_cert_ku[MAX_PARMS ];const char *remote_cert_eku;struct verify_hash_list *verify_hash; +int verify_hash_depth;hash_algo_type verify_hash_algo;char *x509_username_field;src/openvpn/ssl_verify.c +6
-7@@ -693,19 +693,18 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep goto cleanup;/* Reject connection */ } -/* verify level 1 cert, i.e. the CA that signed our leaf cert */ -if (cert_depth ==1 && opt->verify_hash) +if (cert_depth == opt->verify_hash_depth && opt->verify_hash) { -struct buffer ca_hash = {0 }; +struct buffer cert_fp = {0 };switch (opt->verify_hash_algo) {case MD_SHA1 : - ca_hash =x509_get_sha1_fingerprint (cert, &gc); + cert_fp =x509_get_sha1_fingerprint (cert, &gc);break ;case MD_SHA256 : - ca_hash =x509_get_sha256_fingerprint (cert, &gc); + cert_fp =x509_get_sha256_fingerprint (cert, &gc);break ;default :@@ -725,8 +724,8 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depwhile (current_hash) { -if (memcmp_constant_time (BPTR (&ca_hash), current_hash->hash, -BLEN (&ca_hash)) ==0 ) +if (memcmp_constant_time (BPTR (&cert_fp), current_hash->hash, +BLEN (&cert_fp)) ==0 ) { hash_matched = true; }@@ -735,7 +734,11 @@ verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_depif (!hash_matched)
src/openvpn/ssl_verify.c verify_cert(struct tls_session *session, openvpn_x509_cert_t *cert, int cert_dep · line 744
Quoted 10 lines
src/openvpn/ssl_verify.c +5
-1{ -msg (D_TLS_ERRORS ,"TLS Error: --tls-verify certificate hash verification failed" ); +const char *hex_fp =format_hex_ex (BPTR (&cert_fp),BLEN (&cert_fp), +0 ,1 ,":" , &gc); +msg (D_TLS_ERRORS ,"TLS Error: --tls-verify/--peer-fingerprint" +"certificate hash verification failed. (got " +"fingerprint: %s" , hex_fp); goto cleanup; } }
The rest look good. This change smartly relies on the generalization of the verify-hash code (patch 1).
Cheers,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH 4/4] Document the simple self-signed certificate setup in examples
In reply to Arne SchwabeHi,
Minor change below
Quoted 97 lines · Arne Schwabe
Also remove the static key setup example as it is less secure and we want to avoid it for new setups as we want to slowly deprecate these.
Signed-off-by Arne Schwabe <[email protected]...>--- Changes.rst | 5 ++++ doc/man-sections/examples.rst | 46 ++++++++++++++++++++------------ doc/man-sections/tls-options.rst | 4 +++ 3 files changed, 38 insertions(+), 17 deletions(-)Changes.rst +5
-0@@ -8,6 +8,11 @@ Certificate pinning/verify peer fingerprint fingerprint of the peer. The option has use a number of SHA256 fingerprints. +TLS mode with self-signed certificates + When ``--peer-fingerprint`` is used, the ``--ca`` and ``--capath`` option + become optional. This allows for small OpenVPN setups without setting up + a PKI with Easy-RSA or similar software. + New features ------------ Client-specific tls-crypt keys (``--tls-crypt-v2``)doc/man-sections/examples.rst +25
-15@@ -60,8 +60,8 @@ that is part of your local subnet for either of the tunnel endpoints, you will get a weird feedback loop. -Example 1: A simple tunnel without security -------------------------------------------- +Example 1: A simple tunnel without security (not recommended) +------------------------------------------------------------- On bob: ::@@ -92,31 +92,41 @@ The ``--verb 9`` option will produce verbose output, similar to the quietly. -Example 2: A tunnel with static-key security (i.e. using a pre-shared secret) ------------------------------------------------------------------------------ +Example 2: A tunnel with self-signed certificates and fingerprint +----------------------------------------------------------------- -First build a static key on bob. +First build a self-signed certificate on bob and display its fingerprint. :: - openvpn --genkey --secret key + openssl req -x509 -newkey ec:<(openssl ecparam -name secp384r1) -keyout bob.pem -out bob.pem -nodes -sha256 -days 3650 -subj '/CN=bob' + openssl x509 -noout -sha256 -fingerprint -in bob.pem -This command will build a key file called ``key`` (in ascii format). Now -copy ``key`` to ``alice.example.com`` over a secure medium such as by using -the ``scp``\(1) program. +and the same on alice: +:: + + openssl req -x509 -newkey ec:<(openssl ecparam -name secp384r1) -keyout alice.pem -out alice.pem -nodes -sha256 -days 3650 -subj '/CN=alice' + openssl x509 -noout -sha256 -fingerprint -in alice.pem + + +These commands will build a text file called ``bob.pem`` or ``alice.pem`` (in ascii format) +that contain both self-signed certificate and key and show the fingerprint of the certificates. +Transfer the fingerprints over a secure medium such as by using +the ``scp``\(1) or ``ssh``\(1) program. On bob: :: - openvpn --remote alice.example.com --dev tun1 \ - --ifconfig 10.4.0.1 10.4.0.2 --verb 5 \ - --secret key + openvpn --ifconfig 10.4.0.1 10.4.0.2 --tls-server --dev tun --dh none \ + --cert bob.pem --key bob.pem --cipher AES-256-GCM \ + --peer-fingerprint "$fingerprint_of_alices_cert" On alice: :: - openvpn --remote bob.example.com --dev tun1 \ - --ifconfig 10.4.0.2 10.4.0.1 --verb 5 \ - --secret key + openvpn --remote bob.example.com --tls-client --dev tun1 \ + --ifconfig 10.4.0.2 10.4.0.1 --cipher AES-256-GCM \ + --cert alice.pem --key alice.pem + --peer-fingerprint "$fingerprint_of_bobs_cert" Now verify the tunnel is working by pinging across the tunnel.
doc/man-sections/examples.rst On alice: · line 144
Quoted 5 lines
doc/man-sections/examples.rst +2
-0@@ -130,9 +140,11 @@ On alice: ping 10.4.0.1 +Note: This example use a elliptic curve (`secp384`), which allows +``--dh`` and to ``none``.
and to -> to be set to
Quoted 14 lines
doc/man-sections/examples.rst +2
-2-Example 3: A tunnel with full TLS-based security ------------------------------------------------- +Example 3: A tunnel with full PKI and TLS-based security +-------------------------------------------------------- For this test, we will designate ``bob`` as the TLS client and ``alice`` as the TLS server.doc/man-sections/tls-options.rst +0
-0
doc/man-sections/tls-options.rst If the option is inlined, ``algo`` is always :code:`SHA256`. · line 618
Quoted 10 lines
doc/man-sections/tls-options.rst +4
-0@@ -609,6 +609,10 @@ If the option is inlined, ``algo`` is always :code:`SHA256`. 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 </peer-fingerprint> + When the ``--peer-fingerprint`` option is used, specifying a CA with ``--ca`` or ``--capath`` is + optional. This allows the he ``--peer-fingerprint`` to be used as alternative to a PKI with + self-signed certificates for small setups. See the examples section for such a setup. + --verify-x509-name args Accept connections only if a host's X.509 name is equal to **name.** The remote host must also pass all other tests of verification.
Rest looks good. Maybe the typ0 can be fixed on the fly upon commit. In any case, this patch has to wait for the others before being merged.
Signature · 1 line
Antonio Quartulli
[Openvpn-devel] [PATCH applied] Re: Document the simple self-signed certificate setup in examples
In reply to Arne SchwabeYour patch has been applied to the master branch.
commit 26117a82d70dbd90f2260dd9895620394f040239
Author: Arne Schwabe Date: Tue Sep 8 17:41:57 2020 +0200
Document the simple self-signed certificate setup in examples
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg20904.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering