summaryrefslogtreecommitdiffstats
path: root/lib/puppet/ssl
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2010-01-13 08:07:30 +1100
committerJames Turnbull <james@lovedthanlost.net>2010-01-13 08:07:30 +1100
commitb6f90dfcd96123c245b6f5fd93753790006387c0 (patch)
tree1668fd8ed480dc0d0cb49c4a3d7f8a13c77dbeb9 /lib/puppet/ssl
parente26e8319186c57a41ea7ca58b0e8e853e9b452e3 (diff)
parentf7e14356ad7781fafa52a459d3c24372fa6c0900 (diff)
downloadpuppet-b6f90dfcd96123c245b6f5fd93753790006387c0.tar.gz
puppet-b6f90dfcd96123c245b6f5fd93753790006387c0.tar.xz
puppet-b6f90dfcd96123c245b6f5fd93753790006387c0.zip
Merge branch '0.25.x'
Conflicts: lib/puppet/ssl/host.rb spec/spec_helper.rb
Diffstat (limited to 'lib/puppet/ssl')
-rw-r--r--lib/puppet/ssl/certificate.rb5
-rw-r--r--lib/puppet/ssl/host.rb47
2 files changed, 17 insertions, 35 deletions
diff --git a/lib/puppet/ssl/certificate.rb b/lib/puppet/ssl/certificate.rb
index f9297f380..b6cba99a7 100644
--- a/lib/puppet/ssl/certificate.rb
+++ b/lib/puppet/ssl/certificate.rb
@@ -28,7 +28,8 @@ class Puppet::SSL::Certificate < Puppet::SSL::Base
end
def expiration
- return nil unless content
- return content.not_after
+ # Our expiration is either that of the cache or the content, whichever comes first
+ cache_expiration = @expiration
+ [(content and content.not_after), cache_expiration].compact.sort.first
end
end
diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb
index 98061c5e2..5de2c5a18 100644
--- a/lib/puppet/ssl/host.rb
+++ b/lib/puppet/ssl/host.rb
@@ -94,12 +94,7 @@ class Puppet::SSL::Host
# Remove all traces of a given host
def self.destroy(name)
- [Key, Certificate, CertificateRequest].inject(false) do |result, klass|
- if klass.destroy(name)
- result = true
- end
- result
- end
+ [Key, Certificate, CertificateRequest].collect { |part| part.destroy(name) }.any? { |x| x }
end
# Search for more than one host, optionally only specifying
@@ -107,12 +102,7 @@ class Puppet::SSL::Host
# This just allows our non-indirected class to have one of
# indirection methods.
def self.search(options = {})
- classes = [Key, CertificateRequest, Certificate]
- if klass = options[:for]
- classlist = [klass].flatten
- else
- classlist = [Key, CertificateRequest, Certificate]
- end
+ classlist = [options[:for] || [Key, CertificateRequest, Certificate]].flatten
# Collect the results from each class, flatten them, collect all of the names, make the name list unique,
# then create a Host instance for each one.
@@ -127,8 +117,7 @@ class Puppet::SSL::Host
end
def key
- return nil unless @key ||= Key.find(name)
- @key
+ @key ||= Key.find(name)
end
# This is the private key; we can create it from scratch
@@ -146,8 +135,7 @@ class Puppet::SSL::Host
end
def certificate_request
- return nil unless @certificate_request ||= CertificateRequest.find(name)
- @certificate_request
+ @certificate_request ||= CertificateRequest.find(name)
end
# Our certificate request requires the key but that's all.
@@ -166,26 +154,19 @@ class Puppet::SSL::Host
end
def certificate
- unless @certificate
- generate_key unless key
-
+ @certificate ||= (
# get the CA cert first, since it's required for the normal cert
# to be of any use.
- return nil unless Certificate.find(CA_NAME) unless ca?
- return nil unless @certificate = Certificate.find(name)
-
- unless certificate_matches_key?
- raise Puppet::Error, "Retrieved certificate does not match private key; please remove certificate from server and regenerate it with the current key"
+ if not (key or generate_key) or not (ca? or Certificate.find("ca")) or not (cert = Certificate.find(name)) or cert.expired?
+ nil
+ elsif not cert.content.check_private_key(key.content)
+ Certificate.expire(name)
+ Puppet.warning "Retrieved certificate does not match private key"
+ nil
+ else
+ cert
end
- end
- @certificate
- end
-
- def certificate_matches_key?
- return false unless key
- return false unless certificate
-
- return certificate.content.check_private_key(key.content)
+ )
end
# Generate all necessary parts of our ssl host.