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

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