1 /* suspend.c - Suspend/Resume a crypto container
2 * Copyright (C) 2016 Werner Koch
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
36 #include "server.h" /*(g13_keyblob_decrypt)*/
40 /* Suspend the container with name FILENAME. */
42 g13_suspend_container (ctrl_t ctrl, const char *filename)
47 /* A quick check to see whether the container exists. */
48 if (access (filename, R_OK))
49 return gpg_error_from_syserror ();
51 /* Decide whether we need to use the g13-syshelp because we can't
52 use lock files for them. This is most likely the case for device
53 files; thus we test for this. FIXME: The correct solution would
54 be to call g13-syshelp to match the file against the g13tab. */
55 needs_syshelp = !strncmp (filename, "/dev/", 5);
58 err = gpg_error (GPG_ERR_NOT_SUPPORTED);
60 err = be_suspend_container (ctrl, CONTTYPE_DM_CRYPT, filename);
66 /* Resume the container with name FILENAME. */
68 g13_resume_container (ctrl_t ctrl, const char *filename)
72 void *enckeyblob = NULL;
76 tupledesc_t tuples = NULL;
78 const unsigned char *value;
80 char *mountpoint_buffer = NULL;
82 /* A quick check to see whether the container exists. */
83 if (access (filename, R_OK))
84 return gpg_error_from_syserror ();
86 /* Decide whether we need to use the g13-syshelp because we can't
87 use lock files for them. This is most likely the case for device
88 files; thus we test for this. FIXME: The correct solution would
89 be to call g13-syshelp to match the file against the g13tab. */
90 needs_syshelp = !strncmp (filename, "/dev/", 5);
94 err = gpg_error (GPG_ERR_NOT_SUPPORTED);
98 /* Read the encrypted keyblob. */
99 /* Fixme: Should we move this to syshelp for dm-crypt or do we
100 assume that the encrypted device is world readable? */
101 err = g13_keyblob_read (filename, &enckeyblob, &enckeybloblen);
105 /* Decrypt that keyblob and store it in a tuple descriptor. */
106 err = g13_keyblob_decrypt (ctrl, enckeyblob, enckeybloblen,
107 &keyblob, &keybloblen);
113 err = create_tupledesc (&tuples, keyblob, keybloblen);
118 if (gpg_err_code (err) == GPG_ERR_NOT_SUPPORTED)
119 log_error ("unknown keyblob version\n");
123 dump_tupledesc (tuples);
125 value = find_tuple (tuples, KEYBLOB_TAG_CONTTYPE, &n);
126 if (!value || n != 2)
129 conttype = (value[0] << 8 | value[1]);
130 if (!be_is_supported_conttype (conttype))
132 log_error ("content type %d is not supported\n", conttype);
133 err = gpg_error (GPG_ERR_NOT_SUPPORTED);
136 err = be_resume_container (ctrl, conttype, filename, tuples);
139 destroy_tupledesc (tuples);
142 xfree (mountpoint_buffer);