jeudi 27 août 2015

server side encryption on s3 in javascript sdk

I'm trying to upload a video to S3 from javascript using a client managed key according to this documentation

I'm working in meteor (really just node for this application), and my code is in coffeescript.

params = {
    Bucket: 'videocache'
    Key: 'videos/'+key
    #Body: base64data
    Body: data
}

if Meteor.settings.public.s3Encryption
  raw_key = <some_binary_string_key>
  enc_key = raw_key.toString("base64")
  hash = crypto.createHash("md5").update(enc_key, "base64").digest("base64")
  params.SSECustomerAlgorithm = 'AES256'
  params.SSECustomerKey = enc_key
  params.SSECustomerKeyMD5 = hash

Meteor.S3.upload(params,
  ((err, data) ->
    if err
      throw err
    else
      doStuff(data)
    return)
)
)

Here's the code I'm using to generate the request:

I'm using node's crypto to generate the required md5 hash, but still getting the following error:

error:  message=The calculated MD5 hash of the key did not match the
  hash that was provided., code=InvalidArgument, time=Thu Aug 27 2015
  09:19:49 GMT-0400 (EDT), statusCode=400, retryable=false, retryDelay=30

I've also tried omitting the hash completely since the library is supposed to generate the hash when omitted, with the same results.




Aucun commentaire:

Enregistrer un commentaire