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

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