Blame SOURCES/0002-Add-script-to-add-common-root-CAs.patch

1beea6
From 61985f642b0b5cc75fc3f254ef6c99aeb56acbe2 Mon Sep 17 00:00:00 2001
1beea6
From: Alexander Scheel <ascheel@redhat.com>
1beea6
Date: Thu, 29 Aug 2019 16:14:08 -0400
1beea6
Subject: [PATCH 2/3] Add script to add common root CAs
1beea6
1beea6
When given an NSS DB, common_roots.sh uses the trust command to extract
1beea6
the root CAs trusted by the local system and add them to said NSS DB.
1beea6
1beea6
Signed-off-by: Alexander Scheel <ascheel@redhat.com>
1beea6
---
1beea6
 tools/common_roots.sh | 36 ++++++++++++++++++++++++++++++++++++
1beea6
 1 file changed, 36 insertions(+)
1beea6
 create mode 100755 tools/common_roots.sh
1beea6
1beea6
diff --git a/tools/common_roots.sh b/tools/common_roots.sh
1beea6
new file mode 100755
1beea6
index 00000000..97341c4c
1beea6
--- /dev/null
1beea6
+++ b/tools/common_roots.sh
1beea6
@@ -0,0 +1,36 @@
1beea6
+#!/bin/bash
1beea6
+
1beea6
+# This script reads the contents of the OS CA bundle store,
1beea6
+#   /usr/share/pki/ca-trust-source/ca-bundle.trust.p11-kit
1beea6
+# and places the contained CAs into the specified NSS DB.
1beea6
+#
1beea6
+# This NSS DB is used by various JSS tests that aren't enabled
1beea6
+# by default because they require an active internet connection.
1beea6
+
1beea6
+nssdb="$1"
1beea6
+
1beea6
+if [ -z "$nssdb" ] && [ -e "build" ]; then
1beea6
+    nssdb="build/results/cadb"
1beea6
+elif [ -z "$nssdb" ] && [ -e "../build" ]; then
1beea6
+    nssdb="../build/results/cadb"
1beea6
+else
1beea6
+    echo "Must provide path to NSS DB!" 1>&2
1beea6
+    exit 1
1beea6
+fi
1beea6
+
1beea6
+if [ -e "$nssdb" ]; then
1beea6
+    rm -rf "$nssdb"
1beea6
+fi
1beea6
+
1beea6
+mkdir -p "$nssdb"
1beea6
+echo "" > "$nssdb/password.txt"
1beea6
+certutil -N -d "$nssdb" -f "$nssdb/password.txt"
1beea6
+
1beea6
+trust extract --format=pem-bundle  --filter=ca-anchors "$nssdb/complete.pem"
1beea6
+
1beea6
+# From: https://serverfault.com/questions/391396/how-to-split-a-pem-file
1beea6
+csplit -f "$nssdb/individual-" "$nssdb/complete.pem" '/-----BEGIN CERTIFICATE-----/' '{*}'
1beea6
+
1beea6
+for cert in "$nssdb"/individual*; do
1beea6
+    certutil -A -a -i "$cert" -n "$cert" -t CT,C,C -d "$nssdb" -f "$nssdb/password.txt"
1beea6
+done
1beea6
-- 
1beea6
2.21.0
1beea6