Sha256: 43d04a09dee6eacbcf394dc8c2fb89533550f24c3ef567ecdf490010c6b7f118

Contents?: true

Size: 703 Bytes

Versions: 209

Compression:

Stored size: 703 Bytes

Contents

# frozen_string_literal: true

require 'openssl'

module Aws
  module EC2
    class Instance

      # @param [String, Pathname] key_pair_path
      # @return [String]
      def decrypt_windows_password(key_pair_path)
        decoded = Base64.decode64(encrypted_password)
        pem_bytes = File.open(key_pair_path, 'rb') { |f| f.read }
        private_key = OpenSSL::PKey::RSA.new(pem_bytes)
        private_key.private_decrypt(decoded)
      end

      private

      def encrypted_password
        bytes = client.get_password_data(instance_id: id).password_data
        if bytes == ''
          raise 'password not available yet'
        else
          bytes
        end
      end

    end
  end
end

Version data entries

209 entries across 209 versions & 1 rubygems

Version Path
aws-sdk-ec2-1.339.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.338.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.337.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.336.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.335.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.334.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.333.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.332.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.331.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.330.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.329.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.328.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.327.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.326.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.325.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.324.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.323.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.322.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.321.0 lib/aws-sdk-ec2/customizations/instance.rb
aws-sdk-ec2-1.320.0 lib/aws-sdk-ec2/customizations/instance.rb