mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
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
This commit is contained in:
@@ -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 \
|
||||
|
||||
35
tests/keys-dump.sh
Executable file
35
tests/keys-dump.sh
Executable file
@@ -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
|
||||
Reference in New Issue
Block a user