Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2c1b0ff1
Commit
2c1b0ff1
authored
May 10, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update key store to new spec but keep address field for now
* Also fix address types post-rebase
parent
fe9e95a3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
72 deletions
+59
-72
admin.go
cmd/geth/admin.go
+1
-1
crypto.go
crypto/crypto.go
+1
-1
key.go
crypto/key.go
+25
-25
key_store_passphrase.go
crypto/key_store_passphrase.go
+29
-42
worker.go
miner/worker.go
+1
-1
block_test_util.go
tests/block_test_util.go
+1
-1
xeth.go
xeth/xeth.go
+1
-1
No files found.
cmd/geth/admin.go
View file @
2c1b0ff1
...
@@ -126,7 +126,7 @@ func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
...
@@ -126,7 +126,7 @@ func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value {
// Add the accouns to a new set
// Add the accouns to a new set
accountSet
:=
set
.
New
()
accountSet
:=
set
.
New
()
for
_
,
account
:=
range
accounts
{
for
_
,
account
:=
range
accounts
{
accountSet
.
Add
(
common
.
BytesToAddress
(
account
.
Address
)
)
accountSet
.
Add
(
account
.
Address
)
}
}
//ltxs := make([]*tx, len(txs))
//ltxs := make([]*tx, len(txs))
...
...
crypto/crypto.go
View file @
2c1b0ff1
...
@@ -185,7 +185,7 @@ func ImportBlockTestKey(privKeyBytes []byte) error {
...
@@ -185,7 +185,7 @@ func ImportBlockTestKey(privKeyBytes []byte) error {
ecKey
:=
ToECDSA
(
privKeyBytes
)
ecKey
:=
ToECDSA
(
privKeyBytes
)
key
:=
&
Key
{
key
:=
&
Key
{
Id
:
uuid
.
NewRandom
(),
Id
:
uuid
.
NewRandom
(),
Address
:
PubkeyToAddress
(
ecKey
.
PublicKey
),
Address
:
common
.
BytesToAddress
(
PubkeyToAddress
(
ecKey
.
PublicKey
)
),
PrivateKey
:
ecKey
,
PrivateKey
:
ecKey
,
}
}
err
:=
ks
.
StoreKey
(
key
,
""
)
err
:=
ks
.
StoreKey
(
key
,
""
)
...
...
crypto/key.go
View file @
2c1b0ff1
...
@@ -48,47 +48,47 @@ type Key struct {
...
@@ -48,47 +48,47 @@ type Key struct {
}
}
type
plainKeyJSON
struct
{
type
plainKeyJSON
struct
{
Version
string
Address
string
`json:"address"`
Id
string
PrivateKey
string
`json:"privatekey"`
Address
string
Id
string
`json:"id"`
PrivateKey
string
Version
string
`json:"version"`
}
}
type
encryptedKeyJSON
struct
{
type
encryptedKeyJSON
struct
{
Version
string
Address
string
`json:"address"`
Id
string
Crypto
cryptoJSON
Address
string
Id
string
`json:"id"`
Crypto
cipherJSON
Version
string
`json:"version"`
}
}
type
cipherJSON
struct
{
type
cryptoJSON
struct
{
MAC
string
Cipher
string
`json:"cipher"`
Salt
string
CipherText
string
`json:"ciphertext"`
IV
string
CipherParams
cipherparamsJSON
`json:"cipherparams"`
KeyHeader
keyHeaderJSON
KDF
string
`json:"kdf"`
CipherText
string
KDFParams
scryptParamsJSON
`json:"kdfparams"`
MAC
string
`json:"mac"`
Version
string
`json:"version"`
}
}
type
keyHeaderJSON
struct
{
type
cipherparamsJSON
struct
{
Version
string
IV
string
`json:"iv"`
Kdf
string
KdfParams
scryptParamsJSON
}
}
type
scryptParamsJSON
struct
{
type
scryptParamsJSON
struct
{
N
int
N
int
`json:"n"`
R
int
R
int
`json:"r"`
P
int
P
int
`json:"p"`
DkLen
int
DkLen
int
`json:"dklen"`
Salt
Len
int
Salt
string
`json:"salt"`
}
}
func
(
k
*
Key
)
MarshalJSON
()
(
j
[]
byte
,
err
error
)
{
func
(
k
*
Key
)
MarshalJSON
()
(
j
[]
byte
,
err
error
)
{
jStruct
:=
plainKeyJSON
{
jStruct
:=
plainKeyJSON
{
version
,
k
.
Id
.
String
(),
hex
.
EncodeToString
(
k
.
Address
[
:
]),
hex
.
EncodeToString
(
k
.
Address
[
:
]),
hex
.
EncodeToString
(
FromECDSA
(
k
.
PrivateKey
)),
hex
.
EncodeToString
(
FromECDSA
(
k
.
PrivateKey
)),
k
.
Id
.
String
(),
version
,
}
}
j
,
err
=
json
.
Marshal
(
jStruct
)
j
,
err
=
json
.
Marshal
(
jStruct
)
return
j
,
err
return
j
,
err
...
...
crypto/key_store_passphrase.go
View file @
2c1b0ff1
...
@@ -143,41 +143,36 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) {
...
@@ -143,41 +143,36 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) {
cipherText
:=
make
([]
byte
,
len
(
toEncrypt
))
cipherText
:=
make
([]
byte
,
len
(
toEncrypt
))
AES128CBCEncrypter
.
CryptBlocks
(
cipherText
,
toEncrypt
)
AES128CBCEncrypter
.
CryptBlocks
(
cipherText
,
toEncrypt
)
paramsJSON
:=
scryptParamsJSON
{
mac
:=
Sha3
(
derivedKey
[
16
:
32
],
cipherText
)
N
:
scryptN
,
R
:
scryptr
,
P
:
scryptp
,
DkLen
:
scryptdkLen
,
SaltLen
:
32
,
}
keyHeaderJSON
:=
keyHeaderJSON
{
scryptParamsJSON
:=
scryptParamsJSON
{
Version
:
keyHeaderVersion
,
N
:
scryptN
,
Kdf
:
keyHeaderKDF
,
R
:
scryptr
,
KdfParams
:
paramsJSON
,
P
:
scryptp
,
DkLen
:
scryptdkLen
,
Salt
:
hex
.
EncodeToString
(
salt
),
}
}
keyHeaderJSONStr
,
err
:=
json
.
Marshal
(
keyHeaderJSON
)
cipherParamsJSON
:=
cipherparamsJSON
{
if
err
!=
nil
{
IV
:
hex
.
EncodeToString
(
iv
),
return
err
}
}
mac
:=
Sha3
(
keyHeaderJSONStr
,
derivedKey
[
16
:
32
],
cipherText
)
cryptoStruct
:=
cryptoJSON
{
Cipher
:
"aes-128-cbc"
,
cipherStruct
:=
cipherJSON
{
CipherText
:
hex
.
EncodeToString
(
cipherText
),
hex
.
EncodeToString
(
mac
)
,
CipherParams
:
cipherParamsJSON
,
hex
.
EncodeToString
(
salt
)
,
KDF
:
"scrypt"
,
hex
.
EncodeToString
(
iv
)
,
KDFParams
:
scryptParamsJSON
,
keyHeaderJSON
,
MAC
:
hex
.
EncodeToString
(
mac
)
,
hex
.
EncodeToString
(
cipherText
)
,
Version
:
"1"
,
}
}
keyStruct
:=
encryptedKeyJSON
{
encryptedKeyJSON
:=
encryptedKeyJSON
{
version
,
key
.
Id
.
String
(),
hex
.
EncodeToString
(
key
.
Address
[
:
]),
hex
.
EncodeToString
(
key
.
Address
[
:
]),
cipherStruct
,
cryptoStruct
,
key
.
Id
.
String
(),
version
,
}
}
keyJSON
,
err
:=
json
.
Marshal
(
keyStruct
)
keyJSON
,
err
:=
json
.
Marshal
(
encryptedKeyJSON
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -212,33 +207,25 @@ func DecryptKey(ks keyStorePassphrase, keyAddr common.Address, auth string) (key
...
@@ -212,33 +207,25 @@ func DecryptKey(ks keyStorePassphrase, keyAddr common.Address, auth string) (key
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
salt
,
err
:=
hex
.
DecodeString
(
keyProtected
.
Crypto
.
Salt
)
iv
,
err
:=
hex
.
DecodeString
(
keyProtected
.
Crypto
.
CipherParams
.
IV
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
iv
,
err
:=
hex
.
DecodeString
(
keyProtected
.
Crypto
.
IV
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
keyHeader
:=
keyProtected
.
Crypto
.
KeyHeader
cipherText
,
err
:=
hex
.
DecodeString
(
keyProtected
.
Crypto
.
CipherText
)
cipherText
,
err
:=
hex
.
DecodeString
(
keyProtected
.
Crypto
.
CipherText
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
// used in MAC
salt
,
err
:=
hex
.
DecodeString
(
keyProtected
.
Crypto
.
KDFParams
.
Salt
)
keyHeaderJSONStr
,
err
:=
json
.
Marshal
(
keyHeader
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
// TODO: make this more generic when we support different KDF params / key versions
n
:=
keyProtected
.
Crypto
.
KDFParams
.
N
n
:=
keyHeader
.
KdfParams
.
N
r
:=
keyProtected
.
Crypto
.
KDFParams
.
R
r
:=
keyHeader
.
KdfParams
.
R
p
:=
keyProtected
.
Crypto
.
KDFParams
.
P
p
:=
keyHeader
.
KdfParams
.
P
dkLen
:=
keyProtected
.
Crypto
.
KDFParams
.
DkLen
dkLen
:=
keyHeader
.
KdfParams
.
DkLen
authArray
:=
[]
byte
(
auth
)
authArray
:=
[]
byte
(
auth
)
derivedKey
,
err
:=
scrypt
.
Key
(
authArray
,
salt
,
n
,
r
,
p
,
dkLen
)
derivedKey
,
err
:=
scrypt
.
Key
(
authArray
,
salt
,
n
,
r
,
p
,
dkLen
)
...
@@ -246,7 +233,7 @@ func DecryptKey(ks keyStorePassphrase, keyAddr common.Address, auth string) (key
...
@@ -246,7 +233,7 @@ func DecryptKey(ks keyStorePassphrase, keyAddr common.Address, auth string) (key
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
calculatedMAC
:=
Sha3
(
keyHeaderJSONStr
,
derivedKey
[
16
:
32
],
cipherText
)
calculatedMAC
:=
Sha3
(
derivedKey
[
16
:
32
],
cipherText
)
if
!
bytes
.
Equal
(
calculatedMAC
,
mac
)
{
if
!
bytes
.
Equal
(
calculatedMAC
,
mac
)
{
err
=
errors
.
New
(
"Decryption failed: MAC mismatch"
)
err
=
errors
.
New
(
"Decryption failed: MAC mismatch"
)
return
nil
,
nil
,
err
return
nil
,
nil
,
err
...
...
miner/worker.go
View file @
2c1b0ff1
...
@@ -474,7 +474,7 @@ func gasprice(price *big.Int, pct int64) *big.Int {
...
@@ -474,7 +474,7 @@ func gasprice(price *big.Int, pct int64) *big.Int {
func
accountAddressesSet
(
accounts
[]
accounts
.
Account
)
*
set
.
Set
{
func
accountAddressesSet
(
accounts
[]
accounts
.
Account
)
*
set
.
Set
{
accountSet
:=
set
.
New
()
accountSet
:=
set
.
New
()
for
_
,
account
:=
range
accounts
{
for
_
,
account
:=
range
accounts
{
accountSet
.
Add
(
common
.
BytesToAddress
(
account
.
Address
)
)
accountSet
.
Add
(
account
.
Address
)
}
}
return
accountSet
return
accountSet
}
}
tests/block_test_util.go
View file @
2c1b0ff1
...
@@ -113,7 +113,7 @@ func (t *BlockTest) InsertPreState(ethereum *eth.Ethereum) (*state.StateDB, erro
...
@@ -113,7 +113,7 @@ func (t *BlockTest) InsertPreState(ethereum *eth.Ethereum) (*state.StateDB, erro
if
acct
.
PrivateKey
!=
""
{
if
acct
.
PrivateKey
!=
""
{
privkey
,
err
:=
hex
.
DecodeString
(
strings
.
TrimPrefix
(
acct
.
PrivateKey
,
"0x"
))
privkey
,
err
:=
hex
.
DecodeString
(
strings
.
TrimPrefix
(
acct
.
PrivateKey
,
"0x"
))
err
=
crypto
.
ImportBlockTestKey
(
privkey
)
err
=
crypto
.
ImportBlockTestKey
(
privkey
)
err
=
ethereum
.
AccountManager
()
.
TimedUnlock
(
addr
,
""
,
999999
*
time
.
Second
)
err
=
ethereum
.
AccountManager
()
.
TimedUnlock
(
common
.
BytesToAddress
(
addr
)
,
""
,
999999
*
time
.
Second
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
xeth/xeth.go
View file @
2c1b0ff1
...
@@ -817,7 +817,7 @@ func (self *XEth) ConfirmTransaction(tx string) bool {
...
@@ -817,7 +817,7 @@ func (self *XEth) ConfirmTransaction(tx string) bool {
}
}
func
(
self
*
XEth
)
doSign
(
from
common
.
Address
,
hash
common
.
Hash
,
didUnlock
bool
)
([]
byte
,
error
)
{
func
(
self
*
XEth
)
doSign
(
from
common
.
Address
,
hash
common
.
Hash
,
didUnlock
bool
)
([]
byte
,
error
)
{
sig
,
err
:=
self
.
backend
.
AccountManager
()
.
Sign
(
accounts
.
Account
{
Address
:
from
.
Bytes
()
},
hash
.
Bytes
())
sig
,
err
:=
self
.
backend
.
AccountManager
()
.
Sign
(
accounts
.
Account
{
Address
:
from
},
hash
.
Bytes
())
if
err
==
accounts
.
ErrLocked
{
if
err
==
accounts
.
ErrLocked
{
if
didUnlock
{
if
didUnlock
{
return
nil
,
fmt
.
Errorf
(
"signer account still locked after successful unlock"
)
return
nil
,
fmt
.
Errorf
(
"signer account still locked after successful unlock"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment