fix: fallback to pk decryption when failed to decrypt with machine uid#486
fix: fallback to pk decryption when failed to decrypt with machine uid#48621pages wants to merge 1 commit intorustdesk:mainfrom
Conversation
3650dea to
7fc18b7
Compare
There was a problem hiding this comment.
Pull request overview
Improves resilience of the password/config encryption/decryption path when machine-UID retrieval is flaky (e.g., during shutdown) and when historical encryptions may have used the config key-pair instead of the machine UID.
Changes:
- Cache machine UID after successful retrieval and add retry/backoff behavior when retrieval fails.
- Add a decryption fallback path: if decryption with machine UID fails, retry with the key-pair-derived key.
- Add a unit test intended to cover the pk fallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/lib.rs |
Adds machine-UID caching plus retry logic in get_uuid() before falling back to key-pair bytes. |
src/password_security.rs |
Updates symmetric_crypt to retry decryption with pk-derived key on failure; adds a new test for the fallback behavior. |
Comments suppressed due to low confidence (1)
src/password_security.rs:192
secretboxis used with a constant all-zero nonce. Reusing a nonce with the same key in XSalsa20-Poly1305 breaks confidentiality and can allow plaintext recovery across multiple encrypted values. Consider generating a random nonce per encryption (and storing it alongside the ciphertext, e.g., prefixing it) so decrypt can read it back safely; this can be rolled out via a new version tag.
let nonce = secretbox::Nonce([0; secretbox::NONCEBYTES]);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7fc18b7 to
2b698cf
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2b698cf to
bee6933
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
codex review • Findings:
If you want, I can propose a minimal patch for #1 and #2 (deadlock-safe key loading + stronger duplicate-encryption check). |
bee6933 to
1ccb382
Compare
Config::get_existing_key_pair() does hold KEY_PAIR while calling Config::load_::("") (src/config.rs:1004, src/config.rs:1009), but load_ is only a raw deserialize The fallback in symmetric_crypt (src/password_security.rs:208) is only reachable from actual decryption flows, not from load_. So there is no recursive re-entry into KEY_PAIR |
a3660ba to
3bbb416
Compare
WARNING The is_encrypted() check is a heuristic, not cryptographic proof. A user-chosen password like 00SGVsbG8= would be silently stored in plaintext. Consider adding a stronger magic/sentinel or a length check — real encrypted output from secretbox::seal has a fixed overhead (MAC tag), so checking decoded_len >= secretbox::MACBYTES would significantly reduce false positives.
NOTE It would be prudent to add a code comment in get_existing_key_pair() explicitly stating that Config::load_ must never call symmetric_crypt / decrypt_* to avoid deadlock, so future refactors don't accidentally introduce re-entry.
|
- Cache machine_uid in get_uuid with retry logic for macOS - Fallback to pk decryption when machine_uid decryption fails - Add is_encrypted check to prevent duplicate encryption - Add get_existing_key_pair to get key pair without generating new one Signed-off-by: 21pages <sunboeasy@gmail.com>
3bbb416 to
5d2acc7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test
pk decryption
I found that decrypting with my password failed, but decrypting with the PK worked. So it’s possible that the machine UID failed to be retrieved during a previous encryption, and the PK was used for encryption instead.
The PK is only attempted during the second decryption. In the first attempt, the machine UID is given priority for decryption. If the PK were also used in the first attempt, then the second attempt to retrieve the machine UID would most likely fail as well.
encrypted judgement
Encrypt the local password in str form and the peer password in vec form as usual. Modify get_uuid so that it only returns pk, preventing str and vec from being encrypted again. Then revert the change — both the local password and the peer password can work normally.