Skip to content

chore: x509 refactor, part 11: The Valley Of Horrors#2116

Merged
istankovic merged 65 commits into
mainfrom
ivan/x509-part-11
May 13, 2026
Merged

chore: x509 refactor, part 11: The Valley Of Horrors#2116
istankovic merged 65 commits into
mainfrom
ivan/x509-part-11

Conversation

@istankovic
Copy link
Copy Markdown
Member

@istankovic istankovic commented May 7, 2026

This comprises several changes:

  • PKI env now stores trust anchors, intermediate certs and CRLs to the db
  • cert and credential validation is done via the outer PKI env, instead of using the inner directly
  • introduction of AuthenticationService that is just a wrapper around a PKI env; the purpose
    of this type is linking the MLS parts of the crypto crate and PKI env/e2e-identity
  • time of interest is now computed internally during cert validation
  • removal of PkiEnvironmentProvider
  • misc simplifications

⚠️ x509 tests in the crypto crate are disabled because they are broken with this PR. The idea is to fix them as part of a later PR.

@istankovic istankovic requested a review from a team May 7, 2026 08:23
@istankovic istankovic changed the title Ivan/x509 part 11 chore: x509 refactor, part 11: The Valley Of Horrors May 7, 2026
@istankovic istankovic force-pushed the ivan/x509-part-11 branch 4 times, most recently from cbfbde1 to c4ee6b1 Compare May 8, 2026 09:52
Comment thread e2e-identity/src/pki_env/mod.rs Outdated
Comment thread e2e-identity/src/pki_env/mod.rs Outdated
Comment thread e2e-identity/src/pki_env/mod.rs Outdated
Comment thread e2e-identity/src/pki_env/mod.rs Outdated
@istankovic istankovic force-pushed the ivan/x509-part-11 branch from fa09a67 to ef18ac2 Compare May 8, 2026 13:50
Copy link
Copy Markdown
Contributor

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

  • commit 2797333 has a message which appears entirely unrelated to its contents

Comment thread e2e-identity/src/pki_env/mod.rs Outdated
Comment thread crypto/src/mls_provider/mod.rs Outdated
Comment thread crypto/src/mls_provider/mod.rs Outdated
Comment thread e2e-identity/src/pki_env/mod.rs Outdated
Comment thread e2e-identity/src/pki_env/mod.rs
Comment thread e2e-identity/src/acquisition/checks.rs
Comment thread e2e-identity/src/pki_env/mod.rs
Comment thread crypto/src/mls/conversation/mod.rs Outdated
@coriolinus
Copy link
Copy Markdown
Contributor

And as mentioned in chat, it's not obvious why 4d60315 is necessary. If we can remove that, then we can remove several downstream changes.

@istankovic
Copy link
Copy Markdown
Member Author

istankovic commented May 8, 2026

commit 2797333 has a message which appears entirely unrelated to its contents

I admit it's not quite obvious, but if you look at the types being imported, you will see that the PkiEnvironment type no longer comes from the revocation module (the inner PKI env) but the pki_env module (the outer PKI env). 😅

@istankovic istankovic force-pushed the ivan/x509-part-11 branch 3 times, most recently from 1f15539 to c671834 Compare May 11, 2026 11:24
Comment thread e2e-identity/src/pki_env/mod.rs
Comment thread e2e-identity/src/pki_env/mod.rs Outdated
Comment thread e2e-identity/src/pki_env/mod.rs Outdated
@istankovic istankovic force-pushed the ivan/x509-part-11 branch 5 times, most recently from 3bdfe0d to eba0fdd Compare May 12, 2026 15:15
Copy link
Copy Markdown
Contributor

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

I really want to get this PR into place, but the trust anchor stuff is underbaked. Could you just split the last commits into the start of part 12 so I can approve this?

Comment thread e2e-identity/src/pki_env/mod.rs
Comment thread e2e-identity/src/pki_env/mod.rs
Comment thread e2e-identity/src/pki_env/mod.rs
We're going to eventually remove the inner PKI environment and this is
the first step towards that. The goal is to have any code external to the
e2e-identity crate be sure that if it has a reference to the outer PKI
environment, it can verify X509 credentials. In particular, the crypto
crate knows whether a PKI environment has been configured by user code.
This also allows us to simplify e2e-identity internally because if we
have a reference to the outer PKI environment, we know we also have the
inner one and can proceed without any checks.
We're not going to implement openmls auth service trait, leaving that to
the crypto crate. This crate should merely provide a way to validate
X509 credentials, which is now done via PkiEnvironment::validate_credential.

Calling that function with a basic credential is a programmer error and
will panic. Ideally, we would have a way to ensure correct credential
type at compile time, but this is good enough for now.
We are going to be computing time of interest (TOI) as needed, when we
do certificate validation. External users will not be able to set
arbitrary TOI. This will also allows us to drop the `toi` field from
the (inner) PkiEnvironment struct.
TOI is computed internally during validation.
istankovic added 27 commits May 13, 2026 10:38
This finally removes the last remaining user of `mls_pki_env_provider`.
It is not needed anymore because `add_trust_anchor` does everything already.
We have

    pki_environment: Arc<RwLock<Option<Arc<PkiEnvironment>>>>
                      ^    ^      ^     ^
                      |    |      |     |
                      |    |      |     `----- because of FFI and PkiEnvironment: !Clone; the same
                      |    |      |            PKI env instance must be referenced by foreign language
                      |    |      |            objects and Rust
                      |    |      |
                      |    |      `----------- because clients can set the PKI env to None
                      |    |
                      |    `------------------ because of FFI: we have to use interior mutability
                      |                        since uniffi does not support &mut self references
                      |
                      `----------------------- because we need CoreCrypto: Clone
                                               (instances are shared in tests)
These tests previously worked with the inner PKI env directly, but we've moved
everything to the outer PKI env so we also need to adjust the tests.
Trying to create a new db transaction may result in a deadlock if there is
already one in progress.
This is only temporary, until we get x509 tests fully working.
This is only temporary, until we get x509 tests fully working.
…sync

This is really not ideal. It's caused by IdentityStatus::from_cert being
async, which in turn is caused by cert validation on PKI env being async
(has to be because the inner PKI env is behind an async mutex). So,
sadly, we cannot avoid it without refactoring the whole User/Device
identity status stuff, which we should do eventually, also for other
reasons. But not today.
We already have one at the top of the file.
We use the "immediate" API because if there's already a transaction in
progress, we want to get an error, instead of risking a deadlock.
It is now unused. We allow multiple trust anchors, which one can get via
get_trust_anchors.
@istankovic istankovic force-pushed the ivan/x509-part-11 branch from 6cdd314 to 911d137 Compare May 13, 2026 08:39
@istankovic istankovic merged commit 911d137 into main May 13, 2026
62 checks passed
@istankovic istankovic deleted the ivan/x509-part-11 branch May 13, 2026 09:21
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