# class Key

Manage private and public keys as a pair.

### Public Class Methods

new(name) click to toggle source
Calls superclass method Puppet::SSL::Base.new

    # File lib/puppet/ssl/key.rb, line 25
    def initialize(name)
      super

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

supported_formats() click to toggle source

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

    # File lib/puppet/ssl/key.rb, line 13
    def self.supported_formats
      [:s]
    end

### Public Instance Methods

generate() click to toggle source

Knows how to create keys with our system defaults.

    # File lib/puppet/ssl/key.rb, line 20
    def generate
      Puppet.info "Creating a new SSL key for #{name}"
      @content = OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i)
    end

password() click to toggle source

    # File lib/puppet/ssl/key.rb, line 35
    def password
      return nil unless password_file and FileTest.exist?(password_file)

      ::File.read(password_file)
    end

read(path) click to toggle source

Optionally support specifying a password file.

Calls superclass method Puppet::SSL::Base#read

    # File lib/puppet/ssl/key.rb, line 42
    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_s() click to toggle source
Calls superclass method Puppet::SSL::Base#to_s

    # File lib/puppet/ssl/key.rb, line 49
    def to_s
      if pass = password
        @content.export(OpenSSL::Cipher::DES.new(:EDE3, :CBC), pass)
      else
        return super
      end
    end