summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-10-18 11:50:31 -0700
committerdanielsdeleo <dan@opscode.com>2013-10-18 11:50:31 -0700
commita8eabfdc15547203e2c326680752e67c17c430a9 (patch)
tree0a122daa16ffd3cd64685c858c42ce9f09cbff67
parent4761c2e27ddb8dafcf224e4c51d3146ceba1f26f (diff)
parentb0e918b22ae15a58af61c16509fafe82dc97cc16 (diff)
downloadchef-a8eabfdc15547203e2c326680752e67c17c430a9.tar.gz
Merge branch 'duplicate-cert-fix'
-rw-r--r--lib/chef/http/ssl_policies.rb10
-rw-r--r--spec/unit/http/ssl_policies_spec.rb9
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/chef/http/ssl_policies.rb b/lib/chef/http/ssl_policies.rb
index 17b46a6762..f2a9c5b845 100644
--- a/lib/chef/http/ssl_policies.rb
+++ b/lib/chef/http/ssl_policies.rb
@@ -79,7 +79,7 @@ class Chef
certs = Dir.glob(File.join(config.trusted_certs_dir, "*.{crt,pem}"))
certs.each do |cert_file|
cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
- http_client.cert_store.add_cert(cert)
+ add_trusted_cert(cert)
end
end
end
@@ -104,6 +104,14 @@ class Chef
Chef::Config
end
+ private
+
+ def add_trusted_cert(cert)
+ http_client.cert_store.add_cert(cert)
+ rescue OpenSSL::X509::StoreError => e
+ raise e unless e.message == 'cert already in hash table'
+ end
+
end
class APISSLPolicy < DefaultSSLPolicy
diff --git a/spec/unit/http/ssl_policies_spec.rb b/spec/unit/http/ssl_policies_spec.rb
index c80f989180..b95e13a370 100644
--- a/spec/unit/http/ssl_policies_spec.rb
+++ b/spec/unit/http/ssl_policies_spec.rb
@@ -139,6 +139,15 @@ describe "HTTP SSL Policy" do
# The system under test **SHOULD** do both of these things.
http_client.cert_store.verify(additional_pem).should be_true
end
+
+ context "and some certs are duplicates" do
+ it "skips duplicate certs" do
+ # For whatever reason, OpenSSL errors out when adding a
+ # cert you already have to the certificate store.
+ ssl_policy.set_custom_certs
+ ssl_policy.set_custom_certs #should not raise an error
+ end
+ end
end
end