All pastes #350668 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-02-11 16:51 UTC
rendered paste body
I had this working in the model with different methods (getCommonName), but this seems to be the more RoR sort of way to do it, at least before I override find().

  def list
    # The DB has only ID, CSR and X509 cert data (PEM formatted)
    @certificates = Certificate.find(:all)
    for certificate in @certificates
      x509 = OpenSSL::X509::Certificate.new(certificate.data)
      certificate.validFrom = x509.not_before
      certificate.validTo = x509.not_after
      certificate.certificateAuthority = x509.issuer.to_s.split('/').select { |item| item =~ /^CN=/ }.to_s.gsub(/^CN=/,'')
      certificate.commonName = x509.subject.to_s.split('/').select { |item| item =~ /^CN=/ }.to_s.gsub(/^CN=/,'')
    end
#    @certificate_pages, @certificates = paginate :certificates, :per_page => 10
  end