4331834003
* Move tests -> testing * Directory restructure * Update Cargo.toml during restructure * Update Makefile during restructure * Fix arbitrary path
323 lines
11 KiB
Rust
323 lines
11 KiB
Rust
#![cfg(test)]
|
|
|
|
use eth2_keystore::{Error, Keystore};
|
|
|
|
const PASSWORD: &str = "testpassword";
|
|
|
|
fn decrypt_error(vector: &str) -> Error {
|
|
Keystore::from_json_str(&vector)
|
|
.unwrap()
|
|
.decrypt_keypair(PASSWORD.as_bytes())
|
|
.err()
|
|
.unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn scrypt_zero_n() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "scrypt",
|
|
"params": {
|
|
"dklen": 32,
|
|
"n": 0,
|
|
"p": 1,
|
|
"r": 8,
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "149aafa27b041f3523c53d7acba1905fa6b1c90f9fef137568101f44b531a3cb"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "54ecc8863c0550351eee5720f3be6a5d4a016025aa91cd6436cfec938d6a8d30"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"uuid": "1d85ae20-35c5-4611-98e8-aa14a633906f",
|
|
"path": "",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidScryptParam);
|
|
}
|
|
|
|
#[test]
|
|
fn scrypt_dklen_not_32() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "scrypt",
|
|
"params": {
|
|
"dklen": 33,
|
|
"n": 262144,
|
|
"p": 1,
|
|
"r": 8,
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "149aafa27b041f3523c53d7acba1905fa6b1c90f9fef137568101f44b531a3cb"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "54ecc8863c0550351eee5720f3be6a5d4a016025aa91cd6436cfec938d6a8d30"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"uuid": "1d85ae20-35c5-4611-98e8-aa14a633906f",
|
|
"path": "",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidScryptParam);
|
|
}
|
|
|
|
#[test]
|
|
fn scrypt_zero_p() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "scrypt",
|
|
"params": {
|
|
"dklen": 32,
|
|
"n": 262144,
|
|
"p": 0,
|
|
"r": 8,
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "149aafa27b041f3523c53d7acba1905fa6b1c90f9fef137568101f44b531a3cb"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "54ecc8863c0550351eee5720f3be6a5d4a016025aa91cd6436cfec938d6a8d30"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"uuid": "1d85ae20-35c5-4611-98e8-aa14a633906f",
|
|
"path": "",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidScryptParam);
|
|
}
|
|
|
|
#[test]
|
|
fn scrypt_zero_r() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "scrypt",
|
|
"params": {
|
|
"dklen": 32,
|
|
"n": 262144,
|
|
"p": 1,
|
|
"r": 0,
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "149aafa27b041f3523c53d7acba1905fa6b1c90f9fef137568101f44b531a3cb"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "54ecc8863c0550351eee5720f3be6a5d4a016025aa91cd6436cfec938d6a8d30"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"uuid": "1d85ae20-35c5-4611-98e8-aa14a633906f",
|
|
"path": "",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidScryptParam);
|
|
}
|
|
|
|
#[test]
|
|
fn scrypt_zero_dklen() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "scrypt",
|
|
"params": {
|
|
"dklen": 0,
|
|
"n": 262144,
|
|
"p": 1,
|
|
"r": 8,
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "149aafa27b041f3523c53d7acba1905fa6b1c90f9fef137568101f44b531a3cb"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "54ecc8863c0550351eee5720f3be6a5d4a016025aa91cd6436cfec938d6a8d30"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"uuid": "1d85ae20-35c5-4611-98e8-aa14a633906f",
|
|
"path": "",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidScryptParam);
|
|
}
|
|
|
|
#[test]
|
|
fn pbkdf2_zero_c() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "pbkdf2",
|
|
"params": {
|
|
"dklen": 32,
|
|
"c": 0,
|
|
"prf": "hmac-sha256",
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "18b148af8e52920318084560fd766f9d09587b4915258dec0676cba5b0da09d8"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "a9249e0ca7315836356e4c7440361ff22b9fe71e2e2ed34fc1eb03976924ed48"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"path": "m/12381/60/0/0",
|
|
"uuid": "64625def-3331-4eea-ab6f-782f3ed16a83",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidPbkdf2Param);
|
|
}
|
|
|
|
#[test]
|
|
fn pbkdf2_zero_dken() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "pbkdf2",
|
|
"params": {
|
|
"dklen": 0,
|
|
"c": 262144,
|
|
"prf": "hmac-sha256",
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "18b148af8e52920318084560fd766f9d09587b4915258dec0676cba5b0da09d8"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "a9249e0ca7315836356e4c7440361ff22b9fe71e2e2ed34fc1eb03976924ed48"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"path": "m/12381/60/0/0",
|
|
"uuid": "64625def-3331-4eea-ab6f-782f3ed16a83",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidPbkdf2Param);
|
|
}
|
|
|
|
#[test]
|
|
fn pbkdf2_dklen_not_32() {
|
|
let vector = r#"
|
|
{
|
|
"crypto": {
|
|
"kdf": {
|
|
"function": "pbkdf2",
|
|
"params": {
|
|
"dklen": 33,
|
|
"c": 262144,
|
|
"prf": "hmac-sha256",
|
|
"salt": "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
|
},
|
|
"message": ""
|
|
},
|
|
"checksum": {
|
|
"function": "sha256",
|
|
"params": {},
|
|
"message": "18b148af8e52920318084560fd766f9d09587b4915258dec0676cba5b0da09d8"
|
|
},
|
|
"cipher": {
|
|
"function": "aes-128-ctr",
|
|
"params": {
|
|
"iv": "264daa3f303d7259501c93d997d84fe6"
|
|
},
|
|
"message": "a9249e0ca7315836356e4c7440361ff22b9fe71e2e2ed34fc1eb03976924ed48"
|
|
}
|
|
},
|
|
"pubkey": "9612d7a727c9d0a22e185a1c768478dfe919cada9266988cb32359c11f2b7b27f4ae4040902382ae2910c15e2b420d07",
|
|
"path": "m/12381/60/0/0",
|
|
"uuid": "64625def-3331-4eea-ab6f-782f3ed16a83",
|
|
"version": 4
|
|
}
|
|
"#;
|
|
|
|
assert_eq!(decrypt_error(vector), Error::InvalidPbkdf2Param);
|
|
}
|