Skip to content

Commit

Permalink
Change Stronghold password to be required
Browse files Browse the repository at this point in the history
  • Loading branch information
cycraig committed Mar 29, 2022
1 parent 5365702 commit 9293237
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 26 deletions.
2 changes: 2 additions & 0 deletions bindings/stronghold-nodejs/.license_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Copyright {20\d{2}(-20\d{2})?} IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
4 changes: 2 additions & 2 deletions bindings/stronghold-nodejs/js/stronghold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export class Stronghold implements Storage {

constructor() {}

public async init(snapshot: string, password?: string, dropsave?: boolean) {
public async init(snapshot: string, password: string, dropsave?: boolean) {
this.napiStronghold = await NapiStronghold.new(snapshot, password, dropsave);
}

public static async build(snapshot: string, password?: string, dropsave?: boolean) {
public static async build(snapshot: string, password: string, dropsave?: boolean) {
const stronghold = new Stronghold();
await stronghold.init(snapshot, password, dropsave)
return stronghold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl NapiStronghold {

/// Creates an instance of `Stronghold`.
#[napi]
pub async fn new(snapshot: String, password: Option<String>, dropsave: Option<bool>) -> Result<NapiStronghold> {
pub async fn new(snapshot: String, password: String, dropsave: Option<bool>) -> Result<NapiStronghold> {
Ok(NapiStronghold(
Stronghold::new(&snapshot, password, dropsave).await.napi_result()?,
))
Expand Down
4 changes: 2 additions & 2 deletions examples/account/create_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async fn main() -> Result<()> {
// Stronghold is an encrypted file that manages private keys.
// It implements best practices for security and is the recommended way of handling private keys.
let stronghold_path: PathBuf = "./example-strong.hodl".into();
let password: String = "my-password".into();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, Some(password), None).await?;
let password: String = "my-password".to_owned();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, password, None).await?;

// Create a new identity using Stronghold as local storage.
//
Expand Down
4 changes: 2 additions & 2 deletions examples/account/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async fn main() -> Result<()> {

// Stronghold settings
let stronghold_path: PathBuf = "./example-strong.hodl".into();
let password: String = "my-password".into();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, Some(password), None).await?;
let password: String = "my-password".to_owned();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, password, None).await?;

// Create a new Account with auto publishing set to false.
// This means updates are not pushed to the tangle automatically.
Expand Down
4 changes: 2 additions & 2 deletions examples/account/manipulate_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ async fn main() -> Result<()> {

// Stronghold settings
let stronghold_path: PathBuf = "./example-strong.hodl".into();
let password: String = "my-password".into();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, Some(password), None).await?;
let password: String = "my-password".to_owned();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, password, None).await?;

// Create a new Account with the default configuration
let mut account: Account = Account::builder()
Expand Down
4 changes: 2 additions & 2 deletions examples/account/multiple_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async fn main() -> Result<()> {
// Stronghold is an encrypted file that manages private keys.
// It implements best practices for security and is the recommended way of handling private keys.
let stronghold_path: PathBuf = "./example-strong.hodl".into();
let password: String = "my-password".into();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, Some(password), None).await?;
let password: String = "my-password".to_owned();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, password, None).await?;

// Create an AccountBuilder to make it easier to create multiple identities.
// Every account created from the builder will use the same storage - stronghold in this case.
Expand Down
4 changes: 2 additions & 2 deletions examples/account/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async fn main() -> Result<()> {

// Stronghold settings
let stronghold_path: PathBuf = "./example-strong.hodl".into();
let password: String = "my-password".into();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, Some(password), None).await?;
let password: String = "my-password".to_owned();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, password, None).await?;

// Create a new Account with stronghold storage.
let mut account: Account = Account::builder()
Expand Down
4 changes: 2 additions & 2 deletions examples/account/unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async fn main() -> Result<()> {
// Stronghold is an encrypted file that manages private keys.
// It implements best practices for security and is the recommended way of handling private keys.
let stronghold_path: PathBuf = "./example-strong.hodl".into();
let password: String = "my-password".into();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, Some(password), None).await?;
let password: String = "my-password".to_owned();
let stronghold: Stronghold = Stronghold::new(&stronghold_path, password, None).await?;

// Create a new identity using Stronghold as local storage.
//
Expand Down
10 changes: 3 additions & 7 deletions identity-account-storage/src/storage/stronghold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@ impl Stronghold {
/// * snapshot: path to a local Stronghold file, will be created if it does not exist.
/// * password: password for the Stronghold file, optional.
/// * dropsave: save all changes when the instance is dropped. Default: true.
pub async fn new<'a, T, U>(snapshot: &T, password: U, dropsave: Option<bool>) -> Result<Self>
pub async fn new<'a, T>(snapshot: &T, mut password: String, dropsave: Option<bool>) -> Result<Self>
where
T: AsRef<Path> + ?Sized,
U: Into<Option<String>>,
{
let snapshot: Snapshot = Snapshot::new(snapshot);

if let Some(mut password) = password.into() {
snapshot.load(derive_encryption_key(&password)).await?;
password.zeroize();
}
snapshot.load(derive_encryption_key(&password)).await?;
password.zeroize();

Ok(Self {
snapshot: Arc::new(snapshot),
Expand Down
5 changes: 1 addition & 4 deletions identity-account/src/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ async fn test_account_builder() -> Result<()> {
crate::Error::IdentityNotFound
));

// Release the lease on did1.
std::mem::drop(account1);

assert!(builder.load_identity(did1).await.is_ok());

Ok(())
Expand Down Expand Up @@ -502,7 +499,7 @@ async fn test_account_sync_diff_msg_update() {
async fn create_account(network: Network) -> Account {
Account::builder()
.storage(
Stronghold::new("./example-strong.hodl", Some("my-password".to_owned()), None)
Stronghold::new("./example-strong.hodl", "my-password".to_owned(), None)
.await
.unwrap(),
)
Expand Down

0 comments on commit 9293237

Please sign in to comment.