mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-31 17:13:57 +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 (
|
||||
"bufio"
|
||||
"crypto/ecdsa"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
|
|
@ -49,6 +47,7 @@ import (
|
|||
)
|
||||
|
||||
const quitCommand = "~Q"
|
||||
const symKeyName = "da919ea33001b04dfc630522e33078ec0df11"
|
||||
|
||||
// singletons
|
||||
var (
|
||||
|
|
@ -68,6 +67,7 @@ var (
|
|||
nodeid *ecdsa.PrivateKey
|
||||
topic whisper.TopicType
|
||||
filterID uint32
|
||||
symPass string
|
||||
msPassword string
|
||||
)
|
||||
|
||||
|
|
@ -88,7 +88,6 @@ var (
|
|||
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)")
|
||||
argSalt = flag.String("salt", "", "salt (for topic and key derivation)")
|
||||
argPub = flag.String("pub", "", "public key for asymmetric encryption")
|
||||
argDBPath = flag.String("dbpath", "", "path to the server's DB directory")
|
||||
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("mspow = %f \n", *argServerPoW)
|
||||
fmt.Printf("ip = %s \n", *argIP)
|
||||
fmt.Printf("salt = %s \n", *argSalt)
|
||||
fmt.Printf("pub = %s \n", common.ToHex(crypto.FromECDSAPub(pub)))
|
||||
fmt.Printf("idfile = %s \n", *argIDFile)
|
||||
fmt.Printf("dbpath = %s \n", *argDBPath)
|
||||
|
|
@ -172,10 +170,7 @@ func initialize() {
|
|||
}
|
||||
|
||||
if *testMode {
|
||||
password := []byte("test password for symmetric encryption")
|
||||
salt := []byte("test salt for symmetric encryption")
|
||||
symKey = pbkdf2.Key(password, salt, 64, 32, sha256.New)
|
||||
topic = whisper.TopicType{0xFF, 0xFF, 0xFF, 0xFF}
|
||||
symPass = "test"
|
||||
msPassword = "mail server test password"
|
||||
}
|
||||
|
||||
|
|
@ -286,20 +281,18 @@ func configureNode() {
|
|||
}
|
||||
}
|
||||
|
||||
if !*asymmetricMode && !*forwarderMode && !*testMode {
|
||||
pass, err := console.Stdin.PromptPassword("Please enter the password: ")
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to read passphrase: %v", err)
|
||||
if !*asymmetricMode && !*forwarderMode {
|
||||
if len(symPass) == 0 {
|
||||
symPass, err = console.Stdin.PromptPassword("Please enter the password: ")
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to read passphrase: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(*argSalt) == 0 {
|
||||
argSalt = scanLineA("Please enter the salt: ")
|
||||
}
|
||||
|
||||
symKey = pbkdf2.Key([]byte(pass), []byte(*argSalt), 65356, 32, sha256.New)
|
||||
|
||||
shh.AddSymKey(symKeyName, []byte(symPass))
|
||||
symKey = shh.GetSymKey(symKeyName)
|
||||
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)
|
||||
}
|
||||
|
||||
func generateTopic(password, salt []byte) {
|
||||
const rounds = 4000
|
||||
const size = 128
|
||||
x1 := pbkdf2.Key(password, salt, rounds, size, sha512.New)
|
||||
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]
|
||||
func generateTopic(password []byte) {
|
||||
x := pbkdf2.Key(password, password, 8196, 128, sha512.New)
|
||||
for i := 0; i < len(x); i++ {
|
||||
topic[i%whisper.TopicLength] ^= x[i]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -379,9 +367,9 @@ func sendLoop() {
|
|||
if *asymmetricMode {
|
||||
// print your own message for convenience,
|
||||
// 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)
|
||||
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