Skip to content

Conversation

sgrams
Copy link

@sgrams sgrams commented Aug 25, 2025

The spdm-rs library, which utilizes rustls-webpki for certificate validation, encountered an issue with custom EKU OID validation as described in spdm-rs issue #220.

To maintain backward compatibility with SPDM 1.0, spdm-rs must support the following EKU OID verification scenarios:

  • For the Requester’s certificate: EKU OID { id-DMTF-spdm 4 } is required if EKU OID { id-DMTF-spdm 3 } is present.
  • For the Responder’s certificate: EKU OID { id-DMTF-spdm 3 } is required if EKU OID { id-DMTF-spdm 4 } is present.

The current implementation of rustls/webpki does not support this specific EKU policy.
This PR introduces a new policy to enable the required EKU OID validation logic, ensuring proper interoperability with SPDM 1.0 devices.

Copy link

codecov bot commented Aug 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.56%. Comparing base (7739a54) to head (086a348).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #372      +/-   ##
==========================================
+ Coverage   97.52%   97.56%   +0.04%     
==========================================
  Files          20       20              
  Lines        4081     4156      +75     
==========================================
+ Hits         3980     4055      +75     
  Misses        101      101              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sgrams sgrams force-pushed the eku_xrequiredifypresent branch from 249f37c to 5abeabd Compare August 25, 2025 13:20
@djc
Copy link
Member

djc commented Aug 25, 2025

It's not obvious to me that we'd want to support this kind of policy in the library. Couldn't you just handle this in an extra validation step?

@cpu
Copy link
Member

cpu commented Aug 25, 2025

Is there an equivalent API exposed by another popular certificate chain verifier library as a point of reference? At face value it seems off to encode a policy this fine-grained into the API.

sgrams added 2 commits August 25, 2025 15:30
This introduces new ExtendedKeyUsage policy, which requires EKU OID X
to be present only if EKU OID Y is present.

This is to support SPDM EKU OID checks for SPDM-RS, which leverages
rustls-webpki.
E.g. Requester's cert EKU OID { id-DMTF-spdm 4 } is
required when OID { id-DMTF-spdm 3 } is present.
Responder's cert EKU OID { id-DMTF-spdm 3 } is required when
EKU OID { id-DMTF-spdm 4 } is present.

Signed-off-by: Stanislaw Grams <[email protected]>
…Present

This introduces three test cases for XRequiredIfYPresent
ExtendedKeyUsage policy.

Signed-off-by: Stanislaw Grams <[email protected]>
@sgrams sgrams force-pushed the eku_xrequiredifypresent branch from 5abeabd to 086a348 Compare August 25, 2025 13:30
@ctz
Copy link
Member

ctz commented Aug 26, 2025

I wonder if it is instead worth doing something like:

impl Cert {
  pub fn satisfies_extended_key_usage(&self, eku: ExtendedKeyUsage, _verified_path: &VerifiedPath<'_>)
    -> Result<(), Error>;
}

That would allow the particular logic to be constructed as needed, and then applied either after path verification, or during it using the existing verify_path callback (in case the logic has any path-dependent nature, which would allow alternative paths to be found.)

(The unused _verified_path parameter is a misuse-resistance measure, to ensure this function is only callable during or after a path verification.)

@sgrams
Copy link
Author

sgrams commented Aug 26, 2025

Is there an equivalent API exposed by another popular certificate chain verifier library as a point of reference? At face value it seems off to encode a policy this fine-grained into the API.

I don't think there is any similar API proposed as a point of reference, as libspdm (the standard SPDM library) seems to implement this policy on its own and does not reuse any 3rd party verifier.
See https://github.com/DMTF/libspdm/blob/main/library/spdm_crypt_lib/libspdm_crypt_cert.c#L1257

I proposed the PR mainly because I wanted to reuse webpki library but couldn't find a correct way to skip EKU verification within verify_for_usage as eku is not an optional argument and for spdm-rs use case the "required" or "required_if_present" policy will always fail.

If you disagree to push this PR, please close it, I'll try to find another solution

@cpu
Copy link
Member

cpu commented Aug 26, 2025

I don't think there is any similar API proposed as a point of reference, as libspdm (the standard SPDM library) seems to implement this policy on its own and does not reuse any 3rd party verifier.

With a casual look this seems closer to what @ctz is proposing. Hopefully (🤞 ) some higher level of libspdm is doing the end to end path building and signature validation or you have bigger issues.

I think we would want to manage this similarly and have webpki do it's usual path building & verification, but offering your code a place to interrogate the EKUs for a specific end entity cert after that process has completed successfully.

@cpu
Copy link
Member

cpu commented Aug 26, 2025

(The unused _verified_path parameter is a misuse-resistance measure, to ensure this function is only callable during or after a path verification.)

If we take this route we should probably check self is on the verified path to prevent someone passing in a verified path for an unrelated chain.

@sgrams
Copy link
Author

sgrams commented Sep 15, 2025

The newly defined API is resolving my issue, but it seems it lacks pub re-exports of KeyPurposeId and KeyPurposeIdIter. See #380

@sgrams sgrams closed this Sep 15, 2025
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