Sha256: 43627fabb9306b8e061ab83dfac5b1fa7f860a1c442ad54ea783bc3a58edd157

Contents?: true

Size: 1.06 KB

Versions: 59

Compression:

Stored size: 1.06 KB

Contents

module Dap
module Filter

require 'openssl'

class FilterDecodeX509
  include BaseDecoder

  def decode(data)
    save = {}
    cert = OpenSSL::X509::Certificate.new(data) rescue nil
    return unless cert 

    dnames = []
    cert.subject.to_s.split("/").each do |bit|
      var,val = bit.split("=", 2)
      next unless (var and val)
      var = var.to_s.downcase.strip
      save["s_#{var}"] = val 
      if var == "cn"
        dnames << val
      end
    end

    cert.issuer.to_s.split("/").each do |bit|
      var,val = bit.split("=", 2)
      next unless (var and val)
      var = var.to_s.downcase.strip
      save["i_#{var}"] = val 
    end

    cert.extensions.each do |e|
      next unless e.to_s =~ /^([^\s]+)\s*=\s*(.*)/
      var,val = $1,$2
      var = var.to_s.downcase.strip
      save["e_#{var}"] = val.strip

      if var == "subjectaltname"
        val.split(",").map{|x| x.gsub("DNS:", "").gsub("IP:", "").gsub("email:", "").strip }.each do |name|
          dnames << name
        end
      end

    end

    save["names"] = dnames
    save
  end

end

end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
dap-1.3.1 lib/dap/filter/openssl.rb
dap-1.3.0 lib/dap/filter/openssl.rb
dap-1.2.9 lib/dap/filter/openssl.rb
dap-1.2.8 lib/dap/filter/openssl.rb
dap-1.2.7 lib/dap/filter/openssl.rb
dap-1.2.6 lib/dap/filter/openssl.rb
dap-1.2.5 lib/dap/filter/openssl.rb
dap-1.2.4 lib/dap/filter/openssl.rb
dap-1.2.3 lib/dap/filter/openssl.rb
dap-1.2.2 lib/dap/filter/openssl.rb
dap-1.2.1 lib/dap/filter/openssl.rb
dap-1.2.0 lib/dap/filter/openssl.rb
dap-1.0.2 lib/dap/filter/openssl.rb
dap-1.0.1 lib/dap/filter/openssl.rb
dap-1.0.0 lib/dap/filter/openssl.rb
dap-0.1.24 lib/dap/filter/openssl.rb
dap-0.1.23 lib/dap/filter/openssl.rb
dap-0.1.22 lib/dap/filter/openssl.rb
dap-0.1.21 lib/dap/filter/openssl.rb
dap-0.1.20 lib/dap/filter/openssl.rb