Skip to content

Commit 8158f1b

Browse files
zombieobjecttuddmanneekolas
authored
Update to Latest OpenMLS (#596)
* Update xmtp/openmls to latest * Intermediate Commit with TLS Naming Fixes * Resolve errors in identity.rs * Update to New BasicCredential API * Standardize Errors Passed * Use StagedWelcome + Other Fixes * Remove use of `.map_err` where appropriate * fix: fixes error handling * fix: fixes imports formatting * Cleanup StagedWelcome * Update aggregate_member_list() .filter_map * Create basic credentials directly * One more case of Credential::new() * One more * Fix legacy credential * Lint * One last lint --------- Co-authored-by: tuddman <tuddman@users.noreply.github.com> Co-authored-by: Nicholas Molnar <65710+neekolas@users.noreply.github.com>
1 parent d9b67d8 commit 8158f1b

File tree

13 files changed

+698
-544
lines changed

13 files changed

+698
-544
lines changed

Cargo.lock

+506-452
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ resolver = "2"
2424

2525
[workspace.dependencies]
2626
async-trait = "0.1.77"
27+
chrono = "0.4"
2728
ethers = "2.0.11"
2829
ethers-core = "2.0.4"
2930
futures = "0.3.30"
3031
futures-core = "0.3.30"
3132
hex = "0.4.3"
3233
log = "0.4"
33-
tracing = "0.1"
34-
openmls = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
35-
openmls_basic_credential = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
36-
openmls_rust_crypto = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
37-
openmls_traits = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
34+
openmls = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" }
35+
openmls_basic_credential = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" }
36+
openmls_rust_crypto = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" }
37+
openmls_traits = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" }
3838
prost = "^0.12"
3939
prost-types = "^0.12"
4040
rand = "0.8.5"
@@ -44,7 +44,7 @@ thiserror = "1.0"
4444
tls_codec = "0.4.0"
4545
tokio = { version = "1.35.1", features = ["macros"] }
4646
tonic = "^0.11"
47-
chrono = "0.4"
47+
tracing = "0.1"
4848

4949
# Internal Crate Dependencies
5050
xmtp_cryptography = { path = "xmtp_cryptography" }

bindings_ffi/Cargo.lock

+75-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mls_validation_service/src/handlers.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use openmls::prelude::{MlsMessageIn, ProtocolMessage, TlsDeserializeTrait};
1+
use openmls::{
2+
credentials::BasicCredential,
3+
prelude::{tls_codec::Deserialize, MlsMessageIn, ProtocolMessage},
4+
};
25
use openmls_rust_crypto::RustCrypto;
36
use tonic::{Request, Response, Status};
47

@@ -85,10 +88,12 @@ struct ValidateGroupMessageResult {
8588
}
8689

8790
fn validate_group_message(message: Vec<u8>) -> Result<ValidateGroupMessageResult, String> {
88-
let msg_result = MlsMessageIn::tls_deserialize(&mut message.as_slice())
89-
.map_err(|_| "failed to decode".to_string())?;
91+
let msg_result =
92+
MlsMessageIn::tls_deserialize(&mut message.as_slice()).map_err(|e| e.to_string())?;
9093

91-
let protocol_message: ProtocolMessage = msg_result.into();
94+
let protocol_message: ProtocolMessage = msg_result
95+
.try_into_protocol_message()
96+
.map_err(|e| e.to_string())?;
9297

9398
Ok(ValidateGroupMessageResult {
9499
group_id: serialize_group_id(protocol_message.group_id().as_slice()),
@@ -108,15 +113,14 @@ fn validate_key_package(key_package_bytes: Vec<u8>) -> Result<ValidateKeyPackage
108113
VerifiedKeyPackage::from_bytes(&rust_crypto, key_package_bytes.as_slice())
109114
.map_err(|e| e.to_string())?;
110115

116+
let credential = verified_key_package.inner.leaf_node().credential();
117+
118+
let basic_credential = BasicCredential::try_from(credential).map_err(|e| e.to_string())?;
119+
111120
Ok(ValidateKeyPackageResult {
112121
installation_id: verified_key_package.installation_id(),
113122
account_address: verified_key_package.account_address,
114-
credential_identity_bytes: verified_key_package
115-
.inner
116-
.leaf_node()
117-
.credential()
118-
.identity()
119-
.to_vec(),
123+
credential_identity_bytes: basic_credential.identity().to_vec(),
120124
expiration: verified_key_package.inner.life_time().not_after(),
121125
})
122126
}
@@ -127,8 +131,8 @@ mod tests {
127131
use openmls::{
128132
extensions::{ApplicationIdExtension, Extension, Extensions},
129133
prelude::{
130-
Ciphersuite, Credential as OpenMlsCredential, CredentialType, CredentialWithKey,
131-
CryptoConfig, TlsSerializeTrait,
134+
tls_codec::Serialize, Ciphersuite, Credential as OpenMlsCredential, CredentialWithKey,
135+
CryptoConfig,
132136
},
133137
prelude_test::KeyPackage,
134138
versions::ProtocolVersion,
@@ -192,7 +196,7 @@ mod tests {
192196
async fn test_validate_key_packages_happy_path() {
193197
let (identity, keypair, account_address) = generate_identity();
194198

195-
let credential = OpenMlsCredential::new(identity, CredentialType::Basic).unwrap();
199+
let credential: OpenMlsCredential = BasicCredential::new(identity).unwrap().into();
196200
let credential_with_key = CredentialWithKey {
197201
credential,
198202
signature_key: keypair.to_public_vec().into(),
@@ -222,7 +226,7 @@ mod tests {
222226
let (identity, keypair, account_address) = generate_identity();
223227
let (_, other_keypair, _) = generate_identity();
224228

225-
let credential = OpenMlsCredential::new(identity, CredentialType::Basic).unwrap();
229+
let credential: OpenMlsCredential = BasicCredential::new(identity).unwrap().into();
226230
let credential_with_key = CredentialWithKey {
227231
credential,
228232
// Use the wrong signature key to make the validation fail

xmtp_mls/src/client.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use std::{collections::HashSet, mem::Discriminant};
22

33
use openmls::{
4-
framing::{MlsMessageIn, MlsMessageInBody},
4+
credentials::errors::BasicCredentialError,
5+
framing::{MlsMessageBodyIn, MlsMessageIn},
56
group::GroupEpoch,
67
messages::Welcome,
7-
prelude::TlsSerializeTrait,
8+
prelude::tls_codec::{Deserialize, Error as TlsCodecError, Serialize},
89
};
910
use openmls_traits::OpenMlsProvider;
1011
use prost::EncodeError;
1112
use thiserror::Error;
12-
use tls_codec::{Deserialize, Error as TlsSerializationError};
1313

1414
use xmtp_proto::{
1515
api_client::XmtpMlsClient,
@@ -62,8 +62,8 @@ pub enum ClientError {
6262
QueryError(#[from] xmtp_proto::api_client::Error),
6363
#[error("identity error: {0}")]
6464
Identity(#[from] crate::identity::IdentityError),
65-
#[error("serialization error: {0}")]
66-
Serialization(#[from] TlsSerializationError),
65+
#[error("TLS Codec error: {0}")]
66+
TlsError(#[from] TlsCodecError),
6767
#[error("key package verification: {0}")]
6868
KeyPackageVerification(#[from] KeyPackageVerificationError),
6969
#[error("syncing errors: {0:?}")]
@@ -105,10 +105,10 @@ pub enum MessageProcessingError {
105105
Intent(#[from] IntentError),
106106
#[error("storage error: {0}")]
107107
Storage(#[from] crate::storage::StorageError),
108-
#[error("tls deserialization: {0}")]
109-
TlsDeserialization(#[from] tls_codec::Error),
108+
#[error("TLS Codec error: {0}")]
109+
TlsError(#[from] TlsCodecError),
110110
#[error("unsupported message type: {0:?}")]
111-
UnsupportedMessageType(Discriminant<MlsMessageInBody>),
111+
UnsupportedMessageType(Discriminant<MlsMessageBodyIn>),
112112
#[error("commit validation")]
113113
CommitValidation(#[from] CommitValidationError),
114114
#[error("codec")]
@@ -119,6 +119,8 @@ pub enum MessageProcessingError {
119119
EpochIncrementNotAllowed,
120120
#[error("Welcome processing error: {0}")]
121121
WelcomeProcessing(String),
122+
#[error("wrong credential type")]
123+
WrongCredentialType(#[from] BasicCredentialError),
122124
#[error("proto decode error: {0}")]
123125
DecodeError(#[from] prost::DecodeError),
124126
}
@@ -269,7 +271,6 @@ where
269271
.identity
270272
.new_key_package(&self.mls_provider(&connection))?;
271273
let kp_bytes = kp.tls_serialize_detached()?;
272-
273274
self.api_client.upload_key_package(kp_bytes).await?;
274275

275276
Ok(())
@@ -488,7 +489,7 @@ pub fn deserialize_welcome(welcome_bytes: &Vec<u8>) -> Result<Welcome, ClientErr
488489
// let welcome_proto = WelcomeMessageProto::decode(&mut welcome_bytes.as_slice())?;
489490
let welcome = MlsMessageIn::tls_deserialize(&mut welcome_bytes.as_slice())?;
490491
match welcome.extract() {
491-
MlsMessageInBody::Welcome(welcome) => Ok(welcome),
492+
MlsMessageBodyIn::Welcome(welcome) => Ok(welcome),
492493
_ => Err(ClientError::Generic(
493494
"unexpected message type in welcome".to_string(),
494495
)),

xmtp_mls/src/groups/intents.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use openmls::prelude::MlsMessageOut;
1+
use openmls::prelude::{
2+
tls_codec::{Error as TlsCodecError, Serialize},
3+
MlsMessageOut,
4+
};
25
use prost::{DecodeError, Message};
36
use thiserror::Error;
4-
use tls_codec::Serialize;
57

68
use xmtp_proto::xmtp::mls::database::{
79
add_members_data::{Version as AddMembersVersion, V1 as AddMembersV1},
@@ -28,8 +30,8 @@ pub enum IntentError {
2830
Decode(#[from] DecodeError),
2931
#[error("key package verification: {0}")]
3032
KeyPackageVerification(#[from] KeyPackageVerificationError),
31-
#[error("tls codec: {0}")]
32-
TlsCodec(#[from] tls_codec::Error),
33+
#[error("TLS Codec error: {0}")]
34+
TlsError(#[from] TlsCodecError),
3335
#[error("generic: {0}")]
3436
Generic(String),
3537
}

0 commit comments

Comments
 (0)