Skip to content

Conversation

@jasonheath
Copy link
Contributor

Currently this PR represents very early work towards removing the sodiumoxide crate and replacing it with the dryoc crate. The motivation for replacement is that the sodiumoxide crate is unmaintained. While other options exist the reason for choosing dryoc is that it seems to be the best and most flexible option identified so far. Additionally, dryoc seems to have an active and engaged owner.

@netlify
Copy link

netlify bot commented Sep 2, 2025

👷 Deploy Preview for chef-habitat processing.

Name Link
🔨 Latest commit a92f0ff
🔍 Latest deploy log https://app.netlify.com/projects/chef-habitat/deploys/69028285542b840008bcb911

Copilot AI review requested due to automatic review settings October 29, 2025 21:09
@jasonheath jasonheath force-pushed the sodiumoxide-replacement branch from 817f74c to a92f0ff Compare October 29, 2025 21:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR begins the process of replacing the unmaintained sodiumoxide cryptography crate with the dryoc crate. The changes update comments referencing libsodium vendoring, remove the sodiumoxide security advisory ignore rule, introduce dryoc dependencies, and start migrating cryptographic primitives to use dryoc APIs. This is early exploratory work with incomplete implementations (containing todo!() macros) focused on establishing the foundation for the migration.

Key Changes:

  • Removed sodiumoxide from dependencies and added dryoc and libsodium-sys-stable as replacements
  • Updated cryptographic key modules to use dryoc primitives for encryption and signing operations
  • Removed the RUSTSEC-2021-0137 advisory ignore for unmaintained sodiumoxide

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
support/linux/install_dev_0_ubuntu_14.04.sh Updated comment to clarify libsodium is only needed for zmq
support/linux/install_dev_0_centos_7.sh Updated comment to clarify libsodium is only needed for zmq
components/core/src/crypto/keys/signing.rs Replaced sodiumoxide signing primitives with crypto_box types and stub implementation
components/core/src/crypto/keys/ring_key.rs Migrated secret box encryption/decryption from sodiumoxide to dryoc, updated signatures
components/core/src/crypto/keys/encryption.rs Replaced sodiumoxide box primitives with dryoc equivalents
components/core/src/crypto.rs Replaced sodiumoxide init and secure_eq with direct libsodium-sys calls
components/core/Cargo.toml Removed sodiumoxide dependency, added dryoc and libsodium-sys-stable
.cargo/audit.toml Removed sodiumoxide unmaintained advisory from ignore list

wget

# Install libsodium for zmq even though it will be automatically vendered with the sodiumoxide crate
# libsodium is being installed here only for zmq so it can dropped if zmq no longer used
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

Grammar error: 'can dropped' should be 'can be dropped'.

Suggested change
# libsodium is being installed here only for zmq so it can dropped if zmq no longer used
# libsodium is being installed here only for zmq so it can be dropped if zmq no longer used

Copilot uses AI. Check for mistakes.
export LD_LIBRARY_PATH=/usr/local/lib

# Install libsodium for zmq even though it will be automatically vendered with the sodiumoxide crate
# libsodium is being installed here only for zmq so it can dropped if zmq no longer used
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

Grammar error: 'can dropped' should be 'can be dropped'.

Suggested change
# libsodium is being installed here only for zmq so it can dropped if zmq no longer used
# libsodium is being installed here only for zmq so it can be dropped if zmq no longer used

Copilot uses AI. Check for mistakes.
let nonce = primitives::gen_nonce();
(nonce.as_ref().to_vec(), primitives::seal(data, &nonce, &self.key))
let mut ciphertext = vec![0u8; data.len() + CRYPTO_SECRETBOX_MACBYTES];
dryoc::classic::crypto_secretbox::crypto_secretbox_easy(ciphertext.as_mut_slice(), data, &nonce, &self.key);
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The return value from crypto_secretbox_easy is ignored. If this function can fail, the error should be propagated to the caller. If it cannot fail, this should be documented.

Copilot uses AI. Check for mistakes.
dryoc::classic::crypto_secretbox::crypto_secretbox_open_easy(decrypted.as_mut_slice(), ciphertext, nonce, &self.key).map_err(|_| {
Error::CryptoError("Secret key and nonce could not decrypt ciphertext".to_string())
})
});
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The result of map_err is discarded with a semicolon on line 59, and then Ok(decrypted) is always returned. This means decryption errors are silently ignored and potentially uninitialized/incorrect data is returned. The semicolon should be removed and the expression should be followed by ? operator: .map_err(|_| Error::CryptoError(...))?; before the Ok(decrypted) return.

Suggested change
});
})?;

Copilot uses AI. Check for mistakes.

pub fn init() -> Result<()> { sodiumoxide::init().map_err(|_| Error::SodiumInitFailed) }
pub fn init() -> Result<()> {
if (unsafe { libsodium_sys::sodium_init() } > 0) {
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The condition check is incorrect. According to libsodium documentation, sodium_init() returns -1 on failure, 0 on first successful initialization, and 1 on subsequent calls. The check should be < 0 to detect actual failures: if unsafe { libsodium_sys::sodium_init() } < 0 {.

Suggested change
if (unsafe { libsodium_sys::sodium_init() } > 0) {
if (unsafe { libsodium_sys::sodium_init() } < 0) {

Copilot uses AI. Check for mistakes.
Comment on lines +268 to 274
unsafe {
libsodium_sys::sodium_memcmp(t_ref.as_ptr() as *const c_void,
u_ref.as_ptr() as *const c_void,
t_ref.len())
== 0
}
}
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

No validation that t_ref.len() equals u_ref.len(). The sodium_memcmp function requires both inputs to have the same length. If they differ, this will compare only up to t_ref.len() bytes, leading to incorrect results. Add a check: if t_ref.len() != u_ref.len() { return false; }.

Suggested change
unsafe {
libsodium_sys::sodium_memcmp(t_ref.as_ptr() as *const c_void,
u_ref.as_ptr() as *const c_void,
t_ref.len())
== 0
}
}
if t_ref.len() != u_ref.len() {
return false;
}
unsafe {
libsodium_sys::sodium_memcmp(t_ref.as_ptr() as *const c_void,
u_ref.as_ptr() as *const c_void,
t_ref.len())
== 0
}

Copilot uses AI. Check for mistakes.
@sonarqube-for-infrastructure-prod

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.

2 participants