From patchwork Wed Sep 16 01:24:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Spooren X-Patchwork-Id: 1364868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.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=aparcar.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=xBYTZrkA; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Brj9v3Tyhz9sTR for ; Wed, 16 Sep 2020 11:26:43 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dtzCayPwyb3g1ttNDA8nPZCE4u1AMmUxSCT7WentmHw=; b=xBYTZrkAf2u1h2QiOqhkqOyqA 7Qq0pIRMLMpWUyiPiNobGe45l5B/Z8L+VZsgYlWPIq8bovUSXLh2WY/viCxuxJec5OoFXFTbL5ALv keJb+F2Y78mJUcJleCG9PIYYqLd84K5wC+4wISqpQsdSPJg3JseKjJhQCxXwyxg2KvO/xbOnqBuKS mZUDu7TwnI6wZJTBu3v09v4tVoDe3IYvSWYyardWf+4CbDx0LUjIXpVXu0LFM/qeKwL9CSiDACmDC NiAyHQTvpwYWBCLK7aQ1Nfe4GU6jorkqfoNxRVJiZce64uGrrThYWvMk29mz9x6qqFAH0Ldl3dYXz qz5Y6BxKQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIMCP-0003ku-Ow; Wed, 16 Sep 2020 01:25:29 +0000 Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIMCM-0003ju-U6 for openwrt-devel@lists.openwrt.org; Wed, 16 Sep 2020 01:25:28 +0000 X-Originating-IP: 72.234.141.215 Received: from dawn.lan (udp224251uds.hawaiiantel.net [72.234.141.215]) (Authenticated sender: mail@aparcar.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPA id BF20520007; Wed, 16 Sep 2020 01:25:21 +0000 (UTC) From: Paul Spooren To: openwrt-devel@lists.openwrt.org Subject: [PATCH v2] imagebuilder: add package signature verification Date: Tue, 15 Sep 2020 15:24:58 -1000 Message-Id: <20200916012457.1748220-1-mail@aparcar.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200826082455.82021-1-mail@aparcar.org> References: <20200826082455.82021-1-mail@aparcar.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200915_212527_164841_19F01996 X-CRM114-Status: GOOD ( 13.06 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: baptiste@bitsofnetworks.org, jo@mein.io, Paul Spooren Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The ImageBuilder downloads pre-built packages and adds them to images. This process uses `opkg` which has the capability to verify package list signatures via `usign`, as enabled per default on running OpenWrt devices. Until now this was disabled for ImageBuilders because neither the `opkg` keys nor the `opkg-add` script was present during first packagelist update. To harden the ImageBuilder against *drive-by-download-attacks* both keys and verification script are added to the ImageBuilder allowing `opkg` to verify downloaded package indices. This commit adds `opkg-add` to the ImageBuilder scripts folder. The keys folder is added to ImageBuilder $TOPDIR to have an obvious place for users to store their own keys. The `option check_signature` is appended to the repositories.conf file. All of the above only happens if the Buildbot runs with the SIGNATURE_CHECK option. The keys stored in the ImageBuilder keys/ folder are the same as stored within images in `/etc/opkg/keys`. To allow a local package feed in which the user can add additional packages, the local *imagebuilder* feed is set to `src/trusted` which skips signature verification only on this particular feed. Signed-off-by: Paul Spooren --- target/imagebuilder/Makefile | 10 +++++++++- target/imagebuilder/files/Makefile | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/target/imagebuilder/Makefile b/target/imagebuilder/Makefile index ad19ab2b53..0cdc1f4d93 100644 --- a/target/imagebuilder/Makefile +++ b/target/imagebuilder/Makefile @@ -42,7 +42,7 @@ endif echo '' >> $(PKG_BUILD_DIR)/repositories.conf echo '## This is the local package repository, do not remove!' >> $(PKG_BUILD_DIR)/repositories.conf - echo 'src imagebuilder file:packages' >> $(PKG_BUILD_DIR)/repositories.conf + echo 'src/trusted imagebuilder file:packages' >> $(PKG_BUILD_DIR)/repositories.conf $(VERSION_SED_SCRIPT) $(PKG_BUILD_DIR)/repositories.conf @@ -57,6 +57,14 @@ else find $(wildcard $(PACKAGE_SUBDIRS)) -type f -name '*.ipk' -exec $(CP) {} $(PKG_BUILD_DIR)/packages/ \; endif +ifneq ($(CONFIG_SIGNATURE_CHECK),) + echo '' >> $(PKG_BUILD_DIR)/repositories.conf + echo 'option check_signature' >> $(PKG_BUILD_DIR)/repositories.conf + $(INSTALL_DIR) $(PKG_BUILD_DIR)/keys + $(CP) -L $(STAGING_DIR_ROOT)/etc/opkg/keys/ $(PKG_BUILD_DIR)/ + $(CP) -L $(STAGING_DIR_ROOT)/usr/sbin/opkg-key $(PKG_BUILD_DIR)/scripts/ +endif + $(CP) $(TOPDIR)/target/linux $(PKG_BUILD_DIR)/target/ if [ -d $(TOPDIR)/staging_dir/host/lib/grub ]; then \ $(CP) $(TOPDIR)/staging_dir/host/lib/grub/ $(PKG_BUILD_DIR)/staging_dir/host/lib; \ diff --git a/target/imagebuilder/files/Makefile b/target/imagebuilder/files/Makefile index 27d3cfa8df..56b70f16b5 100644 --- a/target/imagebuilder/files/Makefile +++ b/target/imagebuilder/files/Makefile @@ -64,8 +64,10 @@ help: FORCE # override variables from rules.mk PACKAGE_DIR:=$(TOPDIR)/packages LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR) +export OPKG_KEYS:=$(TOPDIR)/keys OPKG:=$(call opkg,$(TARGET_DIR)) \ -f $(TOPDIR)/repositories.conf \ + --verify-program $(SCRIPT_DIR)/opkg-key \ --cache $(DL_DIR) \ --lists-dir $(LISTS_DIR)