Class: Puppet::SSL::StateMachine::NeedKey
- Defined in:
- lib/puppet/ssl/state_machine.rb
Overview
Load or generate a private key. If the key exists, try to load the client cert and transition to Done. If the cert is mismatched or otherwise fails valiation, raise an error. If the key doesn't exist yet, generate one, and save it. If the cert doesn't exist yet, transition to NeedSubmitCSR.
Instance Attribute Summary
Attributes inherited from SSLState
Instance Method Summary collapse
Methods inherited from SSLState
Constructor Details
This class inherits a constructor from Puppet::SSL::StateMachine::SSLState
Instance Method Details
#next_state ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/puppet/ssl/state_machine.rb', line 141 def next_state Puppet.debug(_("Loading/generating private key")) password = @cert_provider.load_private_key_password key = @cert_provider.load_private_key(Puppet[:certname], password: password) if key cert = @cert_provider.load_client_cert(Puppet[:certname]) if cert next_ctx = @ssl_provider.create_context( cacerts: @ssl_context.cacerts, crls: @ssl_context.crls, private_key: key, client_cert: cert ) return Done.new(@machine, next_ctx) end else if Puppet[:key_type] == 'ec' Puppet.info _("Creating a new EC SSL key for %{name} using curve %{curve}") % { name: Puppet[:certname], curve: Puppet[:named_curve] } key = OpenSSL::PKey::EC.generate(Puppet[:named_curve]) else Puppet.info _("Creating a new RSA SSL key for %{name}") % { name: Puppet[:certname] } key = OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i) end @cert_provider.save_private_key(Puppet[:certname], key, password: password) end NeedSubmitCSR.new(@machine, @ssl_context, key) end |