Sha256: b0528e19df284dae896a31f099b8440072203723d13ff1d1e32aa96ce8121ada

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

module Kafo
  module Params
    # A password paramater is stored encrypted in answer file using AES 256 in CBC mode
    #
    # we use a passphrase that is stored in kafo.yaml for encryption
    # encrypted password is prefixed with $1$ (for historical reasons, no connection to
    # Modular Crypt Format)
    class Password < Param
      def value=(value)
        super
        if @value.nil? || @value.empty?
          @value = password_manager.password
        end
        setup_password if @value.is_a?(::String)
        @value
      end

      def value
        @encrypted
      end

      def condition_value
        %{"#{value}"}
      end

      def dump_default
        %{"#{super}"}
      end

      private

      def setup_password
        encrypted? ? decrypt : encrypt
      end

      def encrypted?
        @value.length > 3 && @value[0..2] == '$1$'
      end

      def decrypt
        @encrypted = @value
        @value     = password_manager.aes_decrypt(@value[3..-1], phrase)
      end

      def encrypt
        @encrypted = '$1$' + password_manager.aes_encrypt(@value, phrase)
      end

      def password_manager
        @password_manager ||= PasswordManager.new
      end

      def phrase
        KafoConfigure.config.app[:password]
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kafo-0.6.12 lib/kafo/params/password.rb
kafo-0.6.11 lib/kafo/params/password.rb
kafo-0.6.10 lib/kafo/params/password.rb
kafo-0.6.9 lib/kafo/params/password.rb
kafo-0.6.8 lib/kafo/params/password.rb
kafo-0.6.7 lib/kafo/params/password.rb
kafo-0.6.6 lib/kafo/params/password.rb
kafo-0.6.5 lib/kafo/params/password.rb
kafo-0.6.4 lib/kafo/params/password.rb