Blame SOURCES/0008-Fix-client-cert-issues-found-by-CI-tests.patch

19981c
From 8afa0ce578ecd5cc3a397707fdb163cc169b9bd1 Mon Sep 17 00:00:00 2001
19981c
From: Stephen Gallagher <sgallagh@redhat.com>
19981c
Date: Fri, 13 Dec 2019 08:25:01 -0500
19981c
Subject: [PATCH 8/8] Fix client-cert issues found by CI tests
19981c
19981c
Resolves: rhbz#1720667
19981c
19981c
Better error message for client certs without public key file
19981c
19981c
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
19981c
19981c
Fix memory leak in sscg_sign_x509_csr()
19981c
19981c
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
19981c
19981c
Address clang-analyzer warning
19981c
19981c
clang-analyzer determined that it was possible for the GET_BIO()
19981c
return value to have changed between conditional creation of the
19981c
client certificate and writing it out. This patch stores the result
19981c
of the lookup so it's certain to be consistent.
19981c
19981c
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
19981c
---
19981c
 src/io_utils.c | 4 ++--
19981c
 src/sscg.c     | 8 +++++---
19981c
 src/x509.c     | 1 +
19981c
 3 files changed, 8 insertions(+), 5 deletions(-)
19981c
19981c
diff --git a/src/io_utils.c b/src/io_utils.c
19981c
index 809a1da0e455afa0dba0796a5f7ac406742328a1..a2502afb20f4bcb536428f3528900c2bb06997f5 100644
19981c
--- a/src/io_utils.c
19981c
+++ b/src/io_utils.c
19981c
@@ -363,8 +363,8 @@ sscg_io_utils_open_output_files (struct sscg_stream **streams, bool overwrite)
19981c
 
19981c
     case IO_UTILS_CLIENT_UNMATCHED:
19981c
       SSCG_ERROR (
19981c
-        "The client certificate must have both public and private key "
19981c
-        "locations specified.\n");
19981c
+        "The client certificate must have the public key location "
19981c
+        "specified.\n");
19981c
       ret = EINVAL;
19981c
       goto done;
19981c
 
19981c
diff --git a/src/sscg.c b/src/sscg.c
19981c
index 470af815d91f5170a1e8fe00006dbaee4d07b209..f34a43b83e562d0bd7da9a77e25911762db83693 100644
19981c
--- a/src/sscg.c
19981c
+++ b/src/sscg.c
19981c
@@ -300,6 +300,7 @@ main (int argc, const char **argv)
19981c
   char *cert_key_password = NULL;
19981c
   char *cert_key_passfile = NULL;
19981c
 
19981c
+  bool build_client_cert = false;
19981c
   int client_mode = SSCG_CERT_DEFAULT_MODE;
19981c
   int client_key_mode = SSCG_KEY_DEFAULT_MODE;
19981c
   char *client_key_password = NULL;
19981c
@@ -1118,7 +1119,8 @@ main (int argc, const char **argv)
19981c
   /* If requested, generate the client auth certificate and sign it with the
19981c
    * private CA.
19981c
    */
19981c
-  if (GET_BIO (SSCG_FILE_TYPE_CLIENT))
19981c
+  build_client_cert = !!(GET_BIO (SSCG_FILE_TYPE_CLIENT));
19981c
+  if (build_client_cert)
19981c
     {
19981c
       ret = create_cert (main_ctx,
19981c
                          options,
19981c
@@ -1136,7 +1138,7 @@ main (int argc, const char **argv)
19981c
 
19981c
   /* Write private keys first */
19981c
 
19981c
-  if (GET_BIO (SSCG_FILE_TYPE_CLIENT_KEY))
19981c
+  if (build_client_cert)
19981c
     {
19981c
       /* This function has a default mechanism for prompting for the
19981c
        * password if it is passed a cipher and gets a NULL password.
19981c
@@ -1201,7 +1203,7 @@ main (int argc, const char **argv)
19981c
   /* Public keys come next, in chain order */
19981c
 
19981c
   /* Start with the client certificate */
19981c
-  if (GET_BIO (SSCG_FILE_TYPE_CLIENT))
19981c
+  if (build_client_cert)
19981c
     {
19981c
       sret = PEM_write_bio_X509 (GET_BIO (SSCG_FILE_TYPE_CLIENT),
19981c
                                  client_cert->certificate);
19981c
diff --git a/src/x509.c b/src/x509.c
19981c
index 18f0627bc64e7cb503a9e81c36dbe726186d1144..c173f539791fbbc51e52e6b121e587dca43924d4 100644
19981c
--- a/src/x509.c
19981c
+++ b/src/x509.c
19981c
@@ -482,5 +482,6 @@ done:
19981c
       *_cert = talloc_steal (mem_ctx, scert);
19981c
     }
19981c
   X509_NAME_free (subject);
19981c
+  talloc_free(tmp_ctx);
19981c
   return ret;
19981c
 }
19981c
-- 
19981c
2.23.0
19981c