Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ jobs:

- name: Run tests (--no-default-features --features ring,getrandom)
run: cargo test --no-default-features --features ring,getrandom

- name: Run tests (--no-default-features --features graviola,getrandom)
run: cargo test --no-default-features --features graviola,getrandom
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ rust:test:
- cargo test
- cargo test --features websocket,portable-atomic
- cargo test --no-default-features --features ring,getrandom
- cargo test --no-default-features --features graviola,getrandom
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions watermelon-mini/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ features = ["websocket", "non-standard-zstd"]
[dependencies]
tokio = { version = "1.36", features = ["net"] }
tokio-rustls = { version = "0.26", default-features = false }
rustls-graviola = { version = "0.3.4", default-features = false, optional = true }
rustls-platform-verifier = "0.6"

watermelon-net = { version = "0.2", path = "../watermelon-net", default-features = false }
Expand All @@ -32,6 +33,7 @@ websocket = ["watermelon-net/websocket"]
aws-lc-rs = ["tokio-rustls/aws-lc-rs", "watermelon-net/aws-lc-rs", "watermelon-nkeys/aws-lc-rs"]
ring = ["tokio-rustls/ring", "watermelon-net/ring", "watermelon-nkeys/ring"]
fips = ["tokio-rustls/fips", "watermelon-net/fips", "watermelon-nkeys/fips"]
graviola = ["dep:rustls-graviola", "watermelon-net/graviola", "watermelon-nkeys/graviola"]
rand = ["watermelon-net/rand"]
getrandom = ["watermelon-net/getrandom"]
non-standard-zstd = ["watermelon-net/non-standard-zstd", "watermelon-proto/non-standard-zstd", "dep:async-compression", "async-compression/zstd"]
Expand Down
16 changes: 11 additions & 5 deletions watermelon-mini/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustls_platform_verifier::Verifier;
use tokio::net::TcpStream;
use tokio_rustls::{
TlsConnector,
rustls::{self, ClientConfig, crypto::CryptoProvider, version::TLS13},
rustls::{ClientConfig, crypto::CryptoProvider, version::TLS13},
};
use watermelon_net::Connection;
use watermelon_proto::{ServerAddr, ServerInfo};
Expand Down Expand Up @@ -87,9 +87,15 @@ pub async fn easy_connect(

fn crypto_provider() -> CryptoProvider {
#[cfg(feature = "aws-lc-rs")]
return rustls::crypto::aws_lc_rs::default_provider();
return tokio_rustls::rustls::crypto::aws_lc_rs::default_provider();
#[cfg(all(not(feature = "aws-lc-rs"), feature = "ring"))]
return rustls::crypto::ring::default_provider();
#[cfg(not(any(feature = "aws-lc-rs", feature = "ring")))]
compile_error!("Please enable the `aws-lc-rs` or the `ring` feature")
return tokio_rustls::rustls::crypto::ring::default_provider();
#[cfg(all(
not(feature = "aws-lc-rs"),
not(feature = "ring"),
feature = "graviola"
))]
return rustls_graviola::default_provider();
#[cfg(not(any(feature = "aws-lc-rs", feature = "ring", feature = "graviola")))]
compile_error!("Please enable the `aws-lc-rs`, the `ring` or the `graviola` feature")
}
1 change: 1 addition & 0 deletions watermelon-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ websocket = ["dep:tokio-websockets", "dep:futures-sink", "dep:http"]
ring = ["tokio-websockets?/ring"]
aws-lc-rs = ["tokio-websockets?/aws_lc_rs"]
fips = []
graviola = ["tokio-websockets?/sha1_smol"]
rand = ["tokio-websockets?/rand"]
getrandom = ["tokio-websockets?/getrandom"]
non-standard-zstd = ["watermelon-proto/non-standard-zstd"]
Expand Down
2 changes: 2 additions & 0 deletions watermelon-nkeys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rust-version.workspace = true
[dependencies]
aws-lc-rs = { version = "1.12.2", default-features = false, features = ["aws-lc-sys", "prebuilt-nasm"], optional = true }
ring = { version = "0.17", optional = true }
graviola = { version = "0.3.4", optional = true }
crc = "3.2.1"
thiserror = "2"
data-encoding = { version = "2.7.0", default-features = false }
Expand All @@ -23,6 +24,7 @@ claims = "0.8"
default = ["aws-lc-rs"]
aws-lc-rs = ["dep:aws-lc-rs"]
ring = ["dep:ring"]
graviola = ["dep:graviola"]
fips = ["aws-lc-rs", "aws-lc-rs/fips"]

[lints]
Expand Down
26 changes: 23 additions & 3 deletions watermelon-nkeys/src/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ use std::fmt::{self, Debug, Display};
#[cfg(feature = "aws-lc-rs")]
use aws_lc_rs::signature::{Ed25519KeyPair, KeyPair as _, Signature as LlSignature};
use data_encoding::{BASE32_NOPAD, BASE64URL_NOPAD};
#[cfg(all(
not(feature = "aws-lc-rs"),
not(feature = "ring"),
feature = "graviola"
))]
use graviola::signing::eddsa::Ed25519SigningKey as Ed25519KeyPair;
#[cfg(all(not(feature = "aws-lc-rs"), feature = "ring"))]
use ring::signature::{Ed25519KeyPair, KeyPair as _, Signature as LlSignature};

#[cfg(not(any(feature = "aws-lc-rs", feature = "ring")))]
compile_error!("Please enable the `aws-lc-rs` or the `ring` feature");
#[cfg(not(any(feature = "aws-lc-rs", feature = "ring", feature = "graviola")))]
compile_error!("Please enable the `aws-lc-rs`, the `ring` or the `graviola` feature");

use crate::crc::Crc16;

#[cfg(all(
not(feature = "aws-lc-rs"),
not(feature = "ring"),
feature = "graviola"
))]
type LlSignature = [u8; 64];

const SEED_PREFIX_BYTE: u8 = 18 << 3;

/// A `NKey` private/public key pair.
Expand Down Expand Up @@ -91,8 +104,11 @@ impl KeyPair {

let kind = raw_seed[1];

#[cfg(any(feature = "aws-lc-rs", feature = "ring"))]
let key = Ed25519KeyPair::from_seed_unchecked(&raw_seed[2..])
.map_err(|_| KeyPairFromSeedError::DecodeError)?;
#[cfg(not(any(feature = "aws-lc-rs", feature = "ring")))]
let key = Ed25519KeyPair::from_bytes(raw_seed[2..].try_into().unwrap()).unwrap();
Ok(Self { kind, key })
}

Expand Down Expand Up @@ -126,7 +142,11 @@ impl Display for PublicKey<'_> {
let mut full_raw_seed = [0; 36];
full_raw_seed[0] = SEED_PREFIX_BYTE;
full_raw_seed[1] = self.0.kind;
full_raw_seed[2..34].copy_from_slice(self.0.key.public_key().as_ref());
#[cfg(any(feature = "aws-lc-rs", feature = "ring"))]
let public_key_bytes = self.0.key.public_key().as_ref();
#[cfg(not(any(feature = "aws-lc-rs", feature = "ring")))]
let public_key_bytes = &self.0.key.public_key().as_bytes();
full_raw_seed[2..34].copy_from_slice(public_key_bytes);
let crc = Crc16::compute(&full_raw_seed[..34]);
full_raw_seed[34..36].copy_from_slice(&crc.to_raw_encoded());
Display::fmt(&BASE32_NOPAD.encode_display(&full_raw_seed), f)
Expand Down
1 change: 1 addition & 0 deletions watermelon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ websocket = ["watermelon-mini/websocket"]
aws-lc-rs = ["watermelon-mini/aws-lc-rs", "watermelon-nkeys/aws-lc-rs"]
ring = ["watermelon-mini/ring", "watermelon-nkeys/ring"]
fips = ["watermelon-mini/fips", "watermelon-nkeys/fips"]
graviola = ["watermelon-mini/graviola", "watermelon-nkeys/graviola"]
from-env = ["dep:envy"]
rand = ["dep:rand", "watermelon-mini/rand", "watermelon-net/rand"]
getrandom = ["dep:getrandom", "watermelon-mini/getrandom", "watermelon-net/getrandom"]
Expand Down