Skip to content
Browse files

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
  • Loading branch information...
1 parent 2e975b0 commit e0a029591f1ed1abca4e2b7472945b36be56ca6b @jschauma jschauma committed
Showing with 36 additions and 20 deletions.
  1. +8 −0 CHANGES
  2. +3 −3 doc/sigsh.1
  3. +2 −2 doc/sigsh.1.html
  4. +15 −12 src/sigsh.sh
  5. +8 −3 test/sigsh.test.pl
View
8 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
View
6 doc/sigsh.1
@@ -2,7 +2,7 @@
.\"
.\" 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
@@ -10,7 +10,7 @@
.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
@@ -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
View
4 doc/sigsh.1.html
@@ -17,7 +17,7 @@
<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>
@@ -38,7 +38,7 @@
<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>
View
27 src/sigsh.sh 100644 → 100755
@@ -63,14 +63,13 @@ 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
@@ -78,8 +77,8 @@ error() {
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
@@ -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
@@ -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
View
11 test/sigsh.test.pl
@@ -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");
@@ -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";

0 comments on commit e0a0295

Please sign in to comment.
Something went wrong with that request. Please try again.