Guest User

Untitled

a guest
Jan 22nd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. require 'openssl'
  2.  
  3. # find first SEQUENCE of SEQUENCE in TBSCertificate
  4. # tag == 16 is a SEQUENCE chunk
  5. def spki_sha1_hash(cert)
  6. spki = OpenSSL::ASN1.decode(cert).value[0].find { |e|
  7. e.tag == 16 && e.value[0].tag == 16
  8. }
  9. return unless spki
  10. ["sha1", [OpenSSL::Digest::SHA1.digest(spki.to_der)].pack('m*').chomp].join("/")
  11. end
  12.  
  13. if $0 == __FILE__
  14. ARGV.each do |file|
  15. cert = OpenSSL::X509::Certificate.new(File.read(file))
  16. spkihash = spki_sha1_hash(cert.to_der)
  17. sha1, b64 = spkihash.split('/')
  18. puts '=='
  19. puts 'Subject: ' + cert.subject.to_s
  20. puts 'Issuer: ' + cert.issuer.to_s
  21. puts spkihash
  22. puts b64.unpack('m*')[0].each_byte.map { |e| sprintf("%02x", e) }.join
  23. end
  24. end
Add Comment
Please, Sign In to add comment