Skip to content

Commit

Permalink
correctly check all keys for decrypting
Browse files Browse the repository at this point in the history
  • Loading branch information
justone committed Feb 17, 2016
1 parent 07439d3 commit 31a3bd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api/pmb.go
Expand Up @@ -241,6 +241,8 @@ func parseKeys(keystring string) ([]string, error) {

if len(keys) == 0 {
return []string{}, fmt.Errorf("Auth key(s) invalid.")
} else {
logrus.Debugf("keys: %s", keys)
}

return keys, nil
Expand Down
6 changes: 4 additions & 2 deletions api/util.go
Expand Up @@ -123,7 +123,7 @@ func parseMessage(body []byte, keys []string, ch chan Message, id string) {
decrypted, err := decrypt([]byte(key), string(body))
if err != nil {
logrus.Warningf("Unable to decrypt message!")
return
continue
}

// check if message was decrypted into json
Expand All @@ -134,13 +134,14 @@ func parseMessage(body []byte, keys []string, ch chan Message, id string) {
// multiple keys exist, this will always print
// something, and it's not error worthy
logrus.Debugf("Unable to decrypt message (bad key)!")
return
continue
}

decryptedOk = true
logrus.Debugf("Successfully decrypted with %s...", key[0:10])
message = []byte(decrypted)
rawData = rd
break
}

if !decryptedOk {
Expand All @@ -149,6 +150,7 @@ func parseMessage(body []byte, keys []string, ch chan Message, id string) {

} else {
logrus.Warningf("Encrypted message and no key!")
return
}
} else {
message = body
Expand Down

0 comments on commit 31a3bd6

Please sign in to comment.