From patchwork Sat Apr 4 01:56:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3397 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 BE43D62D75 for ; Sat, 4 Apr 2020 03:56:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="plxhs3b4"; 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 53C5972E for ; Sat, 4 Apr 2020 03:56:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585965400; bh=Tjf4ysA5abCtPCGqTHgiPAFLJPzsHsoVi+vX8ZWT5r4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=plxhs3b4oWHNDxDYBoWxcMrL6Q4iH6RpXf97jyPHJhUW1BjZUZCGsiY49feWc/L86 Qd9uy7x2Eu/UkiNUjP43cIW0nQHr7DC9eY8ZgIyncKyrKgcqXxL7shW+3AzCe5qzG4 lgEPRjKEeB30ldSlUDJp6HvVLaJ8V4s1Yqvm5hl0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Apr 2020 04:56:20 +0300 Message-Id: <20200404015624.30440-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200404015624.30440-1-laurent.pinchart@ideasonboard.com> References: <20200404015624.30440-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: Sat, 04 Apr 2020 01:56:43 -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 *