def _PromptUserForEncryptedVolumeCredential(
      self, scan_context, locked_scan_node, output_writer):
    """Prompts the user to provide a credential for an encrypted volume.

    Args:
      scan_context (SourceScannerContext): the source scanner context.
      locked_scan_node (SourceScanNode): the locked scan node.
      output_writer (StdoutWriter): the output writer.
    """
    credentials = credentials_manager.CredentialsManager.GetCredentials(
        locked_scan_node.path_spec)

    # TODO: print volume description.
    if locked_scan_node.type_indicator == (
        definitions.TYPE_INDICATOR_APFS_CONTAINER):
      line = 'Found an APFS encrypted volume.'
    elif locked_scan_node.type_indicator == definitions.TYPE_INDICATOR_BDE:
      line = 'Found a BitLocker encrypted volume.'
    elif locked_scan_node.type_indicator == definitions.TYPE_INDICATOR_FVDE:
      line = 'Found a CoreStorage (FVDE) encrypted volume.'
    else:
      line = 'Found an encrypted volume.'

    output_writer.WriteLine(line)

    credentials_list = list(credentials.CREDENTIALS)
    credentials_list.append('skip')

    # TODO: check which credentials are available.
    output_writer.WriteLine('Supported credentials:')
    output_writer.WriteLine('')
    for index, name in enumerate(credentials_list):
      output_writer.WriteLine('  {0:d}. {1:s}'.format(index + 1, name))
    output_writer.WriteLine('')

    result = False
    while not result:
      output_writer.WriteString(
          'Select a credential to unlock the volume: ')
      # TODO: add an input reader.
      input_line = sys.stdin.readline()
      input_line = input_line.strip()

      if input_line in credentials_list:
        credential_identifier = input_line
      else:
        try:
          credential_identifier = int(input_line, 10)
          credential_identifier = credentials_list[credential_identifier - 1]
        except (IndexError, ValueError):
          output_writer.WriteLine(
              'Unsupported credential: {0:s}'.format(input_line))
          continue

      if credential_identifier == 'skip':
        break

      getpass_string = 'Enter credential data: '
      if sys.platform.startswith('win') and sys.version_info[0] < 3:
        # For Python 2 on Windows getpass (win_getpass) requires an encoded
        # byte string. For Python 3 we need it to be a Unicode string.
        getpass_string = self._EncodeString(getpass_string)

      credential_data = getpass.getpass(getpass_string)
      output_writer.WriteLine('')

      result = self._source_scanner.Unlock(
          scan_context, locked_scan_node.path_spec, credential_identifier,
          credential_data)

      if not result:
        output_writer.WriteLine('Unable to unlock volume.')
        output_writer.WriteLine('')
def _PromptUserForEncryptedVolumeCredential ( self , scan_context , locked_scan_node , output_writer ) : credentials = credentials_manager . CredentialsManager . GetCredentials ( locked_scan_node . path_spec ) if locked_scan_node . type_indicator == ( definitions . TYPE_INDICATOR_APFS_CONTAINER ) : line = 'Found an APFS encrypted volume.' elif locked_scan_node . type_indicator == definitions . TYPE_INDICATOR_BDE : line = 'Found a BitLocker encrypted volume.' elif locked_scan_node . type_indicator == definitions . TYPE_INDICATOR_FVDE : line = 'Found a CoreStorage (FVDE) encrypted volume.' else : line = 'Found an encrypted volume.' output_writer . WriteLine ( line ) credentials_list = list ( credentials . CREDENTIALS ) credentials_list . append ( 'skip' ) output_writer . WriteLine ( 'Supported credentials:' ) output_writer . WriteLine ( '' ) for index , name in enumerate ( credentials_list ) : output_writer . WriteLine ( '  {0:d}. {1:s}' . format ( index + 1 , name ) ) output_writer . WriteLine ( '' ) result = False while not result : output_writer . WriteString ( 'Select a credential to unlock the volume: ' ) input_line = sys . stdin . readline ( ) input_line = input_line . strip ( ) if input_line in credentials_list : credential_identifier = input_line else : try : credential_identifier = int ( input_line , 10 ) credential_identifier = credentials_list [ credential_identifier - 1 ] except ( IndexError , ValueError ) : output_writer . WriteLine ( 'Unsupported credential: {0:s}' . format ( input_line ) ) continue if credential_identifier == 'skip' : break getpass_string = 'Enter credential data: ' if sys . platform . startswith ( 'win' ) and sys . version_info [ 0 ] < 3 : getpass_string = self . _EncodeString ( getpass_string ) credential_data = getpass . getpass ( getpass_string ) output_writer . WriteLine ( '' ) result = self . _source_scanner . Unlock ( scan_context , locked_scan_node . path_spec , credential_identifier , credential_data ) if not result : output_writer . WriteLine ( 'Unable to unlock volume.' ) output_writer . WriteLine ( '' )
Prompts the user to provide a credential for an encrypted volume.

    Args:
      scan_context (SourceScannerContext): the source scanner context.
      locked_scan_node (SourceScanNode): the locked scan node.
      output_writer (StdoutWriter): the output writer.