libcamera: Make IPA module signing optional

The IPA module signing mechanism relies on openssl to generate keys and
sign the module. If openssl is not found on the system, the build will
fail. Make the dependency optional by detecting openssl, and skip
generation of signatures if openssl isn't found.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2020-04-15 22:27:33 +03:00
parent 2155a9b74e
commit b7c5e0e4f0
7 changed files with 44 additions and 23 deletions

View file

@ -9,9 +9,11 @@ mod = shared_module(ipa_name,
install : true, install : true,
install_dir : ipa_install_dir) install_dir : ipa_install_dir)
custom_target(ipa_name + '.so.sign', if ipa_sign_module
input : mod, custom_target(ipa_name + '.so.sign',
output : ipa_name + '.so.sign', input : mod,
command : [ ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@' ], output : ipa_name + '.so.sign',
install : true, command : [ ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@' ],
install_dir : ipa_install_dir) install : true,
install_dir : ipa_install_dir)
endif

View file

@ -9,9 +9,11 @@ mod = shared_module(ipa_name,
install : true, install : true,
install_dir : ipa_install_dir) install_dir : ipa_install_dir)
custom_target(ipa_name + '.so.sign', if ipa_sign_module
input : mod, custom_target(ipa_name + '.so.sign',
output : ipa_name + '.so.sign', input : mod,
command : [ ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@' ], output : ipa_name + '.so.sign',
install : true, command : [ ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@' ],
install_dir : ipa_install_dir) install : true,
install_dir : ipa_install_dir)
endif

View file

@ -40,8 +40,10 @@ private:
bool isSignatureValid(IPAModule *ipa) const; bool isSignatureValid(IPAModule *ipa) const;
#if HAVE_IPA_PUBKEY
static const uint8_t publicKeyData_[]; static const uint8_t publicKeyData_[];
static const PubKey pubKey_; static const PubKey pubKey_;
#endif
}; };
} /* namespace libcamera */ } /* namespace libcamera */

View file

@ -304,6 +304,7 @@ std::unique_ptr<IPAInterface> IPAManager::createIPA(PipelineHandler *pipe,
bool IPAManager::isSignatureValid(IPAModule *ipa) const bool IPAManager::isSignatureValid(IPAModule *ipa) const
{ {
#if HAVE_IPA_PUBKEY
File file{ ipa->path() }; File file{ ipa->path() };
if (!file.open(File::ReadOnly)) if (!file.open(File::ReadOnly))
return false; return false;
@ -319,6 +320,9 @@ bool IPAManager::isSignatureValid(IPAModule *ipa) const
<< (valid ? "valid" : "not valid"); << (valid ? "valid" : "not valid");
return valid; return valid;
#else
return false;
#endif
} }
} /* namespace libcamera */ } /* namespace libcamera */

View file

@ -2,7 +2,7 @@
/* /*
* Copyright (C) 2020, Laurent Pinchart <laurent.pinchart@ideasonboard.com> * Copyright (C) 2020, Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* *
* ipa_key.cpp - IPA module signing public key * ipa_pub_key.cpp - IPA module signing public key
* *
* This file is auto-generated. Do not edit. * This file is auto-generated. Do not edit.
*/ */
@ -11,10 +11,12 @@
namespace libcamera { namespace libcamera {
#if HAVE_IPA_PUBKEY
const uint8_t IPAManager::publicKeyData_[] = { const uint8_t IPAManager::publicKeyData_[] = {
${ipa_key} ${ipa_key}
}; };
const PubKey IPAManager::pubKey_{ { IPAManager::publicKeyData_ } }; const PubKey IPAManager::pubKey_{ { IPAManager::publicKeyData_ } };
#endif
} /* namespace libcamera */ } /* namespace libcamera */

View file

@ -101,13 +101,15 @@ version_cpp = vcs_tag(command : [gen_version, meson.build_root()],
libcamera_sources += version_cpp libcamera_sources += version_cpp
gen_ipa_pub_key = files('gen-ipa-pub-key.py') if ipa_sign_module
ipa_pub_key_cpp = custom_target('ipa_pub_key_cpp', gen_ipa_pub_key = files('gen-ipa-pub-key.py')
input : [ ipa_priv_key, 'ipa_pub_key.cpp.in' ], ipa_pub_key_cpp = custom_target('ipa_pub_key_cpp',
output : 'ipa_pub_key.cpp', input : [ ipa_priv_key, 'ipa_pub_key.cpp.in' ],
command : [ gen_ipa_pub_key, '@INPUT@', '@OUTPUT@' ]) output : 'ipa_pub_key.cpp',
command : [ gen_ipa_pub_key, '@INPUT@', '@OUTPUT@' ])
libcamera_sources += ipa_pub_key_cpp libcamera_sources += ipa_pub_key_cpp
endif
libcamera_deps = [ libcamera_deps = [
libatomic, libatomic,

View file

@ -2,10 +2,17 @@ if get_option('android')
subdir('android') subdir('android')
endif endif
ipa_gen_priv_key = find_program('ipa/gen-ipa-priv-key.sh') openssl = find_program('openssl', required : false)
ipa_priv_key = custom_target('ipa-priv-key', if openssl.found()
output : [ 'ipa-priv-key.pem' ], ipa_gen_priv_key = find_program('ipa/gen-ipa-priv-key.sh')
command : [ ipa_gen_priv_key, '@OUTPUT@' ]) ipa_priv_key = custom_target('ipa-priv-key',
output : [ 'ipa-priv-key.pem' ],
command : [ ipa_gen_priv_key, '@OUTPUT@' ])
config_h.set('HAVE_IPA_PUBKEY', 1)
ipa_sign_module = true
else
ipa_sign_module = false
endif
subdir('libcamera') subdir('libcamera')
subdir('ipa') subdir('ipa')