-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Key Package Generation / Join API 1.x (#226)
* Fix CI (#223) * feat(mls-rs): Verify the update path even in case of a self removal (#224) * Fix bug where double-hitting a ciphertext deleted the whole ratchet (#228) Co-authored-by: Marta Mularczyk <[email protected]> * Work around rust < 1.78 crash (#231) Somehow the DWARF info generated by the compiler for the `hash`-replacement assignment is confusing to LLVM, which crashes. By using a different form for the same operation, the compiler is happy. * Avoid intermediate Vec in TreeKemPublic::update_hashes (#230) [slice, slice].concat() creates an intermediate Vec, which can be avoided by chaining updated_leaves and trailing_blanks before the first Vec is created. * Add API for deleting exporters (#227) * Add API for deleting exporters * Apply suggestions from code review Co-authored-by: Stephane Raux <[email protected]> --------- Co-authored-by: Marta Mularczyk <[email protected]> Co-authored-by: Tom Leavy <[email protected]> Co-authored-by: Stephane Raux <[email protected]> * Key package generation 1.x * Fix clippy warnings * Initial implementation of group join 1.x * Add example for 1x API * Apply suggestions from code review * Add SigningData struct * Fixup * Add more tests * Fixup * Fixup --------- Co-authored-by: Félix Lescaudey de Maneville <[email protected]> Co-authored-by: Marta Mularczyk <[email protected]> Co-authored-by: Mike Hommey <[email protected]> Co-authored-by: Tom Leavy <[email protected]> Co-authored-by: Stephane Raux <[email protected]>
- Loading branch information
1 parent
cb25022
commit 8da6828
Showing
51 changed files
with
1,230 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// Copyright by contributors to this project. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
|
||
use std::convert::Infallible; | ||
|
||
use mls_rs::{ | ||
client_builder::MlsConfig, | ||
error::MlsError, | ||
identity::{ | ||
basic::{BasicCredential, BasicIdentityProvider}, | ||
SigningIdentity, | ||
}, | ||
CipherSuite, CipherSuiteProvider, Client, CryptoProvider, ExtensionList, KeyPackageStorage, | ||
}; | ||
use mls_rs_core::key_package::KeyPackageData; | ||
|
||
const CIPHERSUITE: CipherSuite = CipherSuite::CURVE25519_AES128; | ||
|
||
fn main() -> Result<(), MlsError> { | ||
let crypto_provider = mls_rs_crypto_openssl::OpensslCryptoProvider::default(); | ||
|
||
// Create clients for Alice and Bob | ||
let alice = make_client(crypto_provider.clone(), "alice")?; | ||
let bob = make_client(crypto_provider.clone(), "bob")?; | ||
|
||
// Bob generates key package. We store secrets in memory, no need for any storage. | ||
let key_package_generation = bob | ||
.key_package_builder(CIPHERSUITE, None)? | ||
.valid_for_sec(123) | ||
.build()?; | ||
|
||
let stored_secrets = key_package_generation.key_package_data; | ||
|
||
// Alice creates a group with Bob. | ||
let mut alice_group = alice.create_group(ExtensionList::default(), Default::default())?; | ||
|
||
let welcomes = alice_group | ||
.commit_builder() | ||
.add_member(key_package_generation.key_package_message)? | ||
.build()? | ||
.welcome_messages; | ||
|
||
alice_group.apply_pending_commit()?; | ||
|
||
// Bob joins | ||
let mut bob_group = bob.group_joiner(&welcomes[0], stored_secrets)?.join()?.0; | ||
|
||
// Alice and bob can chat | ||
let msg = alice_group.encrypt_application_message(b"hello world", Default::default())?; | ||
let msg = bob_group.process_incoming_message(msg)?; | ||
|
||
println!("Received message: {:?}", msg); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Clone)] | ||
struct NoOpKeyPackageStorage; | ||
|
||
impl KeyPackageStorage for NoOpKeyPackageStorage { | ||
type Error = Infallible; | ||
|
||
fn delete(&mut self, _: &[u8]) -> Result<(), Infallible> { | ||
Ok(()) | ||
} | ||
|
||
fn get(&self, _: &[u8]) -> Result<Option<KeyPackageData>, Infallible> { | ||
Ok(None) | ||
} | ||
|
||
fn insert(&mut self, _: Vec<u8>, _: KeyPackageData) -> Result<(), Infallible> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn make_client<P: CryptoProvider + Clone>( | ||
crypto_provider: P, | ||
name: &str, | ||
) -> Result<Client<impl MlsConfig>, MlsError> { | ||
let cipher_suite = crypto_provider.cipher_suite_provider(CIPHERSUITE).unwrap(); | ||
let (secret, public) = cipher_suite.signature_key_generate().unwrap(); | ||
let basic_identity = BasicCredential::new(name.as_bytes().to_vec()); | ||
let signing_identity = SigningIdentity::new(basic_identity.into_credential(), public); | ||
|
||
Ok(Client::builder() | ||
.identity_provider(BasicIdentityProvider) | ||
.crypto_provider(crypto_provider) | ||
.signing_identity(signing_identity, secret, CIPHERSUITE) | ||
.key_package_repo(NoOpKeyPackageStorage) | ||
.build()) | ||
} |
Oops, something went wrong.