aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad <gluk256@gmail.com>2018-03-02 21:54:54 +0800
committerVlad <gluk256@gmail.com>2018-03-02 21:54:54 +0800
commit6219a338225f1a4dfb7e51212ec3dde6e32785ce (patch)
tree194e340c55df55eb08deabe6b6ae89f97a26b430
parenta76e46e3d7cb77bfcbc95d92df9f4b6ccdd742f2 (diff)
downloadgo-tangerine-6219a338225f1a4dfb7e51212ec3dde6e32785ce.tar
go-tangerine-6219a338225f1a4dfb7e51212ec3dde6e32785ce.tar.gz
go-tangerine-6219a338225f1a4dfb7e51212ec3dde6e32785ce.tar.bz2
go-tangerine-6219a338225f1a4dfb7e51212ec3dde6e32785ce.tar.lz
go-tangerine-6219a338225f1a4dfb7e51212ec3dde6e32785ce.tar.xz
go-tangerine-6219a338225f1a4dfb7e51212ec3dde6e32785ce.tar.zst
go-tangerine-6219a338225f1a4dfb7e51212ec3dde6e32785ce.zip
whisper: filereader mode introduced to wnode
-rw-r--r--cmd/wnode/main.go37
-rw-r--r--whisper/whisperv6/envelope.go4
2 files changed, 41 insertions, 0 deletions
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
index ccfdd4626..76590e7f5 100644
--- a/cmd/wnode/main.go
+++ b/cmd/wnode/main.go
@@ -86,6 +86,7 @@ var (
asymmetricMode = flag.Bool("asym", false, "use asymmetric encryption")
generateKey = flag.Bool("generatekey", false, "generate and show the private key")
fileExMode = flag.Bool("fileexchange", false, "file exchange mode")
+ fileReader = flag.Bool("filereader", false, "load and decrypt messages saved as files, display as plain text")
testMode = flag.Bool("test", false, "use of predefined parameters for diagnostics (password, etc.)")
echoMode = flag.Bool("echo", false, "echo mode: prints some arguments for diagnostics")
@@ -433,6 +434,8 @@ func run() {
requestExpiredMessagesLoop()
} else if *fileExMode {
sendFilesLoop()
+ } else if *fileReader {
+ fileReaderLoop()
} else {
sendLoop()
}
@@ -483,6 +486,40 @@ func sendFilesLoop() {
}
}
+func fileReaderLoop() {
+ watcher1 := shh.GetFilter(symFilterID)
+ watcher2 := shh.GetFilter(asymFilterID)
+ if watcher1 == nil && watcher2 == nil {
+ fmt.Println("Error: neither symmetric nor asymmetric filter is installed")
+ close(done)
+ return
+ }
+
+ for {
+ s := scanLine("")
+ if s == quitCommand {
+ fmt.Println("Quit command received")
+ close(done)
+ return
+ }
+ raw, err := ioutil.ReadFile(s)
+ if err != nil {
+ fmt.Printf(">>> Error: %s \n", err)
+ } else {
+ env := whisper.Envelope{Data: raw} // the topic is zero
+ msg := env.Open(watcher1) // force-open envelope regardless of the topic
+ if msg == nil {
+ msg = env.Open(watcher2)
+ }
+ if msg == nil {
+ fmt.Printf(">>> Error: failed to decrypt the message \n")
+ } else {
+ printMessageInfo(msg)
+ }
+ }
+ }
+}
+
func scanLine(prompt string) string {
if len(prompt) > 0 {
fmt.Print(prompt)
diff --git a/whisper/whisperv6/envelope.go b/whisper/whisperv6/envelope.go
index 2c80d47bc..2f947f1a4 100644
--- a/whisper/whisperv6/envelope.go
+++ b/whisper/whisperv6/envelope.go
@@ -208,6 +208,10 @@ func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error) {
// Open tries to decrypt an envelope, and populates the message fields in case of success.
func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage) {
+ if watcher == nil {
+ return nil
+ }
+
// The API interface forbids filters doing both symmetric and asymmetric encryption.
if watcher.expectsAsymmetricEncryption() && watcher.expectsSymmetricEncryption() {
return nil