class Configuration

Public Class Methods

new(params = {}) click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 4
def initialize(params = {})
  params.symbolize_keys!
  params.each_pair { |k, v| self.send("#{k}=".to_sym, v) }
end

Public Instance Methods

certs_path() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 38
def certs_path
  @certs_path || ActionMailerX509.default_certs_path
end
certs_path=(path) click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 42
def certs_path=(path)
  @certs_path = Pathname.new(path)
end
crypt_cert() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 58
def crypt_cert
  certs_path.join(@crypt_cert)
end
crypt_cert_p12() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 62
def crypt_cert_p12
  certs_path.join(@crypt_cert_p12)
end
crypt_key() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 66
def crypt_key
  certs_path.join(@crypt_key)
end
crypt_require?() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 34
def crypt_require?
  crypt_enable == true
end
get_certificate_info() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 78
def get_certificate_info
  if valid?
    if sign_require? || crypt_require?
      worker = sign_require? ? get_signer : get_crypter

      subject_attrs = worker.certificate.subject.to_a
      subject_attrs = subject_attrs.each_with_object({}) do |attr, obj|
        obj.update(SecurityObject::ATTRS[attr.first] => attr[1])
      end

      {
        from: worker.certificate.not_before,
        to: worker.certificate.not_after,
      }.reverse_merge!(subject_attrs)
    end || {}
  end || {}
end
get_crypter() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 70
def get_crypter
  ActionMailerX509::X509.new(crypt_configuration)
end
get_signer() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 74
def get_signer
  ActionMailerX509::X509.new(sign_configuration)
end
sign_cert() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 46
def sign_cert
  certs_path.join(@sign_cert)
end
sign_cert_p12() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 50
def sign_cert_p12
  certs_path.join(@sign_cert_p12)
end
sign_key() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 54
def sign_key
  certs_path.join(@sign_key)
end
sign_require?() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 30
def sign_require?
  sign_enable == true
end
valid?() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 96
def valid?
  validate_sign && validate_crypt
end

Protected Instance Methods

cert=(cert) click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 128
def cert=(cert)
  self.crypt_cert = cert
  self.sign_cert = cert
end
cert_p12=(cert) click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 133
def cert_p12=(cert)
  self.crypt_cert_p12 = cert
  self.sign_cert_p12 = cert
end
key=(key) click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 123
def key=(key)
  self.crypt_key = key
  self.sign_key = key
end
passphrase=(pass) click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 138
def passphrase=(pass)
  self.crypt_passphrase = pass
  self.sign_passphrase = pass
end
validate_crypt() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 112
def validate_crypt
  if crypt_require?
    begin
      get_crypter.encode('test')
    rescue
      return false
    end
  end
  true
end
validate_sign() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 101
def validate_sign
  if sign_require?
    begin
      get_signer.sign('test')
    rescue
      return false
    end
  end
  true
end

Private Instance Methods

crypt_configuration() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 154
def crypt_configuration
  conf = {
      cipher_type_str: crypt_cipher,
      pass_phrase: crypt_passphrase
  }

  conf.merge!(certificate_p12: crypt_cert_p12) if @crypt_cert_p12
  conf.merge!(certificate: crypt_cert, rsa_key: crypt_key) unless @crypt_cert_p12
  conf
end
sign_configuration() click to toggle source
# File lib/action_mailer_x509/configuration.rb, line 144
def sign_configuration
  conf = {
      pass_phrase: sign_passphrase
  }

  conf.merge!(certificate_p12: sign_cert_p12) if @sign_cert_p12
  conf.merge!(certificate: sign_cert, rsa_key: sign_key) unless @sign_cert_p12
  conf
end