Skip to content

Commit 961c2de

Browse files
feat(plugins): finalize Stronghold plugin docs (#2759)
Co-authored-by: Tillmann <[email protected]>
1 parent 0fba715 commit 961c2de

File tree

1 file changed

+56
-59
lines changed

1 file changed

+56
-59
lines changed

src/content/docs/plugin/stronghold.mdx

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
title: Stronghold
33
description: Encrypted, secure database.
4-
sidebar:
5-
badge:
6-
text: WIP
7-
variant: caution
84
plugin: stronghold
95
---
106

@@ -17,7 +13,7 @@ import PluginPermissions from '@components/PluginPermissions.astro';
1713

1814
<PluginLinks plugin={frontmatter.plugin} />
1915

20-
Store secrets and keys using the [IOTA Stronghold](https://github.com/iotaledger/stronghold.rs) encrypted database and secure runtime.
16+
Store secrets and keys using the [IOTA Stronghold](https://github.com/iotaledger/stronghold.rs) secret management engine.
2117

2218
## Supported Platforms
2319

@@ -79,56 +75,65 @@ Install the stronghold plugin to get started.
7975

8076
## Usage
8177

82-
### Initialize with custom password hash function
78+
The plugin must be initialized with a password hash function, which takes the password string and must return a 32 bytes hash derived from it.
79+
80+
### Initialize with argon2 password hash function
81+
82+
The Stronghold plugin offers a default hash function using the [argon2] algorithm.
8383

8484
```rust title="src-tauri/src/lib.rs"
85+
use tauri::Manager;
86+
8587
pub fn run() {
86-
tauri::Builder::default()
87-
.plugin(
88-
tauri_plugin_stronghold::Builder::new(|password| {
89-
// Hash the password here with e.g. argon2, blake2b or any other secure algorithm
90-
// Here is an example implementation using the `rust-argon2` crate for hashing the password
91-
use argon2::{hash_raw, Config, Variant, Version};
92-
93-
let config = Config {
94-
lanes: 4,
95-
mem_cost: 10_000,
96-
time_cost: 10,
97-
variant: Variant::Argon2id,
98-
version: Version::Version13,
99-
..Default::default()
100-
};
101-
let salt = "your-salt".as_bytes();
102-
let key =
103-
hash_raw(password.as_ref(), salt, &config).expect("failed to hash password");
104-
105-
key.to_vec()
106-
})
107-
.build(),
108-
)
109-
.run(tauri::generate_context!())
110-
.expect("error while running tauri application");
88+
tauri::Builder::default()
89+
.setup(|app| {
90+
let salt_path = app
91+
.path()
92+
.app_local_data_dir()
93+
.expect("could not resolve app local data path")
94+
.join("salt.txt");
95+
app.handle().plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?;
96+
Ok(())
97+
})
98+
.run(tauri::generate_context!())
99+
.expect("error while running tauri application");
111100
}
112101
```
113102

114-
### Initialize with argon2 password hash function
103+
### Initialize with custom password hash function
115104

116-
```rust title="src-tauri/src/lib.rs"
117-
use tauri::Manager;
105+
Alternatively you can provide your own hash algorithm by using the `tauri_plugin_stronghold::Builder::new` constructor.
118106

107+
:::note
108+
The password hash must contain exactly 32 bytes. This is a Stronghold requirement.
109+
:::
110+
111+
```rust title="src-tauri/src/lib.rs"
119112
pub fn run() {
120-
tauri::Builder::default()
121-
.setup(|app| {
122-
let salt_path = app
123-
.path()
124-
.app_local_data_dir()
125-
.expect("could not resolve app local data path")
126-
.join("salt.txt");
127-
app.handle().plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?;
128-
Ok(())
129-
})
130-
.run(tauri::generate_context!())
131-
.expect("error while running tauri application");
113+
tauri::Builder::default()
114+
.plugin(
115+
tauri_plugin_stronghold::Builder::new(|password| {
116+
// Hash the password here with e.g. argon2, blake2b or any other secure algorithm
117+
// Here is an example implementation using the `rust-argon2` crate for hashing the password
118+
use argon2::{hash_raw, Config, Variant, Version};
119+
120+
let config = Config {
121+
lanes: 4,
122+
mem_cost: 10_000,
123+
time_cost: 10,
124+
variant: Variant::Argon2id,
125+
version: Version::Version13,
126+
..Default::default()
127+
};
128+
let salt = "your-salt".as_bytes();
129+
let key = hash_raw(password.as_ref(), salt, &config).expect("failed to hash password");
130+
131+
key.to_vec()
132+
})
133+
.build(),
134+
)
135+
.run(tauri::generate_context!())
136+
.expect("error while running tauri application");
132137
}
133138
```
134139

@@ -200,23 +205,15 @@ By default all potentially dangerous plugin commands and scopes are blocked and
200205

201206
See the [Capabilities Overview](/security/capabilities/) for more information and the [step by step guide](/learn/security/using-plugin-permissions/) to use plugin permissions.
202207

203-
```json title="src-tauri/capabilities/main.json" ins={8-14}
208+
```json title="src-tauri/capabilities/main.json" ins={4}
204209
{
205-
"$schema": "../gen/schemas/desktop-schema.json",
206-
"identifier": "main-capability",
207-
"description": "Capability for the main window",
208-
"windows": ["main"],
210+
...,
209211
"permissions": [
210-
"path:default",
211-
"stronghold:allow-initialize",
212-
"stronghold:allow-create-client",
213-
"stronghold:allow-load-client",
214-
"stronghold:allow-save",
215-
"stronghold:allow-save-store-record"
216-
"stronghold:allow-get-store-record",
217-
"stronghold:allow-remove-store-record",
212+
"stronghold:default",
218213
]
219214
}
220215
```
221216

222217
<PluginPermissions plugin={frontmatter.plugin} />
218+
219+
[argon2]: https://docs.rs/rust-argon2/latest/argon2/

0 commit comments

Comments
 (0)