Add a wrapper for using cassh with a keyfile

This commit is contained in:
Lucas 2022-04-07 15:29:37 +00:00
parent f8ca9d4974
commit 8db9f9c7de
3 changed files with 110 additions and 1 deletions

View File

@ -24,7 +24,7 @@ V = 0
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/man
BIN = cassh
BIN = cassh cassh-keyfile
MAN1 = ${BIN:=.1}
SRC = ${BIN:=.sh} ${MAN1}

64
cassh-keyfile.1 Normal file
View File

@ -0,0 +1,64 @@
.\" cassh - Manager for an OpenSSH Certification Authority
.\"
.\" Written in 2022 by Lucas
.\"
.\" To the extent possible under law, the author(s) have dedicated all
.\" copyright and related and neighboring rights to this software to the
.\" public domain worldwide. This software is distributed without any
.\" warranty.
.\"
.\" You should have received a copy of the CC0 Public Domain Dedication
.\" along with this software. If not, see
.\" <http://creativecommons.org/publicdomain/zero/1.0/>.
.\"
.Dd March 01, 2022
.Dt CASSH-KEYFILE 1
.Os
.Sh NAME
.Nm cassh-keyfile
.Nd Wrapper for using a private key file with cassh
.Sh SYNOPSIS
.Nm
.Ar private_key
.Cm cassh_command
.Op Ar options ...
.Sh DESCRIPTION
.Xr cassh 1
requires a running
.Xr ssh-agent 1
with the Certification Authority private key already loaded.
.Nm
provides a thin wrapper around
.Xr cassh 1 ,
initiating an
.Xr ssh-agent 1
instance and loading the Certification Authority private key from
.Ar private_key
file before calling
.Xr cassh 1 .
The
.Xr ssh-agent 1
instance exits when the commands are completed.
.Pp
.Nm
will only instantiate an
.Xr ssh-agent 1
if
.Cm cassh_command
does need one.
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
.Xr ssh-agent 1 ,
.Xr ssh-keygen 1
.Sh AUTHORS
.An Lucas
.Sh LICENSE
.Nm
is in the public domain.
.Pp
To the extent possible under law, the author(s) have dedicated all
copyright and related and neighboring rights to this software to the
public domain worldwide.
.Pp
.Lk http://creativecommons.org/publicdomain/zero/1.0/

45
cassh-keyfile.sh Normal file
View File

@ -0,0 +1,45 @@
#!/bin/sh
# cassh - Manager for an OpenSSH Certification Authority
#
# Written in 2022 by Lucas
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any
# warranty.
# You should have received a copy of the CC0 Public Domain Dedication
# along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage()
{
cat - <<EOF >&2
Usage:
${0##*/} private_key cassh_command [options ...]
EOF
exit 1
}
if [ $# -lt 2 ]; then
usage
fi
cassh_command=$2
needs_agent=false
case $cassh_command in
issue)
needs_agent=true
;;
esac
if $needs_agent; then
ssh-agent sh -s "$@" <<'EOF'
ssh-add -q "$1" && shift && cassh "$@"
rc=$?
ssh-agent -k >/dev/null
exit $rc
EOF
else
shift
cassh "$@"
fi