From patchwork Fri May 10 02:11:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 733 X-Patchwork-Delegate: davids@openvpn.net Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id EJCRGTJv1VywZgAAIUCqbw for ; Fri, 10 May 2019 08:31:46 -0400 Received: from proxy20.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id 2ESsGDJv1VydWQAAvGGmqA ; Fri, 10 May 2019 08:31:46 -0400 Received: from smtp14.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy20.mail.iad3b.rsapps.net with LMTP id AKYlETJv1VzEMQAAcDxLoQ ; Fri, 10 May 2019 08:31:46 -0400 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: smtp14.gate.iad3b.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: 92ab135e-731f-11e9-9658-52540057873d-1-1 Received: from [216.105.38.7] ([216.105.38.7:58674] helo=lists.sourceforge.net) by smtp14.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id E0/40-08826-13F65DC5; Fri, 10 May 2019 08:31:46 -0400 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 1hP4g2-0001iX-2e; Fri, 10 May 2019 12:31:02 +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 1hP4g0-0001i0-9c for openvpn-devel@lists.sourceforge.net; Fri, 10 May 2019 12:31:00 +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:Cc: To:From:Sender:Reply-To: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=w+TDuAXefIA6kx05qvz7lJIobj1bUxbn+y7QV8uee7c=; b=IrN8PkwFT0swN791jUGWdb0iFM w8fDDO66xp4OdETTdkUMfyUrj6TmMtWeiEfvWhm7m6YgU8BipGRHpSUBdxRSv85lBOQtxSVc5vhrP 9bFD1zooFFc0D8Kk0+v1p+oq92o6L0ZiKuP8/pNrNqYDHNps9UMYEgWTU7bQe0nZhLYY=; 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:Cc:To:From:Sender:Reply-To :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=w+TDuAXefIA6kx05qvz7lJIobj1bUxbn+y7QV8uee7c=; b=LHDGbiYJB5e3NbqhXaU6b6vI71 QOLObgC6SWEadTx/pIqp8J/Hyi8IJWbekQYzh+QEV6dQFeI8KzHoiGLIJMa3yuIfqNBA8mh9FkYRV GtWwgxMjiTJAIUANP8wcEaMn+ulXB3jHULC1DAiaJyZJ1P++FiCKyeP5Qi/thN37SzAY=; 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.90_1) id 1hP4fz-00BysK-6V for openvpn-devel@lists.sourceforge.net; Fri, 10 May 2019 12:31:00 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.91 (FreeBSD)) (envelope-from ) id 1hP4Mt-000B4s-5h; Fri, 10 May 2019 14:11:15 +0200 Received: (nullmailer pid 30522 invoked by uid 10006); Fri, 10 May 2019 12:11:15 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Fri, 10 May 2019 14:11:10 +0200 Message-Id: <20190510121114.30468-4-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510121114.30468-1-arne@rfc2549.org> References: <20190510121114.30468-1-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: openvpn.net] 0.1 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.1 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1hP4fz-00BysK-6V Subject: [Openvpn-devel] [PATCH v3 3/7] Add pem_read_key_file variant that allows a random key 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: , Cc: Arne Schwabe MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Arne Schwabe This is useful for features that can use enither a persistent or an ephemeral key. Patch V2: Move the functionality of generating a random key into a separate function that acts as wrapper for pem_read_key_file --- src/openvpn/crypto.c | 22 ++++++++++++++++++++++ src/openvpn/crypto.h | 15 +++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index eb56421b..0e17c351 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -1892,6 +1892,28 @@ cleanup: return; } +bool +load_pem_file_or_ephemeral_key(struct buffer *key, const char *pem_name, + const char *key_file, const char *key_inline) +{ + if (key_file == NULL) + { + msg(M_INFO, "Using random %s.", pem_name); + uint8_t rand[BCAP(key)]; + if (!rand_bytes(rand, BCAP(key))) + { + msg(M_WARN, "ERROR: could not generate random key"); + return false; + } + buf_write(key, rand, BCAP(key)); + return true; + } + else + { + return read_pem_key_file(key, pem_name, key_file, key_inline); + } +} + bool read_pem_key_file(struct buffer *key, const char *pem_name, const char *key_file, const char *key_inline) diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index c5947483..4ae02571 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -430,6 +430,21 @@ unsigned int crypto_max_overhead(void); void write_pem_key_file(const char *filename, const char *pem_name); +/** + * Read key material from a PEM encoded files into the key structure or if + * the filename is not passed generate a ephemeral key + * + * @param key the key structure that will hold the key material + * @param pem_name the name used in the pem encoding start/end lines + * @param key_file name of the file to read or NULL if an ephermal key + * should be generated + * @param key_inline a string holding the data in case of an inline key + * @return true if reading into key was successful or generated + */ +bool +load_pem_file_or_ephemeral_key(struct buffer *key, const char *pem_name, + const char *key_file, const char *key_inline); + /** * Read key material from a PEM encoded files into the key structure * @param key the key structure that will hold the key material