Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

Support KMS Encryption #166

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Client.prototype.uploadFile = function(params) {
var defaultContentType = params.defaultContentType || 'application/octet-stream';
s3Params.ContentType = mime.lookup(localFile, defaultContentType);
}
var sse = s3Params.ServerSideEncryption;
var fatalError = false;
var localFileSlicer = null;
var parts = [];
Expand Down Expand Up @@ -222,7 +223,7 @@ Client.prototype.uploadFile = function(params) {
Key: encodeSpecialCharacters(s3Params.Key),
SSECustomerAlgorithm: s3Params.SSECustomerAlgorithm,
SSECustomerKey: s3Params.SSECustomerKey,
SSECustomerKeyMD5: s3Params.SSECustomerKeyMD5,
SSECustomerKeyMD5: s3Params.SSECustomerKeyMD5
};
queueAllParts(data.UploadId, multipartUploadSize);
});
Expand Down Expand Up @@ -315,11 +316,13 @@ Client.prototype.uploadFile = function(params) {
}
pend.wait(function() {
if (fatalError) return;
if (!compareMultipartETag(data.ETag, multipartETag)) {
errorOccurred = true;
uploader.progressAmount -= overallDelta;
cb(new Error("ETag does not match MD5 checksum"));
return;
if (sse !== 'aws:kms') {
if (!compareMultipartETag(data.ETag, multipartETag)) {
errorOccurred = true;
uploader.progressAmount -= overallDelta;
cb(new Error("ETag does not match MD5 checksum"));
return;
}
}
part.ETag = data.ETag;
cb(null, data);
Expand Down Expand Up @@ -411,9 +414,11 @@ Client.prototype.uploadFile = function(params) {
}
pend.wait(function() {
if (fatalError) return;
if (!compareMultipartETag(data.ETag, localFileStat.multipartETag)) {
cb(new Error("ETag does not match MD5 checksum"));
return;
if (sse !== 'aws:kms') {
if (!compareMultipartETag(data.ETag, localFileStat.multipartETag)) {
cb(new Error("ETag does not match MD5 checksum"));
return;
}
}
cb(null, data);
});
Expand Down Expand Up @@ -507,9 +512,11 @@ Client.prototype.downloadFile = function(params) {
handleError(new Error("Downloaded size does not match Content-Length"));
return;
}
if (eTagCount === 1 && !multipartETag.anyMatch(eTag)) {
handleError(new Error("ETag does not match MD5 checksum"));
return;
if (headers['x-amz-server-side-encryption'] !== 'aws:kms' ) {
if (eTagCount === 1 && !multipartETag.anyMatch(eTag)) {
handleError(new Error("ETag does not match MD5 checksum"));
return;
}
}
cb();
});
Expand Down Expand Up @@ -825,9 +832,11 @@ Client.prototype.downloadBuffer = function(s3Params) {
handleError(new Error("Downloaded size does not match Content-Length"));
return;
}
if (eTagCount === 1 && !multipartETag.anyMatch(eTag)) {
handleError(new Error("ETag does not match MD5 checksum"));
return;
if (headers['x-amz-server-side-encryption'] !== 'aws:kms' ) {
if (eTagCount === 1 && !multipartETag.anyMatch(eTag)) {
handleError(new Error("ETag does not match MD5 checksum"));
return;
}
}
cb();
});
Expand Down