Class: Puppet::SSL::Key

Inherits:
Base show all
Extended by:
Indirector
Defined in:
lib/puppet/ssl/key.rb

Overview

Manage private and public keys as a pair.

Defined Under Namespace

Classes: Ca, DisabledCa, File, Memory

Constant Summary

Constants included from Indirector

Indirector::BadNameRegexp

Constants inherited from Base

Base::SEPARATOR, Base::VALID_CERTNAME

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indirector

configure_routes, indirects

Methods inherited from Base

#ca?, #digest, #digest_algorithm, #fingerprint, from_instance, from_multiple_s, from_s, name_from_subject, #to_data_hash, to_multiple_s, #to_text, validate_certname, wrapped_class, wraps

Constructor Details

#initialize(name) ⇒ Key

Returns a new instance of Key.



28
29
30
31
32
33
34
35
36
# File 'lib/puppet/ssl/key.rb', line 28

def initialize(name)
  super

  if ca?
    @password_file = Puppet[:capass]
  else
    @password_file = Puppet[:passfile]
  end
end

Instance Attribute Details

#password_fileObject



20
21
22
# File 'lib/puppet/ssl/key.rb', line 20

def password_file
  @password_file
end

Class Method Details

.supported_formatsObject

Because of how the format handler class is included, this can’t be in the base class.



16
17
18
# File 'lib/puppet/ssl/key.rb', line 16

def self.supported_formats
  [:s]
end

Instance Method Details

#generateObject

Knows how to create keys with our system defaults.



23
24
25
26
# File 'lib/puppet/ssl/key.rb', line 23

def generate
  Puppet.info "Creating a new SSL key for #{name}"
  @content = OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i)
end

#passwordObject



38
39
40
41
42
# File 'lib/puppet/ssl/key.rb', line 38

def password
  return nil unless password_file and Puppet::FileSystem.exist?(password_file)

  ::File.read(password_file)
end

#read(path) ⇒ Object

Optionally support specifying a password file.



45
46
47
48
49
50
# File 'lib/puppet/ssl/key.rb', line 45

def read(path)
  return super unless password_file

  #@content = wrapped_class.new(::File.read(path), password)
  @content = wrapped_class.new(::File.read(path), password)
end

#to_sObject



52
53
54
55
56
57
58
# File 'lib/puppet/ssl/key.rb', line 52

def to_s
  if pass = password
    @content.export(OpenSSL::Cipher::DES.new(:EDE3, :CBC), pass)
  else
    return super
  end
end