whisper: down cased error messages

This commit is contained in:
Vlad 2017-03-28 16:35:06 +02:00
parent 85973778c7
commit 2eec953e47
5 changed files with 20 additions and 50 deletions

View file

@ -138,18 +138,6 @@ func (api *PublicWhisperAPI) GetPublicKey(id string) (hexutil.Bytes, error) {
return crypto.FromECDSAPub(&key.PublicKey), nil return crypto.FromECDSAPub(&key.PublicKey), nil
} }
// todo: delete is tests pass
//func (api *PublicWhisperAPI) GetPublicKey(id string) (string, error) {
// if api.whisper == nil {
// return "", whisperOffLineErr
// }
// key, err := api.whisper.GetPrivateKey(id)
// if err != nil {
// return "", err
// }
// return common.ToHex(crypto.FromECDSAPub(&key.PublicKey)), nil
//}
// GetPrivateKey returns the private key for identity id // GetPrivateKey returns the private key for identity id
func (api *PublicWhisperAPI) GetPrivateKey(id string) (string, error) { func (api *PublicWhisperAPI) GetPrivateKey(id string) (string, error) {
if api.whisper == nil { if api.whisper == nil {
@ -209,20 +197,6 @@ func (api *PublicWhisperAPI) GetSymmetricKey(name string) (hexutil.Bytes, error)
return b, nil return b, nil
} }
// todo: delete if tests pass
//func (api *PublicWhisperAPI) GetSymmetricKey(name string) (string, error) {
// if api.whisper == nil {
// return "", whisperOffLineErr
// }
//
// b, err := api.whisper.GetSymKey(name)
// if err != nil {
// return "", err
// }
// //return fmt.Sprintf("%x", b), nil // todo: delete if tests pass
// return common.ToHex(b), nil
//}
// DeleteSymmetricKey deletes the key associated with the name string if it exists. // DeleteSymmetricKey deletes the key associated with the name string if it exists.
func (api *PublicWhisperAPI) DeleteSymmetricKey(name string) (bool, error) { func (api *PublicWhisperAPI) DeleteSymmetricKey(name string) (bool, error) {
if api.whisper == nil { if api.whisper == nil {

View file

@ -120,7 +120,7 @@ func (e *Envelope) Seal(options *MessageParams) error {
} }
if target > 0 && bestBit < target { if target > 0 && bestBit < target {
return fmt.Errorf("Failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime) return fmt.Errorf("failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime)
} }
return nil return nil

View file

@ -168,7 +168,7 @@ func (msg *SentMessage) sign(key *ecdsa.PrivateKey) error {
// encryptAsymmetric encrypts a message with a public key. // encryptAsymmetric encrypts a message with a public key.
func (msg *SentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error { func (msg *SentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
if !ValidatePublicKey(key) { if !ValidatePublicKey(key) {
return fmt.Errorf("Invalid public key provided for asymmetric encryption") return fmt.Errorf("invalid public key provided for asymmetric encryption")
} }
encrypted, err := ecies.Encrypt(crand.Reader, ecies.ImportECDSAPublic(key), msg.Raw, nil, nil) encrypted, err := ecies.Encrypt(crand.Reader, ecies.ImportECDSAPublic(key), msg.Raw, nil, nil)
if err == nil { if err == nil {
@ -238,7 +238,7 @@ func (msg *SentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er
} else if options.KeySym != nil { } else if options.KeySym != nil {
salt, nonce, err = msg.encryptSymmetric(options.KeySym) salt, nonce, err = msg.encryptSymmetric(options.KeySym)
} else { } else {
err = errors.New("Unable to encrypt the message: neither Dst nor Key") err = errors.New("unable to encrypt the message: neither symmetric nor assymmmetric key provided")
} }
if err != nil { if err != nil {
@ -270,7 +270,7 @@ func (msg *ReceivedMessage) decryptSymmetric(key []byte, salt []byte, nonce []by
return err return err
} }
if len(nonce) != aesgcm.NonceSize() { if len(nonce) != aesgcm.NonceSize() {
info := fmt.Sprintf("Wrong AES nonce size - want: %d, got: %d", len(nonce), aesgcm.NonceSize()) info := fmt.Sprintf("wrong AES nonce size - want: %d, got: %d", len(nonce), aesgcm.NonceSize())
log.Error(info) log.Error(info)
return errors.New(info) return errors.New(info)
} }
@ -342,7 +342,7 @@ func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey {
pub, err := crypto.SigToPub(msg.hash(), msg.Signature) pub, err := crypto.SigToPub(msg.hash(), msg.Signature)
if err != nil { if err != nil {
log.Error(fmt.Sprintf("Could not get public key from signature: %v", err)) log.Error(fmt.Sprintf("could not get public key from signature: %v", err))
return nil return nil
} }
return pub return pub

View file

@ -120,9 +120,6 @@ func initialize(t *testing.T) {
topics = append(topics, sharedTopic) topics = append(topics, sharedTopic)
f := Filter{KeySym: sharedKey} f := Filter{KeySym: sharedKey}
f.Topics = [][]byte{topics[0][:]} f.Topics = [][]byte{topics[0][:]}
// todo: delete if pass
//f.Topics = make([][]byte, 1)
//f.Topics[0] = topics[0][:]
node.filerId, err = node.shh.Watch(&f) node.filerId, err = node.shh.Watch(&f)
if err != nil { if err != nil {
t.Fatalf("failed to install the filter: %s.", err) t.Fatalf("failed to install the filter: %s.", err)

View file

@ -132,7 +132,7 @@ func (w *Whisper) Version() uint {
// SetMaxMessageLength sets the maximal message length allowed by this node // SetMaxMessageLength sets the maximal message length allowed by this node
func (w *Whisper) SetMaxMessageLength(val int) error { func (w *Whisper) SetMaxMessageLength(val int) error {
if val <= 0 { if val <= 0 {
return fmt.Errorf("Invalid message length: %d", val) return fmt.Errorf("invalid message length: %d", val)
} }
w.maxMsgLength = val w.maxMsgLength = val
return nil return nil
@ -141,7 +141,7 @@ func (w *Whisper) SetMaxMessageLength(val int) error {
// SetMinimumPoW sets the minimal PoW required by this node // SetMinimumPoW sets the minimal PoW required by this node
func (w *Whisper) SetMinimumPoW(val float64) error { func (w *Whisper) SetMinimumPoW(val float64) error {
if val <= 0.0 { if val <= 0.0 {
return fmt.Errorf("Invalid PoW: %f", val) return fmt.Errorf("invalid PoW: %f", val)
} }
w.minPoW = val w.minPoW = val
return nil return nil
@ -190,7 +190,6 @@ func (w *Whisper) SendP2PMessage(peerID []byte, envelope *Envelope) error {
if err != nil { if err != nil {
return err return err
} }
//return p2p.Send(p.ws, p2pCode, envelope) // todo: delete if tests pass
return w.SendP2PDirect(p, envelope) return w.SendP2PDirect(p, envelope)
} }
@ -210,19 +209,19 @@ func (w *Whisper) NewKeyPair() (string, error) {
return "", err return "", err
} }
if !validatePrivateKey(key) { if !validatePrivateKey(key) {
return "", fmt.Errorf("Failed to generate valid key") return "", fmt.Errorf("failed to generate valid key")
} }
id, err := GenerateRandomID() id, err := GenerateRandomID()
if err != nil { if err != nil {
return "", fmt.Errorf("Failed to generate ID: %s", err) return "", fmt.Errorf("failed to generate ID: %s", err)
} }
w.keyMu.Lock() w.keyMu.Lock()
defer w.keyMu.Unlock() defer w.keyMu.Unlock()
if w.privateKeys[id] != nil { if w.privateKeys[id] != nil {
return "", fmt.Errorf("Failed to generate unique ID") return "", fmt.Errorf("failed to generate unique ID")
} }
w.privateKeys[id] = key w.privateKeys[id] = key
return id, nil return id, nil
@ -254,7 +253,7 @@ func (w *Whisper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error) {
defer w.keyMu.RUnlock() defer w.keyMu.RUnlock()
key := w.privateKeys[id] key := w.privateKeys[id]
if key == nil { if key == nil {
return nil, fmt.Errorf("GetPrivateKey: invalid id") return nil, fmt.Errorf("invalid id")
} }
return key, nil return key, nil
} }
@ -282,14 +281,14 @@ func (w *Whisper) GenerateSymKey() (string, error) {
id, err := GenerateRandomID() id, err := GenerateRandomID()
if err != nil { if err != nil {
return "", fmt.Errorf("Failed to generate ID: %s", err) return "", fmt.Errorf("failed to generate ID: %s", err)
} }
w.keyMu.Lock() w.keyMu.Lock()
defer w.keyMu.Unlock() defer w.keyMu.Unlock()
if w.symKeys[id] != nil { if w.symKeys[id] != nil {
return "", fmt.Errorf("Failed to generate unique ID") return "", fmt.Errorf("failed to generate unique ID")
} }
w.symKeys[id] = derived w.symKeys[id] = derived
return id, nil return id, nil
@ -298,19 +297,19 @@ func (w *Whisper) GenerateSymKey() (string, error) {
// AddSymKeyDirect stores the key, and returns its id. // AddSymKeyDirect stores the key, and returns its id.
func (w *Whisper) AddSymKeyDirect(key []byte) (string, error) { func (w *Whisper) AddSymKeyDirect(key []byte) (string, error) {
if len(key) != aesKeyLength { if len(key) != aesKeyLength {
return "", fmt.Errorf("Wrong key size: %d", len(key)) return "", fmt.Errorf("wrong key size: %d", len(key))
} }
id, err := GenerateRandomID() id, err := GenerateRandomID()
if err != nil { if err != nil {
return "", fmt.Errorf("Failed to generate ID: %s", err) return "", fmt.Errorf("failed to generate ID: %s", err)
} }
w.keyMu.Lock() w.keyMu.Lock()
defer w.keyMu.Unlock() defer w.keyMu.Unlock()
if w.symKeys[id] != nil { if w.symKeys[id] != nil {
return "", fmt.Errorf("Failed to generate unique ID") return "", fmt.Errorf("failed to generate unique ID")
} }
w.symKeys[id] = key w.symKeys[id] = key
return id, nil return id, nil
@ -320,10 +319,10 @@ func (w *Whisper) AddSymKeyDirect(key []byte) (string, error) {
func (w *Whisper) AddSymKeyFromPassword(password string) (string, error) { func (w *Whisper) AddSymKeyFromPassword(password string) (string, error) {
id, err := GenerateRandomID() id, err := GenerateRandomID()
if err != nil { if err != nil {
return "", fmt.Errorf("Failed to generate ID: %s", err) return "", fmt.Errorf("failed to generate ID: %s", err)
} }
if w.HasSymKey(id) { if w.HasSymKey(id) {
return "", fmt.Errorf("Failed to generate unique ID") return "", fmt.Errorf("failed to generate unique ID")
} }
derived, err := deriveKeyMaterial([]byte(password), EnvelopeVersion) derived, err := deriveKeyMaterial([]byte(password), EnvelopeVersion)
@ -336,7 +335,7 @@ func (w *Whisper) AddSymKeyFromPassword(password string) (string, error) {
// double check is necessary, because deriveKeyMaterial() is very slow // double check is necessary, because deriveKeyMaterial() is very slow
if w.symKeys[id] != nil { if w.symKeys[id] != nil {
return "", fmt.Errorf("Severe error: failed to generate unique ID") return "", fmt.Errorf("critical error: failed to generate unique ID")
} }
w.symKeys[id] = derived w.symKeys[id] = derived
return id, nil return id, nil
@ -749,7 +748,7 @@ func (s *Statistics) reset() {
func ValidateKeyID(id string) error { func ValidateKeyID(id string) error {
const target = keyIdSize * 2 const target = keyIdSize * 2
if len(id) != target { if len(id) != target {
return fmt.Errorf("Wrong size of key ID (expected %d bytes, got %d)", target, len(id)) return fmt.Errorf("wrong size of key ID (expected %d bytes, got %d)", target, len(id))
} }
return nil return nil
} }