Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions lib/private/Files/ObjectStore/S3ConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,34 @@ protected function getCertificateBundlePath(): ?string {
return null;
}
}

protected function getSSECKey(): ?string {
if (isset($this->params['sse_c_key'])) {
return $this->params['sse_c_key'];
}

return null;
}

protected function getSSECParameters(bool $copy = false): array {
$key = $this->getSSECKey();

if ($key === null) {
return [];
}

$rawKey = base64_decode($key);
if ($copy) {
return [
'CopySourceSSECustomerAlgorithm' => 'AES256',
'CopySourceSSECustomerKey' => $rawKey,
'CopySourceSSECustomerKeyMD5' => md5($rawKey, true)
];
}
return [
'SSECustomerAlgorithm' => 'AES256',
'SSECustomerKey' => $rawKey,
'SSECustomerKeyMD5' => md5($rawKey, true)
];
}
}
13 changes: 8 additions & 5 deletions lib/private/Files/ObjectStore/S3ObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ trait S3ObjectTrait {
abstract protected function getConnection();

abstract protected function getCertificateBundlePath(): ?string;
abstract protected function getSSECParameters(bool $copy = false): array;

/**
* @param string $urn the unified resource name used to identify the object
Expand All @@ -58,7 +59,7 @@ public function readObject($urn) {
'Bucket' => $this->bucket,
'Key' => $urn,
'Range' => 'bytes=' . $range,
]);
] + $this->getSSECParameters());
$request = \Aws\serialize($command);
$headers = [];
foreach ($request->getHeaders() as $key => $values) {
Expand Down Expand Up @@ -106,7 +107,7 @@ protected function writeSingle(string $urn, StreamInterface $stream, string $mim
'ACL' => 'private',
'ContentType' => $mimetype,
'StorageClass' => $this->storageClass,
]);
] + $this->getSSECParameters());
}


Expand All @@ -126,7 +127,7 @@ protected function writeMultiPart(string $urn, StreamInterface $stream, string $
'params' => [
'ContentType' => $mimetype,
'StorageClass' => $this->storageClass,
],
] + $this->getSSECParameters(),
]);

try {
Expand Down Expand Up @@ -181,10 +182,12 @@ public function deleteObject($urn) {
}

public function objectExists($urn) {
return $this->getConnection()->doesObjectExist($this->bucket, $urn);
return $this->getConnection()->doesObjectExist($this->bucket, $urn, $this->getSSECParameters());
}

public function copyObject($from, $to) {
$this->getConnection()->copy($this->getBucket(), $from, $this->getBucket(), $to);
$this->getConnection()->copy($this->getBucket(), $from, $this->getBucket(), $to, 'private', [
'params' => $this->getSSECParameters() + $this->getSSECParameters(true)
]);
}
}