#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1997-12-24 06:47 EST by <ggr@avalon.qualcomm.com>.
# Source directory was `/export/home/ggr/usenix/kss'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   1050 -rwxrwxr-x addkey.exp
#   1032 -rwxrwxr-x createring.exp
#   1329 -rwxrwxr-x decrypt.exp
#   1239 -rwxrwxr-x extract.exp
#   1368 -rwxrwxr-x signkey.exp
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh02306; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= addkey.exp ==============
if test -f 'addkey.exp' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'addkey.exp' '(file already exists)'
else
  $echo 'x -' extracting 'addkey.exp' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'addkey.exp' &&
#!/pkg/expect/bin/expect -f
X
# add a key to specified keyring, exit status correct.
X
# generic subroutine for the suspect error cases.
proc die {s} {
X    global pgp argv0
X
X    set str "Unknown exit status"
X    switch $s {
X    1	{ set str "Unknown error" }
X    2	{ set str "Timeout from PGP" }
X    3	{ set str "Password incorrect" }
X    4	{ set str "Bad signature" }
X    5	{ set str "No output file" }
X    6	{ set str "No keys matched" }
X    }
X    puts stderr "$argv0: $str"
X    exit $s
}
X
if {$argc != 2} {
X    puts stderr "Usage: $argv0 keyring keyfile\n"
X    exit 255
}
X
set timeout 10
log_user 0
X
catch {exec sh -c "rm -f pubring.pkr; cp [lindex $argv 0] pubring.pkr"}
set pgp [spawn -noecho pgpk -a +BATCHMODE=on [lindex $argv 1]]
X
expect {
X    "Enter pass phrase:"	{ system kill $pgp; die 3 }
X    -re "Error:|Cannot open|Unable"
X				{ die 1 }
X    "BAD signature"		{ die 4 }
X    "No keys"			{ die 6 }
X    timeout			{ die 2 }
}
X
# Stupid PGP has trouble switching keyrings, so I have to do it instead.
exec cp pubring.pkr [lindex $argv 0]
X
Xexit 0
SHAR_EOF
  $shar_touch -am 1223135397 'addkey.exp' &&
  chmod 0775 'addkey.exp' ||
  $echo 'restore of' 'addkey.exp' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'addkey.exp:' 'MD5 check failed'
385b88e40f0b14e6492326d4e8818f70  addkey.exp
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'addkey.exp'`"
    test 1050 -eq "$shar_count" ||
    $echo 'addkey.exp:' 'original size' '1050,' 'current size' "$shar_count!"
  fi
fi
# ============= createring.exp ==============
if test -f 'createring.exp' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'createring.exp' '(file already exists)'
else
  $echo 'x -' extracting 'createring.exp' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'createring.exp' &&
#!/pkg/expect/bin/expect -f
X
# create specified keyring with one key in it, exit status correct.
X
# generic subroutine for the suspect error cases.
proc die {s} {
X    global pgp argv0
X
X    set str "Unknown exit status"
X    switch $s {
X    1	{ set str "Unknown error" }
X    2	{ set str "Timeout from PGP" }
X    3	{ set str "Password incorrect" }
X    4	{ set str "Bad signature" }
X    5	{ set str "No output file" }
X    6	{ set str "No keys matched" }
X    }
X    puts stderr "$argv0: $str"
X    exit $s
}
X
if {$argc != 2} {
X    puts stderr "Usage: $argv0 keyring keyfile\n"
X    exit 255
}
X
set timeout 100
log_user 0
X
exec rm -f pubring.pkr [lindex $argv 0]
set pgp [spawn -noecho pgpk -a +BATCHMODE=on [lindex $argv 1]]
X
expect {
X    "Enter pass phrase:"	{ system kill $pgp; die 3 }
X    -re "Error:|Cannot open|Unable"
X				{ die 1 }
X    "BAD signature"		{ die 4 }
X    "No keys"			{ die 6 }
X    timeout			{ die 2 }
}
X
# Stupid PGP has trouble switching keyrings, so I have to do it instead.
exec cp pubring.pkr [lindex $argv 0]
X
Xexit 0
SHAR_EOF
  $shar_touch -am 1223135397 'createring.exp' &&
  chmod 0775 'createring.exp' ||
  $echo 'restore of' 'createring.exp' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'createring.exp:' 'MD5 check failed'
f209bd34a582838c24896c0e7d81ae38  createring.exp
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'createring.exp'`"
    test 1032 -eq "$shar_count" ||
    $echo 'createring.exp:' 'original size' '1032,' 'current size' "$shar_count!"
  fi
fi
# ============= decrypt.exp ==============
if test -f 'decrypt.exp' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'decrypt.exp' '(file already exists)'
else
  $echo 'x -' extracting 'decrypt.exp' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'decrypt.exp' &&
#!/pkg/expect/bin/expect -f
X
# decrypt a file, result on stdout, exit status correct.
X
# generic subroutine for the suspect error cases.
proc die {s} {
X    global pgp argv0
X
X    set str "Unknown exit status"
X    switch $s {
X    1	{ set str "Can't check signature" }
X    2	{ set str "Timeout from PGP" }
X    3	{ set str "Password incorrect" }
X    4	{ set str "Bad signature" }
X    5	{ set str "No output file" }
X    6	{ set str "Unknown error" }
X    }
X    puts stderr "$argv0: $str"
X    exit $s
}
X
if {$argc != 2} {
X    puts stderr "Usage: $argv0 pubring pgpfile"
X    exit 255
}
X
gets stdin kf
set timeout 10
log_user 0
log_file -a decryption.log
set exit_status 0
X
# Stupid PGP has trouble switching keyrings, so I have to do it instead.
exec sh -c "rm -f pubring.pkr; cp [lindex $argv 0] pubring.pkr"
X
set pgp [spawn -noecho sh -c "(echo '$kf'; cat [lindex $argv 1]) | PGPPASSFD=0 pgpv +BATCHMODE=on >/tmp/xxx$$"]
X
expect {
X    "Enter pass phrase:"	{ system kill $pgp; die 3 }
X    -re "Error:|Cannot open"	{ die 6 }
X    "BAD signature"		{ die 4 }
X    "Signature by unknown key"	{ set exit_status 1 }
X    timeout			{ die 2 }
}
X
# copy the output file to stdout
if [catch {set outfile [open /tmp/xxx$pgp r]}] { die 5 }
set contents [read $outfile]
puts -nonewline $contents
X
# clean up
system rm -f /tmp/xxx$pgp
exit $exit_status
SHAR_EOF
  $shar_touch -am 1223150797 'decrypt.exp' &&
  chmod 0775 'decrypt.exp' ||
  $echo 'restore of' 'decrypt.exp' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'decrypt.exp:' 'MD5 check failed'
3fc7d0cfa1459d21d935fc1e4ce6850f  decrypt.exp
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'decrypt.exp'`"
    test 1329 -eq "$shar_count" ||
    $echo 'decrypt.exp:' 'original size' '1329,' 'current size' "$shar_count!"
  fi
fi
# ============= extract.exp ==============
if test -f 'extract.exp' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'extract.exp' '(file already exists)'
else
  $echo 'x -' extracting 'extract.exp' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'extract.exp' &&
#!/pkg/expect/bin/expect -f
X
# extract a key from specified keyring, result on stdout, exit status correct.
X
# generic subroutine for the suspect error cases.
proc die {s} {
X    global pgp argv0
X
X    set str "Unknown exit status"
X    switch $s {
X    1	{ set str "Unknown error" }
X    2	{ set str "Timeout from PGP" }
X    3	{ set str "Password incorrect" }
X    4	{ set str "Bad signature" }
X    5	{ set str "No output file" }
X    6	{ set str "No keys matched" }
X    }
X    puts stderr "$argv0: $str"
X    exit $s
}
X
if {$argc != 2} {
X    puts stderr "Usage: $argv0 pgpfile keyid"
X    exit 255
}
X
set timeout 10
# log_user 0
X
# Stupid PGP has trouble switching keyrings, so I have to do it instead.
catch {exec sh -c "rm -f pubring.pkr; cp [lindex $argv 0] pubring.pkr"}
X
set pgp [spawn -noecho sh -c "pgpk +ARMOR=on +BATCHMODE=on -x '[lindex $argv 1]' >/tmp/xxx$$"]
X
expect {
X    "Enter pass phrase:"	{ system kill $pgp; die 3 }
X    -re "Error:|Cannot open"	{ die 1 }
X    "BAD signature"		{ die 4 }
X    "No keys"			{ die 6 }
X    timeout			{ die 2 }
}
X
# copy the output file to stdout
if [catch {set outfile [open /tmp/xxx$pgp r]}] { die 5 }
set contents [read $outfile]
puts -nonewline $contents
X
# clean up
system rm -f /tmp/xxx$pgp
Xexit 0
SHAR_EOF
  $shar_touch -am 1223135397 'extract.exp' &&
  chmod 0775 'extract.exp' ||
  $echo 'restore of' 'extract.exp' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'extract.exp:' 'MD5 check failed'
220b37cd5e451c715be6d7a7ac4db2e9  extract.exp
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'extract.exp'`"
    test 1239 -eq "$shar_count" ||
    $echo 'extract.exp:' 'original size' '1239,' 'current size' "$shar_count!"
  fi
fi
# ============= signkey.exp ==============
if test -f 'signkey.exp' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'signkey.exp' '(file already exists)'
else
  $echo 'x -' extracting 'signkey.exp' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'signkey.exp' &&
#!/pkg/expect/bin/expect -f
X
# Sign a key, exit status correct.
X
# generic subroutine for the suspect error cases.
proc die {s} {
X    global pgp argv0
X
X    set str "Unknown exit status"
X    switch $s {
X    1	{ set str "Can't check signature" }
X    2	{ set str "Timeout from PGP" }
X    3	{ set str "Password incorrect" }
X    4	{ set str "Bad signature" }
X    5	{ set str "No output file" }
X    6	{ set str "Unknown error" }
X    7	{ set str "More than one key matches" }
X    }
X    puts stderr "$argv0: $str"
X    exit $s
}
X
if {$argc != 3} {
X    puts stderr "Usage: $argv0 pubring signing_key user_key"
X    exit 255
}
X
gets stdin kf
set timeout 10
log_user 0
set exit_status 0
X
# Stupid PGP has trouble switching keyrings, so I have to do it instead.
exec sh -c "rm -f pubring.pkr; cp [lindex $argv 0] pubring.pkr"
X
set pgp [spawn -noecho sh -c "(echo 'y'; echo '$kf') | PGPPASSFD=0 pgpk +BATCHMODE=on -s '[lindex $argv 2]' -u '[lindex $argv 1]'"]
X
expect {
X    "Bad passphrase"		{ catch {system kill $pgp}; die 3 }
X    -re "Error:|Cannot open"	{ die 6 }
X    "BAD signature"		{ die 4 }
X    timeout			{ die 2 }
X    "Choose one of the above"	{ catch {system kill $pgp}; die 7 }
X    "Duplicate certification"	{ puts stderr "Already signed" }
}
X
# Stupid PGP has trouble switching keyrings, so I have to do it instead.
exec cp pubring.pkr [lindex $argv 0]
X
# clean up
Xexit 0
SHAR_EOF
  $shar_touch -am 1223141097 'signkey.exp' &&
  chmod 0775 'signkey.exp' ||
  $echo 'restore of' 'signkey.exp' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'signkey.exp:' 'MD5 check failed'
f30e3e0ff06d963163b397e2a5596c63  signkey.exp
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'signkey.exp'`"
    test 1368 -eq "$shar_count" ||
    $echo 'signkey.exp:' 'original size' '1368,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh02306
exit 0
