Module: Watobo::ClientCertStore
- Defined in:
- lib/watobo/core/client_cert_store.rb
Overview
:nodoc: all
Class Method Summary collapse
- .add_pem(site, cert_file, key_file, password = nil) ⇒ Object
- .add_pkcs12(site, cert_file, password = nil) ⇒ Object
- .certs ⇒ Object
- .certs=(client_certs) ⇒ Object
-
.clear ⇒ Object
:ssl_client_cert :ssl_client_key :extra_chain_certs.
- .get(site) ⇒ Object
- .load ⇒ Object
- .save ⇒ Object
- .set(site, cert) ⇒ Object
Class Method Details
.add_pem(site, cert_file, key_file, password = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/watobo/core/client_cert_store.rb', line 15 def self.add_pem( site, cert_file, key_file, password=nil) cinfo = { :type => :pem, :certificate_file => cert_file, :key_file => key_file, :password => password } begin cinfo[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(cert_file)) cinfo[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(key_file)) @client_certs[site] = cinfo return false rescue => bang puts bang end false end |
.add_pkcs12(site, cert_file, password = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/watobo/core/client_cert_store.rb', line 33 def self.add_pkcs12( site, cert_file, password=nil ) cinfo = { :type => :pkcs12, :certificate_file => cert_file, :password => password } begin p12 = OpenSSL::PKCS12.new( File.read(cert_file), password) cinfo[:ssl_client_cert] = p12.certificate cinfo[:ssl_client_key] = p12.key cinfo[:extra_chain_certs] = p12.ca_certs @client_certs[site] = cinfo return true rescue => bang puts bang end false end |
.certs ⇒ Object
60 61 62 |
# File 'lib/watobo/core/client_cert_store.rb', line 60 def self.certs Marshal::load(Marshal::dump(@client_certs)) end |
.certs=(client_certs) ⇒ Object
64 65 66 |
# File 'lib/watobo/core/client_cert_store.rb', line 64 def self.certs=(client_certs) @client_certs = client_certs end |
.clear ⇒ Object
:ssl_client_cert
:ssl_client_key
:extra_chain_certs
11 12 13 |
# File 'lib/watobo/core/client_cert_store.rb', line 11 def self.clear @client_certs.clear end |
.get(site) ⇒ Object
68 69 70 71 |
# File 'lib/watobo/core/client_cert_store.rb', line 68 def self.get( site ) return nil unless @client_certs.has_key? site.to_sym @client_certs[ site.to_sym ] end |
.load ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/watobo/core/client_cert_store.rb', line 73 def self.load certs = Watobo::DataStore.load_project_settings('ClientCertStore') return false if certs.nil? @client_certs = certs @client_certs.each do |site, cinfo| begin case cinfo[:type] when :pem add_pem(site, cinfo[:certificate_file], cinfo[:key_file], cinfo[:password]) when :pkcs12 add_pkcs12(site, cinfo[:certificate_file], cinfo[:password]) end rescue => bang puts bang puts bang.backtrace end end end |
.save ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/watobo/core/client_cert_store.rb', line 93 def self.save out = {} @client_certs.each do |site, cinfo| data = {} [:certificate_file, :key_file, :type ].each do |k| data[k] = cinfo[k] end out[site] = data end Watobo::DataStore.save_project_settings('ClientCertStore', out) end |
.set(site, cert) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/watobo/core/client_cert_store.rb', line 53 def self.set( site, cert ) return false if cert.nil? @client_certs[ site.to_sym ] = cert save true end |