From 024120f8ea3e3faab4d87a2f083c3da16e15b91a Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 10:46:56 +0100 Subject: [PATCH 1/8] tls-eap: Only servers conclude EAP method after processing packets As client with older TLS versions, we have to ack the receipt of the server's Finished message instead. Fixes: 083f38259c79 ("tls-eap: Conclude EAP method also after processing packets") --- src/libtls/tls_eap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtls/tls_eap.c b/src/libtls/tls_eap.c index 196cf92fe..a784c4b47 100644 --- a/src/libtls/tls_eap.c +++ b/src/libtls/tls_eap.c @@ -394,7 +394,7 @@ METHOD(tls_eap_t, process, status_t, switch (status) { case INVALID_STATE: - if (this->tls->is_complete(this->tls)) + if (this->is_server && this->tls->is_complete(this->tls)) { return SUCCESS; } From d5606ec350fed1366aa17958735af2aa6f3e8c02 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 12:01:02 +0100 Subject: [PATCH 2/8] testing: Adapt some checks as SHA-384 is now preferred for TLS signatures --- testing/tests/ikev2/rw-eap-tls-only/evaltest.dat | 2 +- testing/tests/swanctl/rw-eap-tls-only/evaltest.dat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/tests/ikev2/rw-eap-tls-only/evaltest.dat b/testing/tests/ikev2/rw-eap-tls-only/evaltest.dat index 2c1b69ed5..100919a05 100644 --- a/testing/tests/ikev2/rw-eap-tls-only/evaltest.dat +++ b/testing/tests/ikev2/rw-eap-tls-only/evaltest.dat @@ -1,6 +1,6 @@ carol::cat /var/log/daemon.log::server requested EAP_TLS authentication::YES carol::cat /var/log/daemon.log::allow mutual EAP-only authentication::YES -carol::cat /var/log/daemon.log::negotiated TLS 1.2 using suite TLS_DHE_RSA_WITH_AES_128_GCM_SHA256::YES +carol::cat /var/log/daemon.log::negotiated TLS 1.2 using suite TLS_DHE_RSA_WITH_AES_256_GCM_SHA384::YES carol::cat /var/log/daemon.log::authentication of 'C=CH, O=strongSwan Project, CN=moon.strongswan.org' with EAP successful::YES moon:: cat /var/log/daemon.log::authentication of 'C=CH, O=strongSwan Project, OU=Research, CN=carol@strongswan.org' with EAP successful::YES moon:: ipsec status 2> /dev/null::rw-eap.*ESTABLISHED::YES diff --git a/testing/tests/swanctl/rw-eap-tls-only/evaltest.dat b/testing/tests/swanctl/rw-eap-tls-only/evaltest.dat index 48a706d9d..c9f346293 100644 --- a/testing/tests/swanctl/rw-eap-tls-only/evaltest.dat +++ b/testing/tests/swanctl/rw-eap-tls-only/evaltest.dat @@ -1,6 +1,6 @@ carol::cat /var/log/daemon.log::server requested EAP_TLS authentication::YES carol::cat /var/log/daemon.log::allow mutual EAP-only authentication::YES -carol::cat /var/log/daemon.log::negotiated TLS 1.2 using suite TLS_DHE_RSA_WITH_AES_128_GCM_SHA256::YES +carol::cat /var/log/daemon.log::negotiated TLS 1.2 using suite TLS_DHE_RSA_WITH_AES_256_GCM_SHA384::YES carol::cat /var/log/daemon.log::authentication of 'C=CH, O=strongSwan Project, CN=moon.strongswan.org' with EAP successful::YES moon:: cat /var/log/daemon.log::authentication of 'C=CH, O=strongSwan Project, OU=Research, CN=carol@strongswan.org' with EAP successful::YES carol::ping -c 1 PH_IP_ALICE::64 bytes from PH_IP_ALICE: icmp_.eq=1::YES From 4b7cfb252e583c9ef46ebf5a569faa53cb747a8d Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 12:31:17 +0100 Subject: [PATCH 3/8] tls-server: Use subject DN as peer identity if it was ID_ANY To request client authentication if we don't know the client's identity, it's possible to use ID_ANY. However, if we don't change the identity get_peer_id() would still report ID_ANY after the authentication. --- src/libtls/tls_server.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libtls/tls_server.c b/src/libtls/tls_server.c index 687fd0ce2..247b9f636 100644 --- a/src/libtls/tls_server.c +++ b/src/libtls/tls_server.c @@ -729,6 +729,12 @@ static status_t process_certificate(private_tls_server_t *this, DBG1(DBG_TLS, "received TLS peer certificate '%Y'", cert->get_subject(cert)); first = FALSE; + if (this->peer && this->peer->get_type(this->peer) == ID_ANY) + { + this->peer->destroy(this->peer); + this->peer = cert->get_subject(cert); + this->peer = this->peer->clone(this->peer); + } } else { From 602947d48acdb1cfb4835a654721fb040ccc8101 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 12:34:29 +0100 Subject: [PATCH 4/8] pt-tls-server: Explicitly request client authentication if necessary The PT_TLS_AUTH_TLS_OR_SASL case currently can't be implemented properly as TLS authentication will be enforced if a client identity is configured on the TLS server socket. --- src/libpttls/pt_tls_server.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libpttls/pt_tls_server.c b/src/libpttls/pt_tls_server.c index 1ad6165f6..ba217aa9b 100644 --- a/src/libpttls/pt_tls_server.c +++ b/src/libpttls/pt_tls_server.c @@ -524,6 +524,18 @@ pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd, pt_tls_auth_t auth, tnccs_t *tnccs) { private_pt_tls_server_t *this; + identification_t *client = NULL; + + switch (auth) + { + case PT_TLS_AUTH_TLS: + case PT_TLS_AUTH_TLS_OR_SASL: + case PT_TLS_AUTH_TLS_AND_SASL: + client = identification_create_from_encoding(ID_ANY, chunk_empty); + break; + default: + break; + } INIT(this, .public = { @@ -532,12 +544,14 @@ pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd, .destroy = _destroy, }, .state = PT_TLS_SERVER_VERSION, - .tls = tls_socket_create(TRUE, server, NULL, fd, NULL, TLS_UNSPEC, + .tls = tls_socket_create(TRUE, server, client, fd, NULL, TLS_UNSPEC, TLS_UNSPEC, FALSE), .tnccs = (tls_t*)tnccs, .auth = auth, ); + DESTROY_IF(client); + if (!this->tls) { this->tnccs->destroy(this->tnccs); From 11a4687930f4ea9e95ab75d2b40719d731f2f140 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 15:03:29 +0100 Subject: [PATCH 5/8] libtls: Add control flags and replace GENERIC_NULLOK purpose with one --- scripts/tls_test.c | 4 ++-- src/libcharon/plugins/eap_peap/eap_peap.c | 2 +- src/libcharon/plugins/eap_tls/eap_tls.c | 2 +- src/libcharon/plugins/eap_ttls/eap_ttls.c | 2 +- .../plugins/tnc_ifmap/tnc_ifmap_soap.c | 2 +- src/libpttls/pt_tls_client.c | 2 +- src/libpttls/pt_tls_server.c | 2 +- src/libtls/tests/suites/test_socket.c | 6 +++-- src/libtls/tls.c | 17 ++++++++++++-- src/libtls/tls.h | 22 ++++++++++++++++--- src/libtls/tls_crypto.c | 12 +++++----- src/libtls/tls_socket.c | 16 +++----------- src/libtls/tls_socket.h | 4 ++-- 13 files changed, 57 insertions(+), 36 deletions(-) diff --git a/scripts/tls_test.c b/scripts/tls_test.c index 5ee7e3714..4a9acbb49 100644 --- a/scripts/tls_test.c +++ b/scripts/tls_test.c @@ -131,7 +131,7 @@ static int run_client(host_t *host, identification_t *server, return 1; } tls = tls_socket_create(FALSE, server, client, fd, cache, min_version, - max_version, TRUE); + max_version, TLS_FLAG_ENCRYPTION_OPTIONAL); if (!tls) { close(fd); @@ -190,7 +190,7 @@ static int serve(host_t *host, identification_t *server, identification_t *clien DBG1(DBG_TLS, "%#H connected", host); tls = tls_socket_create(TRUE, server, client, cfd, cache, min_version, - max_version, TRUE); + max_version, TLS_FLAG_ENCRYPTION_OPTIONAL); if (!tls) { close(fd); diff --git a/src/libcharon/plugins/eap_peap/eap_peap.c b/src/libcharon/plugins/eap_peap/eap_peap.c index 073af8dc0..1328449ec 100644 --- a/src/libcharon/plugins/eap_peap/eap_peap.c +++ b/src/libcharon/plugins/eap_peap/eap_peap.c @@ -173,7 +173,7 @@ static eap_peap_t *eap_peap_create(private_eap_peap_t * this, include_length = lib->settings->get_bool(lib->settings, "%s.plugins.eap-peap.include_length", FALSE, lib->ns); tls = tls_create(is_server, server, peer, TLS_PURPOSE_EAP_PEAP, - application, NULL); + application, NULL, 0); this->tls_eap = tls_eap_create(EAP_PEAP, tls, frag_size, max_msg_count, include_length); if (!this->tls_eap) diff --git a/src/libcharon/plugins/eap_tls/eap_tls.c b/src/libcharon/plugins/eap_tls/eap_tls.c index 79e87dc89..4283aa025 100644 --- a/src/libcharon/plugins/eap_tls/eap_tls.c +++ b/src/libcharon/plugins/eap_tls/eap_tls.c @@ -158,7 +158,7 @@ static eap_tls_t *eap_tls_create(identification_t *server, lib->ns); include_length = lib->settings->get_bool(lib->settings, "%s.plugins.eap-tls.include_length", TRUE, lib->ns); - tls = tls_create(is_server, server, peer, TLS_PURPOSE_EAP_TLS, NULL, NULL); + tls = tls_create(is_server, server, peer, TLS_PURPOSE_EAP_TLS, NULL, NULL, 0); this->tls_eap = tls_eap_create(EAP_TLS, tls, frag_size, max_msg_count, include_length); if (!this->tls_eap) diff --git a/src/libcharon/plugins/eap_ttls/eap_ttls.c b/src/libcharon/plugins/eap_ttls/eap_ttls.c index 97dbe1890..c56eb01d3 100644 --- a/src/libcharon/plugins/eap_ttls/eap_ttls.c +++ b/src/libcharon/plugins/eap_ttls/eap_ttls.c @@ -170,7 +170,7 @@ static eap_ttls_t *eap_ttls_create(identification_t *server, include_length = lib->settings->get_bool(lib->settings, "%s.plugins.eap-ttls.include_length", TRUE, lib->ns); tls = tls_create(is_server, server, peer, TLS_PURPOSE_EAP_TTLS, - application, NULL); + application, NULL, 0); this->tls_eap = tls_eap_create(EAP_TTLS, tls, frag_size, max_msg_count, include_length); if (!this->tls_eap) diff --git a/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_soap.c b/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_soap.c index 4937f32a2..863d13ccb 100644 --- a/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_soap.c +++ b/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_soap.c @@ -877,7 +877,7 @@ static bool soap_init(private_tnc_ifmap_soap_t *this) /* open TLS socket */ this->tls = tls_socket_create(FALSE, server_id, client_id, this->fd, - NULL, TLS_UNSPEC, TLS_UNSPEC, FALSE); + NULL, TLS_UNSPEC, TLS_UNSPEC, 0); if (!this->tls) { DBG1(DBG_TNC, "creating TLS socket failed"); diff --git a/src/libpttls/pt_tls_client.c b/src/libpttls/pt_tls_client.c index b7fc4c70d..312078fc1 100644 --- a/src/libpttls/pt_tls_client.c +++ b/src/libpttls/pt_tls_client.c @@ -85,7 +85,7 @@ static bool make_connection(private_pt_tls_client_t *this) } this->tls = tls_socket_create(FALSE, this->server, this->client, fd, - NULL, TLS_UNSPEC, TLS_UNSPEC, FALSE); + NULL, TLS_UNSPEC, TLS_UNSPEC, 0); if (!this->tls) { close(fd); diff --git a/src/libpttls/pt_tls_server.c b/src/libpttls/pt_tls_server.c index ba217aa9b..d59240334 100644 --- a/src/libpttls/pt_tls_server.c +++ b/src/libpttls/pt_tls_server.c @@ -545,7 +545,7 @@ pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd, }, .state = PT_TLS_SERVER_VERSION, .tls = tls_socket_create(TRUE, server, client, fd, NULL, TLS_UNSPEC, - TLS_UNSPEC, FALSE), + TLS_UNSPEC, 0), .tnccs = (tls_t*)tnccs, .auth = auth, ); diff --git a/src/libtls/tests/suites/test_socket.c b/src/libtls/tests/suites/test_socket.c index 4707f5849..9e26e91e4 100644 --- a/src/libtls/tests/suites/test_socket.c +++ b/src/libtls/tests/suites/test_socket.c @@ -412,7 +412,8 @@ static job_requeue_t serve_echo(echo_server_config_t *config) } tls = tls_socket_create(TRUE, server, client, cfd, NULL, - TLS_SUPPORTED_MIN, config->version, TRUE); + TLS_SUPPORTED_MIN, config->version, + TLS_FLAG_ENCRYPTION_OPTIONAL); ck_assert(tls != NULL); while (TRUE) @@ -488,7 +489,8 @@ static void run_echo_client(echo_server_config_t *config) ck_assert(connect(fd, host->get_sockaddr(host), *host->get_sockaddr_len(host)) != -1); tls = tls_socket_create(FALSE, server, client, fd, NULL, - TLS_SUPPORTED_MIN, config->version, TRUE); + TLS_SUPPORTED_MIN, config->version, + TLS_FLAG_ENCRYPTION_OPTIONAL); ck_assert(tls != NULL); wr = rd = 0; diff --git a/src/libtls/tls.c b/src/libtls/tls.c index ae14213a0..a44134696 100644 --- a/src/libtls/tls.c +++ b/src/libtls/tls.c @@ -202,6 +202,11 @@ struct private_tls_t { */ tls_purpose_t purpose; + /** + * Flags for this TLS stack + */ + tls_flag_t flags; + /** * TLS record protection layer */ @@ -542,6 +547,12 @@ METHOD(tls_t, get_purpose, tls_purpose_t, return this->purpose; } +METHOD(tls_t, get_flags, tls_flag_t, + private_tls_t *this) +{ + return this->flags; +} + METHOD(tls_t, is_complete, bool, private_tls_t *this) { @@ -590,7 +601,8 @@ METHOD(tls_t, destroy, void, */ tls_t *tls_create(bool is_server, identification_t *server, identification_t *peer, tls_purpose_t purpose, - tls_application_t *application, tls_cache_t *cache) + tls_application_t *application, tls_cache_t *cache, + tls_flag_t flags) { private_tls_t *this; @@ -600,7 +612,6 @@ tls_t *tls_create(bool is_server, identification_t *server, case TLS_PURPOSE_EAP_TTLS: case TLS_PURPOSE_EAP_PEAP: case TLS_PURPOSE_GENERIC: - case TLS_PURPOSE_GENERIC_NULLOK: break; default: return NULL; @@ -617,6 +628,7 @@ tls_t *tls_create(bool is_server, identification_t *server, .get_version_min = _get_version_min, .set_version = _set_version, .get_purpose = _get_purpose, + .get_flags = _get_flags, .is_complete = _is_complete, .get_eap_msk = _get_eap_msk, .get_auth = _get_auth, @@ -625,6 +637,7 @@ tls_t *tls_create(bool is_server, identification_t *server, .is_server = is_server, .application = application, .purpose = purpose, + .flags = flags, ); lib->settings->add_fallback(lib->settings, "%s.tls", "libtls", lib->ns); diff --git a/src/libtls/tls.h b/src/libtls/tls.h index 9de042b26..0d9e1ff0c 100644 --- a/src/libtls/tls.h +++ b/src/libtls/tls.h @@ -40,6 +40,7 @@ typedef enum tls_version_t tls_version_t; typedef enum tls_content_type_t tls_content_type_t; typedef enum tls_handshake_type_t tls_handshake_type_t; typedef enum tls_purpose_t tls_purpose_t; +typedef enum tls_flag_t tls_flag_t; typedef struct tls_t tls_t; #include @@ -130,8 +131,6 @@ enum tls_purpose_t { TLS_PURPOSE_EAP_PEAP, /** non-EAP TLS */ TLS_PURPOSE_GENERIC, - /** non-EAP TLS accepting NULL encryption */ - TLS_PURPOSE_GENERIC_NULLOK, /** EAP binding for TNC */ TLS_PURPOSE_EAP_TNC }; @@ -202,6 +201,14 @@ enum tls_name_type_t { TLS_NAME_TYPE_HOST_NAME = 0, }; +/** + * Flags that control the behavior of the stack + */ +enum tls_flag_t { + /** set if cipher suites with null encryption are acceptable */ + TLS_FLAG_ENCRYPTION_OPTIONAL = 1, +}; + /** * Enum names for tls_extension_t */ @@ -318,6 +325,13 @@ struct tls_t { */ tls_purpose_t (*get_purpose)(tls_t *this); + /** + * Get the flags controlling this TLS stack instance. + * + * @return flags given during construction + */ + tls_flag_t (*get_flags)(tls_t *this); + /** * Check if TLS negotiation completed successfully. * @@ -359,10 +373,12 @@ void libtls_init(void); * @param purpose purpose this TLS stack instance is used for * @param application higher layer application or NULL if none * @param cache session cache to use, or NULL + * @param flags flags that control the behavior of the TLS stack * @return TLS stack */ tls_t *tls_create(bool is_server, identification_t *server, identification_t *peer, tls_purpose_t purpose, - tls_application_t *application, tls_cache_t *cache); + tls_application_t *application, tls_cache_t *cache, + tls_flag_t flags); #endif /** TLS_H_ @}*/ diff --git a/src/libtls/tls_crypto.c b/src/libtls/tls_crypto.c index d3f187def..d94dde9b6 100644 --- a/src/libtls/tls_crypto.c +++ b/src/libtls/tls_crypto.c @@ -1116,22 +1116,22 @@ static void build_cipher_suite_list(private_tls_crypto_t *this) { suite_algs_t suites[countof(suite_algs)]; tls_version_t min_version, max_version, new_min_version, new_max_version; - bool require_encryption; + bool require_encryption = TRUE; int count = 0, i; switch (this->tls->get_purpose(this->tls)) { case TLS_PURPOSE_EAP_TLS: - case TLS_PURPOSE_GENERIC_NULLOK: require_encryption = FALSE; break; - case TLS_PURPOSE_EAP_PEAP: - case TLS_PURPOSE_EAP_TTLS: case TLS_PURPOSE_GENERIC: - require_encryption = TRUE; + if (this->tls->get_flags(this->tls) & TLS_FLAG_ENCRYPTION_OPTIONAL) + { + require_encryption = FALSE; + } break; default: - return; + break; } min_version = this->tls->get_version_min(this->tls); diff --git a/src/libtls/tls_socket.c b/src/libtls/tls_socket.c index 8b427dd1a..75f146929 100644 --- a/src/libtls/tls_socket.c +++ b/src/libtls/tls_socket.c @@ -423,10 +423,9 @@ METHOD(tls_socket_t, destroy, void, tls_socket_t *tls_socket_create(bool is_server, identification_t *server, identification_t *peer, int fd, tls_cache_t *cache, tls_version_t min_version, - tls_version_t max_version, bool nullok) + tls_version_t max_version, tls_flag_t flags) { private_tls_socket_t *this; - tls_purpose_t purpose; INIT(this, .public = { @@ -448,17 +447,8 @@ tls_socket_t *tls_socket_create(bool is_server, identification_t *server, .fd = fd, ); - if (nullok) - { - purpose = TLS_PURPOSE_GENERIC_NULLOK; - } - else - { - purpose = TLS_PURPOSE_GENERIC; - } - - this->tls = tls_create(is_server, server, peer, purpose, - &this->app.application, cache); + this->tls = tls_create(is_server, server, peer, TLS_PURPOSE_GENERIC, + &this->app.application, cache, flags); if (!this->tls || !this->tls->set_version(this->tls, min_version, max_version)) { diff --git a/src/libtls/tls_socket.h b/src/libtls/tls_socket.h index 08ccbd287..944967632 100644 --- a/src/libtls/tls_socket.h +++ b/src/libtls/tls_socket.h @@ -108,12 +108,12 @@ struct tls_socket_t { * @param cache session cache to use, or NULL * @param min_version minimum TLS version to negotiate or TLS_UNSPEC * @param max_version maximum TLS version to negotiate or TLS_UNSPEC - * @param nullok accept NULL encryption ciphers + * @param flags flags controlling the TLS stack * @return TLS socket wrapper */ tls_socket_t *tls_socket_create(bool is_server, identification_t *server, identification_t *peer, int fd, tls_cache_t *cache, tls_version_t min_version, - tls_version_t max_version, bool nullok); + tls_version_t max_version, tls_flag_t flags); #endif /** TLS_SOCKET_H_ @}*/ From 760f3b730fa69a1f8fc5075fcbb34f037d313b16 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 15:10:42 +0100 Subject: [PATCH 6/8] tls-server: Add flag that makes client authentication optional This allows clients to send an empty certificate payload if the server sent a certificate request. If an identity was set previously, it will be reset so get_peer_id() may be used to check if the client was authenticated. --- src/libtls/tls.h | 2 ++ src/libtls/tls_server.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libtls/tls.h b/src/libtls/tls.h index 0d9e1ff0c..f2b79361d 100644 --- a/src/libtls/tls.h +++ b/src/libtls/tls.h @@ -207,6 +207,8 @@ enum tls_name_type_t { enum tls_flag_t { /** set if cipher suites with null encryption are acceptable */ TLS_FLAG_ENCRYPTION_OPTIONAL = 1, + /** set if client authentication is optional even if cert req sent */ + TLS_FLAG_CLIENT_AUTH_OPTIONAL = 2, }; /** diff --git a/src/libtls/tls_server.c b/src/libtls/tls_server.c index 247b9f636..f067549e3 100644 --- a/src/libtls/tls_server.c +++ b/src/libtls/tls_server.c @@ -705,9 +705,18 @@ static status_t process_certificate(private_tls_server_t *this, certs = bio_reader_create(data); if (!certs->remaining(certs)) { - DBG1(DBG_TLS, "no certificate sent by peer"); - this->alert->add(this->alert, TLS_FATAL, TLS_DECODE_ERROR); - return NEED_MORE; + if (this->tls->get_flags(this->tls) & TLS_FLAG_CLIENT_AUTH_OPTIONAL) + { + /* client authentication is not required so we clear the identity */ + DESTROY_IF(this->peer); + this->peer = NULL; + } + else + { + DBG1(DBG_TLS, "no certificate sent by peer"); + this->alert->add(this->alert, TLS_FATAL, TLS_DECODE_ERROR); + return NEED_MORE; + } } while (certs->remaining(certs)) { From 82116dba66a5a4087bb0302f33de154c68c1b2ab Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 15:36:59 +0100 Subject: [PATCH 7/8] tls-test: Add option to make client authentication optional --- scripts/tls_test.c | 50 +++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/scripts/tls_test.c b/scripts/tls_test.c index 4a9acbb49..554bec341 100644 --- a/scripts/tls_test.c +++ b/scripts/tls_test.c @@ -38,7 +38,7 @@ static void usage(FILE *out, char *cmd) { fprintf(out, "usage:\n"); fprintf(out, " %s --connect
--port [--key ] [--cacert ]+ [--times ]\n", cmd); - fprintf(out, " %s --listen
--port --key --cert [--cacert ]+ [--times ]\n", cmd); + fprintf(out, " %s --listen
--port --key --cert [--cacert ]+ [--auth-optional] [--times ]\n", cmd); fprintf(out, "\n"); fprintf(out, "options:\n"); fprintf(out, " --help print help and exit\n"); @@ -48,6 +48,7 @@ static void usage(FILE *out, char *cmd) fprintf(out, " --cert certificate to authenticate itself\n"); fprintf(out, " --key private key to authenticate itself\n"); fprintf(out, " --cacert certificate to verify other peer\n"); + fprintf(out, " --auth-optional don't enforce client authentication\n"); fprintf(out, " --times specify the amount of repeated connection establishments\n"); fprintf(out, " --ipv4 use IPv4\n"); fprintf(out, " --ipv6 use IPv6\n"); @@ -109,7 +110,8 @@ static identification_t *find_client_id() */ static int run_client(host_t *host, identification_t *server, identification_t *client, int times, tls_cache_t *cache, - tls_version_t min_version, tls_version_t max_version) + tls_version_t min_version, tls_version_t max_version, + tls_flag_t flags) { tls_socket_t *tls; int fd, res; @@ -131,7 +133,7 @@ static int run_client(host_t *host, identification_t *server, return 1; } tls = tls_socket_create(FALSE, server, client, fd, cache, min_version, - max_version, TLS_FLAG_ENCRYPTION_OPTIONAL); + max_version, flags); if (!tls) { close(fd); @@ -153,7 +155,7 @@ static int run_client(host_t *host, identification_t *server, */ static int serve(host_t *host, identification_t *server, identification_t *client, int times, tls_cache_t *cache, tls_version_t min_version, - tls_version_t max_version) + tls_version_t max_version, tls_flag_t flags) { tls_socket_t *tls; int fd, cfd; @@ -190,7 +192,7 @@ static int serve(host_t *host, identification_t *server, identification_t *clien DBG1(DBG_TLS, "%#H connected", host); tls = tls_socket_create(TRUE, server, client, cfd, cache, min_version, - max_version, TLS_FLAG_ENCRYPTION_OPTIONAL); + max_version, flags); if (!tls) { close(fd); @@ -301,6 +303,7 @@ int main(int argc, char *argv[]) int port = 0, times = -1, res, family = AF_UNSPEC; identification_t *server, *client = NULL; tls_version_t min_version = TLS_SUPPORTED_MIN, max_version = TLS_SUPPORTED_MAX; + tls_flag_t flags = TLS_FLAG_ENCRYPTION_OPTIONAL; tls_cache_t *cache; host_t *host; @@ -309,20 +312,21 @@ int main(int argc, char *argv[]) while (TRUE) { struct option long_opts[] = { - {"help", no_argument, NULL, 'h' }, - {"connect", required_argument, NULL, 'c' }, - {"listen", required_argument, NULL, 'l' }, - {"port", required_argument, NULL, 'p' }, - {"cert", required_argument, NULL, 'x' }, - {"key", required_argument, NULL, 'k' }, - {"cacert", required_argument, NULL, 'f' }, - {"times", required_argument, NULL, 't' }, - {"ipv4", no_argument, NULL, '4' }, - {"ipv6", no_argument, NULL, '6' }, - {"min-version", required_argument, NULL, 'm' }, - {"max-version", required_argument, NULL, 'M' }, - {"version", required_argument, NULL, 'v' }, - {"debug", required_argument, NULL, 'd' }, + {"help", no_argument, NULL, 'h' }, + {"connect", required_argument, NULL, 'c' }, + {"listen", required_argument, NULL, 'l' }, + {"port", required_argument, NULL, 'p' }, + {"cert", required_argument, NULL, 'x' }, + {"key", required_argument, NULL, 'k' }, + {"cacert", required_argument, NULL, 'f' }, + {"times", required_argument, NULL, 't' }, + {"ipv4", no_argument, NULL, '4' }, + {"ipv6", no_argument, NULL, '6' }, + {"min-version", required_argument, NULL, 'm' }, + {"max-version", required_argument, NULL, 'M' }, + {"version", required_argument, NULL, 'v' }, + {"auth-optional", no_argument, NULL, 'n' }, + {"debug", required_argument, NULL, 'd' }, {0,0,0,0 } }; switch (getopt_long(argc, argv, "", long_opts, NULL)) @@ -402,6 +406,9 @@ int main(int argc, char *argv[]) } max_version = min_version; continue; + case 'n': + flags |= TLS_FLAG_CLIENT_AUTH_OPTIONAL; + continue; default: usage(stderr, argv[0]); return 1; @@ -423,14 +430,15 @@ int main(int argc, char *argv[]) cache = tls_cache_create(100, 30); if (listen) { - res = serve(host, server, client, times, cache, min_version, max_version); + res = serve(host, server, client, times, cache, min_version, + max_version, flags); } else { DESTROY_IF(client); client = find_client_id(); res = run_client(host, server, client, times, cache, min_version, - max_version); + max_version, flags); DESTROY_IF(client); } cache->destroy(cache); From 48f4f9f66715ef9ed3e674a777b81cef32b6f44c Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 18 Feb 2021 15:41:52 +0100 Subject: [PATCH 8/8] pt-tls-server: Make TLS client authentication optional as appropriate --- src/libpttls/pt_tls_server.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libpttls/pt_tls_server.c b/src/libpttls/pt_tls_server.c index d59240334..76180c8a4 100644 --- a/src/libpttls/pt_tls_server.c +++ b/src/libpttls/pt_tls_server.c @@ -525,11 +525,14 @@ pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd, { private_pt_tls_server_t *this; identification_t *client = NULL; + tls_flag_t flags = 0; switch (auth) { - case PT_TLS_AUTH_TLS: case PT_TLS_AUTH_TLS_OR_SASL: + flags |= TLS_FLAG_CLIENT_AUTH_OPTIONAL; + /* fall-through */ + case PT_TLS_AUTH_TLS: case PT_TLS_AUTH_TLS_AND_SASL: client = identification_create_from_encoding(ID_ANY, chunk_empty); break; @@ -545,7 +548,7 @@ pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd, }, .state = PT_TLS_SERVER_VERSION, .tls = tls_socket_create(TRUE, server, client, fd, NULL, TLS_UNSPEC, - TLS_UNSPEC, 0), + TLS_UNSPEC, flags), .tnccs = (tls_t*)tnccs, .auth = auth, );