asafdav / ng-s3upload

Upload to S3 using AngularJS
MIT License
190 stars 83 forks source link

Problem generating policy #13

Closed gabriel4649 closed 10 years ago

gabriel4649 commented 10 years ago

On the documentation it indicates that YYY - HMAC and sha of your private key but in the example it looks like something different going on. ruby Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), GLOBAL[:aws_secret], s3_upload_policy)).gsub("\n","") . My interpretation of this is that HMAC digest should be for both the secret key and the policy and that the result of that should be Base64 encoded. Is that right? This is how I'm generating the policy:

var limit = 10 * 1024 * 1024;

var policy = {
    "expiration": " <period>PT1H</period> ",
    "conditions": [
        {
            "bucket": "curioso-uploads"
        },
        [
            "starts-with",
            "AKIAJL64SWZSQX2UXMA",
            ""
        ],
        {
            "acl": "public-read"
        },
        [
            "starts-with",
            "multipart/form-data",
            ""
        ],
        [
            "content-length-range",
            0,
            limit
        ]
    ]
};

this.policy = Base64.encode(JSON.stringify(policy));
this.signature = Base64.encode("f0513f710e328568ddfdsffsfce5d4d"); // I calculated this using bash as demonstrate in the following lines
echo -n "{\"expiration\":\" <period>PT1H</period> \",\"conditions\":[{\"bucket\":\"curioso-uploads\"},[\"starts-with\",\"AKIAJL64SWZSQX2UXMA\",\"\"],{\"acl\":\"public-read\"},[\"starts-with\",\"multipart/form-data\",\"\"],[\"content-length-range\",0,10485760]]}" | openssl dgst -sha1 -hmac "myprivatekey"
asafdav commented 10 years ago

Hi there, sorry for the late response.

Have you eventually figured it out? Can you please share with us what was your problem ?

asafdav commented 10 years ago

Can't reproduce and didn't get a response