lib/facter/tpm/util.rb
def pubek(status)
        pass_file = "#{Puppet[:vardir]}/simp/tpm_ownership_owner_pass"
        enabled   = status['enabled'] == 1
        owned     = status['owned'] == 1

        out = Hash.new
        raw = ''

        if !enabled
          out['_status'] = 'error: tpm not enabled'
          return out
        elsif !owned
          raw = get_pubek_unowned
          out['_status'] = 'success: tpm unowned'
        else
          if File.exists?(pass_file)
            owner_pass = Facter::Core::Execution.execute("cat #{pass_file} 2> /dev/null")
            if owner_pass.eql? ""
              out['_status'] = 'error: the password file is empty'
              return out
            else
              raw = get_pubek_owned(owner_pass)
              out['_status'] = 'success: raw pubek grabbed' unless raw.nil?
            end
          else
            out['_status'] = 'error: password file not found'
            return out
          end
        end

        if raw.nil? or raw == ""
          out['_status'] = 'error: trousers is not running, the tpm is not enabled, or the password in the password file is incorrect'
        else
          pubek = YAML.load(raw.gsub(/\t/,' '*4).split("\n").drop(1).join("\n"))
          pubek['Public Key'].to_s.gsub!(/ /, '')
          pubek['raw'] = raw
          out.merge!( Hash[pubek.map{ |k,v| [k.downcase.gsub(/ /, '_'), v] }] )
          out['_status'] = 'success: raw parsed'
        end

        out
      end
# If the TPM is unowned, it can be retreived simply with the command. However,
#   when the TPM is owned, the command asks for a password. We use an
#   an interactive PTY to get around this restriction.
#
# @param status [Boolean] whether or not the TPM is owned
#
# @return [Hash] the TPM public key, including the raw key in `['raw']`
#
If the TPM is unowned, it can be retreived simply with the command. However,
when the TPM is owned, the command asks for a password. We use an
an interactive PTY to get around this restriction.
If the TPM is unowned it can be retreived simply with the command . However when the TPM is owned the command asks for a password . We use an an interactive PTY to get around this restriction .
def pubek(status)
        pass_file = "#{Puppet[:vardir]}/simp/tpm_ownership_owner_pass"
        enabled   = status['enabled'] == 1
        owned     = status['owned'] == 1
        out = Hash.new
        raw = ''
        if !enabled
          out['_status'] = 'error: tpm not enabled'
          return out
        elsif !owned
          raw = get_pubek_unowned
          out['_status'] = 'success: tpm unowned'
        else
          if File.exists?(pass_file)
            owner_pass = Facter::Core::Execution.execute("cat #{pass_file} 2> /dev/null")
            if owner_pass.eql? ""
              out['_status'] = 'error: the password file is empty'
              return out
            else
              raw = get_pubek_owned(owner_pass)
              out['_status'] = 'success: raw pubek grabbed' unless raw.nil?
            end
          else
            out['_status'] = 'error: password file not found'
            return out
          end
        end
        if raw.nil? or raw == ""
          out['_status'] = 'error: trousers is not running, the tpm is not enabled, or the password in the password file is incorrect'
        else
          pubek = YAML.load(raw.gsub(/\t/,' '*4).split("\n").drop(1).join("\n"))
          pubek['Public Key'].to_s.gsub!(/ /, '')
          pubek['raw'] = raw
          out.merge!( Hash[pubek.map{ |k,v| [k.downcase.gsub(/ /, '_'), v] }] )
          out['_status'] = 'success: raw parsed'
        end
        out
      end
def pubek ( status ) pass_file = "#{Puppet[:vardir]}/simp/tpm_ownership_owner_pass" enabled = status [ 'enabled' ] == 1 owned = status [ 'owned' ] == 1 out = Hash . new raw = '' if ! enabled out [ '_status' ] = 'error: tpm not enabled' return out elsif ! owned raw = get_pubek_unowned out [ '_status' ] = 'success: tpm unowned' else if File . exists? ( pass_file ) owner_pass = Facter :: Core :: Execution . execute ( "cat #{pass_file} 2> /dev/null" ) if owner_pass . eql? "" out [ '_status' ] = 'error: the password file is empty' return out else raw = get_pubek_owned ( owner_pass ) out [ '_status' ] = 'success: raw pubek grabbed' unless raw . nil? end else out [ '_status' ] = 'error: password file not found' return out end end if raw . nil? or raw == "" out [ '_status' ] = 'error: trousers is not running, the tpm is not enabled, or the password in the password file is incorrect' else pubek = YAML . load ( raw . gsub ( / \t / , ' ' * 4 ) . split ( "\n" ) . drop ( 1 ) . join ( "\n" ) ) pubek [ 'Public Key' ] . to_s . gsub! ( / / , '' ) pubek [ 'raw' ] = raw out . merge! ( Hash [ pubek . map { | k , v | [ k . downcase . gsub ( / / , '_' ) , v ] } ] ) out [ '_status' ] = 'success: raw parsed' end out end
If the TPM is unowned, it can be retreived simply with the command.
If the TPM is unowned it can be retreived simply with the command .
the TPM public key, including the raw key in `['raw']`
the TPM public key including the raw key in ` [ ' raw ' ] `
Hash
status
whether or not the TPM is owned
whether or not the TPM is owned