Class: ParseClientCert
- Inherits:
-
Object
- Object
- ParseClientCert
- Defined in:
- lib/parse_client_cert.rb
Overview
Object wrapper for data from client certificate
Instance Attribute Summary collapse
-
#c ⇒ Object
Returns the value of attribute c.
-
#cn ⇒ Object
Returns the value of attribute cn.
-
#emailaddress ⇒ Object
Returns the value of attribute emailaddress.
-
#loc ⇒ Object
Returns the value of attribute loc.
-
#o ⇒ Object
Returns the value of attribute o.
-
#ou ⇒ Object
Returns the value of attribute ou.
-
#serial ⇒ Object
Returns the value of attribute serial.
-
#st ⇒ Object
Returns the value of attribute st.
Class Method Summary collapse
- .from_apache(request) ⇒ Object
- .from_nginx(request) ⇒ Object
- .process_certificate(certificate) ⇒ Object
Instance Method Summary collapse
-
#initialize(args) ⇒ ParseClientCert
constructor
A new instance of ParseClientCert.
Constructor Details
#initialize(args) ⇒ ParseClientCert
Returns a new instance of ParseClientCert.
9 10 11 12 13 |
# File 'lib/parse_client_cert.rb', line 9 def initialize(args) args.each do |k, v| instance_variable_set("@#{k}", v) unless v.nil? end end |
Instance Attribute Details
#c ⇒ Object
Returns the value of attribute c.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def c @c end |
#cn ⇒ Object
Returns the value of attribute cn.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def cn @cn end |
#emailaddress ⇒ Object
Returns the value of attribute emailaddress.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def emailaddress @emailaddress end |
#loc ⇒ Object
Returns the value of attribute loc.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def loc @loc end |
#o ⇒ Object
Returns the value of attribute o.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def o @o end |
#ou ⇒ Object
Returns the value of attribute ou.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def ou @ou end |
#serial ⇒ Object
Returns the value of attribute serial.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def serial @serial end |
#st ⇒ Object
Returns the value of attribute st.
7 8 9 |
# File 'lib/parse_client_cert.rb', line 7 def st @st end |
Class Method Details
.from_apache(request) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/parse_client_cert.rb', line 16 def from_apache(request) return nil if request.nil? or request.env.nil? pem = request.env['SSL_CLIENT_CERT'] if pem.nil? nil else cert = OpenSSL::X509::Certificate.new(pem) process_certificate(cert) end end |
.from_nginx(request) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/parse_client_cert.rb', line 27 def from_nginx(request) return nil if request.nil? or request.env.nil? pem = request.env['HTTP_X_SSL_CERT'] if pem.nil? nil else cert = OpenSSL::X509::Certificate.new(pem.tr("\t", "\n")) process_certificate(cert) end end |
.process_certificate(certificate) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/parse_client_cert.rb', line 38 def process_certificate(certificate) serial = certificate.serial.to_i.to_s(16) av_pairs = certificate.subject.to_a.map do |i| [i[0].downcase.to_sym, i[1]] end subject = Hash[*av_pairs.flatten].merge(serial: serial) ParseClientCert.new(subject) end |