IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 20 forks source link

Verify integrity of object uploaded by MD5 checksum #64

Closed shahvicky closed 4 years ago

shahvicky commented 4 years ago

Hi all, I want to verify the file upload integrity by passing the ContentMD5: <md5 hash> to the params

IBM.S3({endpoint, apiKeyId, ibmAuthEndpoint, serviceInstanceId})
.upload({Bucket, Key, Body, ContentMD5})

but it uploads the file even if I pass a hardcoded incorrect MD5 hash. I checked the sdk, and it mentions here to not use ContentMD5 and instead set computeChecksums. How can I be sure that it uploads the file that I provided? Is there any other hash that I can check?

kellerbr-ibm commented 4 years ago

Content-MD5 can be used with the legacy v4 signature credential type for HMAC signature calculation to authenticate requests, but is not used with the default IAM credentials unless object retention is turned on (as those files would then be unable to be overwritten for a period of time.)

As long as server-side encryption is not turned on, you can do a headObject request on an object to get the file's MD5. It will be in the ETag field.