~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to tools/gpgsm-gencert.sh

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Mueller
  • Date: 2005-03-29 10:30:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050329103032-sj42n2ain3ipx310
Tags: upstream-1.9.15
ImportĀ upstreamĀ versionĀ 1.9.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#                                                              -*- sh -*-
 
3
# gpgsm-gencert.c - Generate X.509 certificates through GPGSM.  
 
4
#       Copyright (C) 2004 Free Software Foundation, Inc.
 
5
#
 
6
# This file is part of GnuPG.
 
7
#
 
8
# GnuPG is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation; either version 2 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# GnuPG is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program; if not, write to the Free Software
 
20
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
21
# 02111-1307, USA.
 
22
 
 
23
set -e
 
24
 
 
25
ASSUAN_FP_IN=4
 
26
ASSUAN_FP_OUT=5
 
27
 
 
28
ASSUAN_COMMANDS="\
 
29
INPUT FD=$ASSUAN_FP_IN\n\
 
30
OUTPUT FD=$ASSUAN_FP_OUT --armor\n\
 
31
GENKEY\n\
 
32
BYE"
 
33
 
 
34
ANSWER=""
 
35
 
 
36
query_user()
 
37
{
 
38
    message=$1; shift
 
39
    
 
40
    echo "$message" >&2
 
41
    echo -n "> " >&2
 
42
    read answer
 
43
 
 
44
    ANSWER=$answer;
 
45
}
 
46
 
 
47
query_user_menu()
 
48
{
 
49
    message=$1; shift
 
50
    i=0
 
51
    
 
52
    echo "$message" >&2
 
53
    for choice in "$@"; do
 
54
        i=$(expr $i + 1)
 
55
        echo " [$i] $choice" >&2
 
56
    done
 
57
 
 
58
    while true; do
 
59
        j=1
 
60
        echo -n "Your selection: " >&2
 
61
        read idx
 
62
 
 
63
        while [ $j -lt $i -o $j -eq $i ]; do
 
64
            if [ "$idx" = $j ]; then
 
65
                break
 
66
            fi
 
67
            j=$(expr $j + 1)
 
68
        done
 
69
        if [ $j -lt $i -o $j -eq $i ]; then
 
70
            break
 
71
        fi
 
72
    done
 
73
 
 
74
    i=0
 
75
    for choice in "$@"; do
 
76
        i=$(expr $i + 1)
 
77
        if [ $i -eq $idx ]; then
 
78
            ANSWER=$1
 
79
            break;
 
80
        fi
 
81
        shift
 
82
    done
 
83
    
 
84
    echo "You selected: $ANSWER" >&2
 
85
}
 
86
 
 
87
query_user_menu "Key type" "RSA"
 
88
KEY_TYPE=$ANSWER
 
89
 
 
90
query_user_menu "Key length" "1024" "2048"
 
91
KEY_LENGTH=$ANSWER
 
92
 
 
93
query_user_menu "Key usage" "sign, encrypt" "sign" "encrypt"
 
94
KEY_USAGE=$ANSWER
 
95
 
 
96
query_user "Name"
 
97
NAME=$ANSWER
 
98
 
 
99
query_user "E-Mail address"
 
100
EMAIL_ADDRESS=$ANSWER
 
101
 
 
102
file_parameter=$(mktemp "/tmp/gpgsm.XXXXXX")
 
103
outfile=$(mktemp "/tmp/gpgsm.XXXXXX")
 
104
 
 
105
cat > "$file_parameter" <<EOF
 
106
Key-Type: $KEY_TYPE
 
107
Key-Length: $KEY_LENGTH
 
108
Key-Usage: $KEY_USAGE
 
109
Name-DN: $NAME
 
110
Name-Email: $EMAIL_ADDRESS
 
111
EOF
 
112
 
 
113
echo -e "$ASSUAN_COMMANDS" | \
 
114
   gpgsm --server 4< "$file_parameter" 5>"$outfile" >/dev/null
 
115
 
 
116
cat "$outfile"
 
117
 
 
118
rm "$file_parameter" "$outfile"
 
119
exit 0