From patchwork Fri Jan 12 05:48:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emmanuel Deloget X-Patchwork-Id: 177 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director6.mail.ord1d.rsapps.net ([172.30.191.6]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id TQKeCCPnWFrLOwAAgoeIoA for ; Fri, 12 Jan 2018 11:49:39 -0500 Received: from proxy8.mail.ord1d.rsapps.net ([172.30.191.6]) by director6.mail.ord1d.rsapps.net (Dovecot) with LMTP id i60zDyPnWFpROwAAhgvE6Q ; Fri, 12 Jan 2018 11:49:39 -0500 Received: from smtp15.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy8.mail.ord1d.rsapps.net (Dovecot) with LMTP id MCkGDyPnWFpZFAAAGdz6CA ; Fri, 12 Jan 2018 11:49:39 -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.34.181.88] Authentication-Results: smtp15.gate.ord1d.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; 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; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=none (p=nil; dis=none) header.from=free.fr X-Classification-ID: 93a55974-f7b8-11e7-a424-5254007ab6c8-1-1 Received: from [216.34.181.88] ([216.34.181.88:8304] helo=lists.sourceforge.net) by smtp15.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 19/D8-09219-227E85A5; Fri, 12 Jan 2018 11:49:38 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1ea2Vs-0003MI-Lz; Fri, 12 Jan 2018 16:49:04 +0000 Received: from sfi-mx-3.v28.ch3.sourceforge.com ([172.29.28.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ea2Vr-0003M7-Gg for openvpn-devel@lists.sourceforge.net; Fri, 12 Jan 2018 16:49:03 +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=OG6Pmy6aXcv6n7iUnZAEpAO9AYJhi87C/4DS7vGfk+s=; b=IXbSgxqQWbsdZTlsVlOshzJXXx IINy0UrBR7A/tnIMNvsB+Tq/jKhu07xHlcEDdsieAPY78TI04W3HJoCPl56AvtX7XlvwymZ5QNTlB qIWsGPx4uHXHrryTjxrXGEXWCw+IW6cAh29nUgNzf+iSk0N9FBMLqaQHQCXA4dIwyeuI=; 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=OG6Pmy6aXcv6n7iUnZAEpAO9AYJhi87C/4DS7vGfk+s=; b=GCABqnVcd1GT9RyuNLQW396JB5 mWzALhLCL+asnv1owWTfZe5Ao7zZD68h7Y+QLwR5b33IeR/mk4VZLEhSh3qtaCyjSCd8s9hqXfwwQ ky9nZulK1V4qOZTMU7NFWs1X5cMvtvP1ZFJA94JhCu1gwqo0DEdY4OAIZxbAeyppQqdQ=; Received: from mail-wm0-f66.google.com ([74.125.82.66]) by sfi-mx-3.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) id 1ea2Vq-0000vJ-H6 for openvpn-devel@lists.sourceforge.net; Fri, 12 Jan 2018 16:49:03 +0000 Received: by mail-wm0-f66.google.com with SMTP id b76so13134706wmg.1 for ; Fri, 12 Jan 2018 08:49:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=OG6Pmy6aXcv6n7iUnZAEpAO9AYJhi87C/4DS7vGfk+s=; b=FMu+4Cbz+D5zsbg8LwKoYSUg9wVHkZJeaLY20DhsvW08a1JxS8qnoeQqbus1NcWXkP 2/F2gO4xxbwPD8QX1u2jkdY+JqLz1cQjFmRe/0DdFSFlJlDNNedjdhVqidr55bL1StDI NjvlTUB5QlvRcBCdzHlzVAOf1RRn0A7fLr03gPaXaSPlfn4ptSCmv5mxwApSBveealua I6xDeMVqCrPAtSiDSGOxP02NDWb3gL+OfKgh/ZRNOB4eVCIzDOWNLQAcEcXgYJsj1k9r 8eJCjXt69NqABq56FGZaJ2isKaUShS+Oobt8VNElu6pA4RAYNdMEe62Qs0zreGmxBG0u MdpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=OG6Pmy6aXcv6n7iUnZAEpAO9AYJhi87C/4DS7vGfk+s=; b=tOhOf52ZvLoPGYPTbbG+8oqursJDH7oR/8/ClH7kFqnKFG9zhnypOdbX/fPV3Kw5sF DIjrDW6Bs0VfflLlpMr9X26OK0h4bNqSIOXLdl+fTqOWYnIaunVsJV1olYP24bSYxIFB qKf4RaYB/tId43+swfdJQcfX2gZzr0ahon1aDH32P68PtxXqnUa07iZs1ODmV44gCBom YmSqCx6nzxKWb/Qz19/9rdGBuFLaoi4VqWbtdxVtCVMf69Q8POeHaa5G/QX7nNz1lXJ0 WJNccLmY/5UgmRrYwlYCh/PwWRJy+vSA6vKj1f0WYCTiO+H2Nm5qtgi/DGoejIysSbn9 mShA== X-Gm-Message-State: AKwxytdY/8Zp2XESa4ks4lZRsb6sucRNCJl+p1lMV82cHI6JrLQOfj8N lqE5lZKqjbUNxZjBYCNEMCd5OEx/ X-Google-Smtp-Source: ACJfBosaYC5wQKHLofdssspoBNjbxm3Wv+EanZZNNZMxF2w+oGxyN7K80CwLyPf1AQMd/FXB3He11w== X-Received: by 10.28.140.1 with SMTP id o1mr5031076wmd.27.1515775736312; Fri, 12 Jan 2018 08:48:56 -0800 (PST) Received: from edt-thinkpad.eho.intranet ([2a01:cb1c:53c:ce00:144a:841b:886c:3c9c]) by smtp.gmail.com with ESMTPSA id u5sm1606821wmf.47.2018.01.12.08.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 08:48:55 -0800 (PST) From: Emmanuel Deloget To: openvpn-devel@lists.sourceforge.net Date: Fri, 12 Jan 2018 17:48:25 +0100 Message-Id: <3ea860bd412bbc9638cb54ade1a85ee08caf1b42.1515775195.git.logout@free.fr> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (logout[at]free.fr) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [74.125.82.66 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (emmanueldeloget53[at]gmail.com) 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1ea2Vq-0000vJ-H6 Subject: [Openvpn-devel] [PATCH 2/3] OpenSSL: remove some EVP_PKEY type checks 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 Calling EVP_KEY_id() before EVP_PKEY_get0_*() is unnecessary as the same check is also performed in the later. We also make the code a bit better by not calling the various EVP_PKEY_get0_*() functions twice (this needs a bit or reordering to avoid introducing yet another #ifndef OPENSSL_NO_EC in the code). Signed-off-by: Emmanuel Deloget diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 711bba11..9f74acaa 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -1699,22 +1699,13 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix) EVP_PKEY *pkey = X509_get_pubkey(cert); if (pkey != NULL) { - if ((EVP_PKEY_id(pkey) == EVP_PKEY_RSA) && (EVP_PKEY_get0_RSA(pkey) != NULL)) - { - RSA *rsa = EVP_PKEY_get0_RSA(pkey); - openvpn_snprintf(s2, sizeof(s2), ", %d bit RSA", - RSA_bits(rsa)); - } - else if ((EVP_PKEY_id(pkey) == EVP_PKEY_DSA) && (EVP_PKEY_get0_DSA(pkey) != NULL)) - { - DSA *dsa = EVP_PKEY_get0_DSA(pkey); - openvpn_snprintf(s2, sizeof(s2), ", %d bit DSA", - DSA_bits(dsa)); - } + RSA *rsa = NULL; + DSA *dsa = NULL; #ifndef OPENSSL_NO_EC - else if ((EVP_PKEY_id(pkey) == EVP_PKEY_EC) && (EVP_PKEY_get0_EC_KEY(pkey) != NULL)) + EC *ec = NULL; + + if ((ec = EVP_PKEY_get0_EC_KEY(pkey)) != NULL) { - EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey); const EC_GROUP *group = EC_KEY_get0_group(ec); const char* curve; @@ -1726,9 +1717,19 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix) openvpn_snprintf(s2, sizeof(s2), ", %d bit EC, curve: %s", EC_GROUP_order_bits(group), curve); - - } + } else #endif + if ((rsa = EVP_PKEY_get0_RSA(pkey)) != NULL) + { + openvpn_snprintf(s2, sizeof(s2), ", %d bit RSA", + RSA_bits(rsa)); + } + else if ((dsa = EVP_PKEY_get0_DSA(pkey)) != NULL) + { + openvpn_snprintf(s2, sizeof(s2), ", %d bit DSA", + DSA_bits(dsa)); + } + EVP_PKEY_free(pkey); } X509_free(cert);