Skip to content

refactor: upgrade aes gcm 0.11.0 - #3780

Merged
gilcu3 merged 2 commits into
near:mainfrom
metalurgical:3770_upgrade_aes_gcm_0_11
Jul 13, 2026
Merged

refactor: upgrade aes gcm 0.11.0#3780
gilcu3 merged 2 commits into
near:mainfrom
metalurgical:3770_upgrade_aes_gcm_0_11

Conversation

@metalurgical

@metalurgical metalurgical commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

This PR upgrades the aes-gcm crate from version 0.10.3 to 0.11.0.

Updates aes-gcm code to move from crate version 0.10.3 to 0.11.0.
@metalurgical

metalurgical commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Resolves #3770
Closes #3770

@gilcu3

gilcu3 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Jul 13, 2026

Copy link
Copy Markdown

Pull request overview

Upgrades aes-gcm from 0.10.3 to 0.11.0 and migrates the four call sites in mpc-node (DB encryption, migration-service web encryption, and two test helpers) to the new RustCrypto trait layout (aead 0.6 / cipher 0.5 / hybrid-array). Nonce and key generation move from AeadCore::generate_nonce / Aes*Gcm::generate_key to the new Generate trait, and nonces are now built via Nonce::<Aes*Gcm>::try_from(...) instead of .into().

Changes:

  • Bump workspace aes-gcm pin to 0.11.0 (Cargo.toml, Cargo.lock).
  • Migrate crates/node/src/db.rs encrypt/decrypt to Generate + explicit Nonce::<Aes128Gcm>::try_from.
  • Migrate crates/node/src/migration_service/web/encryption.rs to the same pattern for Aes256Gcm.
  • Update test-only helpers in crates/node/src/migration_service/web/test_utils.rs and crates/node/src/tests.rs to use Key::<Aes256Gcm>::generate().

Reviewed changes

Per-file summary
File Description
Cargo.toml / Cargo.lock Bump aes-gcm to 0.11 and pull in new transitive versions (aead 0.6, cipher 0.5, ghash 0.6, polyval 0.7, universal-hash 0.6, inout 0.2, cpubits).
crates/node/src/db.rs New imports (aead::{Generate, Nonce}, drop AeadCore). encrypt now uses Nonce::<Aes128Gcm>::generate(). decrypt builds the nonce via Nonce::<Aes128Gcm>::try_from(&ciphertext[..NONCE_LEN]).
crates/node/src/migration_service/web/encryption.rs Same pattern for Aes256Gcm; removes direct OsRng import (now supplied by Generate::generate()).
crates/node/src/migration_service/web/test_utils.rs Backup key generated via Key::<Aes256Gcm>::generate() instead of Aes256Gcm::generate_key(OsRng).
crates/node/src/tests.rs Same key-generation swap for the integration test setup.

Findings

Blocking: none — the wire format (12-byte nonce ‖ ciphertext ‖ 16-byte tag) is unchanged, so existing on-disk DB values remain decryptable across the upgrade, and the surviving round-trip tests (db.rs:test_encrypt_decrypt, migration_service/web/encryption.rs:test_encrypt_decrypt_roundtrip and siblings) still exercise both call sites.

Non-blocking:

  • crates/node/src/db.rs:76-80NONCE_LEN is defined locally inside decrypt but is now conceptually asserted by Nonce::<Aes128Gcm>::try_from. Consider lifting it to a const at module scope (matching migration_service/web/encryption.rs:8) or dropping the manual length check and mapping the try_from error to "ciphertext is too short" — the current code performs two overlapping length validations.
  • crates/node/src/db.rs:70-72cipher.encrypt(&nonce, plaintext).unwrap() is preserved from the old code, but it's worth calling out as pre-existing: the only documented failure mode for AES-GCM encrypt is plaintext exceeding 2^36 − 32 bytes, which we do not enforce anywhere. Not introduced by this PR; flagging for awareness.
  • crates/node/src/migration_service/web/encryption.rs:32 — pre-existing typo ("encryption failed" in the decryption error path). Not this PR's problem, but touching the file makes it a cheap drive-by fix.
  • Behavioral note (no action required): the previous db::encrypt seeded nonces from rand::thread_rng() (userspace CSPRNG re-seeded from OsRng); the new Generate::generate() calls OsRng directly for every nonce, i.e. a getrandom syscall per DB write. Both are cryptographically secure; the switch is imperceptible for MPC signing throughput but worth being aware of.
  • Consider adding a fixed-vector decryption test (hard-coded key + ciphertext produced by the 0.10 build) to lock in cross-version compatibility for the on-disk SecretDB format — the current tests only round-trip within a single build.

✅ Approved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrades the workspace aes-gcm dependency to v0.11.0 and refactors nonce/key generation call sites in mpc-node to use the updated aead APIs.

Changes:

  • Bump aes-gcm from 0.10.3 to 0.11.0 at the workspace level (and update Cargo.lock accordingly).
  • Update AES-GCM key generation in node tests and migration-service web test utilities to use Key::<Aes256Gcm>::generate().
  • Update nonce generation / parsing in migration-service encryption and SecretDB encryption helpers to use Nonce::<...>::generate() and Nonce::<...>::try_from(...).

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/src/tests.rs Updates integration test secrets to generate AES-GCM backup keys using the new Key::<Aes256Gcm>::generate() API.
crates/node/src/migration_service/web/test_utils.rs Updates migration web test setup to generate backup encryption keys with the new API.
crates/node/src/migration_service/web/encryption.rs Refactors nonce generation/parsing and decrypt call signature to match aes-gcm 0.11 aead APIs.
crates/node/src/db.rs Refactors SecretDB nonce generation/parsing and decrypt call signature to match aes-gcm 0.11 aead APIs.
Cargo.toml Bumps the workspace aes-gcm version to 0.11.0.
Cargo.lock Locks updated transitive dependency graph for the aes-gcm 0.11 upgrade.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/migration_service/web/encryption.rs

@gilcu3 gilcu3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @metalurgical !

@netrome netrome left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

@gilcu3
gilcu3 added this pull request to the merge queue Jul 13, 2026
Merged via the queue into near:main with commit 4cd5c1a Jul 13, 2026
16 of 21 checks passed
@gilcu3 gilcu3 mentioned this pull request Jul 23, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants