]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
cmd_set_passphrase: revoke the invalidated key
authorColin Gillespie <colin@cgillespie.xyz>
Fri, 8 Sep 2023 07:27:51 +0000 (17:27 +1000)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 8 Sep 2023 08:05:36 +0000 (04:05 -0400)
After setting a new passphrase, the previous key is left untouched. This
revokes the old key, preventing future actions from using it in error.

Signed-off-by: Colin Gillespie <colin@cgillespie.xyz>
cmd_key.c
libbcachefs/checksum.c
libbcachefs/checksum.h

index e8c3eeaf6ba3aacf93ea1b7bf333b617613f7d91..d3e5d7bdb7b2a5bbd9aeca78710f799158adcbf3 100644 (file)
--- a/cmd_key.c
+++ b/cmd_key.c
@@ -111,6 +111,7 @@ int cmd_set_passphrase(int argc, char *argv[])
                die("error encrypting key");
        crypt->key = new_key;
 
+       bch2_revoke_key(c->disk_sb.sb);
        bch2_write_super(c);
        bch2_fs_stop(c);
        return 0;
index 36939020f67d11e2d291c1195ecd2163b1e87e49..4c87c596718175a9d16c3f9de428f3fa19afb709 100644 (file)
@@ -558,6 +558,24 @@ int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
        return ret;
 }
 
+int bch2_revoke_key(struct bch_sb *sb)
+{
+       key_serial_t key_id;
+       struct printbuf key_description = PRINTBUF;
+
+       prt_printf(&key_description, "bcachefs:");
+       pr_uuid(&key_description, sb->user_uuid.b);
+
+       key_id = request_key("user", key_description.buf, NULL, KEY_SPEC_USER_KEYRING);
+       printbuf_exit(&key_description);
+       if (key_id < 0)
+               return errno;
+
+       keyctl_revoke(key_id);
+
+       return 0;
+}
+
 int bch2_decrypt_sb_key(struct bch_fs *c,
                        struct bch_sb_field_crypt *crypt,
                        struct bch_key *key)
index c7b1a8fca6850dd91e1ed4432683246d5dbc2fa8..9a4898db31b1475cd7d5497262b35093a23a4b3c 100644 (file)
@@ -48,6 +48,7 @@ struct bch_csum bch2_checksum(struct bch_fs *, unsigned, struct nonce,
 
 int bch2_chacha_encrypt_key(struct bch_key *, struct nonce, void *, size_t);
 int bch2_request_key(struct bch_sb *, struct bch_key *);
+int bch2_revoke_key(struct bch_sb *);
 
 int bch2_encrypt(struct bch_fs *, unsigned, struct nonce,
                 void *data, size_t);