From 8db9f9c7dec976569a01cbc688eb251617685c56 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 7 Apr 2022 15:29:37 +0000 Subject: [PATCH] Add a wrapper for using cassh with a keyfile --- Makefile | 2 +- cassh-keyfile.1 | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ cassh-keyfile.sh | 45 ++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 cassh-keyfile.1 create mode 100644 cassh-keyfile.sh diff --git a/Makefile b/Makefile index 4b77ff3..09e943b 100644 --- a/Makefile +++ b/Makefile @@ -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} diff --git a/cassh-keyfile.1 b/cassh-keyfile.1 new file mode 100644 index 0000000..2e2c5a7 --- /dev/null +++ b/cassh-keyfile.1 @@ -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 +.\" . +.\" +.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/ diff --git a/cassh-keyfile.sh b/cassh-keyfile.sh new file mode 100644 index 0000000..4490a09 --- /dev/null +++ b/cassh-keyfile.sh @@ -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 +# . + +usage() +{ + cat - <&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