From patchwork Sat Aug 4 11:45:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: p.wassi@gmx.at X-Patchwork-Id: 953440 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nYbkoeHz"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41jMYN1Z7Lz9sXZ for ; Sat, 4 Aug 2018 21:45:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:Date:To:From:Message-ID: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=amIyhOqJHn8karG3NbuH2ZMKVo2X8tIqTqJDuOIpxcs=; b=nYb koeHzJWDZ6tFzvh1gyc3O9pXs/pWIAf233azzTV5kJxzNqTZBUTKVxxvl/+kQVFcP6zNPrjkDdVLI OHh2g7kNXXr53gRkpIgH9WXr8lie7E+Nt965dnfkW2j3gVzpGuqysnAhoQNvdKpaS6kkW9k/a4r6B kwQZrY3bZEAmoEel2b63bk+4ZJy7/y0GeUQGlAxJ+YnGu6jD0J2QU6qY+i2aelsREgidUnxwQ2hIT NANu2BAIwRm5SnisQ4NhXG2+KayNt6pWe8qMs4/AW2F59jJuuX/YMllMTHi0diQ5Mv8JzlKHzMgrx xmf6Q37SKp1In/cckOSLfaKnHF9VCSQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fluzy-00080O-QP; Sat, 04 Aug 2018 11:45:30 +0000 Received: from mout.gmx.net ([212.227.17.21]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fluzv-0007zh-UZ for openwrt-devel@lists.openwrt.org; Sat, 04 Aug 2018 11:45:29 +0000 Received: from [81.16.107.248] ([81.16.107.248]) by web-mail.gmx.net (3c-app-gmx-bs62.server.lan [172.19.170.146]) (via HTTP); Sat, 4 Aug 2018 13:45:13 +0200 MIME-Version: 1.0 Message-ID: From: p.wassi@gmx.at To: openwrt-devel@lists.openwrt.org Date: Sat, 4 Aug 2018 13:45:13 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:XQtpIkKj932Yn45dDdttvnkq64DfEUwNiJZ/Tfuv/5EM8awY2Qfh94MwDXAdjwhv+g3PU ROtmMIHa0YKJR2NTI/UyJQ2lT7p/PIoiJvgfMTTXgG2FxrjLRNvajAgucrGIOwqVIGXh1aQJyecP 80Et1tBL2bnxU/qH6lgJUy2AXtNZC7a8ud7uWfJzIYMDtItu35xUGVXKgwYL9JpVpFwH2o3zLuJz yKBgqHf+tPkcbpsQ+yJyvhE34o22QLwmLnEJTcgqK2sHKmzHhi3BOnqc/dCl+8WXTMKKNiRpuOrS nY= X-UI-Out-Filterresults: notjunk:1; V01:K0:nlfdIzXtdFU=:qYgQC2JChKhzDqWA/Lq23Z 5rSJOa2S29qHBkcGlFM9CwJBN1I18aSBaqf1wJ0gHoYOi8FuAoRMb4IXLO+92mnNPNYzhsbUb f0Hfrbsqb8qJlzPDN8RRI5VJLOIY8WDZFD+NAiY3Ux40HuLCdu3bpHLIUrZnSL25E3iWxVau6 W4hD3MVRQjV9pKY/M1uLzM1hdIg7lCJV2itcuowiQK/yYY+W+lOkNS7meOI5i8kTbKqNLmFr4 3DTGbYyzCF04swGXY7FMRBekRYCKgmIXSqjJErAbl+eH07HBPex3BBbLhojFE91mNflZi2Gxy q1C+Jo4aGzxhVLdlMXjRDf0FktaNIF+YzK+4tOi9sSyxGZQeNGDBHAYwNpQ7MQ1JPkNhNFcyu Na8amQNoN7XuX4F+hdondoLFjSz1x7/bV5KYq7xjePVz9cXcmQgrs5qx8ZTlWjN1mWlqDTGox kdJfhoOmVB6hmGT1pRVXYg2Y8bGAYvpaKkigyjdoM9UHSqW1IxnT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180804_044528_296352_3A8A08D8 X-CRM114-Status: UNSURE ( 8.34 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [212.227.17.21 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (p.wassi[at]gmx.at) -0.0 SPF_PASS SPF: sender matches SPF record Subject: [OpenWrt-Devel] uclient-fetch and ustream-mbedtls certificate verification X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Dear list, for SSL connections, uclient offers some options for certificate verification: -) --no-check-certificate (i.e. ignore verification errors) -) --ca-certificate=/path/to/file.crt If "--ca-certificate" is not given, uclient internally uses /etc/ssl/certs/*.crt (probably populated by the "ca-certificates" package). I installed ustream-mbedtls for use with uclient-fetch, and observed - I'd say not optimal behaviour. When you run > uclient-fetch https://server/file.txt (so no explicit certificate is given) and have *not* installed ca-certificates, mbedtls obviously can't do verification since no root certificates available. But then it simply ignores the issue and continues SSL handshake without warning. Further, if you run it like > uclient-fetch --ca-certificate=/etc/ssl/foo.crt https://server/file.txt but foo.crt can't be read (filename misspelled, wrong certificate format, ...), ustream-mbedtls also does not do verification at all (gives no warning either). For me the issue is that ustream starts with verification disabled at first, and enables verification as soon as a *valid* root certificate is given. (No certificate or unparsable cert -> no verification and no warning/error) However, in client mode it should always verify (but ignore the error, if --no-check-certificate is given in uclient). Not providing a root certificate should immediately lead to an error when mbedtls is supposed to do verification for us. I propose the attached change for the ustream-ssl repo: -) leave verification disabled in server mode (is mbedtls' default anyway) -) make verification optional* in client mode at initialisation step * "optional" means that the code calling the mbedtls-library itself must take care of calling verify(), see manual at [1] What about using "required" like stated in the mbedtls reference? This would probably need some tweaking, as --no-check-certificated needs to be passed to ustream-* ... Best regards, Paul [1]: https://tls.mbed.org/api/ssl_8h.html#a5695285c9dbfefec295012b566290f37 diff --git a/ustream-mbedtls.c b/ustream-mbedtls.c index 347c600..262167c 100644 --- a/ustream-mbedtls.c +++ b/ustream-mbedtls.c @@ -144,14 +144,15 @@ __ustream_ssl_context_new(bool server) mbedtls_ssl_config_defaults(conf, ep, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT); - mbedtls_ssl_conf_authmode(conf, MBEDTLS_SSL_VERIFY_NONE); mbedtls_ssl_conf_rng(conf, _urandom, NULL); if (server) { + mbedtls_ssl_conf_authmode(conf, MBEDTLS_SSL_VERIFY_NONE); mbedtls_ssl_conf_ciphersuites(conf, default_ciphersuites_server); mbedtls_ssl_conf_min_version(conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3); } else + mbedtls_ssl_conf_authmode(conf, MBEDTLS_SSL_VERIFY_OPTIONAL); mbedtls_ssl_conf_ciphersuites(conf, default_ciphersuites_client); #if defined(MBEDTLS_SSL_CACHE_C) @@ -189,7 +190,6 @@ __hidden int __ustream_ssl_add_ca_crt_file(struct ustream_ssl_ctx *ctx, const ch return -1; mbedtls_ssl_conf_ca_chain(&ctx->conf, &ctx->ca_cert, NULL); - mbedtls_ssl_conf_authmode(&ctx->conf, MBEDTLS_SSL_VERIFY_OPTIONAL); return 0; }