Sha256: 93b851164dca4283d43015f5a0933387ea7052b61801135a5df12714da49c5fc

Contents?: true

Size: 1.94 KB

Versions: 40

Compression:

Stored size: 1.94 KB

Contents

require 'openssl'
require 'puppet'
require 'xmlrpc/server'
require 'puppet/network/handler'

class Puppet::Network::Handler
  class CA < Handler
    attr_reader :ca

    desc "Provides an interface for signing CSRs.  Accepts a CSR and returns
    the CA certificate and the signed certificate, or returns nil if
    the cert is not signed."

    @interface = XMLRPC::Service::Interface.new("puppetca") { |iface|
      iface.add_method("array getcert(csr)")
    }

    def initialize(hash = {})
      Puppet.settings.use(:main, :ssl, :ca)

      @ca = Puppet::SSL::CertificateAuthority.instance
    end

    # our client sends us a csr, and we either store it for later signing,
    # or we sign it right away
    def getcert(csrtext, client = nil, clientip = nil)
      csr = Puppet::SSL::CertificateRequest.from_s(csrtext)
      hostname = csr.name

      unless @ca
        Puppet.notice "Host #{hostname} asked for signing from non-CA master"
        return ""
      end

      # We used to save the public key, but it's basically unnecessary
      # and it mucks with the permissions requirements.

      # first check to see if we already have a signed cert for the host
      cert = Puppet::SSL::Certificate.indirection.find(hostname)
      cacert = Puppet::SSL::Certificate.indirection.find(@ca.host.name)

      if cert
        Puppet.info "Retrieving existing certificate for #{hostname}"
        unless csr.content.public_key.to_s == cert.content.public_key.to_s
          raise Puppet::Error, "Certificate request does not match existing certificate; run 'puppetca --clean #{hostname}'."
        end
        [cert.to_s, cacert.to_s]
      else
        Puppet::SSL::CertificateRequest.indirection.save(csr)

        # We determine whether we signed the csr by checking if there's a certificate for it
        if cert = Puppet::SSL::Certificate.indirection.find(hostname)
          [cert.to_s, cacert.to_s]
        else
          nil
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/network/handler/ca.rb
puppet-parse-0.1.3 lib/vendor/puppet/network/handler/ca.rb
puppet-parse-0.1.2 lib/vendor/puppet/network/handler/ca.rb
puppet-parse-0.1.1 lib/vendor/puppet/network/handler/ca.rb
puppet-2.7.26 lib/puppet/network/handler/ca.rb
puppet-2.7.25 lib/puppet/network/handler/ca.rb
puppet-2.7.24 lib/puppet/network/handler/ca.rb
puppet-2.7.23 lib/puppet/network/handler/ca.rb
puppet-2.7.22 lib/puppet/network/handler/ca.rb
puppet-parse-0.1.0 lib/vendor/puppet/network/handler/ca.rb
puppet-parse-0.0.6 lib/vendor/puppet/network/handler/ca.rb
puppet-2.7.21 lib/puppet/network/handler/ca.rb
puppet-parse-0.0.5 lib/vendor/puppet/network/handler/ca.rb
puppet-parse-0.0.4 lib/vendor/puppet/network/handler/ca.rb
puppet-parse-0.0.2 lib/vendor/puppet/network/handler/ca.rb
puppet-2.7.20 lib/puppet/network/handler/ca.rb
puppet-2.7.20.rc1 lib/puppet/network/handler/ca.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/network/handler/ca.rb
puppet-2.7.19 lib/puppet/network/handler/ca.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/network/handler/ca.rb