3 # gpgsm-gencert.c - Generate X.509 certificates through GPGSM.
4 # Copyright (C) 2004, 2005 Free Software Foundation, Inc.
6 # This file is part of GnuPG.
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 3 of the License, or
11 # (at your option) any later version.
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.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, see <http://www.gnu.org/licenses/>.
27 INPUT FD=$ASSUAN_FP_IN\n\
28 OUTPUT FD=$ASSUAN_FP_OUT --armor\n\
51 for choice
in "$@"; do
53 echo " [$i] $choice" >&2
58 echo -n "Your selection: " >&2
61 while [ $j -lt $i -o $j -eq $i ]; do
62 if [ "$idx" = $j ]; then
67 if [ $j -lt $i -o $j -eq $i ]; then
73 for choice
in "$@"; do
75 if [ $i -eq $idx ]; then
82 echo "You selected: $ANSWER" >&2
86 echo "WARNING: This script is deprecated; please use" >&2
87 echo " gpgsm --gen-key" >&2
90 while [ -z "$KEY_TYPE" ]; do
91 query_user_menu
"Key type" "RSA" "Existing key" "Direct from card"
95 query_user_menu
"Key length" "1024" "2048"
100 # User requested to use an existing key; need to set some dummy defaults
101 query_user
"Keygrip "
102 if [ -n "$ANSWER" ]; then
109 tmp
=$
(echo 'SCD SERIALNO' | gpg-connect-agent | \
110 awk '$2 == "SERIALNO" {print $3}')
111 if [ -z "$tmp" ]; then
112 echo "No card found" >&2
114 echo "Card with S/N $tmp found" >&2
115 tmp
=$
(echo 'SCD LEARN --force' | gpg-connect-agent | \
116 awk '$2 == "KEYPAIRINFO" {printf " %s", $4}')
117 sshid
=$
(echo 'SCD GETATTR $AUTHKEYID' | gpg-connect-agent | \
118 awk '$2 == "$AUTHKEYID" {print $3}')
119 [ -n "$sshid" ] && echo "gpg-agent uses $sshid as ssh key" >&2
120 query_user_menu
"Select key " $tmp "back"
121 if [ "$ANSWER" != "back" ]; then
122 KEY_TYPE
="card:$ANSWER"
134 query_user_menu
"Key usage" "sign, encrypt" "sign" "encrypt"
137 query_user
"Name (DN)"
143 query_user
"E-Mail addresses (end with an empty line)"
144 [ -z "$ANSWER" ] && break
145 EMAIL_ADDRESSES
="${EMAIL_ADDRESSES}${LF}Name-Email: $ANSWER"
153 query_user
"DNS Names (optional; end with an empty line)"
154 [ -z "$ANSWER" ] && break
155 DNS_ADDRESSES
="${DNS_ADDRESSES}${LF}Name-DNS: $ANSWER"
163 query_user
"URIs (optional; end with an empty line)"
164 [ -z "$ANSWER" ] && break
165 URI_ADDRESSES
="${URI_ADDRESSES}${LF}Name-URI: $ANSWER"
170 file_parameter
=$
(mktemp
"/tmp/gpgsm.XXXXXX")
171 outfile
=$
(mktemp
"/tmp/gpgsm.XXXXXX")
177 Key-Length: $KEY_LENGTH
178 Key-Usage: $KEY_USAGE
181 [ -n "$KEY_GRIP" ] && echo "Key-Grip: $KEY_GRIP"
182 [ -n "$EMAIL_ADDRESSES" ] && echo "$EMAIL_ADDRESSES"
183 [ -n "$DNS_ADDRESSES" ] && echo "$DNS_ADDRESSES"
184 [ -n "$URI_ADDRESSES" ] && echo "$URI_ADDRESSES"
185 ) > "$file_parameter"
188 echo 'Parameters for certificate request to create:' >&2
189 cat -n "$file_parameter" >&2
192 query_user_menu
"Really create such a CSR?" "yes" "no"
193 [ "$ANSWER" != "yes" ] && exit 1
196 printf "$ASSUAN_COMMANDS" | \
197 gpgsm
--no-log-file --debug-level none
--debug-none \
198 --server 4< "$file_parameter" 5>"$outfile" >/dev
/null
202 rm "$file_parameter" "$outfile"