18 static bool fail_stage1(int stage) {
22 static bool fail_stage2(int stage) {
27 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
29 // Open a new meshlink instance.
31 assert(meshlink_destroy("encrypted_conf"));
32 meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
35 // Close the mesh and open it again, now with a different key.
39 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "wrong", 5);
42 // Open it again, now with the right key.
44 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
47 // Change the encryption key.
49 assert(meshlink_encrypted_key_rotate(mesh, "newkey", 6));
52 // Check that we can only reopen it with the new key
54 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
56 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey", 6);
59 // Simulate a failed rotation, we should only be able to open it with the old key
61 devtool_keyrotate_probe = fail_stage1;
62 assert(!meshlink_encrypted_key_rotate(mesh, "newkey2", 7));
64 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey2", 7);
66 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey", 6);
69 // Simulate a succesful rotation that was interrupted before cleaning up old files
71 devtool_keyrotate_probe = fail_stage2;
72 assert(meshlink_encrypted_key_rotate(mesh, "newkey3", 7));
74 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey", 6);
76 mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "newkey3", 7);
85 assert(meshlink_destroy("encrypted_conf"));
87 DIR *dir = opendir("encrypted_conf");
88 assert(!dir && errno == ENOENT);