Skip to content

Commit

Permalink
Merge pull request #1585 from 18F/brody/key-load-err-msg
Browse files Browse the repository at this point in the history
Log useful error message when failing to load key.
  • Loading branch information
jmhooper authored Aug 7, 2017
2 parents 10eb0cc + 81cad98 commit 7ca0230
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 13 additions & 7 deletions app/services/request_key_manager.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
class RequestKeyManager
cattr_accessor :private_key do
def self.read_key_file(key_file, passphrase)
OpenSSL::PKey::RSA.new(
File.read(Rails.root.join('keys', 'saml.key.enc')),
Figaro.env.saml_passphrase
File.read(key_file),
passphrase
)
rescue OpenSSL::PKey::RSAError
raise OpenSSL::PKey::RSAError, "Failed to load #{key_file.inspect}. Bad passphrase?"
end
private_class_method :read_key_file

cattr_accessor :private_key do
key_file = Rails.root.join('keys', 'saml.key.enc')
read_key_file(key_file, Figaro.env.saml_passphrase)
end

cattr_accessor :equifax_ssh_key do
OpenSSL::PKey::RSA.new(
File.read(Rails.root.join('keys', 'equifax_rsa')),
Figaro.env.equifax_ssh_passphrase
)
key_file = Rails.root.join('keys', 'equifax_rsa')
read_key_file(key_file, Figaro.env.equifax_ssh_passphrase)
end
end
10 changes: 9 additions & 1 deletion spec/services/request_key_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
require 'rails_helper'

describe RequestKeyManager do
describe '#equifax_ssh_key' do
describe '.equifax_ssh_key' do
it 'initializes' do
ssh_key = described_class.equifax_ssh_key

expect(ssh_key).to be_a OpenSSL::PKey::RSA
end
end

describe '.private_key' do
it 'initializes' do
ssh_key = described_class.private_key

expect(ssh_key).to be_a OpenSSL::PKey::RSA
end
end
end

0 comments on commit 7ca0230

Please sign in to comment.