diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2010-10-12 21:12:16 -0700 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2010-10-12 21:12:16 -0700 |
commit | 1e2bae61cda7b2556c5185dcd22e9991ef4a8222 (patch) | |
tree | 23a3945fa13e2cdd252169d46c8522264b74b353 /src | |
parent | 56b1eff3f66be2364df9cdbe4b930255ae46a703 (diff) |
Changed remote-peer-struct:public-key to remote-peer-struct:public-key-atom
in order to resolve a identity/value confusion.
Diffstat (limited to 'src')
-rw-r--r-- | src/org/gnu/clojure/gnunet/core.clj | 22 | ||||
-rw-r--r-- | src/org/gnu/clojure/gnunet/peer.clj | 6 | ||||
-rw-r--r-- | src/org/gnu/clojure/gnunet/transport.clj | 51 |
3 files changed, 40 insertions, 39 deletions
diff --git a/src/org/gnu/clojure/gnunet/core.clj b/src/org/gnu/clojure/gnunet/core.clj index f3e77e3..9c6c0df 100644 --- a/src/org/gnu/clojure/gnunet/core.clj +++ b/src/org/gnu/clojure/gnunet/core.clj @@ -32,17 +32,17 @@ (defn handle-set-key! [peer remote-peer message] - (when-let [set-key (first (parse-set-key (:bytes message)))] - (cond - (not (= (:peer-id set-key) (seq (:id peer)))) (.write *out* "SET_KEY not for me\n") - (not (rsa-verify (:public-key remote-peer) - (:signed-material set-key) - (:signature set-key))) (.write *out* "SET_KEY invalid signature\n") - :else (do (.write *out* "Set key message ") - (.write *out* (.toString set-key)) - (.write *out* "\n")) - ) - )) + (when-let [public-key (deref (:public-key-atom remote-peer))] + (when-let [set-key (first (parse-set-key (:bytes message)))] + (cond + (not (= (:peer-id set-key) (seq (:id peer)))) (.write *out* "SET_KEY not for me\n") + (not (rsa-verify public-key + (:signed-material set-key) + (:signature set-key))) (.write *out* "SET_KEY invalid signature\n") + :else (do (.write *out* "Set key message ") + (.write *out* (.toString set-key)) + (.write *out* "\n")) + )))) (defn handle-receive! [peer remote-peer message] diff --git a/src/org/gnu/clojure/gnunet/peer.clj b/src/org/gnu/clojure/gnunet/peer.clj index 4118449..7845320 100644 --- a/src/org/gnu/clojure/gnunet/peer.clj +++ b/src/org/gnu/clojure/gnunet/peer.clj @@ -5,8 +5,8 @@ java.security.SecureRandom)) (defstruct remote-peer-struct - ;; java.security.PublicKey - :public-key + ;; atom of java.security.PublicKey + :public-key-atom ;; 64 byte (512-bit) sequence :id @@ -67,7 +67,7 @@ (let [selector (Selector/open) continuations (ConcurrentLinkedQueue.)] (struct-map peer-struct - :public-key (.getPublic (:keypair options)) + :public-key-atom (atom (.getPublic (:keypair options))) :id (generate-id (.getPublic (:keypair options))) :transport-addresses-agent (agent {}) :private-key (.getPrivate (:keypair options)) diff --git a/src/org/gnu/clojure/gnunet/transport.clj b/src/org/gnu/clojure/gnunet/transport.clj index e6c60ea..2a83bdc 100644 --- a/src/org/gnu/clojure/gnunet/transport.clj +++ b/src/org/gnu/clojure/gnunet/transport.clj @@ -131,7 +131,7 @@ [peer] {:message-type message-type-hello :bytes (encode-hello - {:public-key (:public-key peer) + {:public-key (deref (:public-key-atom peer)) :transport-addresses (list-transport-addresses (deref (:transport-addresses-agent peer)))})}) @@ -155,16 +155,16 @@ (let [remote-peer (remote-peers peer-id)] (if remote-peer (do + (if (:public-key hello) + (swap! (:public-key-atom remote-peer) + #(if (nil? %) (:public-key hello)))) (send (:transport-addresses-agent remote-peer) update-transport-addresses (:transport-addresses hello)) - (if (:public-key remote-peer) - remote-peers - (assoc remote-peers peer-id - (assoc remote-peer :public-key (:public-key hello))))) + remote-peers) (assoc remote-peers peer-id (struct-map remote-peer-struct - :public-key (:public-key hello) + :public-key-atom (atom (:public-key hello)) :id peer-id :transport-addresses-agent (agent (merge-transport-addresses {} @@ -255,25 +255,26 @@ (defn check-pending-validation [addresses remote-peer pong] - (if-let [transport (addresses (:transport pong))] - (if-let [address (transport (:encoded-address pong))] - (cond - (not (= (:challenge address) (:challenge pong))) - addresses - (= signature-purpose-pong-own (:signature-purpose pong)) - (if (rsa-verify (:public-key remote-peer) - (:signed-material pong) - (:signature pong)) - (assoc addresses (:transport pong) - (assoc transport (:encoded-address pong) - {:expiration (hello-address-expiration) - :latency (- (.getTime (Date.)) - (.getTime (:send-time address)))})) - addresses) - (= signature-purpose-pong-using (:signature-purpose pong)) - ;; TODO - fill in this case - addresses - :else addresses) + (if-let [public-key (deref (:public-key-atom remote-peer))] + (if-let [transport (addresses (:transport pong))] + (if-let [address (transport (:encoded-address pong))] + (cond + (not (= (:challenge address) (:challenge pong))) addresses + (= signature-purpose-pong-own (:signature-purpose pong)) + (if (rsa-verify public-key + (:signed-material pong) + (:signature pong)) + (assoc addresses (:transport pong) + (assoc transport (:encoded-address pong) + {:expiration (hello-address-expiration) + :latency (- (.getTime (Date.)) + (.getTime (:send-time address)))})) + addresses) + (= signature-purpose-pong-using (:signature-purpose pong)) + ;; TODO - fill in this case + addresses + :else addresses) + addresses) addresses) addresses)) |