fix #1605 protocol message parser catches all invalid payload as errors
This commit is contained in:
parent
7a06bb8278
commit
a764da2b4b
|
@ -3,28 +3,37 @@
|
||||||
[status-im.protocol.ack :as ack]
|
[status-im.protocol.ack :as ack]
|
||||||
[status-im.protocol.web3.utils :as u]
|
[status-im.protocol.web3.utils :as u]
|
||||||
[status-im.protocol.encryption :as e]
|
[status-im.protocol.encryption :as e]
|
||||||
[taoensso.timbre :refer-macros [debug]]
|
[taoensso.timbre :as log]
|
||||||
[status-im.utils.hex :as i]))
|
[status-im.utils.hex :as i]))
|
||||||
|
|
||||||
|
(defn create-error [description]
|
||||||
|
(log/debug :parse-payload-error description)
|
||||||
|
{:error description})
|
||||||
|
|
||||||
(defn- parse-payload [payload]
|
(defn- parse-payload [payload]
|
||||||
(debug :parse-payload)
|
(log/debug :parse-payload)
|
||||||
(try
|
(try
|
||||||
;; todo figure why we have to call to-utf8 twice
|
;; todo figure why we have to call to-utf8 twice
|
||||||
(let [read (comp r/read-string u/to-utf8 u/to-utf8)]
|
(let [payload' (u/to-utf8 payload)
|
||||||
{:payload (read payload)})
|
payload'' (r/read-string payload')
|
||||||
|
payload''' (if (map? payload'')
|
||||||
|
payload''
|
||||||
|
(r/read-string (u/to-utf8 payload')))]
|
||||||
|
(if (map? payload''')
|
||||||
|
{:payload payload'''}
|
||||||
|
(create-error (str "Invalid payload type " (type payload''')))))
|
||||||
(catch :default err
|
(catch :default err
|
||||||
(debug :parse-payload-error err)
|
(create-error err))))
|
||||||
{:error err})))
|
|
||||||
|
|
||||||
(defn- decrypt [key content]
|
(defn- decrypt [key content]
|
||||||
(try
|
(try
|
||||||
{:content (r/read-string (e/decrypt key content))}
|
{:content (r/read-string (e/decrypt key content))}
|
||||||
(catch :default err
|
(catch :default err
|
||||||
(debug :decrypt-error err)
|
(log/debug :decrypt-error err)
|
||||||
{:error err})))
|
{:error err})))
|
||||||
|
|
||||||
(defn- parse-content [key {:keys [content]} was-encrypted?]
|
(defn- parse-content [key {:keys [content]} was-encrypted?]
|
||||||
(debug :parse-content
|
(log/debug :parse-content
|
||||||
"Key exists:" (not (nil? key))
|
"Key exists:" (not (nil? key))
|
||||||
"Content exists:" (not (nil? content)))
|
"Content exists:" (not (nil? content)))
|
||||||
(if (and (not was-encrypted?) key content)
|
(if (and (not was-encrypted?) key content)
|
||||||
|
@ -36,9 +45,9 @@
|
||||||
(fn [error js-message]
|
(fn [error js-message]
|
||||||
;; todo handle error
|
;; todo handle error
|
||||||
(when error
|
(when error
|
||||||
(debug :listener-error error))
|
(log/debug :listener-error error))
|
||||||
(when-not error
|
(when-not error
|
||||||
(debug :message-received (js->clj js-message))
|
(log/debug :message-received (js->clj js-message))
|
||||||
(let [{:keys [sig payload recipientPublicKey] :as message}
|
(let [{:keys [sig payload recipientPublicKey] :as message}
|
||||||
(js->clj js-message :keywordize-keys true)
|
(js->clj js-message :keywordize-keys true)
|
||||||
|
|
||||||
|
@ -56,7 +65,7 @@
|
||||||
(not= "" recipientPublicKey)
|
(not= "" recipientPublicKey)
|
||||||
(not (nil? recipientPublicKey))))]
|
(not (nil? recipientPublicKey))))]
|
||||||
(if error
|
(if error
|
||||||
(debug :failed-to-handle-message error)
|
(log/debug :failed-to-handle-message error)
|
||||||
(let [payload'' (assoc payload' :content content)
|
(let [payload'' (assoc payload' :content content)
|
||||||
message' (assoc message :payload payload''
|
message' (assoc message :payload payload''
|
||||||
:to recipientPublicKey
|
:to recipientPublicKey
|
||||||
|
|
Loading…
Reference in New Issue