Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround V4 Signing problem #242

Merged
merged 1 commit into from
Oct 6, 2014

Conversation

masahide
Copy link
Contributor

@masahide masahide commented Oct 3, 2014

403 error occurs if the space is included in the message, etc.

        sns_client := sns.New(auth, aws.APNortheast)
        pubOpt := &sns.PublishOpt{
                Message:  "aa      a  hoge",
                Subject:  "SNS_Message",
                TopicArn: "xxxxxxxxxxxxxxxxxxxxxxxxx",
        }
        resp, err := sns_client.Publish(pubOpt)
        log.Printf("resp: %#v\n\n", resp)
        log.Printf("err: %#v\n\n", err)

Execution result of the above

2014/10/04 05:35:53 resp: &sns.PublishResp{MessageId:"", ResponseMetadata:sns.ResponseMetadata{RequestId:"", BoxUsage:0}}

2014/10/04 05:35:53 err: &sns.Error{StatusCode:403, Code:"", Message:"403 Forbidden", RequestId:"e2fe9215-bf24-508b-9c76-debcb490bc6a"}

The cause is believed to be a matter of "Signature Version 4 Signing"

http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html

The space character is a reserved character and must be encoded as "%20" (and not as "+").

but escape of net / url is
https://code.google.com/p/go/source/browse/src/pkg/net/url/url.go?name=go1.3beta1#198

           case c == ' ' && mode == encodeQueryComponent:
                   t[j] = '+'

I tried the implementation of replace "%20",
but the 403 error still occurred.
About this,
Because there is a possibility of the problem of AWS side of a combination of sns and V4 signing,
its problem inquiry to amazon is ongoing.

As a workaround
I was back port "V2 signing".

403 error occurs if the space is included in the message, etc.

This reverts commit a22710c.
@alimoeeny
Copy link
Contributor

@masahide thanks. I don't quite understand what is going on here. Is signing for SNS different from other AWS services? If not why not use and fix the one in goamz/aws ?

@ando-masaki
Copy link
Contributor

There are 2 probrems.

  1. The space character is a reserved character and must be encoded as "%20" (and not as "+").
    See: http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
  2. If the space characters in message, signature does not match.
    API retuens 403 forbidden error and following error message.
    "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."

@masahide
Copy link
Contributor Author

masahide commented Oct 6, 2014

@ando-masaki thanks.

@alimoeeny
Copy link
Contributor

Thanks @ando-masaki and @masahide , so basically the signing is different. in that case it makes sense.

alimoeeny added a commit that referenced this pull request Oct 6, 2014
@alimoeeny alimoeeny merged commit 22444f2 into AdRoll:master Oct 6, 2014
@ando-masaki
Copy link
Contributor

Thanks @lostghost .
Neverthless, a problem remains.
”%20” in the encoded string, signature does not match.
If solve this probrem, we can use V4 signer.

@lostghost
Copy link
Contributor

@ando-masaki Are you saying that even with the "%20" encoded space that the signature is failing?

@ando-masaki
Copy link
Contributor

Yes. When I cut ”%20” from encoded string, API returns 200 OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants