Beispiel #1
0
    v1_name = v1_fh.name

  with tempfile.NamedTemporaryFile(delete=False) as v2_fh:
    v2_fh.write('hello new world and some more!')
    v2_name = v2_fh.name

  print v1_name
  print v2_name

  with open(v1_name) as v1:
    sigfile = SigFile(v1)
    sig = binascii.b2a_base64(sigfile.read())

  from simpledb import _sha1_of_string
  print 'Upload these to the cloud : filepathhash(%s) PGP(filename): PGP(%s) ' \
      'SHA1(PGP(file)): %s.' % (_sha1_of_string(v1_name), v1_name, 'TODO')

  with open(v2_name) as v2:
    sigfile_v2 = SigFile(v2)
    sig_v2 = binascii.b2a_base64(sigfile_v2.read())

  with open(v2_name) as v2:
    deltafile = DeltaFile(binascii.a2b_base64(sig), v2)
    delta = binascii.b2a_base64(deltafile.read())

  import gnupg
  gpg = gnupg.GPG()
  pgp_delta = gpg.encrypt(delta, ["\'Matt Tierney\'"], always_trust=True,
                          armor=True).data
  print 'Upload these to SDB: PGP(delta(file)): (%s), Prev Value: %s\'s %s' % \
      (_sha1_of_string(pgp_delta), _sha1_of_string(v1_name), 'TODO')
Beispiel #2
0
def detected_new_file(new_file_fp, recipients):
  """Original model function for handling created files."""

  logging.debug('Entered detected_new_file.')
  gpg = gnupg.GPG()

  # Write out temporary GPG file to temp directory.
  with tempfile.NamedTemporaryFile(delete=False) as enc_tmp_file:
    edata = gpg.encrypt_file(new_file_fp,
                             recipients,
                             always_trust=True,
                             armor=False,
                             output=enc_tmp_file.name)
    enc_file_name = enc_tmp_file.name
  logging.info('Finished encrypting the original file.')

  # Get the SHA1 of the encrypted file.
  file_sha1 = _sha1_of_file(enc_file_name)

  # Filepath
  filepath = new_file_fp.name # '/home/username/Lockbox/this/is/my/file.path'
  oldfilepath = new_file_fp.name
  for basepath in FLAGS.basepath:
    if filepath.startswith(basepath):
      filepath = re.sub(basepath, '', filepath)
  if oldfilepath == filepath:
    logging.error('Basepath not found for %s.' % filepath)
  else:
    logging.debug('Detected basepath: %s.' % basepath)
    logging.debug('Shortened filepath: %s.' % filepath)

  # Take SHA1 of path relative to the basepath.
  sha_filepath = _sha1_of_string(filepath)

  # Encrypt the exact value of the basepath.
  enc_filepath = gpg.encrypt(
    filepath, recipients, always_trust=True, armor=False)

  sha_enc_fp = _sha1_of_string(enc_filepath.data)
  logging.info("Upload to S3: SHA1(PGP(filepath)): '%s' data: '%s'" % \
                 (sha_enc_fp, enc_filepath.data))

  # Scaffolding for testing.
  sdb_conn = connect_sdb()
  data_domain = get_domain(sdb_conn, 'group1')
  lock_domain = get_domain(sdb_conn, 'group1_locks')
  success, lock = acquire_domain_object_lock(lock_domain, sha_filepath)
  if not success:
    logging.error("Houston, we didn't get a lock for the object.")

  # Meat and potatoes.
  add_path(data_domain, sha_filepath, sha_enc_fp) # enc_filepath)
  add_object_delta(data_domain, sha_filepath, file_sha1)

  # Scaffolding for testing.
  release_domain_object_lock(lock_domain, lock)
  _print_all_domain(data_domain)
  sdb_conn.delete_domain('group1')
  sdb_conn.delete_domain('group1_locks')

  return enc_file_name