From patchwork Mon Jan 25 01:56:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1572 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id yG3aHDzADmCQLAAAIUCqbw (envelope-from ) for ; Mon, 25 Jan 2021 07:57:32 -0500 Received: from proxy19.mail.ord1d.rsapps.net ([172.30.191.6]) by director9.mail.ord1d.rsapps.net with LMTP id IMGnHDzADmCcYAAAalYnBA (envelope-from ) for ; Mon, 25 Jan 2021 07:57:32 -0500 Received: from smtp5.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy19.mail.ord1d.rsapps.net with LMTPS id QL9hHDzADmDPaQAAyH2SIw (envelope-from ) for ; Mon, 25 Jan 2021 07:57:32 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp5.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: e2a66e64-5f0c-11eb-ae2d-a4badb0b200d-1-1 Received: from [216.105.38.7] ([216.105.38.7:41038] helo=lists.sourceforge.net) by smtp5.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id F1/21-14465-B30CE006; Mon, 25 Jan 2021 07:57:31 -0500 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1l41QD-0004qo-2j; Mon, 25 Jan 2021 12:56:45 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l41QC-0004qN-1E for openvpn-devel@lists.sourceforge.net; Mon, 25 Jan 2021 12:56:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JU5KSF1nl/Mzi+aalH2FbM4B8IA9ngx3r1lztOVqbyg=; b=BCKq2282697xhvTxKYUyq+83vO eIOIUlyGETxG10GBjOSGlOd8FoUdBdg+m+khbExwOV6cuZ2cVurLJS4caUsAxL0+fCiiMBzR9cZfX J7fN8cILWgoU/cFP0Oat7FL8MqtEPBG3y1fyxpEm2Kg7+29LK6L7srf7Bux9m8VtGEvA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=JU5KSF1nl/Mzi+aalH2FbM4B8IA9ngx3r1lztOVqbyg=; b=QmZ8io4NwsTJ5T8QbzfboSD+8+ g4502KuIrh64RdScGOnCsxNCEVaU6uozRAkHvtsFLv7WpTZinSMcGoPmsPE7TZwbCgXMQv52M1nGN gOVGniykxty0Yi33q5VW32nULuSy+AJfU31E1qAsaWJqV7g3KROGzdZbNX1IM/daYlVc=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1l41Q9-006gWa-9c for openvpn-devel@lists.sourceforge.net; Mon, 25 Jan 2021 12:56:43 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1l41Px-0007XC-7x for openvpn-devel@lists.sourceforge.net; Mon, 25 Jan 2021 13:56:29 +0100 Received: (nullmailer pid 30432 invoked by uid 10006); Mon, 25 Jan 2021 12:56:29 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Mon, 25 Jan 2021 13:56:25 +0100 Message-Id: <20210125125628.30364-9-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210125125628.30364-1-arne@rfc2549.org> References: <20210125125628.30364-1-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1l41Q9-006gWa-9c Subject: [Openvpn-devel] [PATCH v2 08/11] Allow pending auth to be send from a auth plugin X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Patch v2: removed change that slipped into this patch and belongs into the next Signed-off-by: Arne Schwabe Acked-By: David Sommerseth --- doc/man-sections/generic-options.rst | 3 +- include/openvpn-plugin.h.in | 8 ++ src/openvpn/ssl.c | 2 +- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 161 +++++++++++++++++++++++++-- src/openvpn/ssl_verify.h | 2 +- 6 files changed, 162 insertions(+), 15 deletions(-) diff --git a/doc/man-sections/generic-options.rst b/doc/man-sections/generic-options.rst index d5f08839..32eeda68 100644 --- a/doc/man-sections/generic-options.rst +++ b/doc/man-sections/generic-options.rst @@ -409,7 +409,8 @@ which mode OpenVPN is configured as. * :code:`OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY` plug-in hooks returns success/failure via :code:`auth_control_file` when using deferred auth - method + method and pending authentification via :code:`pending_auth_file`. + * :code:`OPENVPN_PLUGIN_ENABLE_PF` plugin hook to pass filtering rules via ``pf_file`` diff --git a/include/openvpn-plugin.h.in b/include/openvpn-plugin.h.in index 64b20886..bb561643 100644 --- a/include/openvpn-plugin.h.in +++ b/include/openvpn-plugin.h.in @@ -567,6 +567,14 @@ OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC(openvpn_plugin_op * auth_control_file/client_connect_deferred_file * in the environmental variable list (envp). * + * Additionally the auth_pending_file can be written, which causes the openvpn + * server to send a pending auth request to the client. See doc/management.txt + * for more details on this authentication mechanism. The format of the + * auth_pending_file is + * line 1: timeout in seconds + * line 2: Pending auth method the client needs to support (e.g. openurl) + * line 3: EXTRA (e.g. OPEN_URL:http://www.example.com) + * * In addition the OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER and * OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 are called when OpenVPN tries to * get the deferred result. For a V2 call implementing this function is diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index f59b409f..b8e77f0e 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -993,7 +993,7 @@ key_state_free(struct key_state *ks, bool clear) packet_id_free(&ks->crypto_options.packet_id); #ifdef PLUGIN_DEF_AUTH - key_state_rm_auth_control_file(ks); + key_state_rm_auth_control_files(ks); #endif if (clear) diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index bf7f9ba3..b493cbb7 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -215,6 +215,7 @@ struct key_state unsigned int auth_control_status; time_t acf_last_mod; char *auth_control_file; + char *auth_pending_file; }; /** Control channel wrapping (--tls-auth/--tls-crypt) context */ diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index e0ef399f..b9647c1a 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -865,13 +865,129 @@ man_def_auth_test(const struct key_state *ks) } #endif /* ifdef ENABLE_MANAGEMENT */ +/** + * Removes auth_pending file from the file system + * and key_state structure + */ +static void +key_state_rm_auth_pending_file(struct key_state *ks) +{ + if (ks && ks->auth_pending_file) + { + platform_unlink(ks->auth_pending_file); + free(ks->auth_pending_file); + ks->auth_pending_file = NULL; + } +} -/* - * auth_control_file functions +/** + * Check peer_info if the client supports the requested pending auth method + */ +static bool +check_auth_pending_method(const char *peer_info, const char *method) +{ + struct gc_arena gc = gc_new(); + + char *iv_sso = extract_var_peer_info(peer_info, "IV_SSO=", &gc); + if (!iv_sso) + { + gc_free(&gc); + return false; + } + + const char *client_method = strtok(iv_sso, ","); + bool supported = false; + + while (client_method) + { + if (0 == strcmp(client_method, method)) + { + supported = true; + break; + } + client_method = strtok(NULL, ":"); + } + + gc_free(&gc); + return supported; +} + +/** + * Checks if the deferred state should also send auth pending + * request to the client. Also removes the auth_pending control file + * + * @returns true if file was either processed sucessfully or did not + * exist at all + * @returns false The file had an invlaid format or another error occured */ +static bool +key_state_check_auth_pending_file(struct key_state *ks, + struct tls_multi *multi) +{ + bool ret = true; + if (ks && ks->auth_pending_file) + { + struct buffer_list *lines = buffer_list_file(ks->auth_pending_file, + 1024); + if (lines && lines->head) + { + /* Must have at least three lines. further lines are ignored for + * forward compatibility */ + if (!lines->head || !lines->head->next || !lines->head->next->next) + { + msg(M_WARN, "auth pending control file is not at least " + "three lines long."); + buffer_list_free(lines); + return false; + } + struct buffer *timeout_buf = &lines->head->buf; + struct buffer *iv_buf = &lines->head->next->buf; + struct buffer *extra_buf = &lines->head->next->next->buf; + + /* Remove newline chars at the end of the lines */ + buf_chomp(timeout_buf); + buf_chomp(iv_buf); + buf_chomp(extra_buf); + + long timeout = strtol(BSTR(timeout_buf), NULL, 10); + if (timeout == 0) + { + msg(M_WARN, "could not parse auth pending file timeout"); + buffer_list_free(lines); + return false; + } + + const char* pending_method = BSTR(iv_buf); + if (!check_auth_pending_method(multi->peer_info, pending_method)) + { + char buf[128]; + openvpn_snprintf(buf, sizeof(buf), + "Authentication failed, required pending auth " + "method '%s' not supported", pending_method); + auth_set_client_reason(multi, buf); + msg(M_INFO, "Client does not supported auth pending method " + "'%s'", pending_method); + ret = false; + } + else + { + send_auth_pending_messages(multi, BSTR(extra_buf), timeout); + } + } + + buffer_list_free(lines); + } + key_state_rm_auth_pending_file(ks); + return ret; +} + +/** + * Removes auth_pending and auth_control files from file system + * and key_state structure + */ void -key_state_rm_auth_control_file(struct key_state *ks) +key_state_rm_auth_control_files(struct key_state *ks) { if (ks && ks->auth_control_file) { @@ -879,23 +995,34 @@ key_state_rm_auth_control_file(struct key_state *ks) free(ks->auth_control_file); ks->auth_control_file = NULL; } + key_state_rm_auth_pending_file(ks); } +/** + * Generates and creates the control files used for deferred authentification + * in the temporary directory. + * + * @return true if file creation was successful + */ static bool -key_state_gen_auth_control_file(struct key_state *ks, const struct tls_options *opt) +key_state_gen_auth_control_files(struct key_state *ks, const struct tls_options *opt) { struct gc_arena gc = gc_new(); - key_state_rm_auth_control_file(ks); + key_state_rm_auth_control_files(ks); const char *acf = platform_create_temp_file(opt->tmp_dir, "acf", &gc); - if (acf) + const char *apf = platform_create_temp_file(opt->tmp_dir, "apf", &gc); + + if (acf && apf) { ks->auth_control_file = string_alloc(acf, NULL); + ks->auth_pending_file = string_alloc(apf, NULL); setenv_str(opt->es, "auth_control_file", ks->auth_control_file); + setenv_str(opt->es, "auth_pending_file", ks->auth_pending_file); } gc_free(&gc); - return acf; + return (acf && apf); } static unsigned int @@ -1140,7 +1267,7 @@ verify_user_pass_plugin(struct tls_session *session, struct tls_multi *multi, setenv_str(session->opt->es, "password", up->password); /* generate filename for deferred auth control file */ - if (!key_state_gen_auth_control_file(ks, session->opt)) + if (!key_state_gen_auth_control_files(ks, session->opt)) { msg(D_TLS_ERRORS, "TLS Auth Error (%s): " "could not create deferred auth control file", __func__); @@ -1150,10 +1277,20 @@ verify_user_pass_plugin(struct tls_session *session, struct tls_multi *multi, /* call command */ retval = plugin_call(session->opt->plugins, OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY, NULL, NULL, session->opt->es); - /* purge auth control filename (and file itself) for non-deferred returns */ - if (retval != OPENVPN_PLUGIN_FUNC_DEFERRED) + if (retval == OPENVPN_PLUGIN_FUNC_DEFERRED) + { + /* Check if we the plugin has written the pending auth control + * file and send the pending auth to the client */ + if(!key_state_check_auth_pending_file(ks, multi)) + { + retval = OPENVPN_PLUGIN_FUNC_ERROR; + key_state_rm_auth_control_files(ks); + } + } + else { - key_state_rm_auth_control_file(ks); + /* purge auth control filename (and file itself) for non-deferred returns */ + key_state_rm_auth_control_files(ks); } setenv_del(session->opt->es, "password"); @@ -1224,7 +1361,7 @@ set_verify_user_pass_env(struct user_pass *up, struct tls_multi *multi, } } -/* +/** * Main username/password verification entry point * * Will set session->ks[KS_PRIMARY].authenticated according to diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h index 7e8b9710..0221e81f 100644 --- a/src/openvpn/ssl_verify.h +++ b/src/openvpn/ssl_verify.h @@ -117,7 +117,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency); * * @param ks The key state the remove the file for */ -void key_state_rm_auth_control_file(struct key_state *ks); +void key_state_rm_auth_control_files(struct key_state *ks); /** * Frees the given set of certificate hashes.