Skip to content
Snippets Groups Projects
Commit 822d616db7aa authored by Kenneth Chu's avatar Kenneth Chu
Browse files

Compare key_sizes only if the SSL key exists

This prevents errors from occurring during the reconfigure stage in the
following scenarios:

- The first initial run before any SSL files are created.
- If the SSL files were lost/deleted.
parent 82fb71ea9a18
No related branches found
No related tags found
2 merge requests!51Validate shift of Heptapod 0.25 to oldstable series,!44GitLab 14.0
......@@ -22,6 +22,7 @@
helper = LetsEncryptHelper.new(node)
contact_info = helper.contact
staging_key = OpenSSL::PKey::RSA.new ::File.read "#{new_resource.key}-staging"
staging_key_size = staging_key.to_text.split(/\n/).first[/[0-9]* bit/].split.first.to_i
if ::File.file?("#{new_resource.key}-staging")
staging_key = OpenSSL::PKey::RSA.new ::File.read "#{new_resource.key}-staging"
staging_key_size = staging_key.to_text.split(/\n/).first[/[0-9]* bit/].split.first.to_i
......@@ -27,6 +28,14 @@
if new_resource.key_size.nil?
unless staging_key_size == node['acme']['key_size']
if new_resource.key_size.nil?
unless staging_key_size == node['acme']['key_size']
file "#{new_resource.key}-staging" do
action :delete
end
file "#{new_resource.crt}-staging" do
action :delete
end
end
elsif staging_key_size != new_resource.key_size
file "#{new_resource.key}-staging" do
action :delete
end
......@@ -34,13 +43,6 @@
action :delete
end
end
elsif staging_key_size != new_resource.key_size
file "#{new_resource.key}-staging" do
action :delete
end
file "#{new_resource.crt}-staging" do
action :delete
end
end
acme_certificate 'staging' do
......@@ -64,6 +66,7 @@
end
end
production_key = OpenSSL::PKey::RSA.new ::File.read new_resource.key
production_key_size = production_key.to_text.split(/\n/).first[/[0-9]* bit/].split.first.to_i
if ::File.file?(new_resource.key)
production_key = OpenSSL::PKey::RSA.new ::File.read new_resource.key
production_key_size = production_key.to_text.split(/\n/).first[/[0-9]* bit/].split.first.to_i
......@@ -69,6 +72,14 @@
if new_resource.key_size.nil?
unless production_key_size == node['acme']['key_size']
if new_resource.key_size.nil?
unless production_key_size == node['acme']['key_size']
file new_resource.key do
action :delete
end
file new_resource.crt do
action :delete
end
end
elsif production_key_size != new_resource.key_size
file new_resource.key do
action :delete
end
......@@ -76,13 +87,6 @@
action :delete
end
end
elsif production_key_size != new_resource.key_size
file new_resource.key do
action :delete
end
file new_resource.crt do
action :delete
end
end
acme_certificate 'production' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment