This commit is contained in:
parent
1b796d0ce7
commit
d6e49d4930
4 changed files with 25 additions and 4 deletions
|
|
@ -27,6 +27,8 @@ serde = { version = "1", optional = true, features = ["derive"] }
|
||||||
rcgen = { version = "0.14", optional = true }
|
rcgen = { version = "0.14", optional = true }
|
||||||
time = { version = "0.3", optional = true }
|
time = { version = "0.3", optional = true }
|
||||||
tokio = { version = "1", features = ["macros", "rt"], optional = true }
|
tokio = { version = "1", features = ["macros", "rt"], optional = true }
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
rustls = "0.23.41"
|
rustls = "0.23.41"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@ pub mod auth;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod keypair;
|
pub mod keypair;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
static CRYPTO_INIT: Once = Once::new();
|
static CRYPTO_INIT: Once = Once::new();
|
||||||
|
|
||||||
#[cfg(feature = "sha2")]
|
#[cfg(feature = "sha2")]
|
||||||
|
|
@ -70,6 +72,7 @@ pub use enc::EncryptionType;
|
||||||
///
|
///
|
||||||
/// Rustls only accepts one process-wide default provider. Calling this helper
|
/// Rustls only accepts one process-wide default provider. Calling this helper
|
||||||
/// from every TLS entry point makes that initialization idempotent.
|
/// from every TLS entry point makes that initialization idempotent.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn ensure_crypto_provider() {
|
pub fn ensure_crypto_provider() {
|
||||||
CRYPTO_INIT.call_once(|| {
|
CRYPTO_INIT.call_once(|| {
|
||||||
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
|
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ async fn accept_web_connection_inner(
|
||||||
if send_pongs {
|
if send_pongs {
|
||||||
receiver.respond_to_pings(sender.clone()).await;
|
receiver.respond_to_pings(sender.clone()).await;
|
||||||
}
|
}
|
||||||
let connection = mtp_host::MTPConnection::from_transport_parts(
|
let connection: WebMTPConnection = mtp_host::MTPConnection::from_transport_parts(
|
||||||
negotiated,
|
negotiated,
|
||||||
codec,
|
codec,
|
||||||
sender,
|
sender,
|
||||||
|
|
@ -401,7 +401,22 @@ async fn accept_web_connection_inner(
|
||||||
.map_err(AcceptError::Send)?;
|
.map_err(AcceptError::Send)?;
|
||||||
tracing::debug!(elapsed = ?send_challenge_started.elapsed(), "web authentication handshake: send challenge");
|
tracing::debug!(elapsed = ?send_challenge_started.elapsed(), "web authentication handshake: send challenge");
|
||||||
let receive_proof_started = Instant::now();
|
let receive_proof_started = Instant::now();
|
||||||
let proof = connection.receive().await.map_err(AcceptError::Receive)?;
|
let proof = {
|
||||||
|
#[cfg(feature = "pipes")]
|
||||||
|
{
|
||||||
|
connection.receive().await.map_err(AcceptError::Receive)?
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "pipes"))]
|
||||||
|
{
|
||||||
|
let mut proof = connection
|
||||||
|
.receiver
|
||||||
|
.receive()
|
||||||
|
.await
|
||||||
|
.map_err(AcceptError::Receive)?;
|
||||||
|
proof.set_type_map(connection.codec.type_map());
|
||||||
|
proof
|
||||||
|
}
|
||||||
|
};
|
||||||
tracing::debug!(elapsed = ?receive_proof_started.elapsed(), "web authentication handshake: receive client proof");
|
tracing::debug!(elapsed = ?receive_proof_started.elapsed(), "web authentication handshake: receive client proof");
|
||||||
if Some(proof.get_type()) != mtp_codec::CommunicationType::ChallengeResponse.try_to_id(&tm)
|
if Some(proof.get_type()) != mtp_codec::CommunicationType::ChallengeResponse.try_to_id(&tm)
|
||||||
{
|
{
|
||||||
|
|
@ -410,7 +425,7 @@ async fn accept_web_connection_inner(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let nonce = match proof.get_data(DataType::ClientNonce) {
|
let nonce = match proof.get_data(DataType::ClientNonce) {
|
||||||
DataValue::UnsignedNumber(n) => *n,
|
DataValue::UnsignedNumber(n) => n.to_owned(),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(AcceptError::AuthenticationFailed(
|
return Err(AcceptError::AuthenticationFailed(
|
||||||
"missing client nonce".into(),
|
"missing client nonce".into(),
|
||||||
|
|
@ -444,7 +459,7 @@ async fn accept_web_connection_inner(
|
||||||
auth::login_proof_payload(&version.to_string(), client_id, server_challenge, nonce)
|
auth::login_proof_payload(&version.to_string(), client_id, server_challenge, nonce)
|
||||||
};
|
};
|
||||||
let verify_proof_started = Instant::now();
|
let verify_proof_started = Instant::now();
|
||||||
if verify_ed25519(&client_bundle.sig_cl_public_key, &payload, signature).is_err() {
|
if verify_ed25519(&client_bundle.sig_cl_public_key, &payload, &signature).is_err() {
|
||||||
return Err(AcceptError::AuthenticationFailed(
|
return Err(AcceptError::AuthenticationFailed(
|
||||||
"client proof signature invalid".into(),
|
"client proof signature invalid".into(),
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
"wasm/.cargo/",
|
"wasm/.cargo/",
|
||||||
"wasm/Cargo.toml",
|
"wasm/Cargo.toml",
|
||||||
"wasm/src/",
|
"wasm/src/",
|
||||||
|
"wasm/pkg/",
|
||||||
"tsconfig.json"
|
"tsconfig.json"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue