8 #include "libbcachefs.h"
10 int cmd_unlock(int argc, char *argv[])
12 struct bch_sb_handle sb;
17 die("Please supply a single device");
19 err = bch2_read_super(argv[1], bch2_opts_empty(), &sb);
21 die("Error opening %s: %s", argv[1], err);
23 passphrase = read_passphrase("Enter passphrase: ");
25 bch2_add_key(sb.sb, passphrase);
27 memzero_explicit(passphrase, strlen(passphrase));
32 int cmd_set_passphrase(int argc, char *argv[])
34 struct bch_opts opts = bch2_opts_empty();
35 struct bch_fs *c = NULL;
39 die("Please supply one or more devices");
41 opt_set(opts, nostart, true);
42 err = bch2_fs_open(argv + 1, argc - 1, opts, &c);
44 die("Error opening %s: %s", argv[1], err);
46 struct bch_sb_field_crypt *crypt = bch2_sb_get_crypt(c->disk_sb);
48 die("Filesystem does not have encryption enabled");
50 struct bch_encrypted_key new_key;
51 new_key.magic = BCH_KEY_MAGIC;
53 int ret = bch2_decrypt_sb_key(c, crypt, &new_key.key);
55 die("Error getting current key");
57 char *new_passphrase = read_passphrase_twice("Enter new passphrase: ");
58 struct bch_key passphrase_key = derive_passphrase(crypt, new_passphrase);
60 if (bch2_chacha_encrypt_key(&passphrase_key, __bch2_sb_key_nonce(c->disk_sb),
61 &new_key, sizeof(new_key)))
62 die("error encrypting key");
70 int cmd_remove_passphrase(int argc, char *argv[])
72 struct bch_opts opts = bch2_opts_empty();
73 struct bch_fs *c = NULL;
77 die("Please supply one or more devices");
79 opt_set(opts, nostart, true);
80 err = bch2_fs_open(argv + 1, argc - 1, opts, &c);
82 die("Error opening %s: %s", argv[1], err);
84 struct bch_sb_field_crypt *crypt = bch2_sb_get_crypt(c->disk_sb);
86 die("Filesystem does not have encryption enabled");
88 struct bch_encrypted_key new_key;
89 new_key.magic = BCH_KEY_MAGIC;
91 int ret = bch2_decrypt_sb_key(c, crypt, &new_key.key);
93 die("Error getting current key");