2022-06-29 19:12:40 +00:00
|
|
|
From 0cf3235a6d21f17657b78863576a9adda227cc31 Mon Sep 17 00:00:00 2001
|
2022-05-26 18:33:17 +00:00
|
|
|
From: Stephen Gallagher <sgallagh@redhat.com>
|
|
|
|
Date: Wed, 28 Nov 2018 08:00:08 -0500
|
2022-06-29 19:12:40 +00:00
|
|
|
Subject: [PATCH 03/11] Adjust hash defaults based on system security level
|
2022-05-26 18:33:17 +00:00
|
|
|
|
|
|
|
Unlike the key-strength, this does not set a minimum level because
|
|
|
|
it's not a simple calculation. We will have to rely on libcrypto
|
|
|
|
rejecting any explicitly-set algorithms as a violation of policy.
|
|
|
|
|
|
|
|
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
|
|
|
|
---
|
|
|
|
include/sscg.h | 1 +
|
|
|
|
src/sscg.c | 40 +++++++++++++++++++++-------------------
|
|
|
|
2 files changed, 22 insertions(+), 19 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/include/sscg.h b/include/sscg.h
|
|
|
|
index 3e97cfe49a5cd8fc734ecf43a94156e376227eb7..fc90b81a0060af28529f3be6922b1b1501559300 100644
|
|
|
|
--- a/include/sscg.h
|
|
|
|
+++ b/include/sscg.h
|
|
|
|
@@ -140,6 +140,7 @@ struct sscg_options
|
|
|
|
/* Encryption requirements */
|
|
|
|
int key_strength;
|
|
|
|
int minimum_key_strength;
|
|
|
|
+ char *hash_alg;
|
|
|
|
const EVP_MD *hash_fn;
|
|
|
|
|
|
|
|
/* Output Files */
|
|
|
|
diff --git a/src/sscg.c b/src/sscg.c
|
|
|
|
index 85a42404aa94524b560755d506b893300a4414cd..58855f764480d24d6c0f57460b22a3a83281e37e 100644
|
|
|
|
--- a/src/sscg.c
|
|
|
|
+++ b/src/sscg.c
|
|
|
|
@@ -66,14 +66,21 @@ set_default_options (struct sscg_options *opts)
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
/* Security level 2 and below permits lower key-strengths, but SSCG
|
|
|
|
- * will set a minimum of 2048 bits
|
|
|
|
+ * will set a minimum of 2048 bits and the sha256 hash algorithm.
|
|
|
|
*/
|
|
|
|
+ opts->hash_alg = talloc_strdup (opts, "sha256");
|
|
|
|
opts->key_strength = 2048;
|
|
|
|
break;
|
|
|
|
|
|
|
|
- case 3: opts->key_strength = 3072; break;
|
|
|
|
+ case 3:
|
|
|
|
+ opts->hash_alg = talloc_strdup (opts, "sha256");
|
|
|
|
+ opts->key_strength = 3072;
|
|
|
|
+ break;
|
|
|
|
|
|
|
|
- case 4: opts->key_strength = 7680; break;
|
|
|
|
+ case 4:
|
|
|
|
+ opts->hash_alg = talloc_strdup (opts, "sha384");
|
|
|
|
+ opts->key_strength = 7680;
|
|
|
|
+ break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unknown security level. Default to the highest we know about */
|
|
|
|
@@ -83,7 +90,10 @@ set_default_options (struct sscg_options *opts)
|
|
|
|
security_level);
|
|
|
|
/* Fall through */
|
|
|
|
|
|
|
|
- case 5: opts->key_strength = 15360; break;
|
|
|
|
+ case 5:
|
|
|
|
+ opts->hash_alg = talloc_strdup (opts, "sha512");
|
|
|
|
+ opts->key_strength = 15360;
|
|
|
|
+ break;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts->minimum_key_strength = opts->key_strength;
|
|
|
|
@@ -177,7 +187,6 @@ main (int argc, const char **argv)
|
|
|
|
char *email = NULL;
|
|
|
|
char *hostname = NULL;
|
|
|
|
char *packagename;
|
|
|
|
- char *hash_alg = NULL;
|
|
|
|
char **alternative_names = NULL;
|
|
|
|
|
|
|
|
char *ca_file = NULL;
|
|
|
|
@@ -351,10 +360,10 @@ main (int argc, const char **argv)
|
|
|
|
{
|
|
|
|
"hash-alg",
|
|
|
|
'\0',
|
|
|
|
- POPT_ARG_STRING,
|
|
|
|
- &hash_alg,
|
|
|
|
+ POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT,
|
|
|
|
+ &options->hash_alg,
|
|
|
|
0,
|
|
|
|
- _ ("Hashing algorithm to use for signing. (default: sha256)"),
|
|
|
|
+ _ ("Hashing algorithm to use for signing."),
|
|
|
|
_ ("{sha256,sha384,sha512}"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
@@ -592,17 +601,10 @@ main (int argc, const char **argv)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (!hash_alg)
|
|
|
|
- {
|
|
|
|
- /* Default to SHA256 */
|
|
|
|
- options->hash_fn = EVP_sha256 ();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- /* TODO: restrict this to approved hashes.
|
|
|
|
- * For now, we'll only list SHA[256|384|512] in the help */
|
|
|
|
- options->hash_fn = EVP_get_digestbyname (hash_alg);
|
|
|
|
- }
|
|
|
|
+ /* TODO: restrict this to approved hashes.
|
|
|
|
+ * For now, we'll only list SHA[256|384|512] in the help */
|
|
|
|
+ options->hash_fn = EVP_get_digestbyname (options->hash_alg);
|
|
|
|
+
|
|
|
|
if (!options->hash_fn)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Unsupported hashing algorithm.");
|
|
|
|
--
|
2022-06-29 19:12:40 +00:00
|
|
|
2.35.1
|
2022-05-26 18:33:17 +00:00
|
|
|
|