summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Rhymen/go-whatsapp/read.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-08-26 23:22:34 +0200
committerGitHub <noreply@github.com>2019-08-26 23:22:34 +0200
commitd525f1c9e4ac39b74575052b61c4de72de794b4e (patch)
tree90f444dd4046c7d29ed08c005648c573deb484b2 /vendor/github.com/Rhymen/go-whatsapp/read.go
parent921f2dfcdf1a6263220b55eb55716e497373dfcf (diff)
downloadmatterbridge-msglm-d525f1c9e4ac39b74575052b61c4de72de794b4e.tar.gz
matterbridge-msglm-d525f1c9e4ac39b74575052b61c4de72de794b4e.tar.bz2
matterbridge-msglm-d525f1c9e4ac39b74575052b61c4de72de794b4e.zip
Update Rhymen/go-whatsapp vendor (#876)
Diffstat (limited to 'vendor/github.com/Rhymen/go-whatsapp/read.go')
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/read.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/read.go b/vendor/github.com/Rhymen/go-whatsapp/read.go
index 7281ccff..42d91ff4 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/read.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/read.go
@@ -3,6 +3,8 @@ package whatsapp
import (
"crypto/hmac"
"crypto/sha256"
+ "encoding/json"
+ "fmt"
"github.com/Rhymen/go-whatsapp/binary"
"github.com/Rhymen/go-whatsapp/crypto/cbc"
"github.com/gorilla/websocket"
@@ -75,7 +77,13 @@ func (wac *Conn) processReadData(msgType int, msg []byte) error {
wac.listener.Lock()
delete(wac.listener.m, data[0])
wac.listener.Unlock()
- } else if msgType == websocket.BinaryMessage && wac.loggedIn {
+ } else if msgType == websocket.BinaryMessage {
+ wac.loginSessionLock.RLock()
+ sess := wac.session
+ wac.loginSessionLock.RUnlock()
+ if sess == nil || sess.MacKey == nil || sess.EncKey == nil {
+ return ErrInvalidWsState
+ }
message, err := wac.decryptBinaryMessage([]byte(data[1]))
if err != nil {
return errors.Wrap(err, "error decoding binary")
@@ -90,6 +98,21 @@ func (wac *Conn) processReadData(msgType int, msg []byte) error {
func (wac *Conn) decryptBinaryMessage(msg []byte) (*binary.Node, error) {
//message validation
h2 := hmac.New(sha256.New, wac.session.MacKey)
+ if len(msg) < 33 {
+ var response struct {
+ Status int `json:"status"`
+ }
+ err := json.Unmarshal(msg, &response)
+ if err == nil {
+ if response.Status == 404 {
+ return nil, ErrServerRespondedWith404
+ }
+ return nil, errors.New(fmt.Sprintf("server responded with %d", response.Status))
+ } else {
+ return nil, ErrInvalidServerResponse
+ }
+
+ }
h2.Write([]byte(msg[32:]))
if !hmac.Equal(h2.Sum(nil), msg[:32]) {
return nil, ErrInvalidHmac