Add type for passwords.#8920
Conversation
|
It looks like @twittner signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
|
|
||
| /// Changes the password of `account` from `password` to `new_password`. Fails if incorrect `password` given. | ||
| pub fn change_password(&self, address: &Address, password: String, new_password: String) -> Result<(), Error> { | ||
| pub fn change_password(&self, address: &Address, password: Password, new_password: Password) -> Result<(), Error> { |
There was a problem hiding this comment.
Out-of-scope for this PR:
Why not pass-by_ref here?
|
|
||
| /// Exports an account for given address. | ||
| pub fn export_account(&self, address: &Address, password: String) -> Result<KeyFile, Error> { | ||
| pub fn export_account(&self, address: &Address, password: Password) -> Result<KeyFile, Error> { |
There was a problem hiding this comment.
Out-of-scope for this PR:
Why not pass-by_ref here?
|
|
||
| /// Helper method used for unlocking accounts. | ||
| fn unlock_account(&self, address: Address, password: String, unlock: Unlock) -> Result<(), Error> { | ||
| fn unlock_account(&self, address: Address, password: Password, unlock: Unlock) -> Result<(), Error> { |
There was a problem hiding this comment.
Out-of-scope for this PR:
Why not pass-by_ref here?
| let p = vec.as_mut_ptr(); | ||
| for i in 0..n { | ||
| unsafe { | ||
| ptr::write_volatile(p.offset(i as isize), 0) |
There was a problem hiding this comment.
I think it could be worth to add a comment and explaining why write_volatile is used here. i.e., to actually make sure that passwords are erased and not LLVM performs some magic optimization!
Also consider to simply the code to:
let ptr = unsafe { s.as_mut_vec() };
for byte in ptr {
unsafe { ptr::write_volatile(byte, 0) }
}
niklasad1
left a comment
There was a problem hiding this comment.
Looks good but document why volatile writes are used to erase the passwords in the memory!
|
Needs 2nd review. |
|
|
||
| use std::ptr; | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] |
There was a problem hiding this comment.
Should we provide a custom Debug that prints a static Password(******)? 😄
dvdplm
left a comment
There was a problem hiding this comment.
Seems like a good improvement. I wonder if we should accompany this with std::mem::drop(password) calls in the appropriate places as well?
Minor grumble: indentation in a few places look off: https://github.com/paritytech/parity/pull/8920/files#diff-d3979a57cbb0a0d1504cc1f5bab2d007R36 and https://github.com/paritytech/parity/pull/8920/files#diff-4d8151f665cbc6bf2a9fe83d64a61b64R35
| impl Drop for Password { | ||
| fn drop(&mut self) { | ||
| unsafe { | ||
| for byte_ref in self.0.as_mut_vec() { |
There was a problem hiding this comment.
Replace indentation spaces with tabs.
| ptr::write_volatile(p.offset(i as isize), 0) | ||
| unsafe { | ||
| for byte_ref in self.mem.as_mut() { | ||
| ptr::write_volatile(byte_ref, 0) |
|
Explicit Also in context of this |
|
@niklasad1 makes sense, especially considering that |
|
@niklasad1 I think what @dvdplm meant was to use |
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: parity: omit redundant last imported block number in light sync informant (openethereum#8962) Disable hardware-wallets on platforms that don't support `libusb` (openethereum#8464) Bump error-chain and quick_error versions (openethereum#8972) EVM benchmark utilities (openethereum#8944) parity: hide legacy options from cli --help (openethereum#8967) scripts: fix docker build tag on latest using master (openethereum#8952) Add type for passwords. (openethereum#8920)
No description provided.