From patchwork Mon Apr 13 13:30:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3441 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2146E62E17 for ; Mon, 13 Apr 2020 15:31:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aqj9vA1o"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BEA0924B for ; Mon, 13 Apr 2020 15:31:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1586784666; bh=TJnWAwIRmr63ZViJXOO5IvICSVVIB+uo4PmF/VOexgw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=aqj9vA1oSYdZq5Vi4RA/7irWgQs7cuJjPocjMKBe3Typ6+YGcZdJaP64sV5TF0B7Z YI2hwsUlgQHe/vcryaHo6v5ZK4GjYQ5p7tCDQ2Ou7Wp+IpWMDQepiFbOUBUMR+BSEU 1mcCAdH74dP8LyeP2lW1obLdLTmUzXg649PiG7t0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Apr 2020 16:30:43 +0300 Message-Id: <20200413133047.11913-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200413133047.11913-1-laurent.pinchart@ideasonboard.com> References: <20200413133047.11913-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/11] libcamera: ipa_module: Load IPA module signature X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Apr 2020 13:31:09 -0000 Load the signature from the .sign file, if available, when loading the IPA module information and store it in the IPAModule class. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/include/ipa_module.h | 4 ++++ src/libcamera/ipa_module.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/libcamera/include/ipa_module.h b/src/libcamera/include/ipa_module.h index 2028b76a1913..ec3671857a61 100644 --- a/src/libcamera/include/ipa_module.h +++ b/src/libcamera/include/ipa_module.h @@ -7,7 +7,9 @@ #ifndef __LIBCAMERA_IPA_MODULE_H__ #define __LIBCAMERA_IPA_MODULE_H__ +#include #include +#include #include #include @@ -25,6 +27,7 @@ public: bool isValid() const; const struct IPAModuleInfo &info() const; + const std::vector signature() const; const std::string &path() const; bool load(); @@ -38,6 +41,7 @@ public: private: struct IPAModuleInfo info_; + std::vector signature_; std::string libPath_; bool valid_; diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp index 5b6af15f2593..51b238a698f2 100644 --- a/src/libcamera/ipa_module.cpp +++ b/src/libcamera/ipa_module.cpp @@ -308,6 +308,20 @@ int IPAModule::loadIPAModuleInfo() return -EINVAL; } + /* Load the signature. Failures are not fatal. */ + File sign{ libPath_ + ".sign" }; + if (!sign.open(File::ReadOnly)) { + LOG(IPAModule, Debug) + << "IPA module " << libPath_ << " is not signed"; + return 0; + } + + data = sign.map(0, -1, File::MapPrivate); + signature_.resize(data.size()); + memcpy(signature_.data(), data.data(), data.size()); + + LOG(IPAModule, Debug) << "IPA module " << libPath_ << " is signed"; + return 0; } @@ -339,6 +353,21 @@ const struct IPAModuleInfo &IPAModule::info() const return info_; } +/** + * \brief Retrieve the IPA module signature + * + * The IPA module signature is stored alongside the IPA module in a file with a + * '.sign' suffix, and is loaded when the IPAModule instance is created. This + * function returns the signature without verifying it. If the signature is + * missing, the returned vector will be empty. + * + * \return The IPA module signature + */ +const std::vector IPAModule::signature() const +{ + return signature_; +} + /** * \brief Retrieve the IPA module path *