signature_does_not_match_wrapper.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package errors
  2. import (
  3. "strings"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils"
  5. )
  6. const SignatureDostNotMatchErrorCode = "SignatureDoesNotMatch"
  7. const MessagePrefix = "Specified signature is not matched with our calculation. server string to sign is:"
  8. var debug utils.Debug
  9. func init() {
  10. debug = utils.Init("sdk")
  11. }
  12. type SignatureDostNotMatchWrapper struct {
  13. }
  14. func (*SignatureDostNotMatchWrapper) tryWrap(error *ServerError, wrapInfo map[string]string) (ok bool) {
  15. clientStringToSign := wrapInfo["StringToSign"]
  16. if error.errorCode == SignatureDostNotMatchErrorCode && clientStringToSign != "" {
  17. message := error.message
  18. if strings.HasPrefix(message, MessagePrefix) {
  19. serverStringToSign := message[len(MessagePrefix):]
  20. if clientStringToSign == serverStringToSign {
  21. // user secret is error
  22. error.recommend = "Please check you AccessKeySecret"
  23. } else {
  24. debug("Client StringToSign: %s", clientStringToSign)
  25. debug("Server StringToSign: %s", serverStringToSign)
  26. error.recommend = "This may be a bug with the SDK and we hope you can submit this question in the " +
  27. "github issue(https://github.com/aliyun/alibaba-cloud-sdk-go/issues), thanks very much"
  28. }
  29. }
  30. ok = true
  31. return
  32. }
  33. ok = false
  34. return
  35. }