33#define PLUGIN_ALREADY_INSTALLED 100
34#define PLUGIN_OLD_VERSION 200
35#define SIGNATURE_VERIFICATION_FAILED 300
36#define CERTIFICATE_VERIFICATION_FAILED 400
37#define INVALID_PLUGIN 500
41#define LIB_TYPE ".dll"
45#define LIB_TYPE ".dylib"
46#define LIB_PREFIX "lib"
49#define LIB_PREFIX "lib"
69 JAMI_ERROR(
"Unable to read plugin certificate");
72 return cert->getIssuerName();
75std::map<std::string, std::string>
79 if (
detailsIt != pluginDetailsMap_.end()) {
102std::vector<std::string>
110 const auto& p =
entry.path();
117 .pluginPreferences.getInstalledPlugins();
144 }
catch (
const std::exception&
e) {
157 auto result = trust_.verify(*
cert);
159 JAMI_ERROR(
"Certificate verification failed: {}", result.toString());
164std::map<std::string, std::string>
175 if (!std::filesystem::is_regular_file(
jplPath,
ec)){
181 const std::string& name =
manifest[
"id"];
185 if (
file ==
"signatures" ||
file ==
"signatures.sig")
188 if (
file == name +
".crt")
195 }
catch (
const std::exception&
e) {
204 if (!std::filesystem::is_regular_file(
jplPath))
207 const auto& pk =
cert->getPublicKey();
215 if (!pk.checkSignature(
file, signature.second)){
216 JAMI_ERROR(
"{} not correctly signed", signature.first);
220 }
catch (
const std::exception&
e) {
235 }
catch (
const std::exception&
e) {
240std::unique_ptr<dht::crypto::Certificate>
243 if (!std::filesystem::is_regular_file(
jplPath))
251 }
catch (
const std::exception&
e) {
261 if (std::filesystem::is_regular_file(
jplPath,
ec)) {
315 }
catch (
const std::exception&
e) {
328 if (
detailsIt != pluginDetailsMap_.end()) {
331 JAMI_INFO() <<
"PLUGIN: unloading before uninstall.";
334 JAMI_INFO() <<
"PLUGIN: unable to unload, not performing uninstall.";
356 JAMI_INFO() <<
"PLUGIN: load status - " << status;
360 }
catch (
const std::exception&
e) {
388 JAMI_INFO() <<
"PLUGIN: unload status - " << status;
391 }
catch (
const std::exception&
e) {
399std::vector<std::string>
408 [](
const std::string&
soPath) {
409 return PluginUtils::getRootPathFromSoPath(soPath).string();
414std::vector<std::map<std::string, std::string>>
422 const std::string& accountId,
423 const std::string& key,
424 const std::string&
value)
426 std::string acc = accountId;
431 if (!accountId.empty()) {
435 auto it = std::find_if(preferences.cbegin(),
437 [key](
const std::map<std::string, std::string>&
preference) {
438 return preference.at(
"key") == key;
441 if (
it != preferences.cend())
477 }
catch (
const std::exception&
e) {
491std::map<std::string, std::string>
493 const std::string& accountId)
500 const std::string& accountId)
502 bool acc {accountId.empty()};
515JamiPluginManager::registerServices()
519 auto ppp =
static_cast<std::map<std::string, std::string>*
>(data);
527 auto dataPath =
static_cast<std::string*
>(data);
544 PluginPreferencesUtils::getPreferencesValuesMap(path,
accId));
553JamiPluginManager::addPluginAuthority(
const dht::crypto::Certificate&
cert)
bool setPreference(const std::string &key, const std::string &value, const std::string &rootPath)
Sets a preference that may be changed while MediaHandler is active.
bool setPreference(const std::string &key, const std::string &value, const std::string &rootPath)
Sets a preference that may be changed while ChatHandler is active.
This class is used after a plugin library is successfully loaded.
bool loadPlugins()
Returns True if success.
std::vector< std::map< std::string, std::string > > getPluginPreferences(const std::string &rootPath, const std::string &accountId)
Returns contents of plugin's preferences.json file.
std::string getPluginAuthor(const std::string &rootPath, const std::string &pluginId)
get the plugin's author
bool checkPluginSignature(const std::string &jplPath, dht::crypto::Certificate *cert)
Checks if the plugin signature mechanism is valid by signature of files and each files is signed.
bool resetPluginPreferencesValuesMap(const std::string &rootPath, const std::string &accountId)
Reset plugin's preferences values to their defaultValues.
std::vector< std::string > getLoadedPlugins() const
Returns vector with rootpaths of the loaded plugins.
bool loadPlugin(const std::string &rootPath)
Returns True if success.
int installPlugin(const std::string &jplPath, bool force)
Checks if the plugin has a valid manifest, installs the plugin if not previously installed or if inst...
std::unique_ptr< dht::crypto::Certificate > checkPluginCertificate(const std::string &jplPath, bool force)
Checks if the certificate mechanism is valid by checking certificate of the plugin.
bool checkPluginSignatureValidity(const std::string &jplPath, dht::crypto::Certificate *cert)
Check the validity of a plugin signature.
std::map< std::string, std::string > getPluginDetails(const std::string &rootPath, bool reset=false)
Parses a manifest file and return its content along with other internally added values.
bool checkPluginSignatureFile(const std::string &jplPath)
check if all file are present in the signature file
bool unloadPlugin(const std::string &rootPath)
Returns True if success.
std::map< std::string, std::string > getPluginPreferencesValuesMap(const std::string &rootPath, const std::string &accountId)
Returns a Map with preferences keys and values.
std::vector< std::string > getInstalledPlugins()
Returns a vector with installed plugins.
bool checkPluginCertificatePublicKey(const std::string &oldJplPath, const std::string &newJplPath)
check if the if the public key of the certificate is the same as the public key in the new plugin
bool setPluginPreference(const std::filesystem::path &rootPath, const std::string &accountId, const std::string &key, const std::string &value)
Modifies a preference value by saving it to a preferences.msgpack.
bool checkPluginCertificateValidity(dht::crypto::Certificate *cert)
Check the validity of a plugin certificate.
int uninstallPlugin(const std::string &rootPath)
Checks if the plugin has a valid manifest and if the plugin is loaded, tries to unload it and then re...
std::map< std::string, std::string > getPlatformInfo()
Returns a Map of platform system.
std::vector< std::string > getAccountList() const
Get account list.
static LIBJAMI_TEST_EXPORT Manager & instance()
void saveConfig()
Save config to file.
std::vector< std::string > getLoadedPlugins() const
Returns vector with loaded plugins' libraries paths.
bool unload(const std::string &path)
Unloads the plugin.
bool checkLoadedPlugin(const std::string &rootPath) const
Returns True if plugin is loaded.
bool registerService(const std::string &name, ServiceFunction &&func)
Register a new service in the Plugin System.
bool load(const std::string &path)
Load a dynamic plugin by filename.
static std::map< std::string, std::string > getPreferencesValuesMap(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads preferences values.
static std::vector< std::map< std::string, std::string > > getPreferences(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads a preference.json file from the plugin installed in rootPath.
static std::filesystem::path valuesFilePath(const std::filesystem::path &rootPath, const std::string &accountId="")
Given a plugin installation path, returns the path to the preference.msgpack file.
static bool resetPreferencesValuesMap(const std::string &rootPath, const std::string &accountId)
Resets all preferences values to their defaultValues by erasing all data saved in preferences....
static std::map< std::string, std::string > getUserPreferencesValuesMap(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads preferences values which were modified from defaultValue.
void resetPreferences(const std::string &rootPath, const std::string &accountId)
Resets acc preferences to default values.
bool setPreference(const std::string &key, const std::string &value, const std::string &rootPath, const std::string &accountId)
Sets a preference.
#define PLUGIN_ALREADY_INSTALLED
#define PLUGIN_OLD_VERSION
#define SIGNATURE_VERIFICATION_FAILED
#define CERTIFICATE_VERIFICATION_FAILED
#define JAMI_ERROR(formatstr,...)
std::unique_ptr< dht::crypto::Certificate > readPluginCertificate(const std::string &rootPath, const std::string &pluginId)
Read the plugin's certificate.
std::map< std::string, std::string > readPluginManifestFromArchive(const std::string &jplPath)
Reads the manifest file content without uncompressing the whole archive and return a map with manifes...
std::filesystem::path dataPath(const std::filesystem::path &pluginSoPath)
Returns data path given a plugin's library path.
std::map< std::string, std::string > getPlatformInfo()
Returns a map with platform information.
std::filesystem::path getRootPathFromSoPath(const std::filesystem::path &soPath)
Returns installation path given a plugin's library path.
std::vector< uint8_t > readSignatureFileFromArchive(const std::string &jplPath)
Read the signature of the file signature without uncompressing the whole archive.
bool checkPluginValidity(const std::filesystem::path &rootPath)
Validates a plugin based on its manifest.json file.
std::filesystem::path manifestPath(const std::filesystem::path &rootPath)
Returns complete manifest.json file path given a installation path.
std::unique_ptr< dht::crypto::Certificate > readPluginCertificateFromArchive(const std::string &jplPath)
Read plugin certificate without uncompressing the whole archive.and return an object Certificate.
std::pair< bool, std::string_view > uncompressJplFunction(std::string_view relativeFileName)
Function used by archiver to extract files from plugin jpl to the plugin installation path.
std::map< std::string, std::string > parseManifestFile(const std::filesystem::path &manifestFilePath, const std::string &rootPath)
Parses the manifest file of an installed plugin if it's valid.
std::map< std::string, std::vector< uint8_t > > readPluginSignatureFromArchive(const std::string &jplPath)
Reads signature file content without uncompressing the whole archive and.
std::vector< std::string > listFilesFromArchive(const std::string &path)
listFilesFromArchive list all files from an archive
void uncompressArchive(const std::string &archivePath, const std::string &dir, const FileMatchPair &f)
uncompressArchive Uncompresses an archive and puts the different files in dir folder according to a F...
std::vector< uint8_t > readFileFromArchive(const std::string &archivePath, const std::string &fileRelativePathName)
readFileFromArchive read a file from an archive without uncompressing the whole archive
const std::filesystem::path & get_data_dir()
static constexpr int version
void emitSignal(Args... args)
std::map< std::string, std::map< std::string, std::string > > PreferencesMap
std::vector< std::string > getAccountList()
bool unloadPlugin(const std::string &path)
void setPluginsEnabled(bool state)
bool loadPlugin(const std::string &path)
unsigned char store_ca_crt[]