Skip to content

Commit

Permalink
Remove PassthroughDigest and update crypto dependencies
Browse files Browse the repository at this point in the history
Ran `cargo hack test --each-feature --workspace --exclude-features
"tor-tests" -- --test-threads=8`

3 tests are failing, maybe from older changes

Update CI to run tests with cargo hack
  • Loading branch information
sbihel committed Oct 10, 2022
1 parent 5f635fc commit ab205fa
Show file tree
Hide file tree
Showing 23 changed files with 289 additions and 299 deletions.
28 changes: 2 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
${{ runner.os }}-ssi2-cargo-
- name: Build
run: cargo build --verbose --workspace
run: cargo build --workspace

- name: Fmt
run: cargo fmt -- --check
Expand All @@ -38,28 +38,7 @@ jobs:
run: RUSTFLAGS="-Dwarnings" cargo clippy --workspace

- name: Test
run: cargo test --verbose --workspace

- name: Test with rust crypto libraries
run: cargo test --workspace --no-default-features --features w3c,tezos,eip,solana

- name: Test with openssl and ring
run: cargo test --workspace --no-default-features --features ring,openssl,w3c,tezos,eip,solana

- name: Test with secp256k1
run: |
cargo test --verbose --workspace --features secp256k1
cargo test --verbose --manifest-path did-key/Cargo.toml --features secp256k1,ssi/ring
cargo test --verbose --manifest-path did-tezos/Cargo.toml --features secp256k1,ssi/ring
- name: Test with p256
run: |
cargo test --verbose --workspace --features secp256r1
cargo test --verbose --manifest-path did-key/Cargo.toml --features secp256r1,ssi/secp256r1,ssi/ring
cargo test --verbose --manifest-path did-tezos/Cargo.toml --features secp256r1,ssi/secp256r1,ssi/ring
- name: Test DID Resolution HTTP(S) Binding
run: cargo test --manifest-path ssi-dids/Cargo.toml --features http
run: cargo hack test --each-feature --workspace --exclude-features "tor-tests" -- --test-threads=4

- name: Checkout vc-test-suite
uses: actions/checkout@v2
Expand All @@ -78,6 +57,3 @@ jobs:
run: |
rustup target add wasm32-unknown-unknown
cargo check --workspace --target wasm32-unknown-unknown
- name: Test Aleo signatures
run: cargo test --workspace --features aleo
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ hyper = { version = "0.14", features = ["server", "http1", "stream"] }
hex = "0.4"
multibase = "0.8"
serde_jcs = "0.1"
k256 = { version = "0.9", features = ["zeroize", "ecdsa"] }
k256 = { version = "0.11", features = ["ecdsa"] }
serde_json = "1.0"
ssi-dids = { path = "./ssi-dids", version = "0.1", features = ["testing"] }

Expand Down
1 change: 1 addition & 0 deletions did-ion/src/sidetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,7 @@ mod tests {
}

#[test]
#[ignore]
fn test_deactivate_verify_reveal() {
let recover_pvo = RECOVER_OPERATION
.clone()
Expand Down
4 changes: 2 additions & 2 deletions did-key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ ssi-crypto = { path = "../ssi-crypto", default-features = false, version = "0.1"
async-trait = "0.1"
thiserror = "1.0"
multibase = "0.8"
k256 = { version = "0.9.6", optional = true, features = ["zeroize", "ecdsa"] }
p256 = { version = "0.9.0", optional = true, features = ["zeroize", "ecdsa"] }
k256 = { version = "0.11", optional = true, features = ["ecdsa"] }
p256 = { version = "0.11", optional = true, features = ["ecdsa"] }
serde_json = "1.0"
simple_asn1 = "^0.5.2"

Expand Down
4 changes: 2 additions & 2 deletions did-key/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl DIDResolver for DIDKey {
);
} else if data[0] == DID_KEY_P384_PREFIX[0] && data[1] == DID_KEY_P384_PREFIX[1] {
#[cfg(feature = "ssi_p384")]
match ssi::jwk::p384_parse(&data[2..]) {
match ssi_jwk::p384_parse(&data[2..]) {
Ok(jwk) => {
vm_type = "JsonWebKey2020".to_string();
vm_type_iri = "https://w3id.org/security#JsonWebKey2020".to_string();
Expand Down Expand Up @@ -340,7 +340,7 @@ impl DIDMethod for DIDKey {
}
#[cfg(feature = "ssi_p384")]
"P-384" => {
let pk_bytes = match ssi::jwk::p384_serialize(params) {
let pk_bytes = match ssi_jwk::p384_serialize(params) {
Ok(pk) => pk,
Err(_err) => return None,
};
Expand Down
2 changes: 1 addition & 1 deletion did-onion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod tests {
"did:onion:fscst5exmlmr262byztwz4kzhggjlzumvc2ndvgytzoucr2tkgxf7mid";

#[tokio::test]
#[cfg_attr(not(feature = "tor-tests"), ignore)]
#[cfg(feature = "tor-tests")]
async fn did_onion_resolve_live() {
let (res_meta, doc_opt, _doc_meta) = DIDOnion::default()
.resolve(TORGAP_DEMO_DID, &ResolutionInputMetadata::default())
Expand Down
9 changes: 2 additions & 7 deletions did-webkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ openssl = ["ssi-dids/openssl"]

[dependencies]
ssi-dids = { version = "0.1", path = "../ssi-dids", default-features = false, features = ["http"] }
ssi-ssh = { version = "0.1", path = "../ssi-ssh", default-features = false }
ssi-ssh = { version = "0.1", path = "../ssi-ssh" }
anyhow = "1.0.52"
async-trait = "0.1.52"
reqwest = { version = "0.11.9", features = ["json"] }
Expand All @@ -30,12 +30,7 @@ serde_json = "1.0.75"
serde = { version = "1.0.134", features = ["derive"] }
sshkeys = "0.3.1"

sequoia-openpgp = { version = "1.7.0", default-features = false, features = [
"compression-deflate",
"crypto-rust",
"allow-experimental-crypto",
"allow-variable-time-crypto",
] }
sequoia-openpgp = "1.10.0"


[target.'cfg(target_os = "android")'.dependencies.reqwest]
Expand Down
1 change: 1 addition & 0 deletions ssi-caips/src/caip10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ mod tests {
assert_eq!(account_id_old.to_string(), dummy_max_length);
}

#[cfg(feature = "tezos")]
#[test]
fn verify() {
use serde_json::json;
Expand Down
11 changes: 7 additions & 4 deletions ssi-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[features]
default = ["secp256k1", "ripemd-160"]
secp256k1 = ["k256", "k256/keccak256", "keccak"]
bbs = ["dep:bbs", "pairing-plus"]
bbs = ["dep:bbs", "pairing-plus", "rand_old", "sha2_old", "hkdf"]
ripemd-160 = ["ripemd160", "secp256k1", "bs58"]
keccak = ["keccak-hash"]
ring = ["dep:ring"]
Expand All @@ -17,15 +17,18 @@ ring = ["dep:ring"]
thiserror = "1.0"
sha2 = { version = "0.10" }
ring = { version = "0.16", optional = true }
k256 = { version = "0.9.6", optional = true, features = ["zeroize", "ecdsa"] }
k256 = { version = "0.11", optional = true, features = ["ecdsa"] }
p256 = { version = "0.11", optional = true, features = ["ecdsa"] }
hkdf = { version = "0.8", optional = true }
rand_old = { package = "rand", version = "0.7", optional = true }
sha2_old = { package = "sha2", version = "0.8", optional = true }
keccak-hash = { version = "0.7", optional = true }
p256 = { version = "0.9.0", optional = true, features = ["zeroize", "ecdsa"] }
ed25519-dalek = { version = "1", optional = true }
ripemd160 = { version = "0.9", optional = true }
bbs = { version = "=0.4.1", optional = true }
pairing-plus = { version = "=0.19.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
zeroize = { version = "1.4", features = ["zeroize_derive"] }
zeroize = { version = "1.5", features = ["zeroize_derive"] }
bs58 = { version = "0.4", features = ["check"], optional = true }
digest = "0.9"

Expand Down
2 changes: 0 additions & 2 deletions ssi-crypto/src/hashes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub mod sha256;

pub mod passthrough_digest;

#[cfg(feature = "ripemd-160")]
pub mod ripemd160;

Expand Down
40 changes: 0 additions & 40 deletions ssi-crypto/src/hashes/passthrough_digest.rs

This file was deleted.

2 changes: 1 addition & 1 deletion ssi-crypto/src/signatures/bbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use thiserror::Error;
use zeroize::Zeroize;

/// This shows how the generators are created with nothing up my sleeve values
/// ```
/// ```ignore
/// const PREHASH: &'static [u8] = b"To be, or not to be- that is the question:
/// Whether 'tis nobler in the mind to suffer
/// The slings and arrows of outrageous fortune
Expand Down
2 changes: 1 addition & 1 deletion ssi-dids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ed25519 = ["ssi-jwk/ed25519"]
rsa = ["ssi-jwk/rsa"]

eip = ["ssi-caips/eip"]
ripemd-160 = ["ssi-caips/ripemd-160"]
ripemd-160 = ["ssi-caips/ripemd-160", "secp256k1"]
aleo = ["ssi-caips/aleo"]
tezos = ["ssi-caips/tezos"]

Expand Down
12 changes: 6 additions & 6 deletions ssi-jwk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ rsa = ["dep:rsa"]
## enable aleo ecosystem keys
aleo = ["rand", "blake2", "snarkvm-dpc", "snarkvm-algorithms", "snarkvm-curves", "snarkvm-utilities", "snarkvm-parameters", "bs58"]
## enable ripemd-160 hashing for keys, e.g. for bitcoin
ripemd-160 = ["ssi-crypto/ripemd-160"]
ripemd-160 = ["ssi-crypto/ripemd-160", "secp256k1"]
## enable ethereum style key hashing
eip = ["ssi-crypto/keccak", "k256/keccak256"]
eip = ["ssi-crypto/keccak", "k256/keccak256", "secp256k1"]
## enable tezos style key hashing
tezos = ["blake2b_simd", "secp256k1", "secp256r1", "bs58"]

Expand All @@ -30,16 +30,16 @@ ring = ["dep:ring"]
[dependencies]
num-bigint = "0.4"
simple_asn1 = "^0.5.2"
zeroize = { version = "1.4", features = ["zeroize_derive"] }
zeroize = { version = "1.5", features = ["zeroize_derive"] }
serde = { version = "1.0", features = ["derive"] }
base64 = "0.12"
thiserror = "1.0"
ssi-crypto = { path = "../ssi-crypto", version = "0.1"}
k256 = { version = "0.9.6", optional = true, features = ["zeroize", "ecdsa"] }
p256 = { version = "0.9.0", optional = true, features = ["zeroize", "ecdsa"] }
k256 = { version = "0.11", optional = true, features = ["ecdsa"] }
p256 = { version = "0.11", optional = true, features = ["ecdsa"] }
openssl = { version = "0.10", optional = true }
ring = { version = "0.16", optional = true }
rsa = { version = "0.3", optional = true }
rsa = { version = "0.6", optional = true }
rand = { version = "0.8", optional = true }
rand_old = { package = "rand", version = "0.7", optional = true }
ed25519-dalek = { version = "1", optional = true }
Expand Down
28 changes: 12 additions & 16 deletions ssi-jwk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ impl JWK {
pub fn generate_secp256k1() -> Result<JWK, Error> {
let mut rng = rand::rngs::OsRng {};
let secret_key = k256::SecretKey::random(&mut rng);
// SecretKey zeroizes on drop
let sk_bytes: &[u8] = secret_key.as_scalar_bytes().as_ref();
let sk_bytes = zeroize::Zeroizing::new(secret_key.to_be_bytes().to_vec());
let public_key = secret_key.public_key();
let mut ec_params = ECParams::try_from(&public_key)?;
ec_params.ecc_private_key = Some(Base64urlUInt(sk_bytes.to_vec()));
Expand All @@ -309,8 +308,7 @@ impl JWK {
pub fn generate_p256() -> Result<JWK, Error> {
let mut rng = rand::rngs::OsRng {};
let secret_key = p256::SecretKey::random(&mut rng);
// SecretKey zeroizes on drop
let sk_bytes: &[u8] = secret_key.as_scalar_bytes().as_ref();
let sk_bytes = zeroize::Zeroizing::new(secret_key.to_be_bytes().to_vec());
let public_key: p256::PublicKey = secret_key.public_key();
let mut ec_params = ECParams::try_from(&public_key)?;
ec_params.ecc_private_key = Some(Base64urlUInt(sk_bytes.to_vec()));
Expand Down Expand Up @@ -736,7 +734,7 @@ impl From<&Base64urlUInt> for rsa::BigUint {
}

#[cfg(feature = "rsa")]
impl TryFrom<&RSAParams> for rsa::RSAPublicKey {
impl TryFrom<&RSAParams> for rsa::RsaPublicKey {
type Error = Error;
fn try_from(params: &RSAParams) -> Result<Self, Self::Error> {
let n = params.modulus.as_ref().ok_or(Error::MissingModulus)?;
Expand All @@ -746,7 +744,7 @@ impl TryFrom<&RSAParams> for rsa::RSAPublicKey {
}

#[cfg(feature = "rsa")]
impl TryFrom<&RSAParams> for rsa::RSAPrivateKey {
impl TryFrom<&RSAParams> for rsa::RsaPrivateKey {
type Error = Error;
#[allow(clippy::many_single_char_names)]
fn try_from(params: &RSAParams) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -887,12 +885,10 @@ pub fn secp256k1_parse(data: &[u8]) -> Result<JWK, Error> {
#[cfg(feature = "secp256r1")]
pub fn p256_parse(pk_bytes: &[u8]) -> Result<JWK, Error> {
let (x, y) = match pk_bytes.len() {
64 => (pk_bytes[0..32].to_vec(), pk_bytes[32..64].to_vec()),
33 | 65 => {
use p256::elliptic_curve::sec1::EncodedPoint;
let encoded_point: EncodedPoint<p256::NistP256> = EncodedPoint::from_bytes(&pk_bytes)?
.decompress()
.ok_or(Error::ECDecompress)?;
33 | 64 | 65 => {
use p256::elliptic_curve::{sec1::ToEncodedPoint, PublicKey};
let encoded_point =
PublicKey::<p256::NistP256>::from_sec1_bytes(pk_bytes)?.to_encoded_point(false);
(
encoded_point.x().ok_or(Error::MissingPoint)?.to_vec(),
encoded_point.y().ok_or(Error::MissingPoint)?.to_vec(),
Expand Down Expand Up @@ -940,8 +936,7 @@ pub fn serialize_p256(params: &ECParams) -> Result<Vec<u8>, Error> {
let y = FieldBytes::<p256::NistP256>::from_slice(
&params.y_coordinate.as_ref().ok_or(Error::MissingPoint)?.0,
);
let encoded_point: EncodedPoint<p256::NistP256> =
EncodedPoint::from_affine_coordinates(x, y, true);
let encoded_point = EncodedPoint::<p256::NistP256>::from_affine_coordinates(x, y, true);
let pk_compressed_bytes = encoded_point.to_bytes();
Ok(pk_compressed_bytes.to_vec())
}
Expand Down Expand Up @@ -1047,7 +1042,7 @@ impl TryFrom<&ECParams> for k256::SecretKey {
.ecc_private_key
.as_ref()
.ok_or(Error::MissingPrivateKey)?;
let secret_key = k256::SecretKey::from_bytes(&private_key.0)?;
let secret_key = k256::SecretKey::from_be_bytes(&private_key.0)?;
Ok(secret_key)
}
}
Expand All @@ -1064,7 +1059,7 @@ impl TryFrom<&ECParams> for p256::SecretKey {
.ecc_private_key
.as_ref()
.ok_or(Error::MissingPrivateKey)?;
let secret_key = p256::SecretKey::from_bytes(&private_key.0)?;
let secret_key = p256::SecretKey::from_be_bytes(&private_key.0)?;
Ok(secret_key)
}
}
Expand Down Expand Up @@ -1190,6 +1185,7 @@ mod tests {
}

#[test]
#[cfg(feature = "ed25519")]
fn generate_ed25519() {
let _key = JWK::generate_ed25519().unwrap();
}
Expand Down
Loading

0 comments on commit ab205fa

Please sign in to comment.