1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-12-01 05:43:04 +00:00

logging on certificate verification & issuance

closes #94
هذا الالتزام موجود في:
Adam Cooke
2017-05-04 11:18:44 +01:00
الأصل 7ca4e74bbe
التزام e7b88842ca

عرض الملف

@@ -41,15 +41,20 @@ class TrackCertificate < ApplicationRecord
self.verification_path = challenge.filename
self.verification_string = challenge.file_content
self.save!
logger.info "Attempting verification of #{self.domain}"
challenge.request_verification
checks = 0
until challenge.verify_status != "pending"
checks += 1
return false if checks > 30
if checks > 30
logger.info "Status remained at pending for 30 checks"
return false
end
sleep 1
end
unless challenge.verify_status == "valid"
logger.info "Status was not valid (was: #{challenge.verify_status})"
return false
end
@@ -58,6 +63,7 @@ class TrackCertificate < ApplicationRecord
@retries = 0
if e.is_a?(Acme::Client::Error::BadNonce) && @retries < 5
@retries += 1
logger.info "Bad nounce encountered. Retrying (#{@retries} of 5 attempts)"
sleep 1
verify
else
@@ -71,12 +77,14 @@ class TrackCertificate < ApplicationRecord
private_key = OpenSSL::PKey::RSA.new(self.key)
csr.public_key = private_key.public_key
csr.sign(private_key, OpenSSL::Digest::SHA256.new)
logger.info "Getting certificate for #{self.domain}"
https_cert = Postal::LetsEncrypt.client.new_certificate(csr)
self.certificate = https_cert.to_pem
self.intermediaries = https_cert.chain_to_pem
self.expires_at = https_cert.x509.not_after
self.renew_after = (self.expires_at - 1.month) + rand(10).days
self.save!
logger.info "Certificate issued (expires on #{self.expires_at}, will renew after #{self.renew_after})"
return true
end
@@ -92,4 +100,8 @@ class TrackCertificate < ApplicationRecord
@key_object ||= OpenSSL::PKey::RSA.new(self.key)
end
def logger
Postal::LetsEncrypt.logger
end
end