From patchwork Sat Nov 9 04:13:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 895 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id ECT7NMzXxl1kNQAAIUCqbw for ; Sat, 09 Nov 2019 10:14:20 -0500 Received: from proxy4.mail.ord1c.rsapps.net ([172.28.255.1]) by director10.mail.ord1d.rsapps.net with LMTP id +MrLNMzXxl2DKwAApN4f7A ; Sat, 09 Nov 2019 10:14:20 -0500 Received: from smtp35.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy4.mail.ord1c.rsapps.net with LMTP id YElFNMzXxl2BQgAAjcXvpA ; Sat, 09 Nov 2019 10:14:20 -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: smtp35.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: 99d65c28-0303-11ea-992f-5452002f485d-1-1 Received: from [216.105.38.7] ([216.105.38.7:39866] helo=lists.sourceforge.net) by smtp35.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id F3/49-13651-BC7D6CD5; Sat, 09 Nov 2019 10:14:19 -0500 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1iTSQS-0001V2-Sv; Sat, 09 Nov 2019 15:13:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iTSQQ-0001Ua-5c for openvpn-devel@lists.sourceforge.net; Sat, 09 Nov 2019 15:13:18 +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=sOKRiF3d5RmcjBFld9Ys65T+gQZn7qRCA7MVXB5Ri98=; b=Chkxbn8XxYnt7NYa6pFY/sdY/H 26hlIdUYyiQU5jnS2g5phNBPttYv0A9petFU9vTtymkvPLz0gcRT3LFulMh0DZ9xGziXNNJwEYNZJ 43e+fsJkwbgWe2nSLhPVcVIfjENCwuB2wXGn+gkflNfdggtIgL6XEYXVFdJRHyct6Lpc=; 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=sOKRiF3d5RmcjBFld9Ys65T+gQZn7qRCA7MVXB5Ri98=; b=TT9MfOBcOuSoWqow3OJOvgGzPo Alj5pKa/6XH2DsY4akT6njVh4DlkvAhOkCw9NLnY2CCFByVrQtja0OjGdVRiJMFCCs+pcA4r3QEH7 zTKMicA/VY8eYtP3euq1mTtlm75jlKMQsntPImTx7vMyp3U9Asvzs7TkR+trg8fGDVIk=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1iTSQL-009bCc-FK for openvpn-devel@lists.sourceforge.net; Sat, 09 Nov 2019 15:13:18 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iTSQE-000Q0A-UH for openvpn-devel@lists.sourceforge.net; Sat, 09 Nov 2019 16:13:06 +0100 Received: (nullmailer pid 18650 invoked by uid 10006); Sat, 09 Nov 2019 15:13:06 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Sat, 9 Nov 2019 16:13:04 +0100 Message-Id: <20191109151306.18597-3-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191109151306.18597-1-arne@rfc2549.org> References: <20191109151306.18597-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: 1iTSQL-009bCc-FK Subject: [Openvpn-devel] [PATCH v2 3/5] Implement sending response to challenge via CR_RESPONSE 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 When a client announces its support to support text based challenge/response via IV_SOO=cr_text,the client needs to also be able to reply to that response. This adds the "cr-response" management function to be able to do this. The answer should be base64 encoded. Signed-off-by: Arne Schwabe --- doc/management-notes.txt | 8 ++++++++ src/openvpn/init.c | 39 +++++++++++++++++++++++++++++++++++++++ src/openvpn/manage.c | 39 ++++++++++++++++++++++++++++++++++++++- src/openvpn/manage.h | 1 + 4 files changed, 86 insertions(+), 1 deletion(-) diff --git a/doc/management-notes.txt b/doc/management-notes.txt index 17645c1d..e380ca2b 100644 --- a/doc/management-notes.txt +++ b/doc/management-notes.txt @@ -806,6 +806,14 @@ To accept connecting to the host and port directly, use this command: proxy NONE +COMMAND -- cr-response (OpenVPN 2.5 or higher) +------------------------------------------------- +Provides support for sending responses a challenge/response +query via INFOMSG,CR_TEXT. The response should be base64 encoded: + + cr-response SGFsbG8gV2VsdCE= + + COMMAND -- pk-sig (OpenVPN 2.5 or higher, management version > 1) COMMAND -- rsa-sig (OpenVPN 2.3 or higher, management version <= 1) ----------------------------------------------------------------- diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 0bdb0a9c..77c1c23b 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -288,6 +288,44 @@ ce_management_query_proxy(struct context *c) return ret; } +/** + * This method sends a custom control channel message + * + * This will write the control message + * + * command parm1,parm2,.. + * . + * to the control channel. + * + * @param arg The context struct + * @param command The command being sent + * @param parameters the parameters to the command + * @return if sending was successful + */ +static bool +management_callback_send_cc_mesage(void *arg, + const char *command, + const char *parameters) +{ + struct context *c = (struct context *) arg; + size_t len = strlen(command) + 1 + sizeof(parameters) + 1; + if (len > PUSH_BUNDLE_SIZE) + { + return false; + } + + struct gc_arena gc = gc_new(); + struct buffer buf = alloc_buf_gc(len, &gc); + ASSERT(buf_printf(&buf, "%s", command)); + if (parameters) + { + ASSERT(buf_printf(&buf, ",%s", parameters)); + } + bool status = send_control_channel_string(c, BSTR(&buf), D_PUSH); + + gc_free(&gc); + return status; +} static bool management_callback_remote_cmd(void *arg, const char **p) @@ -3990,6 +4028,7 @@ init_management_callback_p2p(struct context *c) cb.show_net = management_show_net_callback; cb.proxy_cmd = management_callback_proxy_cmd; cb.remote_cmd = management_callback_remote_cmd; + cb.send_cc_message = management_callback_send_cc_mesage; #ifdef TARGET_ANDROID cb.network_change = management_callback_network_change; #endif diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 1d97c2b6..8dada6f2 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -75,6 +75,7 @@ man_help(void) msg(M_CLIENT, "auth-retry t : Auth failure retry mode (none,interact,nointeract)."); msg(M_CLIENT, "bytecount n : Show bytes in/out, update every n secs (0=off)."); msg(M_CLIENT, "echo [on|off] [N|all] : Like log, but only show messages in echo buffer."); + msg(M_CLIENT, "cr-response response : Send a challenge response answer via CR_RESPONSE to server"); msg(M_CLIENT, "exit|quit : Close management session."); msg(M_CLIENT, "forget-passwords : Forget passwords entered so far."); msg(M_CLIENT, "help : Print this message."); @@ -779,6 +780,27 @@ man_net(struct management *man) } } +static void +man_send_cc_message(struct management *man, const char *message, const char *parameters) +{ + if (man->persist.callback.send_cc_message) + { + const bool status = (*man->persist.callback.send_cc_message) + (man->persist.callback.arg, message, parameters); + if (status) + { + msg(M_CLIENT, "SUCCESS: command succeeded"); + } + else + { + msg(M_CLIENT, "ERROR: command failed"); + } + } + else + { + msg(M_CLIENT, "ERROR: This command is not supported by the current daemon mode"); + } +} #ifdef ENABLE_PKCS11 static void @@ -1144,7 +1166,15 @@ man_load_stats(struct management *man) } #define MN_AT_LEAST (1<<0) - +/** + * Checks if the correct number of arguments to a management command are present + * and otherwise prints an error and returns false. + * + * @param p pointer to the parameter array + * @param n number of arguments required + * @param flags if MN_AT_LEAST require at least n parameters and not exactly n + * @return Return wether p has n (or at least n) parameters + */ static bool man_need(struct management *man, const char **p, const int n, unsigned int flags) { @@ -1460,6 +1490,13 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha man_query_need_str(man, p[1], p[2]); } } + else if (streq(p[0], "cr-response")) + { + if (man_need (man, p, 1, 0)) + { + man_send_cc_message (man, "CR_RESPONSE", p[1]); + } + } else if (streq(p[0], "net")) { man_net(man); diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index d24abe09..8acc18bf 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -164,6 +164,7 @@ struct management_callback int (*kill_by_addr) (void *arg, const in_addr_t addr, const int port); void (*delete_event) (void *arg, event_t event); int (*n_clients) (void *arg); + bool (*send_cc_message) (void *arg, const char *message, const char *parameter); #ifdef MANAGEMENT_DEF_AUTH bool (*kill_by_cid)(void *arg, const unsigned long cid, const char *kill_msg); bool (*client_auth) (void *arg,