don't attempt to decrypt group msg if key has been removed

This commit is contained in:
michaelr 2016-04-11 22:58:31 +03:00
parent 8a1d690518
commit 5d3d511905
2 changed files with 14 additions and 11 deletions

View File

@ -59,8 +59,8 @@
:new-group-chat [from group-id] :new-group-chat [from group-id]
:group-chat-invite-acked [ack-msg-id from group-id] :group-chat-invite-acked [ack-msg-id from group-id]
:group-new-participant [identity group-id from msg-id] :group-new-participant [identity group-id from msg-id]
:group-removed-participant [from identity group-id] :group-removed-participant [from identity group-id msg-id]
:removed-from-group [from group-id] :removed-from-group [from group-id msg-id]
:participant-left-group [from group-id] :participant-left-group [from group-id]
:initialized [identity] :initialized [identity]

View File

@ -72,11 +72,11 @@
:group-id group-topic})))) :group-id group-topic}))))
(defn decrypt-group-msg [group-topic encrypted-payload] (defn decrypt-group-msg [group-topic encrypted-payload]
(let [store (storage) (let [store (storage)]
{private-key :private} (get-keypair store group-topic)] (when-let [{private-key :private} (get-keypair store group-topic)]
(-> (decrypt private-key encrypted-payload) (-> (decrypt private-key encrypted-payload)
(read-string) (read-string)
(assoc :group-topic group-topic)))) (assoc :group-topic group-topic)))))
(defn handle-group-user-msg [web3 from {:keys [msg-id group-topic] :as payload}] (defn handle-group-user-msg [web3 from {:keys [msg-id group-topic] :as payload}]
(send-ack web3 from msg-id) (send-ack web3 from msg-id)
@ -107,7 +107,8 @@
(remove-identity store group-topic removed-identity) (remove-identity store group-topic removed-identity)
(invoke-user-handler :group-removed-participant {:identity removed-identity (invoke-user-handler :group-removed-participant {:identity removed-identity
:group-id group-topic :group-id group-topic
:from from}))) :from from
:msg-id msg-id})))
(log/warn "Ignoring group-removed-participant for group" group-topic "from a non group-admin user" from)))) (log/warn "Ignoring group-removed-participant for group" group-topic "from a non group-admin user" from))))
(defn handle-removed-from-group [web3 from {:keys [group-topic msg-id]}] (defn handle-removed-from-group [web3 from {:keys [group-topic msg-id]}]
@ -119,7 +120,8 @@
(remove-group-data store group-topic) (remove-group-data store group-topic)
(stop-listener group-topic) (stop-listener group-topic)
(invoke-user-handler :removed-from-group {:group-id group-topic (invoke-user-handler :removed-from-group {:group-id group-topic
:from from}))) :from from
:msg-id msg-id})))
(log/warn "Ignoring removed-from-group for group" group-topic "from a non group-admin user" from)))) (log/warn "Ignoring removed-from-group for group" group-topic "from a non group-admin user" from))))
(defn handle-participant-left-group [web3 from {:keys [group-topic msg-id]}] (defn handle-participant-left-group [web3 from {:keys [group-topic msg-id]}]
@ -131,11 +133,12 @@
:from from})))) :from from}))))
(defn handle-group-msg [web3 msg-type from {:keys [enc-payload group-topic]}] (defn handle-group-msg [web3 msg-type from {:keys [enc-payload group-topic]}]
(let [payload (decrypt-group-msg group-topic enc-payload)] (if-let [payload (decrypt-group-msg group-topic enc-payload)]
(case msg-type (case msg-type
:group-user-msg (handle-group-user-msg web3 from payload) :group-user-msg (handle-group-user-msg web3 from payload)
:group-new-participant (handle-group-new-participant web3 from payload) :group-new-participant (handle-group-new-participant web3 from payload)
:left-group (handle-participant-left-group web3 from payload)))) :left-group (handle-participant-left-group web3 from payload))
(log/debug "Could not decrypt group msg, possibly you've left the group.")))
(defn handle-incoming-whisper-msg [web3 msg] (defn handle-incoming-whisper-msg [web3 msg]
(log/info "Got whisper message:" msg) (log/info "Got whisper message:" msg)