Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • anatoli/postal
1 result
Show changes
Commits on Source (6)
Loading
Loading
@@ -10,7 +10,8 @@ controller :send do
param :to, "The e-mail addresses of the recipients (max 50)", :type => Array
param :cc, "The e-mail addresses of any CC contacts (max 50)", :type => Array
param :bcc, "The e-mail addresses of any BCC contacts (max 50)", :type => Array
param :from, "The e-mail address of the sender", :type => String
param :from, "The e-mail address for the From header", :type => String
param :sender, "The e-mail address for the Sender header", :type => String
param :subject, "The subject of the e-mail", :type => String
param :tag, "The tag of the e-mail", :type => String
param :reply_to, "Set the reply-to address for the mail", :type => String
Loading
Loading
Loading
Loading
@@ -231,11 +231,6 @@ class Server < ApplicationRecord
return domain
end
 
# Check with global domains
if route = self.routes.includes(:domain).references(:domain).where(:domains => {:server_id => nil, :name => domain_name}, :name => uname).first
return route.domain
end
if any_domain = self.domains.verified.where(:use_for_any => true).order(:name).first
return any_domain
end
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
@@ -58,9 +63,11 @@ 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
logger.info "Error: #{e.class} (#{e.message})"
return false
end
end
Loading
Loading
@@ -71,12 +78,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
 
Loading
Loading
@@ -92,4 +101,8 @@ class TrackCertificate < ApplicationRecord
@key_object ||= OpenSSL::PKey::RSA.new(self.key)
end
 
def logger
Postal::LetsEncrypt.logger
end
end
Loading
Loading
@@ -10,6 +10,10 @@ module Clockwork
SendNotificationsJob.queue(:main)
end
 
every 15.minutes, 'every-15-minutes', :at => ['**:00', '**:15', '**:30', '**:45'] do
RenewTrackCertificatesJob.queue(:main)
end
every 1.hour, 'every-hour', :at => ['**:15'] do
CheckAllDNSJob.queue(:main)
ExpireHeldMessagesJob.queue(:main)
Loading
Loading
@@ -18,7 +22,6 @@ module Clockwork
 
every 1.hour, 'every-hour', :at => ['**:45'] do
PruneWebhookRequestsJob.queue(:main)
RenewTrackCertificatesJob.queue(:main)
end
 
every 1.day, 'every-day', :at => ['03:00'] do
Loading
Loading
Loading
Loading
@@ -17,7 +17,14 @@ module Postal
 
def self.register_private_key(email_address)
registration = client.register(:contact => "mailto:#{email_address}")
logger.info "Successfully registered private key with address #{email_address}"
registration.agree_terms
logger.info "Terms have been accepted"
true
end
def self.logger
Postal.logger_for(:lets_encrypt)
end
 
end
Loading
Loading