You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

  1. #!/usr/bin/env sh
  2. # Script to create certificate to qiniu.com
  3. #
  4. # This deployment required following variables
  5. # export QINIU_AK="QINIUACCESSKEY"
  6. # export QINIU_SK="QINIUSECRETKEY"
  7. QINIU_API_BASE="https://api.qiniu.com"
  8. qiniu_deploy() {
  9. _cdomain="$1"
  10. _ckey="$2"
  11. _ccert="$3"
  12. _cca="$4"
  13. _cfullchain="$5"
  14. _debug _cdomain "$_cdomain"
  15. _debug _ckey "$_ckey"
  16. _debug _ccert "$_ccert"
  17. _debug _cca "$_cca"
  18. _debug _cfullchain "$_cfullchain"
  19. if [ -z "$QINIU_AK" ]; then
  20. if [ -z "$Le_Deploy_Qiniu_AK" ]; then
  21. _err "QINIU_AK is not defined."
  22. return 1
  23. fi
  24. else
  25. Le_Deploy_Qiniu_AK="$QINIU_AK"
  26. _savedomainconf Le_Deploy_Qiniu_AK "$Le_Deploy_Qiniu_AK"
  27. fi
  28. if [ -z "$QINIU_SK" ]; then
  29. if [ -z "$Le_Deploy_Qiniu_SK" ]; then
  30. _err "QINIU_SK is not defined."
  31. return 1
  32. fi
  33. else
  34. Le_Deploy_Qiniu_SK="$QINIU_SK"
  35. _savedomainconf Le_Deploy_Qiniu_SK "$Le_Deploy_Qiniu_SK"
  36. fi
  37. string_fullchain=$(awk '{printf "%s\\n", $0}' "$_cfullchain")
  38. string_key=$(awk '{printf "%s\\n", $0}' "$_ckey")
  39. body="{\"name\":\"$_cdomain\",\"common_name\":\"$_cdomain\",\"ca\":\""$string_fullchain"\",\"pri\":\"$string_key\"}"
  40. create_ssl_url="$QINIU_API_BASE/sslcert"
  41. ACCESSTOKEN="$(_make_sslcreate_access_token)"
  42. export _H1="Authorization: QBox $ACCESSTOKEN"
  43. _response=$(_post "$body" "$create_ssl_url" 0 "POST" "application/json" | _dbase64 "multiline")
  44. success_response="certID"
  45. if test "${_response#*$success_response}" == "$_response"; then
  46. _err "Error in deploying certificate:"
  47. _err "$_response"
  48. return 1
  49. fi
  50. _debug response "$_response"
  51. _info "Certificate successfully deployed"
  52. return 0
  53. }
  54. _make_sslcreate_access_token() {
  55. _data="/sslcert\\n"
  56. _token="$(printf "$_data" | openssl sha1 -hmac $Le_Deploy_Qiniu_SK -binary | openssl base64 -e)"
  57. echo "$Le_Deploy_Qiniu_AK:$_token"
  58. }