Let a client seal switch device keys without losing its session

A device whose key pair changes at runtime re-registers its new public key;
its later hellos must be signed by the new secret key, or the server can
never tie a seal to the device again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
This commit is contained in:
rustdeskandClaude Opus 5.5 committed 2026-11-06 03:09:27 +08:00
1 parent 395c54da26
commit 1462a4b17c
1 file changed
+24
+24
View File
@@ -481,6 +481,16 @@ impl ClientSeal {
}
}
/// Whether hellos are signed by the device key whose public half is `pk`.
pub fn signs_as(&self, pk: &[u8]) -> bool {
self.device.as_ref().is_some_and(|sk| sk.0[32..] == *pk)
}
/// The device key changed: later hellos are signed by `device`. The session stays.
pub fn set_device(&mut self, device: Option<sign::SecretKey>) {
self.device = device;
}
/// Forgets the session, so the next datagram is a hello.
pub fn reset(&mut self) {
self.hello = None;
@@ -838,6 +848,20 @@ mod tests {
assert_ne!(sealed, keys);
}
#[test]
fn a_new_device_key_signs_the_hellos_after_it() {
let (pk, sk) = sign::gen_keypair();
let server = ServerKey::new(&sk, [7u8; 32]).unwrap();
let (old_pk, old_sk) = sign::gen_keypair();
let (new_pk, new_sk) = sign::gen_keypair();
let mut client = ClientSeal::new(&pk, Some(old_sk)).unwrap();
assert!(client.signs_as(old_pk.as_ref()) && !client.signs_as(new_pk.as_ref()));
client.set_device(Some(new_sk));
let (opened, _) = server.open(&client.seal(b"r").unwrap(), || 1).unwrap();
assert!(opened.signed_by(new_pk.as_ref()).is_some());
assert!(opened.signed_by(old_pk.as_ref()).is_none());
}
#[test]
fn a_hello_names_the_device_that_signed_it_and_a_rising_time() {
let (pk, sk) = sign::gen_keypair();