Skip to content

Commit

Permalink
Add back shh.identityfile removed in c06d58a. Part of #692
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Pombeiro committed Feb 23, 2018
1 parent 741422a commit 6432aa8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/statusd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
// don't change the name of this flag, https://github.com/ethereum/go-ethereum/blob/master/metrics/metrics.go#L41
_ = flag.Bool("metrics", false, "Expose ethereum metrics with debug_metrics jsonrpc call.")
// shh stuff
identityFile = flag.String("shh.identityfile", "", "Protocol identity file (private key used for asymmetric encryption)")
passwordFile = flag.String("shh.passwordfile", "", "Password file (password is used for symmetric encryption)")
minPow = flag.Float64("shh.pow", params.WhisperMinimumPoW, "PoW for messages to be added to queue, in float format")
ttl = flag.Int("shh.ttl", params.WhisperTTL, "Time to live for messages, in seconds")
Expand Down
7 changes: 7 additions & 0 deletions cmd/statusd/whispercfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ import (
func whisperConfig(nodeConfig *params.NodeConfig) (*params.NodeConfig, error) {
whisperConfig := nodeConfig.WhisperConfig
whisperConfig.Enabled = true
whisperConfig.IdentityFile = *identityFile
whisperConfig.EnableMailServer = *enableMailServer
whisperConfig.MinimumPoW = *minPow
whisperConfig.TTL = *ttl

if whisperConfig.IdentityFile != "" {
if _, err := whisperConfig.ReadIdentityFile(); err != nil {
return nil, fmt.Errorf("read identity file: %v", err)
}
}

if whisperConfig.EnableMailServer {
if *passwordFile == "" {
return nil, errors.New("passwordfile should be specified if MailServer is enabled")
Expand Down
26 changes: 26 additions & 0 deletions geth/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package params

import (
"bytes"
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
Expand All @@ -11,6 +12,7 @@ import (
"strings"

"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/status-im/status-go/geth/log"
"github.com/status-im/status-go/static"
)
Expand All @@ -33,6 +35,8 @@ var (
ErrMissingNetworkID = errors.New("missing required 'NetworkID' parameter")
ErrEmptyPasswordFile = errors.New("password file cannot be empty")
ErrNoPasswordFileValueSet = errors.New("password file path not set")
ErrNoIdentityFileValueSet = errors.New("identity file path not set")
ErrEmptyIdentityFile = errors.New("identity file cannot be empty")
ErrEmptyAuthorizationKeyFile = errors.New("authorization key file cannot be empty")
ErrAuthorizationKeyFileNotSet = errors.New("authorization key file is not set")
)
Expand Down Expand Up @@ -84,6 +88,10 @@ type WhisperConfig struct {
// Enabled flag specifies whether protocol is enabled
Enabled bool

// IdentityFile path to private key, that will be loaded as identity into Whisper.
// Currently, it's used by Push Notification service.
IdentityFile string

// PasswordFile contains a password for symmetric encryption with MailServer.
PasswordFile string

Expand Down Expand Up @@ -129,6 +137,24 @@ func (c *WhisperConfig) ReadPasswordFile() error {
return nil
}

// ReadIdentityFile reads and loads identity private key
func (c *WhisperConfig) ReadIdentityFile() (*ecdsa.PrivateKey, error) {
if len(c.IdentityFile) == 0 {
return nil, ErrNoIdentityFileValueSet
}

identity, err := crypto.LoadECDSA(c.IdentityFile)
if err != nil {
return nil, err
}

if identity == nil {
return nil, ErrEmptyIdentityFile
}

return identity, nil
}

// String dumps config object as nicely indented JSON
func (c *WhisperConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ") // nolint: gas
Expand Down
6 changes: 3 additions & 3 deletions static/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6432aa8

Please sign in to comment.