aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorgluk256 <gluk256@users.noreply.github.com>2017-02-23 16:41:47 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2017-02-23 16:41:47 +0800
commit29fac7de448c85049a97cbec3dc0819122bd2cb0 (patch)
treeeaa56d55f2ff5c15fca84a6d408d6aaff7d78404 /cmd
parent555273495b413069e9422b04aa46251146c752b2 (diff)
downloadgo-tangerine-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar
go-tangerine-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.gz
go-tangerine-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.bz2
go-tangerine-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.lz
go-tangerine-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.xz
go-tangerine-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.zst
go-tangerine-29fac7de448c85049a97cbec3dc0819122bd2cb0.zip
Whisper API fixed (#3687)
* whisper: wnode updated for tests with geth * whisper: updated processing of incoming messages * whisper: symmetric encryption updated * whisper: filter id type changed to enhance security * whisper: allow filter without topic for asymmetric encryption * whisper: POW updated * whisper: logging updated * whisper: spellchecker update * whisper: error handling changed * whisper: JSON field names fixed
Diffstat (limited to 'cmd')
-rw-r--r--cmd/wnode/main.go58
1 files changed, 25 insertions, 33 deletions
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
index 175021798..d002497fb 100644
--- a/cmd/wnode/main.go
+++ b/cmd/wnode/main.go
@@ -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 (
@@ -67,7 +66,8 @@ var (
asymKey *ecdsa.PrivateKey
nodeid *ecdsa.PrivateKey
topic whisper.TopicType
- filterID uint32
+ filterID string
+ symPass string
msPassword string
)
@@ -82,13 +82,13 @@ var (
testMode = flag.Bool("t", false, "use of predefined parameters for diagnostics")
generateKey = flag.Bool("k", false, "generate and show the private key")
+ argVerbosity = flag.Int("verbosity", logger.Warn, "log verbosity level")
argTTL = flag.Uint("ttl", 30, "time-to-live for messages in seconds")
argWorkTime = flag.Uint("work", 5, "work time in seconds")
argPoW = flag.Float64("pow", whisper.MinimumPoW, "PoW for normal messages in float format (e.g. 2.7)")
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 +146,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)
@@ -154,7 +153,7 @@ func echo() {
}
func initialize() {
- glog.SetV(logger.Warn)
+ glog.SetV(*argVerbosity)
glog.SetToStderr(true)
done = make(chan struct{})
@@ -172,10 +171,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 = "wwww" // ascii code: 0x77777777
msPassword = "mail server test password"
}
@@ -286,20 +282,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 len(*argSalt) == 0 {
- argSalt = scanLineA("Please enter the salt: ")
+ 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)
+ }
}
- 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))
}
}
@@ -315,19 +309,17 @@ func configureNode() {
Topics: []whisper.TopicType{topic},
AcceptP2P: p2pAccept,
}
- filterID = shh.Watch(&filter)
+ filterID, err = shh.Watch(&filter)
+ if err != nil {
+ utils.Fatalf("Failed to install filter: %s", err)
+ }
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 +371,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)
}
}
}