Class: Aws::S3::EncryptionV3::Client
- Inherits:
-
Object
- Object
- Aws::S3::EncryptionV3::Client
- Extended by:
- Deprecations, Forwardable
- Defined in:
- lib/aws-sdk-s3/encryptionV3/client.rb
Constant Summary collapse
- REQUIRED_PARAMS =
../specification/s3-encryption/client.md#aws-sdk-compatibility
type=implication
% The S3EC MUST provide a different set of configuration options than the conventional S3 client.
[:key_wrap_schema].freeze
- OPTIONAL_PARAMS =
[ :kms_key_id, :kms_client, :key_provider, :encryption_key, :envelope_location, ##= ../specification/s3-encryption/client.md#instruction-file-configuration ##% In this case, the Instruction File Configuration SHOULD be optional, such that its default configuration is used when none is provided. :instruction_file_suffix, ##= ../specification/s3-encryption/client.md#encryption-algorithm ##% The S3EC MUST support configuration of the encryption algorithm (or algorithm suite) during its initialization. :content_encryption_schema, :security_profile, ##= ../specification/s3-encryption/client.md#key-commitment ##% The S3EC MUST support configuration of the [Key Commitment policy](./key-commitment.md) during its initialization. :commitment_policy ].freeze
- SUPPORTED_COMMITMENT_POLICIES =
i[ forbid_encrypt_allow_decrypt require_encrypt_allow_decrypt require_encrypt_require_decrypt ].freeze
- SUPPORTED_SECURITY_PROFILES =
../specification/s3-encryption/client.md#enable-legacy-wrapping-algorithms
% The S3EC MUST support the option to enable or disable legacy wrapping algorithms.
../specification/s3-encryption/client.md#enable-legacy-unauthenticated-modes
% The S3EC MUST support the option to enable or disable legacy unauthenticated modes (content encryption algorithms).
i[v3 v3_and_legacy].freeze
- DEFAULT_SECURITY_PROFILES =
../specification/s3-encryption/client.md#enable-legacy-unauthenticated-modes
% The option to enable legacy unauthenticated modes MUST be set to false by default.
../specification/s3-encryption/client.md#enable-legacy-wrapping-algorithms
% The option to enable legacy wrapping algorithms MUST be set to false by default.
:v3- DEFAULT_COMMITMENT_POLICIES =
:require_encrypt_require_decrypt- DEFAULT_CONTENT_ENCRYPTION_SCHEMA =
:alg_aes_256_gcm_hkdf_sha512_commit_key
Instance Attribute Summary collapse
- #client ⇒ S3::Client readonly
-
#commitment_policy ⇒ Symbol
readonly
Determines the support for reading objects written using older key wrap or content encryption schemas.
- #envelope_location ⇒ Symbol<:metadata, :instruction_file> readonly
-
#instruction_file_suffix ⇒ String
readonly
When #envelope_location is ‘:instruction_file`, the envelope is stored in the object with the object key suffixed by this string.
-
#key_provider ⇒ KeyProvider?
readonly
Returns ‘nil` if you are using AWS Key Management Service (KMS).
-
#kms_allow_decrypt_with_any_cmk ⇒ Boolean
readonly
If true the provided KMS key_id will not be used during decrypt, allowing decryption with the key_id from the object.
Instance Method Summary collapse
-
#get_object(params = {}, &block) ⇒ Types::GetObjectOutput
Gets an object from Amazon S3, decrypting data locally.
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new encryption client.
-
#put_object(params = {}) ⇒ Types::PutObjectOutput
Uploads an object to Amazon S3, encrypting data client-side.
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new encryption client.
## Required Configuration
-
a key or key provider - The key provided also determines the key wrapping schema(s) supported for both encryption and decryption.
-
‘key_wrap_schema` - The key wrapping schema. It must match the type of key configured.
## Optional Configuration (with defaults)
-
‘content_encryption_schema` - Defaults to `:alg_aes_256_gcm_hkdf_sha512_commit_key`
-
‘security_profile` - Defaults to `:v3`. Set to `:v3_and_legacy` to read V2-encrypted objects.
-
‘commitment_policy` - Defaults to `:require_encrypt_require_decrypt` (most secure)
To configure the key you must provide one of the following set of options:
-
‘:encryption_key`
-
‘:kms_key_id`
-
‘:key_provider`
You may also pass any other options accepted by ‘Client#initialize`.
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 375 def initialize( = {}) validate_params() ##= ../specification/s3-encryption/client.md#wrapped-s3-client-s ##% The S3EC MUST support the option to provide an SDK S3 client instance during its initialization. @client = extract_client() ##= ../specification/s3-encryption/data-format/metadata-strategy.md#instruction-file ##% Instruction File writes MUST be optionally configured during client creation or on each PutObject request. ##= ../specification/s3-encryption/client.md#instruction-file-configuration ##% The S3EC MAY support the option to provide Instruction File Configuration during its initialization. ##= ../specification/s3-encryption/client.md#instruction-file-configuration ##% If the S3EC in a given language supports Instruction Files, then it MUST accept Instruction File Configuration during its initialization. @envelope_location = extract_location() @instruction_file_suffix = extract_suffix() @kms_allow_decrypt_with_any_cmk = [:kms_key_id] == :kms_allow_decrypt_with_any_cmk @commitment_policy = extract_commitment_policy() @security_profile = extract_security_profile() ##= ../specification/s3-encryption/client.md#key-commitment ##% The S3EC MUST validate the configured Encryption Algorithm against the provided key commitment policy. if @commitment_policy != :require_encrypt_require_decrypt = .merge( { security_profile: security_profile_to_v2(@security_profile), ##= ../specification/s3-encryption/client.md#key-commitment ##% If the configured Encryption Algorithm is incompatible with the key commitment policy, then it MUST throw an exception. content_encryption_schema: if @commitment_policy == :forbid_encrypt_allow_decrypt [:content_encryption_schema] else # assert @commitment_policy = :require_encrypt_allow_decrypt # In this case the v2_cipher_provider is only used for decrypt :aes_gcm_no_padding end } ) @v2_cipher_provider = build_v2_cipher_provider_for_decrypt() # In this case the v3 cipher is only used for decrypt. @v3_cipher_provider = build_cipher_provider(.reject { |k, _| k == :content_encryption_schema }) @key_provider = @v2_cipher_provider.key_provider if @v2_cipher_provider.is_a?(DefaultCipherProvider) else @v3_cipher_provider = build_cipher_provider() @key_provider = @v3_cipher_provider.key_provider if @v3_cipher_provider.is_a?(DefaultCipherProvider) end end |
Instance Attribute Details
#client ⇒ S3::Client (readonly)
421 422 423 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 421 def client @client end |
#commitment_policy ⇒ Symbol (readonly)
429 430 431 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 429 def commitment_policy @commitment_policy end |
#envelope_location ⇒ Symbol<:metadata, :instruction_file> (readonly)
436 437 438 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 436 def envelope_location @envelope_location end |
#instruction_file_suffix ⇒ String (readonly)
441 442 443 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 441 def instruction_file_suffix @instruction_file_suffix end |
#key_provider ⇒ KeyProvider? (readonly)
425 426 427 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 425 def key_provider @key_provider end |
#kms_allow_decrypt_with_any_cmk ⇒ Boolean (readonly)
433 434 435 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 433 def kms_allow_decrypt_with_any_cmk @kms_allow_decrypt_with_any_cmk end |
Instance Method Details
#get_object(params = {}, &block) ⇒ Types::GetObjectOutput
The ‘:range` request parameter is not supported.
Gets an object from Amazon S3, decrypting data locally. See Client#get_object for documentation on accepted request parameters. Warning: If you provide a block to get_object or set the request parameter :response_target to a Proc, then read the entire object to the end before you start using the decrypted data. This is to verify that the object has not been modified since it was encrypted.
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 521 def get_object(params = {}, &block) raise NotImplementedError, '#get_object with :range not supported' if params[:range] envelope_location, instruction_file_suffix = (params) kms_encryption_context = params.delete(:kms_encryption_context) kms_any_cmk_mode = kms_any_cmk_mode(params) commitment_policy = commitment_policy_from_params(params) ##= ../specification/s3-encryption/client.md#required-api-operations ##% - GetObject MUST be implemented by the S3EC. req = @client.build_request(:get_object, params) ##= ../specification/s3-encryption/client.md#required-api-operations ##% - GetObject MUST decrypt data received from the S3 server and return it as plaintext. req.handlers.add(DecryptHandler) req.context[:encryption] = { v3_cipher_provider: @v3_cipher_provider, envelope_location: envelope_location, instruction_file_suffix: instruction_file_suffix, kms_encryption_context: kms_encryption_context, kms_allow_decrypt_with_any_cmk: kms_any_cmk_mode, commitment_policy: commitment_policy }.tap do |hash| if commitment_policy != :require_encrypt_require_decrypt security_profile = security_profile_from_params(params) hash[:security_profile] = security_profile_to_v2(security_profile) hash[:cipher_provider] = @v2_cipher_provider end end Aws::Plugins::UserAgent.metric('S3_CRYPTO_V3') do req.send_request(target: block) end end |
#put_object(params = {}) ⇒ Types::PutObjectOutput
Uploads an object to Amazon S3, encrypting data client-side. See Client#put_object for documentation on accepted request parameters.
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/aws-sdk-s3/encryptionV3/client.rb', line 461 def put_object(params = {}) kms_encryption_context = params.delete(:kms_encryption_context) ##= ../specification/s3-encryption/client.md#required-api-operations ##% - PutObject MUST be implemented by the S3EC. req = @client.build_request(:put_object, params) ##= ../specification/s3-encryption/client.md#required-api-operations ##% - PutObject MUST encrypt its input data before it is uploaded to S3. req.handlers.add(EncryptHandler, priority: 95) req.context[:encryption] = { cipher_provider: if @commitment_policy == :forbid_encrypt_allow_decrypt ##= ../specification/s3-encryption/key-commitment.md#commitment-policy ##% When the commitment policy is FORBID_ENCRYPT_ALLOW_DECRYPT, the S3EC MUST NOT encrypt using an algorithm suite which supports key commitment. @v2_cipher_provider else ##= ../specification/s3-encryption/key-commitment.md#commitment-policy ##% When the commitment policy is REQUIRE_ENCRYPT_ALLOW_DECRYPT, the S3EC MUST only encrypt using an algorithm suite which supports key commitment. ##= ../specification/s3-encryption/key-commitment.md#commitment-policy ##% When the commitment policy is REQUIRE_ENCRYPT_REQUIRE_DECRYPT, the S3EC MUST only encrypt using an algorithm suite which supports key commitment. @v3_cipher_provider end, envelope_location: @envelope_location, instruction_file_suffix: @instruction_file_suffix, kms_encryption_context: kms_encryption_context } Aws::Plugins::UserAgent.metric('S3_CRYPTO_V3') do req.send_request end end |