v2: Updates

* Simplifies & beautifies everything
* Introduces a new Class system.
* Errors are defaulted to AWS's handler.
* New function names & more efficient handling.
* Should fix a majority of the errors.

Please read the README for more!
This commit is contained in:
Devang Srivastava 2020-09-28 15:32:51 +05:30
parent ad0726e41e
commit e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions

View file

@ -1,14 +1,14 @@
<?php
namespace Aws\S3\Crypto;
use Aws\Crypto\DecryptionTrait;
use Aws\HashingStream;
use Aws\PhpHash;
use Aws\Crypto\AbstractCryptoClient;
use Aws\Crypto\EncryptionTrait;
use Aws\Crypto\DecryptionTrait;
use Aws\Crypto\MetadataEnvelope;
use Aws\Crypto\MaterialsProvider;
use Aws\Crypto\MetadataStrategyInterface;
use Aws\Crypto\Cipher\CipherBuilderTrait;
use Aws\S3\S3Client;
use GuzzleHttp\Promise;
use GuzzleHttp\Promise\PromiseInterface;
@ -17,10 +17,26 @@ use GuzzleHttp\Psr7;
/**
* Provides a wrapper for an S3Client that supplies functionality to encrypt
* data on putObject[Async] calls and decrypt data on getObject[Async] calls.
*
* Legacy implementation using older encryption workflow.
*
* AWS strongly recommends the upgrade to the S3EncryptionClientV2 (over the
* S3EncryptionClient), as it offers updated data security best practices to our
* customers who upgrade. S3EncryptionClientV2 contains breaking changes, so this
* will require planning by engineering teams to migrate. New workflows should
* just start with S3EncryptionClientV2.
*
* @deprecated
*/
class S3EncryptionClient extends AbstractCryptoClient
{
use EncryptionTrait, DecryptionTrait;
use CipherBuilderTrait;
use CryptoParamsTrait;
use DecryptionTrait;
use EncryptionTrait;
use UserAgentTrait;
const CRYPTO_VERSION = '1n';
private $client;
private $instructionFileSuffix;
@ -37,79 +53,16 @@ class S3EncryptionClient extends AbstractCryptoClient
S3Client $client,
$instructionFileSuffix = null
) {
$this->appendUserAgent($client, 'S3CryptoV' . self::CRYPTO_VERSION);
$this->client = $client;
$this->instructionFileSuffix = $instructionFileSuffix;
}
private function getMaterialsProvider(array $args)
{
if ($args['@MaterialsProvider'] instanceof MaterialsProvider) {
return $args['@MaterialsProvider'];
} else {
throw new \InvalidArgumentException('An instance of MaterialsProvider'
. ' must be passed in the "MaterialsProvider" field.');
}
}
private function getInstructionFileSuffix(array $args)
{
return !empty($args['@InstructionFileSuffix'])
? $args['@InstructionFileSuffix']
: $this->instructionFileSuffix;
}
private static function getDefaultStrategy()
{
return new HeadersMetadataStrategy();
}
private function determineGetObjectStrategy(
$result,
$instructionFileSuffix
) {
if (isset($result['Metadata'][MetadataEnvelope::CONTENT_KEY_V2_HEADER])) {
return new HeadersMetadataStrategy();
} else {
return new InstructionFileMetadataStrategy(
$this->client,
$instructionFileSuffix
);
}
}
private function getMetadataStrategy(array $args, $instructionFileSuffix)
{
if (!empty($args['@MetadataStrategy'])) {
if ($args['@MetadataStrategy'] instanceof MetadataStrategyInterface) {
return $args['@MetadataStrategy'];
} elseif (is_string($args['@MetadataStrategy'])) {
switch ($args['@MetadataStrategy']) {
case HeadersMetadataStrategy::class:
return new HeadersMetadataStrategy();
case InstructionFileMetadataStrategy::class:
return new InstructionFileMetadataStrategy(
$this->client,
$instructionFileSuffix
);
default:
throw new \InvalidArgumentException('Could not match the'
. ' specified string in "MetadataStrategy" to a'
. ' predefined strategy.');
}
} else {
throw new \InvalidArgumentException('The metadata strategy that'
. ' was passed to "MetadataStrategy" was unrecognized.');
}
} elseif ($instructionFileSuffix) {
return new InstructionFileMetadataStrategy(
$this->client,
$instructionFileSuffix
);
}
return null;
}
/**
* Encrypts the data in the 'Body' field of $args and promises to upload it
* to the specified location on S3.
@ -124,12 +77,15 @@ class S3EncryptionClient extends AbstractCryptoClient
* - @CipherOptions: (array) Cipher options for encrypting data. Only the
* Cipher option is required. Accepts the following:
* - Cipher: (string) cbc|gcm
* See also: AbstractCryptoClient::$supportedCiphers
* See also: AbstractCryptoClient::$supportedCiphers. Note that
* cbc is deprecated and gcm should be used when possible.
* - KeySize: (int) 128|192|256
* See also: MaterialsProvider::$supportedKeySizes
* - Aad: (string) Additional authentication data. This option is
* passed directly to OpenSSL when using gcm. It is ignored when
* using cbc.
* using cbc. Note if you pass in Aad for gcm encryption, the
* PHP SDK will be able to decrypt the resulting object, but other
* AWS SDKs may not be able to do so.
*
* The optional configuration arguments are as follows:
*
@ -214,12 +170,15 @@ class S3EncryptionClient extends AbstractCryptoClient
* - @CipherOptions: (array) Cipher options for encrypting data. A Cipher
* is required. Accepts the following options:
* - Cipher: (string) cbc|gcm
* See also: AbstractCryptoClient::$supportedCiphers
* See also: AbstractCryptoClient::$supportedCiphers. Note that
* cbc is deprecated and gcm should be used when possible.
* - KeySize: (int) 128|192|256
* See also: MaterialsProvider::$supportedKeySizes
* - Aad: (string) Additional authentication data. This option is
* passed directly to OpenSSL when using gcm. It is ignored when
* using cbc.
* using cbc. Note if you pass in Aad for gcm encryption, the
* PHP SDK will be able to decrypt the resulting object, but other
* AWS SDKs may not be able to do so.
*
* The optional configuration arguments are as follows:
*