diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php index bdda1f8bee829..35c7bdd28d49f 100644 --- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php +++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php @@ -227,4 +227,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) + ]; + } } diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index e6a2cf21cd05d..bd9905c5fc995 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -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 @@ -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) { @@ -105,7 +106,7 @@ protected function writeSingle(string $urn, StreamInterface $stream, string $mim 'Body' => $stream, 'ACL' => 'private', 'ContentType' => $mimetype, - ]); + ] + $this->getSSECParameters()); } @@ -124,7 +125,7 @@ protected function writeMultiPart(string $urn, StreamInterface $stream, string $ 'part_size' => $this->uploadPartSize, 'params' => [ 'ContentType' => $mimetype - ], + ] + $this->getSSECParameters(), ]); try { @@ -179,10 +180,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) + ]); } }