yada

2018-06-21T16:55:43.000232Z

Has anyone been playing with yada and github hooks already? I am not able to compute the hmac as described here https://developer.github.com/webhooks/securing/ I don’t know if my method of getting the body is correct. I tried: - json/stringify the body parsed by yada it doesn’t seem to work - making an interceptor to get the raw bytes

(insert-interceptor
       (yada/handler
         (yada/resource
           {:methods
            {:post
             {:consumes consumes
              :produces produces
              :response hook-handler}}}))
       yada.interceptors/process-request-body (fn [ctx]
(if-let [gh-sig (get-in ctx [:request :headers "x-hub-signature"])]
  (let [raw-body (manifold.stream/take! (:body (:request ctx)))]
    ;; will need to put! it back?
    (let [body @raw-body
          ba (byte-array (.readableBytes body))
          by (.getBytes (.retainedDuplicate @raw-body) 0 ba)]
      (println (hmac
                 by
                 gh-sig)))

    ctx)
  ctx)
   )
So maybe my attempts at computing the sha1 are wrong? I’ve been trying from these sources (it seems to be working with compojure) : - https://gist.github.com/ska2342/4567b02531ff611db6a1208ebd4316e6 - https://clojurians-log.clojureverse.org/ring/2016-07-24 - https://stackoverflow.com/questions/31729163/clojure-or-java-equivalent-to-rubys-hmac-hexdigest So.. anyone already played with Yada and github hooks?

danielcompton 2018-06-21T22:18:58.000146Z

Don't have any specific experience there, but you'll want to be careful about ordering of the keys in the JSON payload

danielcompton 2018-06-21T22:19:22.000393Z

If they are parsed by Yada into a Clojure data structure and then converted back then you may not get the same order

danielcompton 2018-06-21T22:20:18.000232Z

But that's not really what you're doing there

danielcompton 2018-06-21T22:21:18.000086Z

@nha I think you need to be calculating the HMAC based on the bytes that GitHub is giving you and the secret key that you've set

danielcompton 2018-06-21T22:21:28.000406Z

And then you do a secure compare to compare that with X-Hub-Signature

danielcompton 2018-06-21T22:21:52.000282Z

You're calculating a HMAC using the X-Hub-Signature, which won't give you what you want