Method: Tem::Cert.extract_sig_from_cert

Defined in:
lib/tem/_cert.rb

.extract_sig_from_cert(cert) ⇒ Object

cert must be signed with sha1WithRSAEncryption algorithm TODO: how to make this method compatible with any algorithm

Parameters:

  • cert

    A signed OpenSSL::X509::Certificate instance



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/tem/_cert.rb', line 146

def self.extract_sig_from_cert(cert)
  str = 'Signature Algorithm: sha1WithRSAEncryption'
  text_sig = cert.to_text
  first_index = text_sig.index(str)
  text_sig = text_sig[first_index+1..-1]
  second_index = text_sig.index(str)
  sig_start_index = second_index+str.length + 1 #the 1 is for the newline character

  text_sig = text_sig[sig_start_index..-1]
  sig_array = []
  text_sig.each(':') {|byte| sig_array.push(byte.delete(':').hex)}
  return sig_array
end