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

Box zeroize to prevent leaving copies on move. #358

Merged
merged 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ First, add this to your `Cargo.toml`:
web3 = { git = "https://github.com/tomusdrw/rust-web3" }
```

## Examples
## Example
```rust
#[tokio::main]
async fn main() -> web3::Result<()> {
Expand Down Expand Up @@ -100,7 +100,7 @@ web3.api::<CustomNamespace>().custom_method().wait().unwrap()
# Installation on Windows

Currently, Windows does not support IPC, which is enabled in the library by default.
To complile, you need to disable IPC feature:
To complile, you need to disable the IPC feature:
```
web3 = { version = "0.11.0", default-features = false, features = ["http"] }
```
11 changes: 9 additions & 2 deletions src/api/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type TxParams<T> = Join3<MaybeReady<T, U256>, MaybeReady<T, U256>, MaybeReady<T,
/// immediately.
pub struct SignTransactionFuture<T: Transport> {
tx: TransactionParameters,
key: ZeroizeSecretKey,
key: Box<ZeroizeSecretKey>,
inner: TxParams<T>,
}

Expand All @@ -202,7 +202,7 @@ impl<T: Transport> SignTransactionFuture<T> {

SignTransactionFuture {
tx,
key: ZeroizeSecretKey(*key),
key: ZeroizeSecretKey::boxed(*key),
inner,
}
}
Expand Down Expand Up @@ -350,6 +350,13 @@ impl Transaction {
#[derive(Clone, Copy)]
struct ZeroizeSecretKey(SecretKey);

impl ZeroizeSecretKey {
/// Create new boxed instance to make sure we don't leak any copies around.
pub fn boxed(key: SecretKey) -> Box<Self> {
Box::new(Self(key))
}
}

impl Default for ZeroizeSecretKey {
fn default() -> Self {
ZeroizeSecretKey(ONE_KEY)
Expand Down