Class: LetsEncrypt::Certificate

Inherits:
ActiveRecord::Base
  • 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.



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

def active?
  certificate.present?
end

#bundleObject

Returns full-chain bundled certificates



59
60
61
# File 'app/models/lets_encrypt/certificate.rb', line 59

def bundle
  certificate + intermediaries
end

#certificate_objectObject



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

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

#expired?Boolean

Returns true if certificate is expired.



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

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

#getObject Also known as: renew

Returns true if success get a new certificate



52
53
54
# File 'app/models/lets_encrypt/certificate.rb', line 52

def get
  verify && issue
end

#key_objectObject



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

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

#save_to_redisObject

Save certificate into redis



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

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