Module: Google::APIClient::PKCS12

Defined in:
lib/google/api_client/service_account.rb

Overview

Helper for loading keys from the PKCS12 files downloaded when setting up service accounts at the APIs Console.

Class Method Summary collapse

Class Method Details

.load_key(keyfile, passphrase) ⇒ OpenSSL::PKey

Loads a key from PKCS12 file, assuming a single private key is present.

Parameters:

  • keyfile (String)

    Path of the PKCS12 file to load. If not a path to an actual file, assumes the string is the content of the file itself.

  • passphrase (String)

    Passphrase for unlocking the private key

Returns:

  • (OpenSSL::PKey)

    The private key for signing assertions.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/google/api_client/service_account.rb', line 36

def self.load_key(keyfile, passphrase)
  begin
    if File.exists?(keyfile)
      content = File.read(keyfile)
    else
      content = keyfile
    end  
    pkcs12 = OpenSSL::PKCS12.new(content, passphrase)
    return pkcs12.key
  rescue OpenSSL::PKCS12::PKCS12Error
    raise ArgumentError.new("Invalid keyfile or passphrase")
  end
end