Module: CoreRSAKeyService

Defined in:
app/services/core_rsa_key_service.rb

Class Method Summary collapse

Class Method Details

.domainObject


36
37
38
# File 'app/services/core_rsa_key_service.rb', line 36

def domain
  @domain ||= URI.parse(ENV['APP_URL']).host
end

.private_keyObject


28
29
30
# File 'app/services/core_rsa_key_service.rb', line 28

def private_key
  @private_key ||= OpenSSL::PKey::RSA.new(private_key_string)
end

.private_key_stringObject


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/core_rsa_key_service.rb', line 3

def private_key_string
  @private_key_string ||= if ENV['CORE_RSA_PRIVATE_KEY_1'].present?

                            ENV['CORE_RSA_PRIVATE_KEY'] = [
                              ENV['CORE_RSA_PRIVATE_KEY_1'],
                              ENV['CORE_RSA_PRIVATE_KEY_2'],
                              ENV['CORE_RSA_PRIVATE_KEY_3'],
                              ENV['CORE_RSA_PRIVATE_KEY_4']
                            ].join

                            ENV['CORE_RSA_PRIVATE_KEY'].gsub(/\\n/, "\n")
                          else
                            ENV['CORE_RSA_PRIVATE_KEY'].gsub(/\\n/, "\n")
                          end
end

.public_keyObject


32
33
34
# File 'app/services/core_rsa_key_service.rb', line 32

def public_key
  @public_key ||= OpenSSL::PKey::RSA.new(public_key_string)
end

.public_key_stringObject


19
20
21
22
23
24
25
26
# File 'app/services/core_rsa_key_service.rb', line 19

def public_key_string
  @public_key_string ||=
  if ENV['CORE_RSA_PUBLIC_KEY'].present?
    ENV['CORE_RSA_PUBLIC_KEY'].gsub(/\\n/, "\n")
  else
    private_key.public_key.to_s
  end
end