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

Refactor key size comparison to be more efficient

parent fc1c18cc
No related branches found
No related tags found
2 merge requests!51Validate shift of Heptapod 0.25 to oldstable series,!44GitLab 14.0
...@@ -21,8 +21,9 @@ ...@@ -21,8 +21,9 @@
# they provide invalid data # they provide invalid data
helper = LetsEncryptHelper.new(node) helper = LetsEncryptHelper.new(node)
contact_info = helper.contact contact_info = helper.contact
target_key_size = new_resource.key_size || node['acme']['key_size']
if ::File.file?("#{new_resource.key}-staging") if ::File.file?("#{new_resource.key}-staging")
staging_key = OpenSSL::PKey::RSA.new ::File.read "#{new_resource.key}-staging" staging_key = OpenSSL::PKey::RSA.new ::File.read "#{new_resource.key}-staging"
staging_key_size = staging_key.n.num_bits staging_key_size = staging_key.n.num_bits
...@@ -24,18 +25,9 @@ ...@@ -24,18 +25,9 @@
if ::File.file?("#{new_resource.key}-staging") if ::File.file?("#{new_resource.key}-staging")
staging_key = OpenSSL::PKey::RSA.new ::File.read "#{new_resource.key}-staging" staging_key = OpenSSL::PKey::RSA.new ::File.read "#{new_resource.key}-staging"
staging_key_size = staging_key.n.num_bits staging_key_size = staging_key.n.num_bits
if new_resource.key_size.nil? if staging_key_size != target_key_size
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 file "#{new_resource.key}-staging" do
action :delete action :delete
end end
...@@ -70,16 +62,7 @@ ...@@ -70,16 +62,7 @@
production_key = OpenSSL::PKey::RSA.new ::File.read new_resource.key production_key = OpenSSL::PKey::RSA.new ::File.read new_resource.key
production_key_size = production_key.n.num_bits production_key_size = production_key.n.num_bits
if new_resource.key_size.nil? if production_key_size != target_key_size
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 file new_resource.key do
action :delete action :delete
end end
......
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