Class: JKS

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, storepass, keytool = nil, process = true) ⇒ JKS

Returns a new instance of JKS.



18
19
20
21
22
23
24
# File 'lib/jks.rb', line 18

def initialize(filename, storepass, keytool = nil, process = true)
  @keytool = keytool ? keytool : 'keytool'
  @filename = filename
  @storepass = storepass
  @certs = []
  self.process if process
end

Instance Attribute Details

#certsObject (readonly)

Returns the value of attribute certs.



16
17
18
# File 'lib/jks.rb', line 16

def certs
  @certs
end

#keytoolObject

Returns the value of attribute keytool.



15
16
17
# File 'lib/jks.rb', line 15

def keytool
  @keytool
end

#storepassObject

Returns the value of attribute storepass.



15
16
17
# File 'lib/jks.rb', line 15

def storepass
  @storepass
end

Instance Method Details

#processObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/jks.rb', line 26

def process
  keytoolcmd = "#{@keytool} -keystore #{@filename} -storepass #{@storepass} -list -rfc"
  filtercmd = "awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/'"
  result = `#{keytoolcmd} | #{filtercmd}`
  result.scan(/(?=-----BEGIN CERTIFICATE-----)(.*?)(?<=-----END CERTIFICATE-----)/m).each do |pem| 
    p pem
    cert = OpenSSL::X509::Certificate.new(pem.first)
    @certs << cert
  end
end