From patchwork Thu Jun 13 03:48:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 745 X-Patchwork-Delegate: davids@openvpn.net Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id AJyXIY9UAl3SZwAAIUCqbw for ; Thu, 13 Jun 2019 09:50:07 -0400 Received: from proxy2.mail.iad3b.rsapps.net ([172.31.255.6]) by director7.mail.ord1d.rsapps.net with LMTP id qCGkHo9UAl3XbgAAovjBpQ ; Thu, 13 Jun 2019 09:50:07 -0400 Received: from smtp25.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy2.mail.iad3b.rsapps.net with LMTP id yBDJF49UAl2RXwAAvAZTew ; Thu, 13 Jun 2019 09:50:07 -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: smtp25.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: 26d7dfee-8de2-11e9-95c3-52540030a522-1-1 Received: from [216.105.38.7] ([216.105.38.7:46068] helo=lists.sourceforge.net) by smtp25.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 44/C7-06961-F84520D5; Thu, 13 Jun 2019 09:50:07 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1hbQ67-0004ZB-II; Thu, 13 Jun 2019 13:48:59 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hbQ63-0004Yl-Mm for openvpn-devel@lists.sourceforge.net; Thu, 13 Jun 2019 13:48:55 +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=A80MV15cVPsN00fnPgT4Aw1b5aAOe795zyaFGj0sq04=; b=klTz2fpqYYVmpeYgK8wV/Rp1Yc e+/9voJgYxWNj7Mm+AGowK4aJEammCPmBzPrepKR+MFiwDAZvCP8DddXTOk9FL7tUlw/71x1zlnCQ FRpAqVaiycbO2Wjv3hpZKbUpsHMExpXVEido+IIiiDyaK1laMUAaJW50DL8tjmDcz/Fc=; 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=A80MV15cVPsN00fnPgT4Aw1b5aAOe795zyaFGj0sq04=; b=hI2zhEbC6u8TauUxIYeIX8PFav NHmqENDhMMRTP50DlxofANEPnk8AP/C5nZm6a5NtdP69FF40T8/Rcge/TXNfLKGk99EP+hKiwWYqc XXBIwnwihhi9tLLMbV9Nf1hYx05GxB1WuY6xO9kQDLK0Yn+bRGAiy3I/2Nxeb2RLWg6U=; Received: from [192.26.174.232] (helo=mail.blinkt.de) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1hbQ5z-00BZVJ-0O for openvpn-devel@lists.sourceforge.net; Thu, 13 Jun 2019 13:48:54 +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 1hbQ5i-000O15-C3; Thu, 13 Jun 2019 15:48:34 +0200 Received: (nullmailer pid 5757 invoked by uid 10006); Thu, 13 Jun 2019 13:48:34 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Thu, 13 Jun 2019 15:48:30 +0200 Message-Id: <20190613134834.5709-2-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190613134834.5709-1-arne@rfc2549.org> References: <20190613134834.5709-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 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.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.0 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1hbQ5z-00BZVJ-0O Subject: [Openvpn-devel] [PATCH v4 3/7] Add generate_ephemeral_key that allows a random ephermal 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 Patch V4: Move wrapper functionality to caller and leave only generate epehermal key functionality in the new function Acked-By: David Sommerseth --- src/openvpn/crypto.c | 14 ++++++++++++++ src/openvpn/crypto.h | 12 +++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 9a150fa2..69877d1d 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -1892,6 +1892,20 @@ cleanup: return; } +bool +generate_ephemeral_key(struct buffer *key, const char *key_name) +{ + msg(M_INFO, "Using random %s.", key_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; +} + 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..72244997 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -428,7 +428,17 @@ unsigned int crypto_max_overhead(void); * @param pem_name The name to use in the PEM header/footer. */ void -write_pem_key_file(const char *filename, const char *pem_name); +write_pem_key_file(const char *filename, const char *key_name); + +/** + * Generate ephermal key material into the key structure or if + * + * @param key the key structure that will hold the key material + * @param pem_name the name used for logging + * @return true if key generation was successful + */ +bool +generate_ephemeral_key(struct buffer *key, const char *pem_name); /** * Read key material from a PEM encoded files into the key structure