You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::S3::EncryptionV2::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Creates a new encryption client. You must configure all of the following:

  • 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.
  • content_encryption_schema - The only supported value currently is :aes_gcm_no_padding More options will be added in future releases.
  • security_profile - Determines the support for reading objects written using older key wrap or content encryption schemas. If you need to read legacy objects encrypted by an existing V1 Client, then set this to :v2_and_legacy. Otherwise, set it to :v2

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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :client (S3::Client)

    A basic S3 client that is used to make api calls. If a :client is not provided, a new Client will be constructed.

  • :encryption_key (OpenSSL::PKey::RSA, String)

    The master key to use for encrypting/decrypting all objects.

  • :kms_key_id (String)

    When you provide a :kms_key_id, then AWS Key Management Service (KMS) will be used to manage the object encryption keys. By default a KMS::Client will be constructed for KMS API calls. Alternatively, you can provide your own via :kms_client. To only support decryption/reads, you may provide :allow_decrypt_with_any_cmk which will use the implicit CMK associated with the data during reads but will not allow you to encrypt/write objects with this client.

  • :key_provider (#key_for)

    Any object that responds to #key_for. This method should accept a materials description JSON document string and return return an encryption key.

  • :key_wrap_schema (required, Symbol)

    The Key wrapping schema to be used. It must match the type of key configured. Must be one of the following:

    • :kms_context (Must provide kms_key_id)
    • :aes_gcm (Must provide an AES (string) key)
    • :rsa_oaep_sha1 (Must provide an RSA key)
  • :content_encryption_schema (required, Symbol)

    Must be one of the following:

    • :aes_gcm_no_padding
  • :security_profile (Required, Symbol)

    Determines the support for reading objects written using older key wrap or content encryption schemas. Must be one of the following:

    • :v2 - Reads of legacy (v1) objects are NOT allowed
    • :v2_and_legacy - Enables reading of legacy (V1) schemas.
  • :envelope_location (Symbol) — default: :metadata

    Where to store the envelope encryption keys. By default, the envelope is stored with the encrypted object. If you pass :instruction_file, then the envelope is stored in a separate object in Amazon S3.

  • :instruction_file_suffix (String) — default: '.instruction'

    When :envelope_location is :instruction_file then the instruction file uses the object key with this suffix appended.

  • :kms_client (KMS::Client)

    A default KMS::Client is constructed when using KMS to manage encryption keys.



310
311
312
313
314
315
316
317
318
319
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 310

def initialize(options = {})
  validate_params(options)
  @client = extract_client(options)
  @cipher_provider = cipher_provider(options)
  @envelope_location = extract_location(options)
  @instruction_file_suffix = extract_suffix(options)
  @kms_allow_decrypt_with_any_cmk =
    options[:kms_key_id] == :kms_allow_decrypt_with_any_cmk
  @security_profile = extract_security_profile(options)
end

Instance Attribute Details

#clientS3::Client (readonly)

Returns:



322
323
324
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 322

def client
  @client
end

#envelope_locationSymbol<:metadata, :instruction_file> (readonly)

Returns:

  • (Symbol<:metadata, :instruction_file>)


337
338
339
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 337

def envelope_location
  @envelope_location
end

#instruction_file_suffixString (readonly)

Returns When #envelope_location is :instruction_file, the envelope is stored in the object with the object key suffixed by this string.

Returns:

  • (String)

    When #envelope_location is :instruction_file, the envelope is stored in the object with the object key suffixed by this string.



342
343
344
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 342

def instruction_file_suffix
  @instruction_file_suffix
end

#key_providerKeyProvider? (readonly)

Returns nil if you are using AWS Key Management Service (KMS).

Returns:

  • (KeyProvider, nil)

    Returns nil if you are using AWS Key Management Service (KMS).



326
327
328
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 326

def key_provider
  @key_provider
end

#kms_allow_decrypt_with_any_cmkBoolean (readonly)

Returns If true the provided KMS key_id will not be used during decrypt, allowing decryption with the key_id from the object.

Returns:

  • (Boolean)

    If true the provided KMS key_id will not be used during decrypt, allowing decryption with the key_id from the object.



334
335
336
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 334

def kms_allow_decrypt_with_any_cmk
  @kms_allow_decrypt_with_any_cmk
end

#security_profileSymbol (readonly)

Returns Determines the support for reading objects written using older key wrap or content encryption schemas.

Returns:

  • (Symbol)

    Determines the support for reading objects written using older key wrap or content encryption schemas.



330
331
332
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 330

def security_profile
  @security_profile
end

Instance Method Details

#get_object(params = {}, &block) ⇒ Types::GetObjectOutput

Note:

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.

Parameters:

  • options (Hash)

    a customizable set of options

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :instruction_file_suffix (String)

    The suffix used to find the instruction file containing the encryption envelope. You should not set this option when the envelope is stored in the object metadata. Defaults to #instruction_file_suffix.

  • :kms_encryption_context (Hash)

    Additional encryption context to use with KMS. Applies only when KMS is used.

Returns:

See Also:



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 393

def get_object(params = {}, &block)
  if params[:range]
    raise NotImplementedError, '#get_object with :range not supported'
  end
  envelope_location, instruction_file_suffix = envelope_options(params)
  kms_encryption_context = params.delete(:kms_encryption_context)
  kms_any_cmk_mode = kms_any_cmk_mode(params)
  security_profile = security_profile_from_params(params)

  req = @client.build_request(:get_object, params)
  req.handlers.add(DecryptHandler)
  req.context[:encryption] = {
    cipher_provider: @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,
    security_profile: security_profile
  }
  req.send_request(target: block)
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.

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :kms_encryption_context (Hash)

    Additional encryption context to use with KMS. Applies only when KMS is used. In order to decrypt the object you will need to provide the identical :kms_encryption_context to get_object.

Returns:

See Also:



354
355
356
357
358
359
360
361
362
363
364
365
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/s3/encryptionV2/client.rb', line 354

def put_object(params = {})
  kms_encryption_context = params.delete(:kms_encryption_context)
  req = @client.build_request(:put_object, params)
  req.handlers.add(EncryptHandler, priority: 95)
  req.context[:encryption] = {
    cipher_provider: @cipher_provider,
    envelope_location: @envelope_location,
    instruction_file_suffix: @instruction_file_suffix,
    kms_encryption_context: kms_encryption_context
  }
  req.send_request
end