Stop all creation of a ssh_host_rsa_key.pub. Use openpgp2ssh to get
[monkeysphere.git] / src / share / mh / gen_key
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere host gen-key subcommand
5 #
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
10 #
11 # They are Copyright 2008-2009, and are all released under the GPL,
12 # version 3 or later.
13
14 gen_key() {
15
16 local hostName
17 local keyType="RSA"
18 local keyLength="2048"
19 local keyUsage="auth"
20 local keyExpire="0"
21 local userID
22
23 # get options
24 while true ; do
25         case "$1" in
26             -l|--length)
27                 keyLength="$2"
28                 shift 2
29                 ;;
30             *)
31                 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
32                     failure "Unknown option '$1'.
33 Type '$PGRM help' for usage."
34                 fi
35                 break
36                 ;;
37         esac
38 done
39
40 hostName=${1:-$(hostname -f)}
41 userID="ssh://${hostName}"
42
43 # create host home
44 mkdir -p "${MHDATADIR}"
45 mkdir -p "${MHTMPDIR}"
46 mkdir -p "${GNUPGHOME_HOST}"
47 chmod 700 "${GNUPGHOME_HOST}"
48
49 log debug "generating host key..."
50 gpg_host --batch --gen-key <<EOF
51 Key-Type: $keyType
52 Key-Length: $keyLength
53 Key-Usage: $keyUsage
54 Name-Real: $userID
55 Expire-Date: $keyExpire
56
57 %commit
58 %echo done
59
60 EOF
61
62 # load the new host fpr into the fpr variable
63 load_fingerprint_secret
64
65 # export the host secret key to the monkeysphere ssh sec key file
66 # NOTE: assumes that the primary key is the proper key to use
67 log debug "creating ssh secret key file..."
68 (umask 077 && \
69     gpg_host --export-secret-key "$HOST_FINGERPRINT" | \
70     openpgp2ssh "$HOST_FINGERPRINT" > "${MHDATADIR}/ssh_host_rsa_key")
71 log info "SSH host secret key file: ${MHDATADIR}/ssh_host_rsa_key"
72
73 # export the host public key to the monkeysphere ssh pub key file
74 log debug "creating ssh public key file..."
75 ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "$HOST_KEY_PUB"
76 log info "SSH host public key file: $HOST_KEY_PUB"
77
78 # export to gpg public key to file
79 create_gpg_pub_file
80
81 # show info about new key
82 show_key
83
84 }