Class: OCI::Auth::SessionKeySupplier

Inherits:
Object
  • Object
show all
Defined in:
lib/oci/auth/session_key_supplier.rb

Overview

A supplier which can vend a public and private key to be used for signing requests

Constant Summary collapse

PUBLIC_EXPONENT =

Ruby docs suggest 3, 17 or 65537

65_537

Instance Method Summary collapse

Constructor Details

#initialize(key_size: 2048) ⇒ SessionKeySupplier

Returns a new instance of SessionKeySupplier.



11
12
13
14
15
16
# File 'lib/oci/auth/session_key_supplier.rb', line 11

def initialize(key_size: 2048)
  @key_size = key_size
  @refresh_lock = Mutex.new

  @private_key = OpenSSL::PKey::RSA.generate(@key_size, PUBLIC_EXPONENT)
end

Instance Method Details

#key_pairHash

Retrieves a public key and private key

Returns:

  • (Hash)

    A 2 element hash, where the key 'private_key' retrieves the private key and the public key can be retrieved by using the key 'public_key'



20
21
22
23
24
25
26
# File 'lib/oci/auth/session_key_supplier.rb', line 20

def key_pair
  @refresh_lock.lock
  private_key = @private_key
  @refresh_lock.unlock

  { 'private_key': private_key, 'public_key': private_key.public_key }
end

#refreshObject

Generates a new public and private key



29
30
31
32
33
34
# File 'lib/oci/auth/session_key_supplier.rb', line 29

def refresh
  @refresh_lock.lock
  @private_key = OpenSSL::PKey::RSA.generate(@key_size, PUBLIC_EXPONENT)
ensure
  @refresh_lock.unlock if @refresh_lock.locked? && @refresh_lock.owned?
end