Class: Inspec::Resources::RsaKey

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/key_rsa.rb

Instance Method Summary collapse

Constructor Details

#initialize(keypath, passphrase = nil) ⇒ RsaKey

Returns a new instance of RsaKey.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/resources/key_rsa.rb', line 23

def initialize(keypath, passphrase = nil)
  @key_path = keypath
  @key_file = inspec.file(@key_path)
  @key = nil
  @passphrase = passphrase

  return skip_resource "Unable to find key file #{@key_path}" unless @key_file.exist?

  begin
    @key = OpenSSL::PKey.read(@key_file.content, @passphrase)
  rescue OpenSSL::PKey::RSAError => _
    return skip_resource "Unable to load key file #{@key_path}"
  end
end

Instance Method Details

#key_lengthObject



58
59
60
61
# File 'lib/resources/key_rsa.rb', line 58

def key_length
  return if @key.nil?
  @key.public_key.n.num_bytes * 8
end

#private?Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/resources/key_rsa.rb', line 48

def private?
  return if @key.nil?
  @key.private?
end

#private_keyObject



53
54
55
56
# File 'lib/resources/key_rsa.rb', line 53

def private_key
  return if @key.nil?
  @key.to_s
end

#public?Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/resources/key_rsa.rb', line 38

def public?
  return if @key.nil?
  @key.public?
end

#public_keyObject



43
44
45
46
# File 'lib/resources/key_rsa.rb', line 43

def public_key
  return if @key.nil?
  @key.public_key.to_s
end

#to_sObject



63
64
65
# File 'lib/resources/key_rsa.rb', line 63

def to_s
  "rsa_key #{@key_path}"
end