mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-15 08:23:46 +00:00
whisper: wnode updated for tests with geth
This commit is contained in:
parent
15a609d5d6
commit
c6125266a1
1 changed files with 18 additions and 30 deletions
|
|
@ -22,8 +22,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/sha1"
|
|
||||||
"crypto/sha256"
|
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
@ -49,6 +47,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const quitCommand = "~Q"
|
const quitCommand = "~Q"
|
||||||
|
const symKeyName = "da919ea33001b04dfc630522e33078ec0df11"
|
||||||
|
|
||||||
// singletons
|
// singletons
|
||||||
var (
|
var (
|
||||||
|
|
@ -68,6 +67,7 @@ var (
|
||||||
nodeid *ecdsa.PrivateKey
|
nodeid *ecdsa.PrivateKey
|
||||||
topic whisper.TopicType
|
topic whisper.TopicType
|
||||||
filterID uint32
|
filterID uint32
|
||||||
|
symPass string
|
||||||
msPassword string
|
msPassword string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -88,7 +88,6 @@ var (
|
||||||
argServerPoW = flag.Float64("mspow", whisper.MinimumPoW, "PoW requirement for Mail Server request")
|
argServerPoW = flag.Float64("mspow", whisper.MinimumPoW, "PoW requirement for Mail Server request")
|
||||||
|
|
||||||
argIP = flag.String("ip", "", "IP address and port of this node (e.g. 127.0.0.1:30303)")
|
argIP = flag.String("ip", "", "IP address and port of this node (e.g. 127.0.0.1:30303)")
|
||||||
argSalt = flag.String("salt", "", "salt (for topic and key derivation)")
|
|
||||||
argPub = flag.String("pub", "", "public key for asymmetric encryption")
|
argPub = flag.String("pub", "", "public key for asymmetric encryption")
|
||||||
argDBPath = flag.String("dbpath", "", "path to the server's DB directory")
|
argDBPath = flag.String("dbpath", "", "path to the server's DB directory")
|
||||||
argIDFile = flag.String("idfile", "", "file name with node id (private key)")
|
argIDFile = flag.String("idfile", "", "file name with node id (private key)")
|
||||||
|
|
@ -146,7 +145,6 @@ func echo() {
|
||||||
fmt.Printf("pow = %f \n", *argPoW)
|
fmt.Printf("pow = %f \n", *argPoW)
|
||||||
fmt.Printf("mspow = %f \n", *argServerPoW)
|
fmt.Printf("mspow = %f \n", *argServerPoW)
|
||||||
fmt.Printf("ip = %s \n", *argIP)
|
fmt.Printf("ip = %s \n", *argIP)
|
||||||
fmt.Printf("salt = %s \n", *argSalt)
|
|
||||||
fmt.Printf("pub = %s \n", common.ToHex(crypto.FromECDSAPub(pub)))
|
fmt.Printf("pub = %s \n", common.ToHex(crypto.FromECDSAPub(pub)))
|
||||||
fmt.Printf("idfile = %s \n", *argIDFile)
|
fmt.Printf("idfile = %s \n", *argIDFile)
|
||||||
fmt.Printf("dbpath = %s \n", *argDBPath)
|
fmt.Printf("dbpath = %s \n", *argDBPath)
|
||||||
|
|
@ -172,10 +170,7 @@ func initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *testMode {
|
if *testMode {
|
||||||
password := []byte("test password for symmetric encryption")
|
symPass = "test"
|
||||||
salt := []byte("test salt for symmetric encryption")
|
|
||||||
symKey = pbkdf2.Key(password, salt, 64, 32, sha256.New)
|
|
||||||
topic = whisper.TopicType{0xFF, 0xFF, 0xFF, 0xFF}
|
|
||||||
msPassword = "mail server test password"
|
msPassword = "mail server test password"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,20 +281,18 @@ func configureNode() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !*asymmetricMode && !*forwarderMode && !*testMode {
|
if !*asymmetricMode && !*forwarderMode {
|
||||||
pass, err := console.Stdin.PromptPassword("Please enter the password: ")
|
if len(symPass) == 0 {
|
||||||
if err != nil {
|
symPass, err = console.Stdin.PromptPassword("Please enter the password: ")
|
||||||
utils.Fatalf("Failed to read passphrase: %v", err)
|
if err != nil {
|
||||||
|
utils.Fatalf("Failed to read passphrase: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*argSalt) == 0 {
|
shh.AddSymKey(symKeyName, []byte(symPass))
|
||||||
argSalt = scanLineA("Please enter the salt: ")
|
symKey = shh.GetSymKey(symKeyName)
|
||||||
}
|
|
||||||
|
|
||||||
symKey = pbkdf2.Key([]byte(pass), []byte(*argSalt), 65356, 32, sha256.New)
|
|
||||||
|
|
||||||
if len(*argTopic) == 0 {
|
if len(*argTopic) == 0 {
|
||||||
generateTopic([]byte(pass), []byte(*argSalt))
|
generateTopic([]byte(symPass))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,15 +312,10 @@ func configureNode() {
|
||||||
fmt.Printf("Filter is configured for the topic: %x \n", topic)
|
fmt.Printf("Filter is configured for the topic: %x \n", topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTopic(password, salt []byte) {
|
func generateTopic(password []byte) {
|
||||||
const rounds = 4000
|
x := pbkdf2.Key(password, password, 8196, 128, sha512.New)
|
||||||
const size = 128
|
for i := 0; i < len(x); i++ {
|
||||||
x1 := pbkdf2.Key(password, salt, rounds, size, sha512.New)
|
topic[i%whisper.TopicLength] ^= x[i]
|
||||||
x2 := pbkdf2.Key(password, salt, rounds, size, sha1.New)
|
|
||||||
x3 := pbkdf2.Key(x1, x2, rounds, size, sha256.New)
|
|
||||||
|
|
||||||
for i := 0; i < size; i++ {
|
|
||||||
topic[i%whisper.TopicLength] ^= x3[i]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,9 +367,9 @@ func sendLoop() {
|
||||||
if *asymmetricMode {
|
if *asymmetricMode {
|
||||||
// print your own message for convenience,
|
// print your own message for convenience,
|
||||||
// because in asymmetric mode it is impossible to decrypt it
|
// because in asymmetric mode it is impossible to decrypt it
|
||||||
hour, min, sec := time.Now().Clock()
|
timestamp := time.Now().Unix()
|
||||||
from := crypto.PubkeyToAddress(asymKey.PublicKey)
|
from := crypto.PubkeyToAddress(asymKey.PublicKey)
|
||||||
fmt.Printf("\n%02d:%02d:%02d <%x>: %s\n", hour, min, sec, from, s)
|
fmt.Printf("\n%d <%x>: %s\n", timestamp, from, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue