Class: LetsEncrypt::Certificate

Inherits:
ApplicationRecord
  • Object
show all
Includes:
CertificateIssuable, CertificateVerifiable
Defined in:
app/models/lets_encrypt/certificate.rb

Overview

Schema Information

Table name: letsencrypt_certificates

id                  :integer          not null, primary key
domain              :string(255)
certificate         :text(65535)
intermediaries      :text(65535)
key                 :text(65535)
expires_at          :datetime
renew_after         :datetime
verification_path   :string(255)
verification_string :string(255)
created_at          :datetime         not null
updated_at          :datetime         not null

Indexes

index_letsencrypt_certificates_on_domain       (domain)
index_letsencrypt_certificates_on_renew_after  (renew_after)

Instance Method Summary collapse

Methods included from CertificateIssuable

#issue

Methods included from CertificateVerifiable

#verify

Instance Method Details

#active?Boolean

Returns false if certificate is not issued.

This method didn’t check certificate is valid, its only uses for checking is there has a certificate.

Returns:

  • (Boolean)


45
46
47
# File 'app/models/lets_encrypt/certificate.rb', line 45

def active?
  certificate.present?
end

#bundleObject

Returns full-chain bundled certificates



64
65
66
# File 'app/models/lets_encrypt/certificate.rb', line 64

def bundle
  (certificate || '') + (intermediaries || '')
end

#certificate_objectObject



68
69
70
# File 'app/models/lets_encrypt/certificate.rb', line 68

def certificate_object
  @certificate_object ||= OpenSSL::X509::Certificate.new(certificate)
end

#delete_from_redisObject

Delete certificate from redis



82
83
84
# File 'app/models/lets_encrypt/certificate.rb', line 82

def delete_from_redis
  LetsEncrypt::Redis.delete(self)
end

#expired?Boolean

Returns true if certificate is expired.

Returns:

  • (Boolean)


50
51
52
# File 'app/models/lets_encrypt/certificate.rb', line 50

def expired?
  Time.zone.now >= expires_at
end

#getObject Also known as: renew

Returns true if success get a new certificate



55
56
57
58
59
# File 'app/models/lets_encrypt/certificate.rb', line 55

def get
  ActiveSupport::Notifications.instrument('letsencrypt.issue', domain: domain) do
    verify && issue
  end
end

#key_objectObject



72
73
74
# File 'app/models/lets_encrypt/certificate.rb', line 72

def key_object
  @key_object ||= OpenSSL::PKey::RSA.new(key)
end

#save_to_redisObject

Save certificate into redis



77
78
79
# File 'app/models/lets_encrypt/certificate.rb', line 77

def save_to_redis
  LetsEncrypt::Redis.save(self)
end