From 96d24a1706c8af1755b8cd6f383e7916a03a43f8 Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 18 Jan 2022 12:00:06 -0800 Subject: [PATCH 1/3] accept EC key type for BLS key Signed-off-by: Andrew Whitehead --- askar-crypto/Cargo.toml | 2 +- askar-crypto/src/alg/any.rs | 12 ++++++++---- askar-crypto/src/alg/bls.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/askar-crypto/Cargo.toml b/askar-crypto/Cargo.toml index ad1032a9..7f7cb7f7 100644 --- a/askar-crypto/Cargo.toml +++ b/askar-crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "askar-crypto" -version = "0.2.3" +version = "0.2.4" authors = ["Hyperledger Aries Contributors "] edition = "2018" description = "Hyperledger Aries Askar cryptography" diff --git a/askar-crypto/src/alg/any.rs b/askar-crypto/src/alg/any.rs index 18696fce..1f5dfbf9 100644 --- a/askar-crypto/src/alg/any.rs +++ b/askar-crypto/src/alg/any.rs @@ -74,7 +74,7 @@ impl AnyKey { } #[inline] - fn key_type_id(&self) -> TypeId { + pub fn key_type_id(&self) -> TypeId { self.0.as_any().type_id() } } @@ -524,11 +524,15 @@ fn from_jwk_any(jwk: JwkParts<'_>) -> Result { X25519KeyPair::from_jwk_parts(jwk).map(R::alloc_key) } #[cfg(feature = "bls")] - ("OKP", c) if c == G1::JWK_CURVE => BlsKeyPair::::from_jwk_parts(jwk).map(R::alloc_key), + ("OKP" | "EC", c) if c == G1::JWK_CURVE => { + BlsKeyPair::::from_jwk_parts(jwk).map(R::alloc_key) + } #[cfg(feature = "bls")] - ("OKP", c) if c == G2::JWK_CURVE => BlsKeyPair::::from_jwk_parts(jwk).map(R::alloc_key), + ("OKP" | "EC", c) if c == G2::JWK_CURVE => { + BlsKeyPair::::from_jwk_parts(jwk).map(R::alloc_key) + } #[cfg(feature = "bls")] - ("OKP", c) if c == G1G2::JWK_CURVE => { + ("OKP" | "EC", c) if c == G1G2::JWK_CURVE => { BlsKeyPair::::from_jwk_parts(jwk).map(R::alloc_key) } #[cfg(feature = "k256")] diff --git a/askar-crypto/src/alg/bls.rs b/askar-crypto/src/alg/bls.rs index 8f5ea39d..df785859 100644 --- a/askar-crypto/src/alg/bls.rs +++ b/askar-crypto/src/alg/bls.rs @@ -175,7 +175,10 @@ impl ToJwk for BlsKeyPair { impl FromJwk for BlsKeyPair { fn from_jwk_parts(jwk: JwkParts<'_>) -> Result { - if jwk.kty != JWK_KEY_TYPE { + if jwk.kty != JWK_KEY_TYPE && + /* compatibility with previous version */ + jwk.kty != "EC" + { return Err(err_msg!(InvalidKeyData, "Unsupported key type")); } if jwk.crv != Pk::JWK_CURVE { @@ -557,4 +560,27 @@ mod tests { // sk_load.to_keypair_bytes().unwrap() // ); } + + #[cfg(feature = "any_key")] + #[test] + // test loading of a key with the EC key type + fn g1_jwk_any_compat() { + use crate::alg::{any::AnyKey, BlsCurves, KeyAlg}; + use alloc::boxed::Box; + + let test_jwk_compat = r#" + { + "crv": "BLS12381_G1", + "kty": "EC", + "x": "osl1NIZnkmrPEvPuywBQROCKept9lfML0oG1VEUQc2ei5dBVi-eUPIvRP5oacDb7" + }"#; + let key = Box::::from_jwk(test_jwk_compat).expect("Error decoding BLS key JWK"); + assert_eq!(key.algorithm(), KeyAlg::Bls12_381(BlsCurves::G1)); + let as_bls = key + .downcast_ref::>() + .expect("Error downcasting BLS key"); + let _ = as_bls + .to_jwk_public(None) + .expect("Error converting key to JWK"); + } } From 3a82011de23724a7282c0854d7cff973a2c12f5e Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 18 Jan 2022 12:03:01 -0800 Subject: [PATCH 2/3] use i64 for error code representation Signed-off-by: Andrew Whitehead --- src/ffi/error.rs | 2 +- wrappers/python/aries_askar/bindings.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ffi/error.rs b/src/ffi/error.rs index c4a8dda9..1ab29e6c 100644 --- a/src/ffi/error.rs +++ b/src/ffi/error.rs @@ -10,7 +10,7 @@ use once_cell::sync::Lazy; static LAST_ERROR: Lazy>> = Lazy::new(|| RwLock::new(None)); #[derive(Debug, PartialEq, Copy, Clone, Serialize)] -#[repr(usize)] +#[repr(i64)] pub enum ErrorCode { Success = 0, Backend = 1, diff --git a/wrappers/python/aries_askar/bindings.py b/wrappers/python/aries_askar/bindings.py index 408f8a03..bc92e0b6 100644 --- a/wrappers/python/aries_askar/bindings.py +++ b/wrappers/python/aries_askar/bindings.py @@ -526,6 +526,7 @@ def _cb(id: int, err: int, result=None): def do_call(fn_name, *args): """Perform a synchronous library function call.""" lib_fn = getattr(get_library(), fn_name) + lib_fn.restype = c_int64 result = lib_fn(*args) if result: raise get_current_error(True) @@ -536,6 +537,7 @@ def do_call_async( ) -> asyncio.Future: """Perform an asynchronous library function call.""" lib_fn = getattr(get_library(), fn_name) + lib_fn.restype = c_int64 loop = asyncio.get_event_loop() fut = loop.create_future() cf_args = [None, c_int64, c_int64] From fcda36c1ccd750621c67c2488a78c9ae8d92d1ff Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 18 Jan 2022 12:03:18 -0800 Subject: [PATCH 3/3] update to env_logger 0.9; update version to 0.2.4 Signed-off-by: Andrew Whitehead --- Cargo.toml | 4 ++-- wrappers/python/aries_askar/version.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 06691488..fbcee068 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["askar-bbs", "askar-crypto"] [package] name = "aries-askar" -version = "0.2.3" +version = "0.2.4" authors = ["Hyperledger Aries Contributors "] edition = "2018" description = "Hyperledger Aries Askar secure storage" @@ -43,7 +43,7 @@ async-stream = "0.3" bs58 = "0.4" chrono = "0.4" digest = "0.10" -env_logger = { version = "0.7", optional = true } +env_logger = { version = "0.9", optional = true } ffi-support = { version = "0.4", optional = true } futures-lite = "1.11" hex = "0.4" diff --git a/wrappers/python/aries_askar/version.py b/wrappers/python/aries_askar/version.py index ab939630..9cc67882 100644 --- a/wrappers/python/aries_askar/version.py +++ b/wrappers/python/aries_askar/version.py @@ -1,3 +1,3 @@ """aries_askar library wrapper version.""" -__version__ = "0.2.3" +__version__ = "0.2.4"