#!/usr/bin/env ruby def cert_info(crt) check_cmd = 'openssl x509 -inform pem -subject -fingerprint -issuer -sha256 -dates' IO.popen(check_cmd, 'w+') do |process| process.write crt process.close_write return process.read end end def split_certs(input) inside_cert = false certs = [] input.each do |line| case line when /^-+BEGIN\s+CERTIFICATE-+$/ certs << line inside_cert = true next when /^-+END\s+CERTIFICATE-+$/ certs.last << line inside_cert = false next end if inside_cert certs.last << line end end certs end split_certs(ARGF).each do |c| puts "", cert_info(c) end