Merge pull request #32798 from nextcloud/enh/sse-c

[S3] Add option to specify an SSE-C customer provided key
pull/36362/head
Julius Härtl 3 years ago committed by GitHub
commit 919a840f34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      lib/private/Files/ObjectStore/S3ConnectionTrait.php
  2. 13
      lib/private/Files/ObjectStore/S3ObjectTrait.php

@ -231,4 +231,34 @@ trait S3ConnectionTrait {
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)
];
}
}

@ -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 @@ trait S3ObjectTrait {
'Bucket' => $this->bucket,
'Key' => $urn,
'Range' => 'bytes=' . $range,
]);
] + $this->getSSECParameters());
$request = \Aws\serialize($command);
$headers = [];
foreach ($request->getHeaders() as $key => $values) {
@ -106,7 +107,7 @@ trait S3ObjectTrait {
'ACL' => 'private',
'ContentType' => $mimetype,
'StorageClass' => $this->storageClass,
]);
] + $this->getSSECParameters());
}
@ -126,7 +127,7 @@ trait S3ObjectTrait {
'params' => [
'ContentType' => $mimetype,
'StorageClass' => $this->storageClass,
],
] + $this->getSSECParameters(),
]);
try {
@ -181,10 +182,12 @@ trait S3ObjectTrait {
}
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)
]);
}
}

Loading…
Cancel
Save