Skip to content

Commit 132b0d9

Browse files
fix: generate a new signature keypair when creating an E2EI enrollment
1 parent 8ed10c3 commit 132b0d9

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

crypto/src/e2e_identity/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod error;
44
pub(crate) mod id;
55
pub(crate) mod identity;
66
mod pki_env;
7+
pub(crate) use crypto::E2eiSignatureKeypair;
78
pub use pki_env::NewCrlDistributionPoints;
89
pub(crate) use pki_env::restore_pki_env;
910
#[cfg(not(test))]

crypto/src/transaction_context/e2e_identity/rotate.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1-
use openmls_traits::OpenMlsCryptoProvider;
1+
use openmls_basic_credential::SignatureKeyPair;
2+
use openmls_traits::{OpenMlsCryptoProvider as _, random::OpenMlsRand as _};
23

34
use super::error::{Error, Result};
45
use crate::{
5-
CertificateBundle, Ciphersuite, Credential, CredentialType, E2eiEnrollment, RecursiveError,
6-
e2e_identity::NewCrlDistributionPoints,
6+
CertificateBundle, Ciphersuite, Credential, CredentialType, E2eiEnrollment, MlsError, RecursiveError,
7+
e2e_identity::{E2eiSignatureKeypair, NewCrlDistributionPoints},
78
mls::credential::{ext::CredentialExt, x509::CertificatePrivateKey},
89
transaction_context::TransactionContext,
910
};
1011

1112
impl TransactionContext {
13+
async fn new_sign_keypair(&self, ciphersuite: Ciphersuite) -> Result<E2eiSignatureKeypair> {
14+
let mls_provider = self
15+
.mls_provider()
16+
.await
17+
.map_err(RecursiveError::transaction("getting mls provider"))?;
18+
19+
let sign_keypair = &SignatureKeyPair::new(
20+
ciphersuite.signature_algorithm(),
21+
&mut *mls_provider
22+
.rand()
23+
.borrow_rand()
24+
.map_err(MlsError::wrap("borrowing rng"))?,
25+
)
26+
.map_err(MlsError::wrap("generating new sign keypair"))?;
27+
28+
sign_keypair
29+
.try_into()
30+
.map_err(RecursiveError::e2e_identity("creating E2eiSignatureKeypair"))
31+
.map_err(Into::into)
32+
}
33+
1234
/// Generates an E2EI enrollment instance for a "regular" client (with a Basic credential)
1335
/// willing to migrate to E2EI. As a consequence, this method does not support changing the
1436
/// ClientId which should remain the same as the Basic one.
@@ -36,11 +58,7 @@ impl TransactionContext {
3658
.map_err(|_| Error::MissingExistingClient(CredentialType::Basic))?;
3759
let client_id = cb.mls_credential().identity().to_owned().into();
3860

39-
let sign_keypair = Some(
40-
cb.signature_key()
41-
.try_into()
42-
.map_err(RecursiveError::e2e_identity("creating E2eiSignatureKeypair"))?,
43-
);
61+
let sign_keypair = self.new_sign_keypair(ciphersuite).await?;
4462

4563
E2eiEnrollment::try_new(
4664
client_id,
@@ -50,7 +68,7 @@ impl TransactionContext {
5068
expiry_sec,
5169
&mls_provider,
5270
ciphersuite,
53-
sign_keypair,
71+
Some(sign_keypair),
5472
false, // no x509 credential yet at this point so no OIDC authn yet so no refresh token to restore
5573
)
5674
.map_err(RecursiveError::e2e_identity("creating new enrollment"))
@@ -84,11 +102,7 @@ impl TransactionContext {
84102
.await
85103
.map_err(|_| Error::MissingExistingClient(CredentialType::X509))?;
86104
let client_id = cb.mls_credential().identity().to_owned().into();
87-
let sign_keypair = Some(
88-
cb.signature_key()
89-
.try_into()
90-
.map_err(RecursiveError::e2e_identity("creating E2eiSignatureKeypair"))?,
91-
);
105+
let sign_keypair = self.new_sign_keypair(ciphersuite).await?;
92106
let existing_identity = cb
93107
.to_mls_credential_with_key()
94108
.extract_identity(ciphersuite, None)
@@ -107,7 +121,7 @@ impl TransactionContext {
107121
expiry_sec,
108122
&mls_provider,
109123
ciphersuite,
110-
sign_keypair,
124+
Some(sign_keypair),
111125
true, /* Since we are renewing an e2ei certificate we MUST have already generated one hence we MUST
112126
* already have done an OIDC authn and gotten a refresh token from it */
113127
)

0 commit comments

Comments
 (0)