2004-08-09 13:58:26 +02:00
|
|
|
#!/bin/sh
|
2004-10-22 14:31:04 +02:00
|
|
|
# -*- sh -*-
|
|
|
|
# gpgsm-gencert.c - Generate X.509 certificates through GPGSM.
|
|
|
|
# Copyright (C) 2004 Free Software Foundation, Inc.
|
2004-08-09 13:58:26 +02:00
|
|
|
#
|
|
|
|
# This file is part of GnuPG.
|
|
|
|
#
|
|
|
|
# GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# GnuPG is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
# 02111-1307, USA.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
ASSUAN_FP_IN=4
|
|
|
|
ASSUAN_FP_OUT=5
|
|
|
|
|
|
|
|
ASSUAN_COMMANDS="\
|
|
|
|
INPUT FD=$ASSUAN_FP_IN\n\
|
|
|
|
OUTPUT FD=$ASSUAN_FP_OUT --armor\n\
|
|
|
|
GENKEY\n\
|
|
|
|
BYE"
|
|
|
|
|
|
|
|
ANSWER=""
|
|
|
|
|
|
|
|
query_user()
|
|
|
|
{
|
|
|
|
message=$1; shift
|
|
|
|
|
2004-10-22 14:31:04 +02:00
|
|
|
echo "$message" >&2
|
|
|
|
echo -n "> " >&2
|
2004-08-09 13:58:26 +02:00
|
|
|
read answer
|
|
|
|
|
|
|
|
ANSWER=$answer;
|
|
|
|
}
|
|
|
|
|
|
|
|
query_user_menu()
|
|
|
|
{
|
|
|
|
message=$1; shift
|
|
|
|
i=0
|
|
|
|
|
2004-10-22 14:31:04 +02:00
|
|
|
echo "$message" >&2
|
2004-08-09 13:58:26 +02:00
|
|
|
for choice in "$@"; do
|
|
|
|
i=$(expr $i + 1)
|
2004-10-22 14:31:04 +02:00
|
|
|
echo " [$i] $choice" >&2
|
2004-08-09 13:58:26 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
j=1
|
2004-10-22 14:31:04 +02:00
|
|
|
echo -n "Your selection: " >&2
|
2004-08-09 13:58:26 +02:00
|
|
|
read idx
|
|
|
|
|
|
|
|
while [ $j -lt $i -o $j -eq $i ]; do
|
|
|
|
if [ "$idx" = $j ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
j=$(expr $j + 1)
|
|
|
|
done
|
|
|
|
if [ $j -lt $i -o $j -eq $i ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
i=0
|
|
|
|
for choice in "$@"; do
|
|
|
|
i=$(expr $i + 1)
|
|
|
|
if [ $i -eq $idx ]; then
|
|
|
|
ANSWER=$1
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2004-10-22 14:31:04 +02:00
|
|
|
echo "You selected: $ANSWER" >&2
|
2004-08-09 13:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
query_user_menu "Key type" "RSA"
|
|
|
|
KEY_TYPE=$ANSWER
|
|
|
|
|
|
|
|
query_user_menu "Key length" "1024" "2048"
|
|
|
|
KEY_LENGTH=$ANSWER
|
|
|
|
|
2004-10-22 14:31:04 +02:00
|
|
|
query_user_menu "Key usage" "sign, encrypt" "sign" "encrypt"
|
2004-08-09 13:58:26 +02:00
|
|
|
KEY_USAGE=$ANSWER
|
|
|
|
|
|
|
|
query_user "Name"
|
|
|
|
NAME=$ANSWER
|
|
|
|
|
|
|
|
query_user "E-Mail address"
|
|
|
|
EMAIL_ADDRESS=$ANSWER
|
|
|
|
|
|
|
|
file_parameter=$(mktemp "/tmp/gpgsm.XXXXXX")
|
2004-10-22 14:31:04 +02:00
|
|
|
outfile=$(mktemp "/tmp/gpgsm.XXXXXX")
|
2004-08-09 13:58:26 +02:00
|
|
|
|
|
|
|
cat > "$file_parameter" <<EOF
|
|
|
|
Key-Type: $KEY_TYPE
|
|
|
|
Key-Length: $KEY_LENGTH
|
|
|
|
Key-Usage: $KEY_USAGE
|
|
|
|
Name-DN: $NAME
|
|
|
|
Name-Email: $EMAIL_ADDRESS
|
|
|
|
EOF
|
|
|
|
|
2004-10-22 14:31:04 +02:00
|
|
|
echo -e "$ASSUAN_COMMANDS" | \
|
|
|
|
gpgsm --server 4< "$file_parameter" 5>"$outfile" >/dev/null
|
|
|
|
|
|
|
|
cat "$outfile"
|
2004-08-09 13:58:26 +02:00
|
|
|
|
2004-10-22 14:31:04 +02:00
|
|
|
rm "$file_parameter" "$outfile"
|
2004-08-09 13:58:26 +02:00
|
|
|
exit 0
|