Skip to content

Update to mbedtls v0.13.0 #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

mridul-manohar
Copy link

rust-mbedtls PR #372 adds combined errors for mbedtls. this enhancement is available from mbedtls v0.13.0

@Taowyoo
Copy link
Collaborator

Taowyoo commented Nov 20, 2024

@mridul-manohar From CI, some errors used in code need to be updated. Please check.

@mridul-manohar mridul-manohar force-pushed the mridul/mbedtls-0.13-update branch from 10ce53b to 731c4e4 Compare April 24, 2025 21:46
Taowyoo
Taowyoo previously approved these changes Apr 24, 2025
@Pagten
Copy link
Contributor

Pagten commented Apr 25, 2025

For all crates that didn't need any rust code modifications when upgrading to mbedtls 0.13, we should consider specifying the dependency as

mbedtls = { version = ">=0.12.0, <0.14.0", ... }

This more accurately presents the actual dependency constraints of these crates and it may ease the process for upgrading them, since consumers won't be forced to simultaneously upgrade to the new mbedtls version.

@mridul-manohar mridul-manohar force-pushed the mridul/mbedtls-0.13-update branch from 17c5949 to 0d2ff55 Compare May 13, 2025 08:23
@mridul-manohar
Copy link
Author

mridul-manohar commented May 19, 2025

For all crates that didn't need any rust code modifications when upgrading to mbedtls 0.13, we should consider specifying the dependency as

mbedtls = { version = ">=0.12.0, <0.14.0", ... }

This more accurately presents the actual dependency constraints of these crates and it may ease the process for upgrading them, since consumers won't be forced to simultaneously upgrade to the new mbedtls version.

For all crates that didn't need any rust code modifications when upgrading to mbedtls 0.13, we should consider specifying the dependency as

mbedtls = { version = ">=0.12.0, <0.14.0", ... }

This more accurately presents the actual dependency constraints of these crates and it may ease the process for upgrading them, since consumers won't be forced to simultaneously upgrade to the new mbedtls version.

@Pagten ^Addressed this change-request.

Copy link
Collaborator

@Taowyoo Taowyoo left a comment

Choose a reason for hiding this comment

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

Since changing error type in most cases is breaking change.
Could you check and bump the version of updated crates ?

@@ -35,11 +35,12 @@ failure = "0.1.1"
anyhow = { version = "1", optional = true }
quick-error = "1.2.3"
num = "0.2"
mbedtls = { version = "0.12.3", features = ["std", "time"], default-features = false, optional = true }
mbedtls = { version = "0.13.2", features = ["std", "time"], default-features = false, optional = true }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
mbedtls = { version = "0.13.2", features = ["std", "time"], default-features = false, optional = true }
mbedtls = { version = ">=0.12.0, <0.14.0", features = ["std", "time"], default-features = false, optional = true }

Copy link
Author

@mridul-manohar mridul-manohar May 20, 2025

Choose a reason for hiding this comment

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

Changed as suggested. We are pointing it to exact version = "0.13.1"

Copy link
Contributor

@raoulstrackx raoulstrackx left a comment

Choose a reason for hiding this comment

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

There are many code changes that are (likely) not compatible with mbedtls 0.12. You may be able to call .into() to ensure the code keeps working for both versions.

static ref NOT_VALID_YET_ERR: NitroError = NitroError::CertificateVerifyFailure("Certificate verify failure: X509CertVerifyFailed, The certificate validity starts in the future\n".to_string());
static ref EXPIRED_ERR: NitroError = NitroError::CertificateVerifyFailure("Certificate verify failure: X509CertVerifyFailed, The certificate validity has expired\n".to_string());
static ref NOT_VALID_YET_ERR: NitroError = NitroError::CertificateVerifyFailure("Certificate verify failure: HighLevel(X509CertVerifyFailed), The certificate validity starts in the future\n".to_string());
static ref EXPIRED_ERR: NitroError = NitroError::CertificateVerifyFailure("Certificate verify failure: HighLevel(X509CertVerifyFailed), The certificate validity has expired\n".to_string());
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change still work on mbedtls 0.12?

Copy link
Author

Choose a reason for hiding this comment

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

This requires v0.13.1 (therefore not backcompt)
and we are pointing to exact version = "0.13.1"

@@ -97,7 +98,7 @@ impl SigningPublicKey for WrappedCert {
// We'll throw error if signature verify does not work
match pk.verify(*md, &digest, &sig) {
Ok(_) => Ok(true),
Err(mbedtls::Error::EcpVerifyFailed) => Ok(false),
Err(ErrMbed::HighLevel(codes::EcpVerifyFailed)) => Ok(false),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change still work on mbedtls 0.12?

Copy link
Author

Choose a reason for hiding this comment

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

This requires v0.13.1 (therefore not backcompt)
and we are pointing to exact version = "0.13.1" now

Certificate::from_pem(cert.as_bytes_with_nul()).map_err(|_| MbedError::X509InvalidFormat)
pub fn pck(&self) -> Result<MbedtlsBox<Certificate>, ErrMbed> {
let cert = CString::new(self.cert.as_bytes()).map_err(|_| ErrMbed::HighLevel(codes::X509InvalidFormat))?;
Certificate::from_pem(cert.as_bytes_with_nul()).map_err(|_| ErrMbed::HighLevel(codes::X509InvalidFormat))
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change still work on mbedtls 0.12?

Copy link
Author

Choose a reason for hiding this comment

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

This requires v0.13.1 (therefore not backcompt)
and we are pointing to exact version = "0.13.1"


[dev-dependencies]
hex = "0.4.2"
tempdir = "0.3.7"
mbedtls = { version = ">=0.12.0, <0.14.0" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Author

Choose a reason for hiding this comment

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

Had added this for mbedtls imports in mod tests { .. }
removed this now since it was not needed.

@mridul-manohar
Copy link
Author

There are many code changes that are (likely) not compatible with mbedtls 0.12. You may be able to call .into() to ensure the code keeps working for both versions.

@raoulstrackx thanks for pointing this out. After discussing with @Taowyoo we have decided to point to specific
version = "0.13.1" for the crates which required code changes for combined error types. This ensures that we don't need to ensure compatibility ( using .into() ) with ver0.12

@raoulstrackx
Copy link
Contributor

There are many code changes that are (likely) not compatible with mbedtls 0.12. You may be able to call .into() to ensure the code keeps working for both versions.

@raoulstrackx thanks for pointing this out. After discussing with @Taowyoo we have decided to point to specific version = "0.13.1" for the crates which required code changes for combined error types. This ensures that we don't need to ensure compatibility ( using .into() ) with ver0.12

What was the reasoning to force upgrades to mbedtls 0.13.1? It'd be at least a breaking change for pcs (I haven't checked the other crates). I'm also a little bit worried about the impact on the fortanixvme target. Just adding .into() to fix the errors should work, and would only require a patch number bump.

@Taowyoo
Copy link
Collaborator

Taowyoo commented May 22, 2025

HI @raoulstrackx
@mridul’s PR is going to upgrade mbedtls in rust-sgx repo to 0.13
Any crates that directly use mbedtls Error type need to upgrade the dependency requirement on mbedtls to 0.13 , include:

  • nitro-attestation-verify
  • pcs

Crates that do not explicitly use mbedtls Error type could use range version ">=0.12.0, <0.14.0" to keep compatibility for 0.12 version

@Taowyoo
Copy link
Collaborator

Taowyoo commented May 22, 2025

I think the main concern from @raoul Strackx is that bumping mbedtls version in vme crates might cause compile issue in roche.

So I suggest @mridul to have a PR on roche side with changes in rust-sgx to ensure changes in rust-sgx is fine with roche CI.

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.

4 participants