Message ID | 20200404015624.30440-8-laurent.pinchart@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Laurent, Thanks for your work. On 2020-04-04 04:56:20 +0300, Laurent Pinchart wrote: > 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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > 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 <stdint.h> > #include <string> > +#include <vector> > > #include <ipa/ipa_interface.h> > #include <ipa/ipa_module_info.h> > @@ -25,6 +27,7 @@ public: > bool isValid() const; > > const struct IPAModuleInfo &info() const; > + const std::vector<uint8_t> signature() const; > const std::string &path() const; > > bool load(); > @@ -38,6 +41,7 @@ public: > > private: > struct IPAModuleInfo info_; > + std::vector<uint8_t> 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<uint8_t> IPAModule::signature() const > +{ > + return signature_; > +} > + > /** > * \brief Retrieve the IPA module path > * > -- > Regards, > > Laurent Pinchart > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
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 <stdint.h> #include <string> +#include <vector> #include <ipa/ipa_interface.h> #include <ipa/ipa_module_info.h> @@ -25,6 +27,7 @@ public: bool isValid() const; const struct IPAModuleInfo &info() const; + const std::vector<uint8_t> signature() const; const std::string &path() const; bool load(); @@ -38,6 +41,7 @@ public: private: struct IPAModuleInfo info_; + std::vector<uint8_t> 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<uint8_t> IPAModule::signature() const +{ + return signature_; +} + /** * \brief Retrieve the IPA module path *
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 <laurent.pinchart@ideasonboard.com> --- src/libcamera/include/ipa_module.h | 4 ++++ src/libcamera/ipa_module.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)