From ad9cbee049c839a441a97af2b713efa87ebc8623 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Wed, 18 Dec 2024 18:30:24 +0200
Subject: [PATCH] Some openssl changes.

- New alias for checking a server's certificate.
- Move everything to a dedicated file under `.bashrc.d/`.
---
 .bashrc           | 21 ---------------------
 .bashrc.d/openssl | 25 +++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 21 deletions(-)
 create mode 100644 .bashrc.d/openssl

diff --git a/.bashrc b/.bashrc
index 35c4037..dbffe22 100644
--- a/.bashrc
+++ b/.bashrc
@@ -186,11 +186,6 @@ genpass () {
     echo
 }
 
-gen_csr () {
-    name="${1:-site}"
-    openssl req -new -newkey rsa:4096 -nodes -out "$name.csr" -keyout "$name.key"
-}
-
 kodi_scan () {
     # shellcheck disable=SC1083
     ssh kodi.shore.co.il curl --silent --fail --show-error --json \'{\"jsonrpc\": \"2.0\", \"id\": \"transmission\", \"method\": \"VideoLibrary.Scan\"}\' http://127.0.0.1:8080/jsonrpc | jt
@@ -198,22 +193,6 @@ kodi_scan () {
     ssh kodi.shore.co.il curl --silent --fail --show-error --json \'{\"jsonrpc\": \"2.0\", \"id\": \"transmission\", \"method\": \"AudioLibrary.Scan\"}\' http://127.0.0.1:8080/jsonrpc | jt
 }
 
-match_ssl_pair () {
-    if [ "$#" -ne 2 ]
-    then
-        echo "Usage: match_ssl_pair private_key certificate"
-        return 1
-    fi
-    tempkey="$(mktemp)"
-    tempcert="$(mktemp)"
-    openssl pkey -pubout -outform PEM -in "$1" > "$tempkey"
-    openssl x509 -pubkey -noout -in "$2" > "$tempcert"
-    cmp "$tempkey" "$tempcert" > /dev/null
-    exitcode="$?"
-    rm "$tempkey" "$tempcert"
-    return "$exitcode"
-}
-
 mnt_lib () {
     mkdir -p "$HOME/Library"
     rclone mount \
diff --git a/.bashrc.d/openssl b/.bashrc.d/openssl
new file mode 100644
index 0000000..5896392
--- /dev/null
+++ b/.bashrc.d/openssl
@@ -0,0 +1,25 @@
+# shellcheck shell=bash
+# vim: ft=sh
+
+alias cert-check="echo | openssl s_client -port 443 -build_chain -showcerts -connect"
+
+gen_csr () {
+    name="${1:-site}"
+    openssl req -new -newkey rsa:4096 -nodes -out "$name.csr" -keyout "$name.key"
+}
+
+match_ssl_pair () {
+    if [ "$#" -ne 2 ]
+    then
+        echo "Usage: match_ssl_pair private_key certificate"
+        return 1
+    fi
+    tempkey="$(mktemp)"
+    tempcert="$(mktemp)"
+    openssl pkey -pubout -outform PEM -in "$1" > "$tempkey"
+    openssl x509 -pubkey -noout -in "$2" > "$tempcert"
+    cmp "$tempkey" "$tempcert" > /dev/null
+    exitcode="$?"
+    rm "$tempkey" "$tempcert"
+    return "$exitcode"
+}
-- 
GitLab