~ubuntu-branches/ubuntu/quantal/puppet/quantal-security

« back to all changes in this revision

Viewing changes to .pc/CVE-2011-3872.patch/lib/puppet/application/cert.rb

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-10-24 15:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20111024150512-yxqwfdp6hcs6of5l
Tags: 2.7.1-1ubuntu3.2
* SECURITY UPDATE: puppet master impersonation via incorrect certificates
  - debian/patches/CVE-2011-3872.patch: refactor certificate handling.
  - Thanks to upstream for providing the patch.
  - CVE-2011-3872

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'puppet/application'
 
2
 
 
3
class Puppet::Application::Cert < Puppet::Application
 
4
 
 
5
  should_parse_config
 
6
  run_mode :master
 
7
 
 
8
  attr_accessor :all, :ca, :digest, :signed
 
9
 
 
10
  def subcommand
 
11
    @subcommand
 
12
  end
 
13
  def subcommand=(name)
 
14
    # Handle the nasty, legacy mapping of "clean" to "destroy".
 
15
    sub = name.to_sym
 
16
    @subcommand = (sub == :clean ? :destroy : sub)
 
17
  end
 
18
 
 
19
  option("--clean", "-c") do
 
20
    self.subcommand = "destroy"
 
21
  end
 
22
 
 
23
  option("--all", "-a") do
 
24
    @all = true
 
25
  end
 
26
 
 
27
  option("--digest DIGEST") do |arg|
 
28
    @digest = arg
 
29
  end
 
30
 
 
31
  option("--signed", "-s") do
 
32
    @signed = true
 
33
  end
 
34
 
 
35
  option("--debug", "-d") do |arg|
 
36
    Puppet::Util::Log.level = :debug
 
37
  end
 
38
 
 
39
  require 'puppet/ssl/certificate_authority/interface'
 
40
  Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.reject {|m| m == :destroy }.each do |method|
 
41
    option("--#{method}", "-#{method.to_s[0,1]}") do
 
42
      self.subcommand = method
 
43
    end
 
44
  end
 
45
 
 
46
  option("--verbose", "-v") do
 
47
    Puppet::Util::Log.level = :info
 
48
  end
 
49
 
 
50
  def help
 
51
    <<-HELP
 
52
 
 
53
puppet-cert(8) -- Manage certificates and requests
 
54
========
 
55
 
 
56
SYNOPSIS
 
57
--------
 
58
Standalone certificate authority. Capable of generating certificates,
 
59
but mostly used for signing certificate requests from puppet clients.
 
60
 
 
61
 
 
62
USAGE
 
63
-----
 
64
puppet cert <action> [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
 
65
  [--digest <digest>] [<host>]
 
66
 
 
67
 
 
68
DESCRIPTION
 
69
-----------
 
70
Because the puppet master service defaults to not signing client
 
71
certificate requests, this script is available for signing outstanding
 
72
requests. It can be used to list outstanding requests and then either
 
73
sign them individually or sign all of them.
 
74
 
 
75
ACTIONS
 
76
-------
 
77
 
 
78
Every action except 'list' and 'generate' requires a hostname to act on,
 
79
unless the '--all' option is set.
 
80
 
 
81
* clean:
 
82
  Revoke a host's certificate (if applicable) and remove all files
 
83
  related to that host from puppet cert's storage. This is useful when
 
84
  rebuilding hosts, since new certificate signing requests will only be
 
85
  honored if puppet cert does not have a copy of a signed certificate
 
86
  for that host. If '--all' is specified then all host certificates,
 
87
  both signed and unsigned, will be removed.
 
88
 
 
89
* fingerprint:
 
90
  Print the DIGEST (defaults to md5) fingerprint of a host's
 
91
  certificate.
 
92
 
 
93
* generate:
 
94
  Generate a certificate for a named client. A certificate/keypair will
 
95
  be generated for each client named on the command line.
 
96
 
 
97
* list:
 
98
  List outstanding certificate requests. If '--all' is specified, signed
 
99
  certificates are also listed, prefixed by '+', and revoked or invalid
 
100
  certificates are prefixed by '-' (the verification outcome is printed
 
101
  in parenthesis).
 
102
 
 
103
* print:
 
104
  Print the full-text version of a host's certificate.
 
105
 
 
106
* revoke:
 
107
  Revoke the certificate of a client. The certificate can be specified
 
108
  either by its serial number (given as a decimal number or a
 
109
  hexadecimal number prefixed by '0x') or by its hostname. The
 
110
  certificate is revoked by adding it to the Certificate Revocation List
 
111
  given by the 'cacrl' configuration option. Note that the puppet master
 
112
  needs to be restarted after revoking certificates.
 
113
 
 
114
* sign:
 
115
  Sign an outstanding certificate request.
 
116
 
 
117
* verify:
 
118
  Verify the named certificate against the local CA certificate.
 
119
 
 
120
 
 
121
OPTIONS
 
122
-------
 
123
Note that any configuration parameter that's valid in the configuration
 
124
file is also a valid long argument. For example, 'ssldir' is a valid
 
125
configuration parameter, so you can specify '--ssldir <directory>' as an
 
126
argument.
 
127
 
 
128
See the configuration file documentation at
 
129
http://docs.puppetlabs.com/references/stable/configuration.html for the
 
130
full list of acceptable parameters. A commented list of all
 
131
configuration options can also be generated by running puppet cert with
 
132
'--genconfig'.
 
133
 
 
134
* --all:
 
135
  Operate on all items. Currently only makes sense with the 'sign',
 
136
  'clean', 'list', and 'fingerprint' actions.
 
137
 
 
138
* --digest:
 
139
  Set the digest for fingerprinting (defaults to md5). Valid values
 
140
  depends on your openssl and openssl ruby extension version, but should
 
141
  contain at least md5, sha1, md2, sha256.
 
142
 
 
143
* --debug:
 
144
  Enable full debugging.
 
145
 
 
146
* --help:
 
147
  Print this help message
 
148
 
 
149
* --verbose:
 
150
  Enable verbosity.
 
151
 
 
152
* --version:
 
153
  Print the puppet version number and exit.
 
154
 
 
155
 
 
156
EXAMPLE
 
157
-------
 
158
    $ puppet cert list
 
159
    culain.madstop.com
 
160
    $ puppet cert sign culain.madstop.com
 
161
 
 
162
 
 
163
AUTHOR
 
164
------
 
165
Luke Kanies
 
166
 
 
167
 
 
168
COPYRIGHT
 
169
---------
 
170
Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
 
171
 
 
172
    HELP
 
173
  end
 
174
 
 
175
  def main
 
176
    if @all
 
177
      hosts = :all
 
178
    elsif @signed
 
179
      hosts = :signed
 
180
    else
 
181
      hosts = command_line.args.collect { |h| h.downcase }
 
182
    end
 
183
    begin
 
184
      @ca.apply(:revoke, :to => hosts) if subcommand == :destroy
 
185
      @ca.apply(subcommand, :to => hosts, :digest => @digest)
 
186
    rescue => detail
 
187
      puts detail.backtrace if Puppet[:trace]
 
188
      puts detail.to_s
 
189
      exit(24)
 
190
    end
 
191
  end
 
192
 
 
193
  def setup
 
194
    require 'puppet/ssl/certificate_authority'
 
195
    exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
 
196
 
 
197
    Puppet::Util::Log.newdestination :console
 
198
 
 
199
    if [:generate, :destroy].include? subcommand
 
200
      Puppet::SSL::Host.ca_location = :local
 
201
    else
 
202
      Puppet::SSL::Host.ca_location = :only
 
203
    end
 
204
 
 
205
    begin
 
206
      @ca = Puppet::SSL::CertificateAuthority.new
 
207
    rescue => detail
 
208
      puts detail.backtrace if Puppet[:trace]
 
209
      puts detail.to_s
 
210
      exit(23)
 
211
    end
 
212
  end
 
213
 
 
214
  def parse_options
 
215
    # handle the bareword subcommand pattern.
 
216
    result = super
 
217
    unless self.subcommand then
 
218
      if sub = self.command_line.args.shift then
 
219
        self.subcommand = sub
 
220
      else
 
221
        help
 
222
      end
 
223
    end
 
224
    result
 
225
  end
 
226
end