lib/chef/provider/aws_key_pair.rb
# For Ruby 1.9 and below, PKCS can be run
For Ruby 1.9 and below, PKCS can be run
For Ruby 1 . 9 and below PKCS can be run
def create_key(action)
    if @should_create_directory
      Cheffish.inline_resource(self, action) do
        directory run_context.config[:private_key_write_path]
      end
    end
    if current_resource_exists?
      if !current_resource.private_key_path
        if new_resource.allow_overwrite
          ensure_keys(action)
        else
          raise "{key_description} already exists on the server, but the private key {new_private_key_path} does not exist!"
        end
      else
        ensure_keys(action)
      end
       The AWS EC2 API uses a PKCS1 MD5 fingerprint for keys that you
       import into EC2, but a PKCS8 SHA1 fingerprint for keys that you
       generate using its web console. Both fingerprints are different
       from the familiar RFC4716 MD5 fingerprint that OpenSSH displays
       for host keys.
       So compute both possible AWS fingerprints and check if either of
       them matches.
      new_fingerprints = [Cheffish::KeyFormatter.encode(desired_key, format: :fingerprint)]
      if RUBY_VERSION.to_f < 2.0
        if @@use_pkcs8.nil?
          begin
            require "openssl_pkcs8"
            @@use_pkcs8 = true
          rescue LoadError
            Chef::Log.warn("The openssl_pkcs8 gem is not loaded: you may not be able to read key fingerprints created by some cloud providers.  gem install openssl_pkcs8 to fix!")
            @@use_pkcs8 = false
          end
        end
        if @@use_pkcs8
          new_fingerprints << Cheffish::KeyFormatter.encode(desired_private_key,
                                                            format: :pkcs8sha1fingerprint)
        end
      end
      if new_fingerprints.none? { |f| compare_public_key f }
        if new_resource.allow_overwrite
          converge_by "update {key_description} to match local key at {new_resource.private_key_path}" do
            driver.ec2.delete_key_pair(key_name: new_resource.name)
            driver.ec2.import_key_pair(key_name: new_resource.name, public_key_material: Cheffish::KeyFormatter.encode(desired_key, format: :openssh))
          end
        else
          raise "{key_description} with fingerprint {@current_fingerprint} does not match local key fingerprint(s) {new_fingerprints}, and allow_overwrite is false!"
        end
      end
    else
       Generate the private and/or public keys if they do not exist
      ensure_keys(action)
       Create key
      converge_by "create {key_description} from local key at {new_resource.private_key_path}" do
        driver.ec2.import_key_pair(key_name: new_resource.name, public_key_material: Cheffish::KeyFormatter.encode(desired_key, format: :openssh))
      end
    end
  end
def create_key ( action ) if @should_create_directory Cheffish . inline_resource ( self , action ) do directory run_context . config [ :private_key_write_path ] end end if current_resource_exists? if ! current_resource . private_key_path if new_resource . allow_overwrite ensure_keys ( action ) else raise "#{key_description} already exists on the server, but the private key #{new_private_key_path} does not exist!" end else ensure_keys ( action ) end new_fingerprints = [ Cheffish :: KeyFormatter . encode ( desired_key , format : :fingerprint ) ] if RUBY_VERSION . to_f < 2.0 if @@use_pkcs8 . nil? begin require "openssl_pkcs8" @@use_pkcs8 = true rescue LoadError Chef :: Log . warn ( "The openssl_pkcs8 gem is not loaded: you may not be able to read key fingerprints created by some cloud providers.  gem install openssl_pkcs8 to fix!" ) @@use_pkcs8 = false end end if @@use_pkcs8 new_fingerprints << Cheffish :: KeyFormatter . encode ( desired_private_key , format : :pkcs8sha1fingerprint ) end end if new_fingerprints . none? { | f | compare_public_key f } if new_resource . allow_overwrite converge_by "update #{key_description} to match local key at #{new_resource.private_key_path}" do driver . ec2 . delete_key_pair ( key_name : new_resource . name ) driver . ec2 . import_key_pair ( key_name : new_resource . name , public_key_material : Cheffish :: KeyFormatter . encode ( desired_key , format : :openssh ) ) end else raise "#{key_description} with fingerprint #{@current_fingerprint} does not match local key fingerprint(s) #{new_fingerprints}, and allow_overwrite is false!" end end else ensure_keys ( action ) converge_by "create #{key_description} from local key at #{new_resource.private_key_path}" do driver . ec2 . import_key_pair ( key_name : new_resource . name , public_key_material : Cheffish :: KeyFormatter . encode ( desired_key , format : :openssh ) ) end end end
For Ruby 1.9 and below, PKCS can be run
For Ruby 1 . 9 and below PKCS can be run
# If the public keys are different, update the server public key # “The nice thing about standards is that you have so many to # choose from.” - Andrew S. Tanenbaum # # The AWS EC2 API uses a PKCS#1 MD5 fingerprint for keys that you # import into EC2, but a PKCS#8 SHA1 fingerprint for keys that you # generate using its web console. Both fingerprints are different # from the familiar RFC4716 MD5 fingerprint that OpenSSH displays # for host keys. # # So compute both possible AWS fingerprints and check if either of # them matches. # Generate the private and/or public keys if they do not exist # Create key
action
<not_specific>