Blame SOURCES/0001-Remove-dependency-on-deprecated-nss-pem.patch

e0b939
From b9005f1a69ad989a50ffa68a41c959551f0cb158 Mon Sep 17 00:00:00 2001
e0b939
From: Matej Habrnal <mhabrnal@redhat.com>
e0b939
Date: Wed, 23 May 2018 11:15:38 +0200
e0b939
Subject: [PATCH 1/1] Remove dependency on deprecated nss-pem
e0b939
e0b939
This commit removes dependency on nss-pem which is deprecated and
e0b939
reimplements TLS client to use libnssckbi.so instead [1].
e0b939
e0b939
Resolves #1578427
e0b939
e0b939
[1] https://docs-old.fedoraproject.org/en-US/Fedora_Security_Team/1/html/Defensive_Coding/sect-Defensive_Coding-TLS-Client-NSS.html#ex-Defensive_Coding-TLS-NSS-Init
e0b939
e0b939
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
e0b939
---
e0b939
 abrt.spec.in                      |  2 +-
e0b939
 src/plugins/abrt-retrace-client.c |  5 ++-
e0b939
 src/plugins/https-utils.c         | 53 ++++++-------------------------
e0b939
 src/plugins/https-utils.h         |  4 +--
e0b939
 4 files changed, 15 insertions(+), 49 deletions(-)
e0b939
e0b939
diff --git a/abrt.spec.in b/abrt.spec.in
e0b939
index f423562c..eb6fdaf9 100644
e0b939
--- a/abrt.spec.in
e0b939
+++ b/abrt.spec.in
e0b939
@@ -255,7 +255,7 @@ Summary: %{name}'s retrace client
e0b939
 Requires: %{name} = %{version}-%{release}
e0b939
 Requires: xz
e0b939
 Requires: tar
e0b939
-Requires: nss-pem
e0b939
+Requires: p11-kit-trust
e0b939
 
e0b939
 %description retrace-client
e0b939
 This package contains the client application for Retrace server
e0b939
diff --git a/src/plugins/abrt-retrace-client.c b/src/plugins/abrt-retrace-client.c
e0b939
index ae5ef83b..d50d45fb 100644
e0b939
--- a/src/plugins/abrt-retrace-client.c
e0b939
+++ b/src/plugins/abrt-retrace-client.c
e0b939
@@ -1281,8 +1281,7 @@ int main(int argc, char **argv)
e0b939
 
e0b939
     /* Initialize NSS */
e0b939
     SECMODModule *mod;
e0b939
-    PK11GenericObject *cert;
e0b939
-    nss_init(&mod, &cert);
e0b939
+    nss_init(&mod);
e0b939
 
e0b939
     /* Run the desired operation. */
e0b939
     int result = 0;
e0b939
@@ -1334,7 +1333,7 @@ int main(int argc, char **argv)
e0b939
         error_msg_and_die(_("Unknown operation: %s."), operation);
e0b939
 
e0b939
     /* Shutdown NSS. */
e0b939
-    nss_close(mod, cert);
e0b939
+    nss_close(mod);
e0b939
 
e0b939
     return result;
e0b939
 }
e0b939
diff --git a/src/plugins/https-utils.c b/src/plugins/https-utils.c
e0b939
index 7a22729b..7a9479ca 100644
e0b939
--- a/src/plugins/https-utils.c
e0b939
+++ b/src/plugins/https-utils.c
e0b939
@@ -142,37 +142,6 @@ static const char *ssl_get_configdir()
e0b939
     return NULL;
e0b939
 }
e0b939
 
e0b939
-static PK11GenericObject *nss_load_cacert(const char *filename)
e0b939
-{
e0b939
-    PK11SlotInfo *slot = PK11_FindSlotByName("PEM Token #0");
e0b939
-    if (!slot)
e0b939
-        error_msg_and_die(_("Failed to get slot 'PEM Token #0': %d."), PORT_GetError());
e0b939
-
e0b939
-    CK_ATTRIBUTE template[4];
e0b939
-    CK_OBJECT_CLASS class = CKO_CERTIFICATE;
e0b939
-
e0b939
-#define PK11_SETATTRS(x,id,v,l) \
e0b939
-    do {                        \
e0b939
-        (x)->type = (id);       \
e0b939
-        (x)->pValue=(v);        \
e0b939
-        (x)->ulValueLen = (l);  \
e0b939
-    } while (0)
e0b939
-
e0b939
-    PK11_SETATTRS(&template[0], CKA_CLASS, &class, sizeof(class));
e0b939
-    CK_BBOOL cktrue = CK_TRUE;
e0b939
-    PK11_SETATTRS(&template[1], CKA_TOKEN, &cktrue, sizeof(CK_BBOOL));
e0b939
-    PK11_SETATTRS(&template[2], CKA_LABEL, (unsigned char*)filename, strlen(filename)+1);
e0b939
-    PK11_SETATTRS(&template[3], CKA_TRUST, &cktrue, sizeof(CK_BBOOL));
e0b939
-    PK11GenericObject *cert = PK11_CreateGenericObject(slot, template, 4, PR_FALSE);
e0b939
-    PK11_FreeSlot(slot);
e0b939
-    return cert;
e0b939
-}
e0b939
-
e0b939
-static char *ssl_get_password(PK11SlotInfo *slot, PRBool retry, void *arg)
e0b939
-{
e0b939
-    return NULL;
e0b939
-}
e0b939
-
e0b939
 void ssl_connect(struct https_cfg *cfg, PRFileDesc **tcp_sock, PRFileDesc **ssl_sock)
e0b939
 {
e0b939
     PRAddrInfo *addrinfo = PR_GetAddrInfoByName(cfg->url, PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
e0b939
@@ -411,7 +380,7 @@ char *http_join_chunked(char *body, int bodylen)
e0b939
     return strbuf_free_nobuf(result);
e0b939
 }
e0b939
 
e0b939
-void nss_init(SECMODModule **mod, PK11GenericObject **cert)
e0b939
+void nss_init(SECMODModule **mod)
e0b939
 {
e0b939
     SECStatus sec_status;
e0b939
     const char *configdir = ssl_get_configdir();
e0b939
@@ -422,21 +391,19 @@ void nss_init(SECMODModule **mod, PK11GenericObject **cert)
e0b939
     if (SECSuccess != sec_status)
e0b939
         error_msg_and_die(_("Failed to initialize NSS."));
e0b939
 
e0b939
-    char *user_module = xstrdup("library=libnsspem.so name=PEM");
e0b939
-    *mod = SECMOD_LoadUserModule(user_module, NULL, PR_FALSE);
e0b939
-    free(user_module);
e0b939
-    if (!*mod || !(*mod)->loaded)
e0b939
-        error_msg_and_die(_("Failed to initialize security module."));
e0b939
-
e0b939
-    *cert = nss_load_cacert("/etc/pki/tls/certs/ca-bundle.crt");
e0b939
-    PK11_SetPasswordFunc(ssl_get_password);
e0b939
-    NSS_SetDomesticPolicy();
e0b939
+    // Initialize the trusted certificate store.
e0b939
+    char module_name[] = "library=libnssckbi.so name=\"Root Certs\"";
e0b939
+    *mod = SECMOD_LoadUserModule(module_name, NULL, PR_FALSE);
e0b939
+    if (*mod == NULL || !(*mod)->loaded)
e0b939
+    {
e0b939
+        const PRErrorCode err = PR_GetError();
e0b939
+        error_msg_and_die("error: NSPR error code %d: %s\n", err, PR_ErrorToName(err));
e0b939
+    }
e0b939
 }
e0b939
 
e0b939
-void nss_close(SECMODModule *mod, PK11GenericObject *cert)
e0b939
+void nss_close(SECMODModule *mod)
e0b939
 {
e0b939
     SSL_ClearSessionCache();
e0b939
-    PK11_DestroyGenericObject(cert);
e0b939
     SECMOD_UnloadUserModule(mod);
e0b939
     SECMOD_DestroyModule(mod);
e0b939
     SECStatus sec_status = NSS_Shutdown();
e0b939
diff --git a/src/plugins/https-utils.h b/src/plugins/https-utils.h
e0b939
index 8ff9aede..f0b167d3 100644
e0b939
--- a/src/plugins/https-utils.h
e0b939
+++ b/src/plugins/https-utils.h
e0b939
@@ -61,7 +61,7 @@ int http_get_response_code(const char *message);
e0b939
 void http_print_headers(FILE *file, const char *message);
e0b939
 char *tcp_read_response(PRFileDesc *tcp_sock);
e0b939
 char *http_join_chunked(char *body, int bodylen);
e0b939
-void nss_init(SECMODModule **mod, PK11GenericObject **cert);
e0b939
-void nss_close(SECMODModule *mod, PK11GenericObject *cert);
e0b939
+void nss_init(SECMODModule **mod);
e0b939
+void nss_close(SECMODModule *mod);
e0b939
 
e0b939
 #endif
e0b939
-- 
e0b939
2.17.0
e0b939