Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stronghold Storage Implementation #1157

Merged
merged 31 commits into from
Aug 15, 2023
Merged

Stronghold Storage Implementation #1157

merged 31 commits into from
Aug 15, 2023

Conversation

abdulmth
Copy link
Contributor

@abdulmth abdulmth commented Apr 14, 2023

Description of change

Stronghold storage implementation.

Still to do:

  • Implement KeyIdStorage
  • Feature gate stronghold.

Links to any relevant issues

Be sure to reference any related issues by adding fixes issue #.

Type of change

  • Bug fix (a non-breaking change which fixes an issue)
  • Enhancement (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Fix

@abdulmth abdulmth added Added A new feature that requires a minor release. Part of "Added" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. labels Apr 14, 2023
@abdulmth abdulmth self-assigned this Apr 14, 2023
@abdulmth abdulmth changed the title Stronghold Implementation for JwkStorage Stronghold Storage Implementation Apr 14, 2023
@abdulmth abdulmth force-pushed the feat/rust-stronghold branch from 0d3feef to a5258e5 Compare April 17, 2023 09:31
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
We have to expose a constant key type for users to use and please annotate types in the storage implementations.

identity_storage/Cargo.toml Outdated Show resolved Hide resolved
identity_storage/Cargo.toml Outdated Show resolved Hide resolved
identity_storage/src/key_id_storage/stronghold.rs Outdated Show resolved Hide resolved
identity_storage/src/key_id_storage/stronghold.rs Outdated Show resolved Hide resolved
identity_storage/src/key_id_storage/stronghold.rs Outdated Show resolved Hide resolved
identity_storage/src/key_storage/stronghold.rs Outdated Show resolved Hide resolved
identity_storage/src/key_storage/stronghold.rs Outdated Show resolved Hide resolved
identity_storage/src/key_storage/stronghold.rs Outdated Show resolved Hide resolved
identity_storage/src/key_storage/stronghold.rs Outdated Show resolved Hide resolved
identity_storage/src/utils/fs.rs Outdated Show resolved Hide resolved
abdulmth and others added 2 commits May 2, 2023 12:37
Co-authored-by: Philipp Gackstatter <philipp.gackstatter@iota.org>
Base automatically changed from feat/jwk-storage-document-ext-2 to main May 12, 2023 09:39
Abdulrahim Al Methiab and others added 10 commits May 30, 2023 21:51
# Conflicts:
#	bindings/wasm/docs/api-reference.md
#	bindings/wasm/src/credential/jwt_credential_validation/jwt_credential_validator.rs
#	bindings/wasm/src/credential/jwt_credential_validation/mod.rs
#	bindings/wasm/src/credential/jwt_credential_validation/options.rs
#	bindings/wasm/src/credential/mod.rs
#	bindings/wasm/src/did/jws_verification_options.rs
#	bindings/wasm/src/did/wasm_core_document.rs
#	bindings/wasm/src/error.rs
#	bindings/wasm/src/iota/iota_document.rs
#	bindings/wasm/src/jose/jws_header.rs
#	bindings/wasm/src/jose/mod.rs
#	bindings/wasm/src/storage/jwk_storage.rs
#	bindings/wasm/src/storage/signature_options.rs
#	bindings/wasm/src/verification/custom_verification.rs
#	bindings/wasm/tests/jwk_storage.ts
#	bindings/wasm/tests/storage.ts
#	identity_core/src/error.rs
#	identity_credential/src/credential/credential.rs
#	identity_credential/src/credential/jwt_serialization.rs
#	identity_credential/src/credential/mod.rs
#	identity_credential/src/validator/vc_jwt_validation/credential_jwt_validator.rs
#	identity_credential/src/validator/vc_jwt_validation/mod.rs
#	identity_document/src/document/core_document.rs
#	identity_document/src/error.rs
#	identity_document/src/verifiable/jws_verification_options.rs
#	identity_iota/Cargo.toml
#	identity_iota_core/src/document/iota_document.rs
#	identity_iota_core/src/error.rs
#	identity_jose/examples/jws_encoding_decoding.rs
#	identity_jose/src/jws/custom_verification/jws_verifier.rs
#	identity_jose/src/jws/decoder.rs
#	identity_jose/src/jws/encoding/mod.rs
#	identity_jose/src/jws/encoding/utils.rs
#	identity_jose/src/tests/rfc7515.rs
#	identity_jose/src/tests/rfc8037.rs
#	identity_jose/src/tests/roundtrip.rs
#	identity_storage/Cargo.toml
#	identity_storage/src/key_id_storage/method_digest.rs
#	identity_storage/src/key_storage/memstore.rs
#	identity_storage/src/lib.rs
#	identity_storage/src/storage/error.rs
#	identity_storage/src/storage/mod.rs
#	identity_storage/src/storage/signature_options.rs
#	identity_storage/src/storage/tests/api.rs
#	identity_storage/src/storage/tests/credential_validation.rs
#	identity_storage/src/storage/tests/mod.rs
#	identity_verification/Cargo.toml
#	identity_verification/src/verification_method/method.rs
#	libjose/src/jwk/key_params.rs
#	libjose/tests/jwe.rs
#	libjose/tests/jws.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Stronghold should be its own example. We already use stronghold for the client in every example and we should encourage using it in identity too by showing stronghold for identity usage in every example. That's how we always did it in the past and I think that was good.

@@ -21,12 +21,15 @@ identity_document = { version = "=0.7.0-alpha.6", path = "../identity_document",
identity_iota_core = { version = "=0.7.0-alpha.6", path = "../identity_iota_core", default-features = false, optional = true }
identity_verification = { version = "=0.7.0-alpha.6", path = "../identity_verification", default_features = false }
iota-crypto = { version = "0.23", default-features = false, features = ["blake2b", "ed25519", "random"], optional = true }
iota-sdk = { version = "1.0", default-features = false, features = ["tls", "client", "stronghold"], optional = true }
iota_stronghold = { version = "2.0", optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please follow our codebase convention and use default-features = false and activate what we need.

pub(crate) static IDENTITY_CLIENT_PATH: &[u8] = b"iota_identity_client";

/// The Ed25519 key type.
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is correctly exported, the lint should not be necessary, right? Why is this here again?

Comment on lines 52 to 53
let keytype: ProceduresKeyType = match key_type.to_string().to_lowercase().as_str() {
"ed25519" => Ok(ProceduresKeyType::Ed25519),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the StrongholdKeyType enum to make this case easy to handle. Not sure why we need to lowercase convert anything here and cause another allocation.

Suggested change
let keytype: ProceduresKeyType = match key_type.to_string().to_lowercase().as_str() {
"ed25519" => Ok(ProceduresKeyType::Ed25519),
let keytype: ProceduresKeyType = match key_type {
StrongholdKeyType::Ed25519 => Ok(ProceduresKeyType::Ed25519),

.write_secret(location, zeroize::Zeroizing::from(secret_key.to_bytes().to_vec()))
.map_err(|err| {
KeyStorageError::new(KeyStorageErrorKind::Unspecified)
.with_custom_message("stronghold client error")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.with_custom_message("stronghold client error")
.with_custom_message("stronghold write secret failed")

}

/// Shared reference to the inner [`SecretManager`].
pub fn inner(&self) -> Arc<SecretManager> {
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn inner(&self) -> Arc<SecretManager> {
pub fn as_secret_manager(&self) -> Arc<SecretManager> {

Follow rust convention with as_ and be more specific about what this fn does.

Actually, does this need to return Arc<SecretManager>? Wouldn't &SecretManager be sufficient?

}

///Acquire lock of the inner [`Stronghold`].
pub async fn get_stronghold(&self) -> MutexGuard<'_, Stronghold> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub async fn get_stronghold(&self) -> MutexGuard<'_, Stronghold> {
pub(crate) async fn get_stronghold(&self) -> MutexGuard<'_, Stronghold> {

This can be pub(crate) if I'm not mistaken.

self.0.clone()
}

///Acquire lock of the inner [`Stronghold`].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///Acquire lock of the inner [`Stronghold`].
/// Acquire lock of the inner [`Stronghold`].

use tokio::sync::MutexGuard;

/// Wrapper around `SecretManager` that implements the storage interfaces.
#[derive(Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we derive Debug as well?

use std::sync::Arc;
use tokio::sync::MutexGuard;

/// Wrapper around `SecretManager` that implements the storage interfaces.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Wrapper around `SecretManager` that implements the storage interfaces.
/// Wrapper around a `StrongholdSecretManager` that implements the [`KeyIdStorage`](todo:link) and [`JwkStorage`](todo:link) interfaces.

Yes, technically it wraps a SecretManager, but conceptually it's a StrongholdSecretManager and that is what matters to the user.

@abdulmth
Copy link
Contributor Author

Maybe we can change the examples in a separate PR.

identity_storage/Cargo.toml Outdated Show resolved Hide resolved
identity_storage/src/lib.rs Outdated Show resolved Hide resolved
identity_storage/src/stronghold_storage.rs Outdated Show resolved Hide resolved
identity_storage/src/stronghold_storage.rs Outdated Show resolved Hide resolved
@abdulmth abdulmth merged commit 2f5faa8 into main Aug 15, 2023
@abdulmth abdulmth deleted the feat/rust-stronghold branch August 15, 2023 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Added A new feature that requires a minor release. Part of "Added" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants