puppet 2.6.11 → 2.6.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (67) hide show
  1. data/CHANGELOG +33 -0
  2. data/conf/redhat/puppet.spec +7 -4
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/application/cert.rb +17 -3
  5. data/lib/puppet/application/kick.rb +0 -2
  6. data/lib/puppet/defaults.rb +52 -3
  7. data/lib/puppet/network/handler/ca.rb +16 -106
  8. data/lib/puppet/network/handler/master.rb +0 -3
  9. data/lib/puppet/network/handler/runner.rb +1 -0
  10. data/lib/puppet/ssl/certificate.rb +6 -0
  11. data/lib/puppet/ssl/certificate_authority.rb +86 -11
  12. data/lib/puppet/ssl/certificate_authority/interface.rb +64 -19
  13. data/lib/puppet/ssl/certificate_factory.rb +112 -91
  14. data/lib/puppet/ssl/certificate_request.rb +88 -1
  15. data/lib/puppet/ssl/host.rb +16 -3
  16. data/lib/puppet/type/file.rb +0 -1
  17. data/lib/puppet/util/command_line/puppetca +23 -2
  18. data/lib/puppet/util/monkey_patches.rb +69 -0
  19. data/lib/puppet/util/settings.rb +5 -0
  20. data/spec/integration/defaults_spec.rb +11 -0
  21. data/spec/integration/network/handler_spec.rb +1 -1
  22. data/spec/unit/configurer_spec.rb +2 -2
  23. data/spec/unit/network/handler/ca_spec.rb +86 -0
  24. data/spec/unit/ssl/certificate_authority/interface_spec.rb +92 -53
  25. data/spec/unit/ssl/certificate_authority_spec.rb +133 -23
  26. data/spec/unit/ssl/certificate_factory_spec.rb +90 -70
  27. data/spec/unit/ssl/certificate_request_spec.rb +62 -1
  28. data/spec/unit/ssl/certificate_spec.rb +31 -0
  29. data/spec/unit/ssl/host_spec.rb +44 -2
  30. data/spec/unit/util/settings_spec.rb +10 -0
  31. data/test/language/functions.rb +0 -1
  32. data/test/language/snippets.rb +0 -9
  33. data/test/lib/puppettest/exetest.rb +1 -1
  34. data/test/lib/puppettest/servertest.rb +0 -1
  35. data/test/rails/rails.rb +0 -1
  36. data/test/ral/type/filesources.rb +0 -60
  37. metadata +5 -34
  38. data/lib/puppet/network/client.rb +0 -179
  39. data/lib/puppet/network/client/ca.rb +0 -56
  40. data/lib/puppet/network/client/file.rb +0 -6
  41. data/lib/puppet/network/client/proxy.rb +0 -27
  42. data/lib/puppet/network/client/report.rb +0 -26
  43. data/lib/puppet/network/client/runner.rb +0 -10
  44. data/lib/puppet/network/client/status.rb +0 -4
  45. data/lib/puppet/network/http_server.rb +0 -3
  46. data/lib/puppet/network/http_server/mongrel.rb +0 -150
  47. data/lib/puppet/network/http_server/webrick.rb +0 -155
  48. data/lib/puppet/network/xmlrpc/client.rb +0 -211
  49. data/lib/puppet/sslcertificates.rb +0 -146
  50. data/lib/puppet/sslcertificates/ca.rb +0 -375
  51. data/lib/puppet/sslcertificates/certificate.rb +0 -255
  52. data/lib/puppet/sslcertificates/inventory.rb +0 -38
  53. data/lib/puppet/sslcertificates/monkey_patch.rb +0 -6
  54. data/lib/puppet/sslcertificates/support.rb +0 -146
  55. data/spec/integration/network/client_spec.rb +0 -19
  56. data/spec/unit/network/client_spec.rb +0 -45
  57. data/spec/unit/network/xmlrpc/client_spec.rb +0 -172
  58. data/spec/unit/sslcertificates/ca_spec.rb +0 -110
  59. data/test/certmgr/certmgr.rb +0 -308
  60. data/test/certmgr/inventory.rb +0 -69
  61. data/test/certmgr/support.rb +0 -105
  62. data/test/network/client/ca.rb +0 -69
  63. data/test/network/client/dipper.rb +0 -34
  64. data/test/network/handler/ca.rb +0 -273
  65. data/test/network/server/mongrel_test.rb +0 -99
  66. data/test/network/server/webrick.rb +0 -128
  67. data/test/network/xmlrpc/client.rb +0 -45
@@ -1,255 +0,0 @@
1
- class Puppet::SSLCertificates::Certificate
2
- SSLCertificates = Puppet::SSLCertificates
3
-
4
- attr_accessor :certfile, :keyfile, :name, :dir, :hash, :type
5
- attr_accessor :key, :cert, :csr, :cacert
6
-
7
- @@params2names = {
8
- :name => "CN",
9
- :state => "ST",
10
- :country => "C",
11
- :email => "emailAddress",
12
- :org => "O",
13
- :city => "L",
14
- :ou => "OU"
15
- }
16
-
17
- def certname
18
- OpenSSL::X509::Name.new self.subject
19
- end
20
-
21
- def delete
22
- [@certfile,@keyfile].each { |file|
23
- File.unlink(file) if FileTest.exists?(file)
24
- }
25
-
26
- if @hash
27
- File.unlink(@hash) if FileTest.symlink?(@hash)
28
- end
29
- end
30
-
31
- def exists?
32
- FileTest.exists?(@certfile)
33
- end
34
-
35
- def getkey
36
- self.mkkey unless FileTest.exists?(@keyfile)
37
- if @password
38
-
39
- @key = OpenSSL::PKey::RSA.new(
40
-
41
- File.read(@keyfile),
42
-
43
- @password
44
- )
45
- else
46
- @key = OpenSSL::PKey::RSA.new(
47
- File.read(@keyfile)
48
- )
49
- end
50
- end
51
-
52
- def initialize(hash)
53
- raise Puppet::Error, "You must specify the common name for the certificate" unless hash.include?(:name)
54
- @name = hash[:name]
55
-
56
- # init a few variables
57
- @cert = @key = @csr = nil
58
-
59
- if hash.include?(:cert)
60
- @certfile = hash[:cert]
61
- @dir = File.dirname(@certfile)
62
- else
63
- @dir = hash[:dir] || Puppet[:certdir]
64
- @certfile = File.join(@dir, @name)
65
- end
66
-
67
- @cacertfile ||= File.join(Puppet[:certdir], "ca.pem")
68
-
69
- Puppet.recmkdir(@dir) unless FileTest.directory?(@dir)
70
-
71
- unless @certfile =~ /\.pem$/
72
- @certfile += ".pem"
73
- end
74
- @keyfile = hash[:key] || File.join(
75
- Puppet[:privatekeydir], [@name,"pem"].join(".")
76
- )
77
- Puppet.recmkdir(@dir) unless FileTest.directory?(@dir)
78
-
79
- [@keyfile].each { |file|
80
- dir = File.dirname(file)
81
-
82
- Puppet.recmkdir(dir) unless FileTest.directory?(dir)
83
- }
84
-
85
- @ttl = hash[:ttl] || 365 * 24 * 60 * 60
86
- @selfsign = hash[:selfsign] || false
87
- @encrypt = hash[:encrypt] || false
88
- @replace = hash[:replace] || false
89
- @issuer = hash[:issuer] || nil
90
-
91
- if hash.include?(:type)
92
- case hash[:type]
93
- when :ca, :client, :server; @type = hash[:type]
94
- else
95
- raise "Invalid Cert type #{hash[:type]}"
96
- end
97
- else
98
- @type = :client
99
- end
100
-
101
- @params = {:name => @name}
102
- [:state, :country, :email, :org, :ou].each { |param|
103
- @params[param] = hash[param] if hash.include?(param)
104
- }
105
-
106
- if @encrypt
107
- if @encrypt =~ /^\//
108
- File.open(@encrypt) { |f|
109
- @password = f.read.chomp
110
- }
111
- else
112
- raise Puppet::Error, ":encrypt must be a path to a pass phrase file"
113
- end
114
- else
115
- @password = nil
116
- end
117
-
118
- @selfsign = hash.include?(:selfsign) && hash[:selfsign]
119
- end
120
-
121
- # this only works for servers, not for users
122
- def mkcsr
123
- self.getkey unless @key
124
-
125
- name = OpenSSL::X509::Name.new self.subject
126
-
127
- @csr = OpenSSL::X509::Request.new
128
- @csr.version = 0
129
- @csr.subject = name
130
- @csr.public_key = @key.public_key
131
- @csr.sign(@key, OpenSSL::Digest::SHA1.new)
132
-
133
- #File.open(@csrfile, "w") { |f|
134
- # f << @csr.to_pem
135
- #}
136
-
137
- raise Puppet::Error, "CSR sign verification failed" unless @csr.verify(@key.public_key)
138
-
139
- @csr
140
- end
141
-
142
- def mkkey
143
- # @key is the file
144
-
145
- @key = OpenSSL::PKey::RSA.new(1024)
146
- # { |p,n|
147
- # case p
148
- # when 0; Puppet.info "key info: ." # BN_generate_prime
149
- # when 1; Puppet.info "key info: +" # BN_generate_prime
150
- # when 2; Puppet.info "key info: *" # searching good prime,
151
- # # n = #of try,
152
- # # but also data from BN_generate_prime
153
- # when 3; Puppet.info "key info: \n" # found good prime, n==0 - p, n==1 - q,
154
- # # but also data from BN_generate_prime
155
- # else; Puppet.info "key info: *" # BN_generate_prime
156
- # end
157
- # }
158
-
159
- if @password
160
- # passwdproc = proc { @password }
161
-
162
- keytext = @key.export(
163
-
164
- OpenSSL::Cipher::DES.new(:EDE3, :CBC),
165
-
166
- @password
167
- )
168
- File.open(@keyfile, "w", 0400) { |f|
169
- f << keytext
170
- }
171
- else
172
- File.open(@keyfile, "w", 0400) { |f|
173
- f << @key.to_pem
174
- }
175
- end
176
-
177
- #cmd = "#{ossl} genrsa -out #{@key} 1024"
178
- end
179
-
180
- def mkselfsigned
181
- self.getkey unless @key
182
-
183
- raise Puppet::Error, "Cannot replace existing certificate" if @cert
184
-
185
- args = {
186
- :name => self.certname,
187
- :ttl => @ttl,
188
- :issuer => nil,
189
- :serial => 0x0,
190
- :publickey => @key.public_key
191
- }
192
- if @type
193
- args[:type] = @type
194
- else
195
- args[:type] = :server
196
- end
197
- @cert = SSLCertificates.mkcert(args)
198
-
199
- @cert.sign(@key, OpenSSL::Digest::SHA1.new) if @selfsign
200
-
201
- @cert
202
- end
203
-
204
- def subject(string = false)
205
- subj = @@params2names.collect { |param, name|
206
- [name, @params[param]] if @params.include?(param)
207
- }.reject { |ary| ary.nil? }
208
-
209
- if string
210
- return "/" + subj.collect { |ary|
211
- "%s=%s" % ary
212
- }.join("/") + "/"
213
- else
214
- return subj
215
- end
216
- end
217
-
218
- # verify that we can track down the cert chain or whatever
219
- def verify
220
- "openssl verify -verbose -CAfile /home/luke/.puppet/ssl/certs/ca.pem -purpose sslserver culain.madstop.com.pem"
221
- end
222
-
223
- def write
224
- files = {
225
- @certfile => @cert,
226
- @keyfile => @key,
227
- }
228
- files[@cacertfile] = @cacert if defined?(@cacert)
229
-
230
- files.each { |file,thing|
231
- if thing
232
- next if FileTest.exists?(file)
233
-
234
- text = nil
235
-
236
- if thing.is_a?(OpenSSL::PKey::RSA) and @password
237
-
238
- text = thing.export(
239
-
240
- OpenSSL::Cipher::DES.new(:EDE3, :CBC),
241
-
242
- @password
243
- )
244
- else
245
- text = thing.to_pem
246
- end
247
-
248
- File.open(file, "w", 0660) { |f| f.print text }
249
- end
250
- }
251
-
252
- SSLCertificates.mkhash(Puppet[:certdir], @cacert, @cacertfile) if defined?(@cacert)
253
- end
254
- end
255
-
@@ -1,38 +0,0 @@
1
- # A module for keeping track of all the certificates issued by the CA, ever
2
- # Maintains the file "$cadir/inventory.txt"
3
- module Puppet::SSLCertificates
4
- module Inventory
5
-
6
- # Add CERT to the inventory of issued certs in '$cadir/inventory.txt'
7
- # If no inventory exists yet, build an inventory and list all the
8
- # certificates that have been signed so far
9
- def self.add(cert)
10
- inited = false
11
- inited = true if FileTest.exists?(Puppet[:cert_inventory])
12
-
13
- Puppet.settings.write(:cert_inventory, "a") do |f|
14
- f.puts((inited ? nil : self.init).to_s + format(cert))
15
- end
16
- end
17
-
18
- private
19
-
20
- def self.init
21
- inv = "# Inventory of signed certificates\n"
22
- inv += "# SERIAL NOT_BEFORE NOT_AFTER SUBJECT\n"
23
- Dir.glob(File::join(Puppet[:signeddir], "*.pem")) do |f|
24
- inv += format(OpenSSL::X509::Certificate.new(File::read(f))) + "\n"
25
- end
26
- inv
27
- end
28
-
29
- def self.format(cert)
30
- iso = '%Y-%m-%dT%H:%M:%S%Z'
31
- return "0x%04x %s %s %s" % [cert.serial,
32
- cert.not_before.strftime(iso),
33
- cert.not_after.strftime(iso),
34
- cert.subject]
35
- end
36
- end
37
- end
38
-
@@ -1,6 +0,0 @@
1
- # This is the file that we use to add indirection to all the SSL Certificate classes.
2
-
3
- require 'puppet/indirector'
4
-
5
- OpenSSL::PKey::RSA.extend Puppet::Indirector
6
- OpenSSL::PKey::RSA.indirects :ssl_rsa, :terminus_class => :file
@@ -1,146 +0,0 @@
1
- require 'puppet/sslcertificates'
2
-
3
- # A module to handle reading of certificates.
4
- module Puppet::SSLCertificates::Support
5
- class MissingCertificate < Puppet::Error; end
6
- class InvalidCertificate < Puppet::Error; end
7
-
8
- attr_reader :cacert
9
-
10
- # Some metaprogramming to create methods for retrieving and creating keys.
11
- # This probably isn't fewer lines than defining each separately...
12
- def self.keytype(name, options, &block)
13
- var = "@#{name}"
14
-
15
- maker = "mk_#{name}"
16
- reader = "read_#{name}"
17
-
18
- unless param = options[:param]
19
- raise ArgumentError, "You must specify the parameter for the key"
20
- end
21
-
22
- unless klass = options[:class]
23
- raise ArgumentError, "You must specify the class for the key"
24
- end
25
-
26
- # Define the method that creates it.
27
- define_method(maker, &block)
28
-
29
- # Define the reading method.
30
- define_method(reader) do
31
- return nil unless FileTest.exists?(Puppet[param]) or rename_files_with_uppercase(Puppet[param])
32
-
33
- begin
34
- instance_variable_set(var, klass.new(File.read(Puppet[param])))
35
- rescue => detail
36
- raise InvalidCertificate, "Could not read #{param}: #{detail}"
37
- end
38
- end
39
-
40
- # Define the overall method, which just calls the reader and maker
41
- # as appropriate.
42
- define_method(name) do
43
- unless cert = instance_variable_get(var)
44
- unless cert = send(reader)
45
- cert = send(maker)
46
- Puppet.settings.write(param) { |f| f.puts cert.to_pem }
47
- end
48
- instance_variable_set(var, cert)
49
- end
50
- cert
51
- end
52
- end
53
-
54
- # The key pair.
55
- keytype :key, :param => :hostprivkey, :class => OpenSSL::PKey::RSA do
56
- Puppet.info "Creating a new SSL key at #{Puppet[:hostprivkey]}"
57
- key = OpenSSL::PKey::RSA.new(Puppet[:keylength])
58
-
59
- # Our key meta programming can only handle one file, so we have
60
- # to separately write out the public key.
61
- Puppet.settings.write(:hostpubkey) do |f|
62
- f.print key.public_key.to_pem
63
- end
64
- return key
65
- end
66
-
67
- # Our certificate request
68
- keytype :csr, :param => :hostcsr, :class => OpenSSL::X509::Request do
69
- Puppet.info "Creating a new certificate request for #{Puppet[:certname]}"
70
-
71
- csr = OpenSSL::X509::Request.new
72
- csr.version = 0
73
- csr.subject = OpenSSL::X509::Name.new([["CN", Puppet[:certname]]])
74
- csr.public_key = key.public_key
75
- csr.sign(key, OpenSSL::Digest::MD5.new)
76
-
77
- return csr
78
- end
79
-
80
- keytype :cert, :param => :hostcert, :class => OpenSSL::X509::Certificate do
81
- raise MissingCertificate, "No host certificate"
82
- end
83
-
84
- keytype :ca_cert, :param => :localcacert, :class => OpenSSL::X509::Certificate do
85
- raise MissingCertificate, "No CA certificate"
86
- end
87
-
88
- # Request a certificate from the remote system. This does all of the work
89
- # of creating the cert request, contacting the remote system, and
90
- # storing the cert locally.
91
- def requestcert
92
- begin
93
- cert, cacert = caclient.getcert(@csr.to_pem)
94
- rescue => detail
95
- puts detail.backtrace if Puppet[:trace]
96
- raise Puppet::Error.new("Certificate retrieval failed: #{detail}")
97
- end
98
-
99
- if cert.nil? or cert == ""
100
- return nil
101
- end
102
- Puppet.settings.write(:hostcert) do |f| f.print cert end
103
- Puppet.settings.write(:localcacert) do |f| f.print cacert end
104
- #File.open(@certfile, "w", 0644) { |f| f.print cert }
105
- #File.open(@cacertfile, "w", 0644) { |f| f.print cacert }
106
- begin
107
- @cert = OpenSSL::X509::Certificate.new(cert)
108
- @cacert = OpenSSL::X509::Certificate.new(cacert)
109
- retrieved = true
110
- rescue => detail
111
- raise Puppet::Error.new(
112
- "Invalid certificate: #{detail}"
113
- )
114
- end
115
-
116
- raise Puppet::DevError, "Received invalid certificate" unless @cert.check_private_key(@key)
117
- retrieved
118
- end
119
-
120
- # A hack method to deal with files that exist with a different case.
121
- # Just renames it; doesn't read it in or anything.
122
- def rename_files_with_uppercase(file)
123
- dir = File.dirname(file)
124
- short = File.basename(file)
125
-
126
- # If the dir isn't present, we clearly don't have the file.
127
- #return nil unless FileTest.directory?(dir)
128
-
129
- raise ArgumentError, "Tried to fix SSL files to a file containing uppercase" unless short.downcase == short
130
-
131
- return false unless File.directory?(dir)
132
-
133
- real_file = Dir.entries(dir).reject { |f| f =~ /^\./ }.find do |other|
134
- other.downcase == short
135
- end
136
-
137
- return nil unless real_file
138
-
139
- full_file = File.join(dir, real_file)
140
-
141
- Puppet.notice "Fixing case in #{full_file}; renaming to #{file}"
142
- File.rename(full_file, file)
143
-
144
- true
145
- end
146
- end
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.dirname(__FILE__) + '/../../spec_helper'
4
-
5
- require 'puppet/network/client'
6
-
7
- describe Puppet::Network::Client do
8
- %w{ca file report runner status}.each do |name|
9
- it "should have a #{name} client" do
10
- Puppet::Network::Client.client(name).should be_instance_of(Class)
11
- end
12
-
13
- [:name, :handler, :drivername].each do |data|
14
- it "should have a #{data} value for the #{name} client" do
15
- Puppet::Network::Client.client(name).send(data).should_not be_nil
16
- end
17
- end
18
- end
19
- end