Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
2015-02-10:
Browse files Browse the repository at this point in the history
 * merge changes from Y!:
   * change '-c' to '-f', since login shells might get invoked with '-c',
     which opens up the possibility of allowing a user to provide their
     own certificate via 'ssh host -- /dev/tty'
   * correct error reporting, since verifyArgs() is executed in a subshell
   * quote args to verifyArgs
  • Loading branch information
jschauma committed Feb 10, 2015
1 parent 2e975b0 commit e0a0295
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
8 changes: 8 additions & 0 deletions CHANGES
@@ -1,3 +1,11 @@
2015-02-10:
* merge changes from Y!:
* change '-c' to '-f', since login shells might get invoked with '-c',
which opens up the possibility of allowing a user to provide their
own certificate via 'ssh host -- /dev/tty'
* correct error reporting, since verifyArgs() is executed in a subshell
* quote args to verifyArgs

2011-08-07:
* significantly increase performance by only handling input line-by-line
if we are in trace mode
6 changes: 3 additions & 3 deletions doc/sigsh.1
Expand Up @@ -2,15 +2,15 @@
.\"
.\" This manual page was originally written by Jan Schaumann
.\" <jschauma@yahoo-inc.com> in September 2010.
.Dd February 09, 2011
.Dd February 10, 2015
.Dt SIGSH 1
.Os
.Sh NAME
.Nm sigsh
.Nd a signature verifying shell
.Sh SYNOPSIS
.Nm
.Op Fl c Ar certs
.Op Fl f Ar certs
.Op Fl x
.Op Fl p Ar prog
.Sh DESCRIPTION
Expand All @@ -26,7 +26,7 @@ interpreter.
.Nm
supports the following flags:
.Bl -tag -width s_shell_
.It Fl c Ar certs
.It Fl f Ar certs
Read ceritificates to trust from this file.
.It Fl p Ar prog
Pipe commands into this interpreter instead of the default
Expand Down
4 changes: 2 additions & 2 deletions doc/sigsh.1.html
Expand Up @@ -17,7 +17,7 @@ <h2><a name='sect0' href='#toc0'>Name</a></h2>
<h2><a name='sect1' href='#toc1'><b>Synopsis</b></a></h2>

<p>
<b>sigsh</b> [<b>-c</b> <i>certs</i>] [<b>-x</b>] [<b>-p</b> <i>prog</i>]
<b>sigsh</b> [<b>-f</b> <i>certs</i>] [<b>-x</b>] [<b>-p</b> <i>prog</i>]

<p>
<h2><a name='sect2' href='#toc2'><b>Description</b></a></h2>
Expand All @@ -38,7 +38,7 @@ <h2><a name='sect3' href='#toc3'><b>Options</b></a></h2>
<p>
<dl>

<dt><b>-c</b> <i>certs</i> </dt></dt>
<dt><b>-f</b> <i>certs</i> </dt></dt>
<dd>Read ceritificates to trust from this file.

<p></dd>
Expand Down
27 changes: 15 additions & 12 deletions src/sigsh.sh 100644 → 100755
Expand Up @@ -63,23 +63,22 @@ XTRACE=0
###

# function : error
# purpose : print given message to STDERR and exit unsuccessfully
# purpose : print given message to STDERR
# inputs : msg

error() {
local msg="$@"

echo "${PROGNAME}: $msg" >&2
exit 1
}

# function : usage
# purpose : print usage statement

usage() {
cat <<EOH
Usage: ${PROGNAME} [-x] [-c certs] [-p program]
-c certs Read certs to trust from this file.
Usage: ${PROGNAME} [-x] [-f certs] [-p program]
-f certs Read certs to trust from this file.
-p program Pipe commands into 'program'.
-x Enabled debugging.
EOH
Expand All @@ -89,17 +88,19 @@ EOH
# purpose : ensure given arg is sane for shell evaluation by matching it
# against a simple restrictive RE
# inputs : a string
# returns : the given string if it matches, errors out otherwise
# prints : the given string if it matches
# returns : 0 on success, 1 on invalid input

verifyArg() {
local arg="${1}"

if expr "${arg}" : "[a-zA-Z0-9/_.-]*$" >/dev/null 2>&1 ; then
echo "${arg}"
else
error "Argument must match ^[a-zA-Z0-9/_.-]*$."
# NOTREACHED
return 0
fi

error "Argument must match ^[a-zA-Z0-9/_.-]*$."
return 1
}

# function : xtrace
Expand All @@ -118,13 +119,15 @@ xtrace() {
### Main
###

while getopts 'c:p:x' opt; do
while getopts 'f:p:x' opt; do
case ${opt} in
c)
CERTS=$(verifyArg ${OPTARG})
f)
CERTS=$(verifyArg "${OPTARG}")
[ $? -gt 0 ] && exit 1
;;
p)
PROGRAM=$(verifyArg ${OPTARG})
PROGRAM=$(verifyArg "${OPTARG}")
[ $? -gt 0 ] && exit 1
;;
x)
XTRACE=1
Expand Down
11 changes: 8 additions & 3 deletions test/sigsh.test.pl
Expand Up @@ -6,7 +6,7 @@
use warnings;

use Test::Command;
use Test::More tests => 10;
use Test::More tests => 11;

system("openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.pem -out mycert.pem -batch >/dev/null 2>&1");

Expand All @@ -17,9 +17,14 @@
my $perl = `which perl`;
chomp($perl);

my $sigsh = "sh ../src/sigsh.sh -c ./mycert.pem";
my $sigsh= "sh ../src/sigsh.sh -f \"foo(); && >/etc/passwd\"";
my $test = Test::Command->new( cmd => $sigsh);
$test->stderr_like(qr/: Argument must match /, "invalid input leads to failure");

$sigsh = "sh ../src/sigsh.sh -f ./mycert.pem";

my $cmd = "echo uname | $signed_input | $sigsh";
my $test = Test::Command->new( cmd => $cmd);
$test = Test::Command->new( cmd => $cmd);
$test->stdout_like(qr/^$uname$/, "uname was invoked after verification");

$cmd = "echo uname | $signed_input | $sigsh -x";
Expand Down

0 comments on commit e0a0295

Please sign in to comment.