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

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