break out a bunch of common functions in monkeysphere-host:
[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=$(hostname -f)
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"
41 userID="ssh://${hostName}"
42
43 # create host home
44 mkdir -p "$GNUPGHOME_HOST"
45 chmod 700 "$GNUPGHOME_HOST"
46
47 log debug "generating host key..."
48 gpg_host --batch --gen-key <<EOF
49 Key-Type: $keyType
50 Key-Length: $keyLength
51 Key-Usage: $keyUsage
52 Name-Real: $userID
53 Expire-Date: $keyExpire
54
55 %commit
56 %echo done
57
58 EOF
59
60 # load the new host fpr into the fpr variable
61 load_fingerprint_secret
62
63 # export to ssh secret key file
64 create_ssh_sec_file
65
66 # export to ssh public key file
67 create_ssh_pub_file
68
69 # export to gpg public key to file
70 create_gpg_pub_file
71
72 # show info about new key
73 show_key
74
75 }