Sha256: d0eb0203f943d56da02b244283f045930867f6bdd403853f3132cd75bce1b7ca

Contents?: true

Size: 1.76 KB

Versions: 48

Compression:

Stored size: 1.76 KB

Contents

require 'puppet/ssl/base'
require 'puppet/indirector'

# Manage private and public keys as a pair.
class Puppet::SSL::Key < Puppet::SSL::Base
  wraps OpenSSL::PKey::RSA

  extend Puppet::Indirector
  indirects :key, :terminus_class => :file, :doc => <<DOC
    This indirection wraps an `OpenSSL::PKey::RSA object, representing a private key.
    The indirection key is the certificate CN (generally a hostname).
DOC

  # Because of how the format handler class is included, this
  # can't be in the base class.
  def self.supported_formats
    [:s]
  end

  attr_accessor :password_file

  # Knows how to create keys with our system defaults.
  def generate
    Puppet.info "Creating a new SSL key for #{name}"
    @content = OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i)
  end

  def initialize(name)
    super

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

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

    # Puppet generates files at the default Puppet[:capass] using ASCII
    # User configured :passfile could be in any encoding
    # Use BINARY given the string is passed to an OpenSSL API accepting bytes
    # note this is only called internally
    Puppet::FileSystem.read(password_file, :encoding => Encoding::BINARY)
  end

  # Optionally support specifying a password file.
  def read(path)
    return super unless password_file

    # RFC 1421 states PEM is 7-bit ASCII https://tools.ietf.org/html/rfc1421
    @content = wrapped_class.new(Puppet::FileSystem.read(path, :encoding => Encoding::ASCII), password)
  end

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

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
puppet-4.10.8 lib/puppet/ssl/key.rb
puppet-4.10.8-x86-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.8-x64-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.8-universal-darwin lib/puppet/ssl/key.rb
puppet-4.10.7 lib/puppet/ssl/key.rb
puppet-4.10.7-x86-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.7-x64-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.7-universal-darwin lib/puppet/ssl/key.rb
puppet-4.10.6 lib/puppet/ssl/key.rb
puppet-4.10.6-x86-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.6-x64-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.6-universal-darwin lib/puppet/ssl/key.rb
puppet-4.10.5 lib/puppet/ssl/key.rb
puppet-4.10.5-x86-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.5-x64-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.5-universal-darwin lib/puppet/ssl/key.rb
puppet-4.10.4 lib/puppet/ssl/key.rb
puppet-4.10.4-x86-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.4-x64-mingw32 lib/puppet/ssl/key.rb
puppet-4.10.4-universal-darwin lib/puppet/ssl/key.rb