From ceb158014badcc51210629e02af6f3ed965036dd Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 3 Sep 2026 09:46:33 +0200 Subject: [PATCH] tests: add script to dump test keys in more parsable formats In some cases this is binary, in others it's textual. To better see what's in the keys, to debug them, and debug code dealing with them. It's a manual script, not run automatically by this repo. Closes #2574 --- tests/Makefile.inc | 1 + tests/keys-dump.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 tests/keys-dump.sh diff --git a/tests/Makefile.inc b/tests/Makefile.inc index 836a15e7..5d3495a5 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -72,6 +72,7 @@ librunner_la_SOURCES = \ EXTRA_DIST = \ .checksrc \ CMakeLists.txt \ + keys-dump.sh \ keys-generate.sh \ keys/ca_host_ecdsa \ keys/ca_host_ecdsa.pub \ diff --git a/tests/keys-dump.sh b/tests/keys-dump.sh new file mode 100755 index 00000000..3e0ce477 --- /dev/null +++ b/tests/keys-dump.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Copyright (C) Viktor Szakats +# SPDX-License-Identifier: BSD-3-Clause + +# Dump keys in more human-parsable formats + +for dir in keys openssh_server; do + [ -d "${dir}-dump" ] || mkdir "${dir}-dump" + rm -f "${dir}-dump"/* + + find "${dir}" -maxdepth 1 \( -name 'ca_*' -o -name 'id_*' -o -name 'ssh_*' \) | while read -r f; do + o="${dir}-dump/$(basename "$f")" + echo "$f" + if [[ "$f" = *'.pub' ]]; then + b64="$(grep -o -E ' .+ ' "$f")" + [ -z "$b64" ] && b64="$(grep -o -E ' .+$' "$f")" + echo "$b64" | tr -d ' ' | base64 -d > "$o.bin" + if [[ "$f" = *'cert'* ]]; then + ssh-keygen -L -f "$f" > "$o.cert.txt" + fi + else + if [[ "$f" = *'pkcs8'* ]]; then + openssl asn1parse -dump -in "$f" > "$o.pkey.asn1.txt" + else + grep -v -E '^(-----|DEK-Info|Proc-Type)' "$f" | base64 -d > "$o.pkey.bin" + fi + openssl pkey -text -noout -passin pass:libssh2 -in "$f" >> "$o.pkey.txt" 2>/dev/null + [ -s "$o.pkey.txt" ] || rm -f "$o.pkey.txt" + fi + cp -p "$f" "$o" + done +done + +openssl -version