diff options
author | Werner Koch <[email protected]> | 2016-02-23 13:32:46 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-02-23 14:40:28 +0000 |
commit | f7968db30b0e0ccae038e354568accb0a05d877c (patch) | |
tree | b6073b29d21a75ba7c7ef4f2849fd9474605d77f /g13/call-syshelp.c | |
parent | g13: Run mount after dmsetup. (diff) | |
download | gnupg-f7968db30b0e0ccae038e354568accb0a05d877c.tar.gz gnupg-f7968db30b0e0ccae038e354568accb0a05d877c.zip |
g13: Add commands --suspend and --remove.
* g13/g13.c (aSuspend, aResume): New.
(opts): Add commands --suspend and --resume.
(main): Implement dummy command aUmount. Implement commands aResume
and aSuspend.
* g13/sh-cmd.c (cmd_suspend): New.
(cmd_resume): New.
(register_commands): Add commands RESUME and SUSPEND.
* g13/server.c (cmd_suspend): New.
(cmd_resume): New.
(register_commands): Add commands RESUME and SUSPEND.
* g13/be-dmcrypt.c (be_dmcrypt_suspend_container): New.
(be_dmcrypt_resume_container): New.
* g13/backend.c (be_suspend_container): New.
(be_resume_container): New.
* g13/suspend.c, g13/suspend.h: New.
* g13/mount.c (parse_header, read_keyblob_prefix, read_keyblob)
(decrypt_keyblob, g13_is_container): Move to ...
* g13/keyblob.c: new file.
(keyblob_read): Rename to g13_keyblob_read and make global.
(keyblob_decrypt): Rename to g13_keyblob_decrypt and make global.
* g13/sh-dmcrypt.c (check_blockdev): Add arg expect_busy.
(sh_dmcrypt_suspend_container): New.
(sh_dmcrypt_resume_container): New.
* g13/call-syshelp.c (call_syshelp_run_suspend): New.
(call_syshelp_run_resume): New.
--
The --suspend command can be used before a hibernate operation to make
the encrypted partition inaccessible and wipe the key from the memory.
Before --suspend is called a sync(1) should be run to make sure that
their are no dirty buffers (dmsetup, as called by g13, actually does
this for you but it does not harm to do it anyway. After the
partition has been suspended a
echo 3 >proc/sys/vm/drop_caches
required to flush all caches which may still have content from the
encrypted partition.
The --resume command reverses the effect of the suspend but to do this
it needs to decrypt again. Now, if the .gnupg directory lives on the
encrypted partition this will be problematic because due to the
suspend all processes accessing data on the encrypted partition will
be put into an uninterruptible sleep (ps(1) shows a state of 'D').
This needs to be avoided. A workaround is to have a separate GnuPG
home directory (say, "~/.gnupg-fallback") with only the public keys
required to decrypt the partition along with a properly setup
conf files. A
GNUPGHOME=$(pwd)/.gnupg-fallback g13 --resume
should then be able to resume the encrypted partition using the
private key stored on a smartcard.
The implementation is pretty basic right now but useful to me.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g13/call-syshelp.c')
-rw-r--r-- | g13/call-syshelp.c | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/g13/call-syshelp.c b/g13/call-syshelp.c index 0e69e9c11..bc93d2014 100644 --- a/g13/call-syshelp.c +++ b/g13/call-syshelp.c @@ -337,6 +337,7 @@ mount_status_cb (void *opaque, const char *line) } +/* Inquire callback for MOUNT and RESUME. */ static gpg_error_t mount_inq_cb (void *opaque, const char *line) { @@ -363,9 +364,11 @@ mount_inq_cb (void *opaque, const char *line) } -/* Run the MOUNT command on the current device. CONTTYPES gives the - requested content type for the new container. MOUNTPOINT the - desired mount point or NULL for default. */ +/* + * Run the MOUNT command on the current device. CONTTYPES gives the + * requested content type for the new container. MOUNTPOINT the + * desired mount point or NULL for default. + */ gpg_error_t call_syshelp_run_mount (ctrl_t ctrl, int conttype, const char *mountpoint, tupledesc_t tuples) @@ -406,3 +409,80 @@ call_syshelp_run_mount (ctrl_t ctrl, int conttype, const char *mountpoint, leave: return err; } + + + +/* + * Run the SUSPEND command on the current device. CONTTYPES gives the + * requested content type for the new container. + */ +gpg_error_t +call_syshelp_run_suspend (ctrl_t ctrl, int conttype) +{ + gpg_error_t err; + assuan_context_t ctx; + + err = start_syshelp (ctrl, &ctx); + if (err) + goto leave; + + if (conttype == CONTTYPE_DM_CRYPT) + { + err = assuan_transact (ctx, "SUSPEND dm-crypt", + NULL, NULL, + NULL, NULL, + NULL, NULL); + } + else + { + log_error ("invalid backend type %d given\n", conttype); + err = GPG_ERR_INTERNAL; + goto leave; + } + + leave: + return err; +} + + + +/* Run the RESUME command on the current device. CONTTYPES gives the + requested content type for the container. */ +gpg_error_t +call_syshelp_run_resume (ctrl_t ctrl, int conttype, tupledesc_t tuples) +{ + gpg_error_t err; + assuan_context_t ctx; + struct mount_parm_s parm; + + memset (&parm, 0, sizeof parm); + + err = start_syshelp (ctrl, &ctx); + if (err) + goto leave; + + /* tty_get ("waiting for debugger"); */ + /* tty_kill_prompt (); */ + + parm.ctx = ctx; + parm.ctrl = ctrl; + if (conttype == CONTTYPE_DM_CRYPT) + { + ref_tupledesc (tuples); + parm.keyblob = get_tupledesc_data (tuples, &parm.keybloblen); + err = assuan_transact (ctx, "RESUME dm-crypt", + NULL, NULL, + mount_inq_cb, &parm, + NULL, NULL); + unref_tupledesc (tuples); + } + else + { + log_error ("invalid backend type %d given\n", conttype); + err = GPG_ERR_INTERNAL; + goto leave; + } + + leave: + return err; +} |