mirror of https://github.com/ethereum/go-ethereum
* Change password protection crypto in keystore to version 3 * Update KeyStoreTests/basic_tests.json * Add support for PBKDF2 with HMAC-SHA256 * Change MAC and encryption key to avoid unnecessary hashing * Add tests for test vectors in new wiki page defining version 3 * Add tests for new keystore tests in ethereum/tests repo * Move JSON loading util to common for use in both tests and crypto packages * Add backwards compatibility with key store version 1pull/1085/head
parent
22c7ce0162
commit
d23ec6c419
@ -0,0 +1,37 @@ |
||||
package common |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"fmt" |
||||
"io/ioutil" |
||||
) |
||||
|
||||
// LoadJSON reads the given file and unmarshals its content.
|
||||
func LoadJSON(file string, val interface{}) error { |
||||
content, err := ioutil.ReadFile(file) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
if err := json.Unmarshal(content, val); err != nil { |
||||
if syntaxerr, ok := err.(*json.SyntaxError); ok { |
||||
line := findLine(content, syntaxerr.Offset) |
||||
return fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err) |
||||
} |
||||
return fmt.Errorf("JSON unmarshal error in %v: %v", file, err) |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// findLine returns the line number for the given offset into data.
|
||||
func findLine(data []byte, offset int64) (line int) { |
||||
line = 1 |
||||
for i, r := range string(data) { |
||||
if int64(i) >= offset { |
||||
return |
||||
} |
||||
if r == '\n' { |
||||
line++ |
||||
} |
||||
} |
||||
return |
||||
} |
@ -0,0 +1 @@ |
||||
{"address":"cb61d5a9c4896fb9658090b597ef0e7be6f7b67e","Crypto":{"cipher":"aes-128-cbc","ciphertext":"6143d3192db8b66eabd693d9c4e414dcfaee52abda451af79ccf474dafb35f1bfc7ea013aa9d2ee35969a1a2e8d752d0","cipherparams":{"iv":"35337770fc2117994ecdcad026bccff4"},"kdf":"scrypt","kdfparams":{"n":262144,"r":8,"p":1,"dklen":32,"salt":"9afcddebca541253a2f4053391c673ff9fe23097cd8555d149d929e4ccf1257f"},"mac":"3f3d5af884b17a100b0b3232c0636c230a54dc2ac8d986227219b0dd89197644","version":"1"},"id":"e25f7c1f-d318-4f29-b62c-687190d4d299","version":"1"} |
@ -0,0 +1,28 @@ |
||||
{ |
||||
"test1": { |
||||
"json": { |
||||
"Crypto": { |
||||
"cipher": "aes-128-cbc", |
||||
"cipherparams": { |
||||
"iv": "35337770fc2117994ecdcad026bccff4" |
||||
}, |
||||
"ciphertext": "6143d3192db8b66eabd693d9c4e414dcfaee52abda451af79ccf474dafb35f1bfc7ea013aa9d2ee35969a1a2e8d752d0", |
||||
"kdf": "scrypt", |
||||
"kdfparams": { |
||||
"dklen": 32, |
||||
"n": 262144, |
||||
"p": 1, |
||||
"r": 8, |
||||
"salt": "9afcddebca541253a2f4053391c673ff9fe23097cd8555d149d929e4ccf1257f" |
||||
}, |
||||
"mac": "3f3d5af884b17a100b0b3232c0636c230a54dc2ac8d986227219b0dd89197644", |
||||
"version": "1" |
||||
}, |
||||
"address": "cb61d5a9c4896fb9658090b597ef0e7be6f7b67e", |
||||
"id": "e25f7c1f-d318-4f29-b62c-687190d4d299", |
||||
"version": "1" |
||||
}, |
||||
"password": "g", |
||||
"priv": "d1b1178d3529626a1a93e073f65028370d14c7eb0936eb42abef05db6f37ad7d" |
||||
} |
||||
} |
@ -0,0 +1,49 @@ |
||||
{ |
||||
"wikipage_test_vector_scrypt": { |
||||
"json": { |
||||
"crypto" : { |
||||
"cipher" : "aes-128-ctr", |
||||
"cipherparams" : { |
||||
"iv" : "83dbcc02d8ccb40e466191a123791e0e" |
||||
}, |
||||
"ciphertext" : "d172bf743a674da9cdad04534d56926ef8358534d458fffccd4e6ad2fbde479c", |
||||
"kdf" : "scrypt", |
||||
"kdfparams" : { |
||||
"dklen" : 32, |
||||
"n" : 262144, |
||||
"r" : 1, |
||||
"p" : 8, |
||||
"salt" : "ab0c7876052600dd703518d6fc3fe8984592145b591fc8fb5c6d43190334ba19" |
||||
}, |
||||
"mac" : "2103ac29920d71da29f15d75b4a16dbe95cfd7ff8faea1056c33131d846e3097" |
||||
}, |
||||
"id" : "3198bc9c-6672-5ab3-d995-4942343ae5b6", |
||||
"version" : 3 |
||||
}, |
||||
"password": "testpassword", |
||||
"priv": "7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d" |
||||
}, |
||||
"wikipage_test_vector_pbkdf2": { |
||||
"json": { |
||||
"crypto" : { |
||||
"cipher" : "aes-128-ctr", |
||||
"cipherparams" : { |
||||
"iv" : "6087dab2f9fdbbfaddc31a909735c1e6" |
||||
}, |
||||
"ciphertext" : "5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46", |
||||
"kdf" : "pbkdf2", |
||||
"kdfparams" : { |
||||
"c" : 262144, |
||||
"dklen" : 32, |
||||
"prf" : "hmac-sha256", |
||||
"salt" : "ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd" |
||||
}, |
||||
"mac" : "517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2" |
||||
}, |
||||
"id" : "3198bc9c-6672-5ab3-d995-4942343ae5b6", |
||||
"version" : 3 |
||||
}, |
||||
"password": "testpassword", |
||||
"priv": "7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d" |
||||
} |
||||
} |
Loading…
Reference in new issue