【问题标题】:Emulate github hook with curl with secret使用带有秘密的 curl 模拟 github 钩子
【发布时间】:2016-02-19 13:02:16
【问题描述】:

我有类似Emulate github service hooks wih curl 的需求,但我也在我的 webhook 中使用了一个秘密,它不能正常工作。

这是我作为接收后挂钩所做的事情:

#!/bin/bash

while read oldrev newrev refname; do
  tmpfile=$(mktemp --suffix=.json)

  cat << EOF > $tmpfile
  {
    "ref": "${refname}"
  }
EOF

  sig=$(cat "${tmpfile}" | openssl dgst -sha1 -hmac "${WEBHOOK_SECRET}" | awk '{print "X-Hub-Signature: sha1="$2}')

  curl -X POST -H "Content-Type: application/json" -H "${sig}" --data-urlencode "payload@${tmpfile}" http://webhook:9000/hooks/r10k

  rm -f "${tmpfile}"
done

webhook(与 github 配合使用)抱怨签名错误。

我做错了什么?

【问题讨论】:

    标签: curl github openssl hmac webhooks


    【解决方案1】:

    问题来自 openssl 命令中输入流末尾的回车。

    我改成了这个:

    #!/bin/bash
    
    while read oldrev newrev refname; do
      tmpfile=$(mktemp --suffix=.json)
    
      data="{\"ref\": \"${refname}\"}"
    
      sig=$(echo -n "${data}" | openssl dgst -sha1 -hmac "%{WEBHOOK_SECRET}" | awk '{print "X-Hub-Signature: sha1="$2}')
    
      curl -X POST -H "Content-Type: application/json" -H "${sig}" --data "${data}" http://webhook:9000/hooks/r10k
    
      rm -f "${tmpfile}"
    done
    

    它成功了。

    【讨论】:

      猜你喜欢
      • 2019-05-13
      • 2021-12-02
      • 1970-01-01
      • 2020-01-26
      • 2022-08-18
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      • 2021-03-27
      相关资源
      最近更新 更多