Merge commit 'jrollins/master'
[monkeysphere.git] / website / bugs / handle-passphrase-locked-secret-keys.mdwn
1 [[meta title="MonkeySphere needs to be able to cleanly export passphrase-locked secret keys from the GPG keyring"]]
2
3 At the moment, the only tool we have to export passphrase-locked
4 secret keys from the GPG keyring is `gpg` itself (and `gpg2`, which
5 has roughly the same behavior).
6
7 As a result, we have the `seckey2sshagent` hack, which is unfriendly
8 and awkward to use.
9
10 Ideally, `openpgp2ssh` would be able to convert passphrase-locked
11 secret keys into clean subkeys.  However, i've tried to do this via
12 GnuTLS, and that library is not ready for this.
13
14 OpenCDK, which is the component of GnuTLS which reads OpenPGP-style
15 keys, cannot cope with encrypted secret key material.  I have had
16 [some
17 success](http://lists.gnu.org/archive/html/gnutls-devel/2008-06/msg00092.html)
18 in getting GnuTLS's OpenCDK to accept the existence of encrypted
19 secret key packets, [i learned that OpenCDK as included in GnuTLS is
20 incapable of dealing with the encrypted packets
21 themselves](http://lists.gnu.org/archive/html/gnutls-devel/2008-07/msg00012.html).
22
23
24 Some possible resolutions:
25
26 ---------
27
28 If we can assume that the passphrase-encrypted key we want to use is
29 actually a subkey, and if we could fix GnuTLS to ignore the use of the
30 "gnu-dummy S2K" produced by `gpg --export-secret-subkeys` for the
31 primary key, then something like the following script should actually
32 work for reasonable values of `$KEYID`:
33
34         TMPDIR=$(mktemp -d)
35         uname 077
36         mkfifo "$TMPDIR/passphrase"
37         kname="MonkeySphere Key $KEYID"
38         mkfifo "$TMPDIR/$kname"
39         ssh-askpass "Please enter the passphrase for MonkeySphere key $KEYID" >"$TMPDIR/passphrase" &
40         gpg  --passphrase-fd 3 3<"$TMPDIR/passphrase" \
41           --export-options export-reset-subkey-passwd,export-minimal,no-export-attributes \
42           --export-secret-subkeys "$KEYID"\! | openpgp2ssh "$KEYID" > "$TMPDIR/$kname" &
43         (cd "$TMPDIR" && ssh-add -c "$kname")
44         rm -rf "$TMPDIR"        
45
46 Good news!  [I've crafted a patch for GnuTLS to enable it to read
47 exported subkeys using this GNU
48 extension](http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00005.html),
49 so if we can get it incorporated into upstream (and/or into debian),
50 we have a possible solution, as long as the authentication key is a
51 subkey, and not a primary key.
52
53 ---------
54
55 Ben Laurie and Rachel Willmer's
56 [OpenPGPSDK](http://openpgp.nominet.org.uk) is a candidate: this is a
57 C-based library that intends to implement RFC 4880 functionality.
58
59 We could potentially re-write `openpgp2ssh` using this library, and it
60 *should* be able to handle everything we need from the OpenPGP side
61 (though it might need to be re-linked to OpenSSL to handle PEM-encoded
62 exports.
63
64 Concerns:
65
66 * OpenPGPSDK is not in debian yet, and doesn't currently (2008-08-13)
67   build with gcc 4.2 or 4.3.
68
69 * OpenPGPSDK uses the apache license and appears to link to OpenSSL,
70   which has a GPL-incompatible license.  I think this would mean that
71   `openpgp2ssh` could not remain GPL (though the rest of the
72   monkeysphere could).
73
74 ---------
75
76 We could try to use perl.  The last time i checked, the pure-perl
77 OpenPGP implementations all depended on Math::PARI, which [is not in
78 debian](http://bugs.debian.org/440527).  The most likely candidate is
79 [Crypt::OpenPGP](http://search.cpan.org/~btrott/Crypt-OpenPGP),
80 despite [some
81 bugginess](http://cpanratings.perl.org/dist/Crypt-OpenPGP).  
82
83 Concerns:
84
85 * the aforementioned buggy reviews
86
87 * there's a lot of dependency chasing to get anything like this
88   available in debian.
89
90 ---------
91
92 Other alternatives?