Skip to content

Instantly share code, notes, and snippets.

@trlinkin
Created May 6, 2014 02:10
Show Gist options
  • Select an option

  • Save trlinkin/be1f6e2fbf6c452db3e6 to your computer and use it in GitHub Desktop.

Select an option

Save trlinkin/be1f6e2fbf6c452db3e6 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'yaml'
pol_file = File.join(File.dirname(__FILE__),"auths.yaml")
pol = YAML.load(File.read(pol_file))
csr = OpenSSL::X509::Request.new STDIN.read
pw = nil
id_oid = pol[:id_oid]
id = nil
extentions = Hash.new
csr.attributes.each do |attr|
pw = attr.value.first.value if attr.oid == 'challengePassword'
if attr.oid == 'extReq'
extraw = attr.value.first.value.map(&:value)
index = -1
extraw.map do |ext|
index += 1
ev = OpenSSL::X509::Extension.new(ext[0].value, ext[1].value)
extentions[ev.oid] = ev.value
end
end
end
id = extentions[id_oid]
puts
if pw and id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment