Skip to content

Instantly share code, notes, and snippets.

@janx
Created November 24, 2013 12:15
Show Gist options
  • Save janx/7626583 to your computer and use it in GitHub Desktop.
Save janx/7626583 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'base64'
require 'openssl'
require 'pp'
if ARGV.size != 1
puts "Usage: #{$0} <pem file>"
exit 1
end
pem_path = ARGV[0]
der_path = "#{pem_path}.der"
cert_path = "#{der_path}.cert"
pem = File.readlines(pem_path)[1..-2].map(&:strip).join('')
der = nil
puts "Unpacking #{pem_path} to #{der_path} .."
File.open(der_path, 'w') do |f|
der = Base64.decode64(pem)
f.write der
end
puts "Decoding #{der_path} to #{cert_path} .."
File.open(cert_path, 'w') do |f|
PP.pp OpenSSL::ASN1.decode(der), f
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment