Blame SOURCES/0003-Adjust-hash-defaults-based-on-system-security-level.patch

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