Multiple algorythms and libraries can be built inside the same SWUpdate
binary, as default the first one is chosen. Allow to set at the startup
which provider for the a service should be used.
Allowed services: decrypt, hash, digest
core/swupdate.c | 67 ++++++++++++++++++++++++++---
examples/configuration/swupdate.cfg | 14 ++++++
include/swupdate.h | 7 +++
3 files changed, 82 insertions(+), 6 deletions(-)
diff --git a/core/swupdate.c b/core/swupdate.c
index ac22185c..eca29846 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -105,9 +105,14 @@ static struct option long_options[] = {
{"gpg-home-dir", required_argument, NULL, '4'},
{"gpg-protocol", required_argument, NULL, '5'},
#endif
+ {"digest-provider", required_argument, NULL, '6'},
#endif
#ifdef CONFIG_ENCRYPTED_IMAGES
{"key-aes", required_argument, NULL, 'K'},
+ {"decrypt-provider", required_argument, NULL, '8'},
+#endif
+#ifdef CONFIG_HASH_VERIFY
+ {"hash-provider", required_argument, NULL, '7'},
#endif
{"loglevel", required_argument, NULL, 'l'},
{"max-version", required_argument, NULL, '3'},
@@ -159,6 +164,7 @@ static void usage(char *programname)
" -l, --loglevel <level> : logging level\n"
" -L, --syslog : enable syslog logger\n"
#ifdef CONFIG_SIGNED_IMAGES
+ " -6, --digest-provider <string> : the provider used to verify the update\n"
" -k, --key <public key file> : file with public key to verify images\n"
" --cert-purpose <purpose> : set expected certificate purpose\n"
" [emailProtection|codeSigning] (default: emailProtection)\n"
@@ -175,6 +181,10 @@ static void usage(char *programname)
#ifdef CONFIG_ENCRYPTED_IMAGES
" -K, --key-aes <key file> : the file contains the symmetric key to be used\n"
" to decrypt images\n"
+ " -8, --decrypt-provider <string>: the provider used for decryption\n"
+#endif
+#ifdef CONFIG_HASH_VERIFY
+ " -7, --hash-provider <string> : the provider used to perform hashes\n"
#endif
" -n, --dry-run : run SWUpdate without installing the software\n"
" -N, --no-downgrading <version> : not install a release older as <version>\n"
@@ -404,6 +414,16 @@ static int read_globals_settings(void *elem, void *data)
char software_select[SWUPDATE_GENERAL_STRING_SIZE] = "";
GET_FIELD_STRING(LIBCFG_PARSER, elem, "select", software_select);
+ GET_FIELD_STRING(LIBCFG_PARSER, elem,
+ "gpg-home-dir", sw->gpg_home_directory);
+ GET_FIELD_STRING(LIBCFG_PARSER, elem,
+ "gpgme-protocol", sw->gpgme_protocol);
+ GET_FIELD_STRING(LIBCFG_PARSER, elem,
+ "hash-provider", sw->hash_provider);
+ GET_FIELD_STRING(LIBCFG_PARSER, elem,
+ "decrypt-provider", sw->decrypt_provider);
+ GET_FIELD_STRING(LIBCFG_PARSER, elem,
+ "digest-provider", sw->digest_provider);
if (software_select[0] != '\0') {
/* by convention, errors in a configuration section are ignored */
(void)parse_image_selector(software_select, sw);
@@ -803,6 +823,21 @@ int main(int argc, char **argv)
optarg,
sizeof(swcfg.gpgme_protocol));
break;
+ case '6':
+ strlcpy(swcfg.digest_provider,
+ optarg,
+ sizeof(swcfg.digest_provider));
+ break;
+ case '7':
+ strlcpy(swcfg.hash_provider,
+ optarg,
+ sizeof(swcfg.hash_provider));
+ break;
+ case '8':
+ strlcpy(swcfg.decrypt_provider,
+ optarg,
+ sizeof(swcfg.decrypt_provider));
+ break;
#ifdef CONFIG_ENCRYPTED_IMAGES
case 'K':
if (optarg) strlcpy(swcfg.aeskeyfname,
@@ -955,15 +990,26 @@ int main(int argc, char **argv)
swupdate_crypto_init();
-#ifdef CONFIG_SIGNED_IMAGES
- if (strlen(swcfg.publickeyfname) || strlen(swcfg.gpg_home_directory)) {
- if (swupdate_dgst_init(&swcfg, swcfg.publickeyfname)) {
- fprintf(stderr,
- "Error: Crypto cannot be initialized.\n");
+ if (strlen(swcfg.hash_provider)) {
+ if (set_HASHlib(swcfg.hash_provider)) {
+ ERROR("HASH provider %s cannot be set", swcfg.hash_provider);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (strlen(swcfg.decrypt_provider)) {
+ if (set_cryptolib(swcfg.decrypt_provider)) {
+ ERROR("Decrypt provider %s cannot be set", swcfg.decrypt_provider);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (strlen(swcfg.digest_provider)) {
+ if (set_dgstlib(swcfg.digest_provider)) {
+ ERROR("Verification provider %s cannot be set", swcfg.digest_provider);
exit(EXIT_FAILURE);
}
}
-#endif
printf("%s\n\n", BANNER);
printf("Licensed under GPLv2. See source distribution for detailed "
@@ -986,6 +1032,15 @@ int main(int argc, char **argv)
print_registered_updatetypes(&swcfg);
print_registered_cryptolib();
+#ifdef CONFIG_SIGNED_IMAGES
+ if (strlen(swcfg.publickeyfname) || strlen(swcfg.gpg_home_directory)) {
+ if (swupdate_dgst_init(&swcfg, swcfg.publickeyfname)) {
+ ERROR("Error: Crypto cannot be initialized.\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+#endif
+
/*
* Install a child handler to check if a subprocess
* dies
diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg
index 7497a8cf..578a47a8 100644
--- a/examples/configuration/swupdate.cfg
+++ b/examples/configuration/swupdate.cfg
@@ -12,6 +12,20 @@
#
# verbose : boolean
# set verbose mode (Default: false)
+#
+# decrypt-provider : string
+# if multiple algos are regitered
+# choose which one should be used (mbedTLS, openssl,wolfssl)
+#
+# hash-provider : string
+# if multiple algos are regitered
+# choose which one should be used (mbedTLS, openssl,wolfssl)
+#
+# digest-provider : string
+# if multiple algos are regitered
+# choose which one should be used
+# (opensslCMS, GPG, pkcs#7WolfSSL, mbedTLSRSA, opensslRSA)
+#
# loglevel : integer
# level for logging from 1 (no log) to 6
# syslog : boolean
diff --git a/include/swupdate.h b/include/swupdate.h
index 4e186bef..59b085b6 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -112,6 +112,13 @@ struct swupdate_cfg {
char gpg_home_directory[SWUPDATE_GENERAL_STRING_SIZE];
char gpgme_protocol[SWUPDATE_GENERAL_STRING_SIZE];
int swdesc_max_size;
+ /*
+ * Select which provider is used in case of multiple
+ * crypto libraries
+ */
+ char hash_provider[SWUPDATE_GENERAL_STRING_SIZE];
+ char decrypt_provider[SWUPDATE_GENERAL_STRING_SIZE];
+ char digest_provider[SWUPDATE_GENERAL_STRING_SIZE];
};
struct swupdate_cfg *get_swupdate_cfg(void);
--
2.43.0