"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/luks2/luks2_token_keyring.c" between
cryptsetup-2.3.6.tar.xz and cryptsetup-2.4.0.tar.xz

About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.

luks2_token_keyring.c  (cryptsetup-2.3.6.tar.xz):luks2_token_keyring.c  (cryptsetup-2.4.0.tar.xz)
skipping to change at line 26 skipping to change at line 26
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <assert.h> #include <assert.h>
#include "luks2_internal.h" #include "luks2_internal.h"
static int keyring_open(struct crypt_device *cd, int keyring_open(struct crypt_device *cd,
int token, int token,
char **buffer, char **buffer,
size_t *buffer_len, size_t *buffer_len,
void *usrptr __attribute__((unused))) void *usrptr __attribute__((unused)))
{ {
json_object *jobj_token, *jobj_key; json_object *jobj_token, *jobj_key;
struct luks2_hdr *hdr; struct luks2_hdr *hdr;
int r; int r;
if (!(hdr = crypt_get_hdr(cd, CRYPT_LUKS2))) if (!(hdr = crypt_get_hdr(cd, CRYPT_LUKS2)))
skipping to change at line 48 skipping to change at line 48
jobj_token = LUKS2_get_token_jobj(hdr, token); jobj_token = LUKS2_get_token_jobj(hdr, token);
if (!jobj_token) if (!jobj_token)
return -EINVAL; return -EINVAL;
json_object_object_get_ex(jobj_token, "key_description", &jobj_key); json_object_object_get_ex(jobj_token, "key_description", &jobj_key);
r = keyring_get_passphrase(json_object_get_string(jobj_key), buffer, buff er_len); r = keyring_get_passphrase(json_object_get_string(jobj_key), buffer, buff er_len);
if (r == -ENOTSUP) { if (r == -ENOTSUP) {
log_dbg(cd, "Kernel keyring features disabled."); log_dbg(cd, "Kernel keyring features disabled.");
return -EINVAL; return -ENOENT;
} else if (r < 0) { } else if (r < 0) {
log_dbg(cd, "keyring_get_passphrase failed (error %d)", r); log_dbg(cd, "keyring_get_passphrase failed (error %d)", r);
return -EINVAL; return -EPERM;
} }
return 0; return 0;
} }
static int keyring_validate(struct crypt_device *cd __attribute__((unused)), int keyring_validate(struct crypt_device *cd __attribute__((unused)),
const char *json) const char *json)
{ {
enum json_tokener_error jerr; enum json_tokener_error jerr;
json_object *jobj_token, *jobj_key; json_object *jobj_token, *jobj_key;
int r = 1; int r = 1;
log_dbg(cd, "Validating keyring token json"); log_dbg(cd, "Validating keyring token json");
jobj_token = json_tokener_parse_verbose(json, &jerr); jobj_token = json_tokener_parse_verbose(json, &jerr);
if (!jobj_token) { if (!jobj_token) {
skipping to change at line 95 skipping to change at line 95
} }
/* TODO: perhaps check that key description is in '%s:%s' /* TODO: perhaps check that key description is in '%s:%s'
* format where both strings are not empty */ * format where both strings are not empty */
r = !strlen(json_object_get_string(jobj_key)); r = !strlen(json_object_get_string(jobj_key));
out: out:
json_object_put(jobj_token); json_object_put(jobj_token);
return r; return r;
} }
static void keyring_dump(struct crypt_device *cd, const char *json) void keyring_dump(struct crypt_device *cd, const char *json)
{ {
enum json_tokener_error jerr; enum json_tokener_error jerr;
json_object *jobj_token, *jobj_key; json_object *jobj_token, *jobj_key;
jobj_token = json_tokener_parse_verbose(json, &jerr); jobj_token = json_tokener_parse_verbose(json, &jerr);
if (!jobj_token) if (!jobj_token)
return; return;
if (!json_object_object_get_ex(jobj_token, "key_description", &jobj_key)) { if (!json_object_object_get_ex(jobj_token, "key_description", &jobj_key)) {
json_object_put(jobj_token); json_object_put(jobj_token);
return; return;
} }
log_std(cd, "\tKey description: %s\n", json_object_get_string(jobj_key)); log_std(cd, "\tKey description: %s\n", json_object_get_string(jobj_key));
json_object_put(jobj_token); json_object_put(jobj_token);
} }
int token_keyring_set(json_object **jobj_builtin_token, int LUKS2_token_keyring_json(char *buffer, size_t buffer_size,
const void *params) const struct crypt_token_params_luks2_keyring *keyring_params)
{ {
json_object *jobj_token, *jobj; int r;
const struct crypt_token_params_luks2_keyring *keyring_params = (const st
ruct crypt_token_params_luks2_keyring *) params;
jobj_token = json_object_new_object();
if (!jobj_token)
return -ENOMEM;
jobj = json_object_new_string(LUKS2_TOKEN_KEYRING);
if (!jobj) {
json_object_put(jobj_token);
return -ENOMEM;
}
json_object_object_add(jobj_token, "type", jobj);
jobj = json_object_new_array();
if (!jobj) {
json_object_put(jobj_token);
return -ENOMEM;
}
json_object_object_add(jobj_token, "keyslots", jobj);
jobj = json_object_new_string(keyring_params->key_description); r = snprintf(buffer, buffer_size, "{ \"type\": \"%s\", \"keyslots\":[],\"
if (!jobj) { key_description\":\"%s\"}",
json_object_put(jobj_token); LUKS2_TOKEN_KEYRING, keyring_params->key_description);
return -ENOMEM; if (r < 0 || (size_t)r >= buffer_size)
} return -EINVAL;
json_object_object_add(jobj_token, "key_description", jobj);
*jobj_builtin_token = jobj_token;
return 0; return 0;
} }
int token_keyring_get(json_object *jobj_token, int LUKS2_token_keyring_get(struct crypt_device *cd __attribute__((unused)), str
void *params) uct luks2_hdr *hdr,
int token, struct crypt_token_params_luks2_keyring *keyring_params)
{ {
json_object *jobj; json_object *jobj_token, *jobj;
struct crypt_token_params_luks2_keyring *keyring_params = (struct crypt_t
oken_params_luks2_keyring *) params;
jobj_token = LUKS2_get_token_jobj(hdr, token);
json_object_object_get_ex(jobj_token, "type", &jobj); json_object_object_get_ex(jobj_token, "type", &jobj);
assert(!strcmp(json_object_get_string(jobj), LUKS2_TOKEN_KEYRING)); assert(!strcmp(json_object_get_string(jobj), LUKS2_TOKEN_KEYRING));
json_object_object_get_ex(jobj_token, "key_description", &jobj); json_object_object_get_ex(jobj_token, "key_description", &jobj);
keyring_params->key_description = json_object_get_string(jobj); keyring_params->key_description = json_object_get_string(jobj);
return 0; return token;
} }
const crypt_token_handler keyring_handler = {
.name = LUKS2_TOKEN_KEYRING,
.open = keyring_open,
.validate = keyring_validate,
.dump = keyring_dump
};
 End of changes. 14 change blocks. 
41 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)