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)


43
44
45
# File 'app/models/lets_encrypt/certificate.rb', line 43

def active?
  certificate.present?
end

#bundleObject

Returns full-chain bundled certificates



62
63
64
# File 'app/models/lets_encrypt/certificate.rb', line 62

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

#certificate_objectObject



66
67
68
# File 'app/models/lets_encrypt/certificate.rb', line 66

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

#delete_from_redisObject

Delete certificate from redis



80
81
82
# File 'app/models/lets_encrypt/certificate.rb', line 80

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

#expired?Boolean

Returns true if certificate is expired.

Returns:

  • (Boolean)


48
49
50
# File 'app/models/lets_encrypt/certificate.rb', line 48

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

#getObject Also known as: renew

Returns true if success get a new certificate



53
54
55
56
57
# File 'app/models/lets_encrypt/certificate.rb', line 53

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

#key_objectObject



70
71
72
# File 'app/models/lets_encrypt/certificate.rb', line 70

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

#save_to_redisObject

Save certificate into redis



75
76
77
# File 'app/models/lets_encrypt/certificate.rb', line 75

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