Example #1
0
      return None
                                  
   volume_pubkey_pem = read_volume_pubkey( email_addr_parsed.volume, prefix=storage_root )
   return volume_pubkey_pem

# -------------------------------------
if __name__ == "__main__":
   import session
   
   fake_module = collections.namedtuple( "FakeModule", ["VOLUME_STORAGE_DIRS", "LOCAL_STORAGE_DIRS"] )
   fake_vol = session.do_test_volume( "/tmp/storage-test/volume" )
   singleton.set_volume( fake_vol )
   
   print "------- setup --------"
   fake_mod = fake_module( LOCAL_STORAGE_DIRS=LOCAL_STORAGE_DIRS + keys.LOCAL_STORAGE_DIRS, VOLUME_STORAGE_DIRS=VOLUME_STORAGE_DIRS + keys.VOLUME_STORAGE_DIRS )
   rc = storage.setup_local_storage( "/tmp/storage-test/local", [fake_mod] )
   assert rc, "setup_local_storage failed"
   
   pubkey_str = """
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxwhi2mh+f/Uxcx6RuO42
EuVpxDHuciTMguJygvAHEuGTM/0hEW04Im1LfXldfpKv772XrCq+M6oKfUiee3tl
sVhTf+8SZfbTdR7Zz132kdP1grNafGrp57mkOwxjFRE3FA23T1bHXpIaEcdhBo0R
rXyEnxpJmnLyNYHaLN8rTOig5WFbnmhIZD+xCNtG7hFy39hKt+vNTWK98kMCOMsY
QPywYw8nJaax/kY5SEiUup32BeZWV9HRljjJYlB5kMdzeAXcjQKvn5y47qmluVmx
L1LRX5T2v11KLSpArSDO4At5qPPnrXhbsH3C2Z5L4jqStdLYB5ZYZdaAsaRKcc8V
WpsmzZaFExJ9Nj05sDS1YMFMvoINqaPEftS6Be+wgF8/klZoHFkuslUNLK9k2f65
A7d9Fn/B42n+dCDYx0SR6obABd89cR8/AASkZl3QKeCzW/wl9zrt5dL1iydOq2kw
JtgiKSCt6m7Hwx2kwHBGI8zUfNMBlfIlFu5CP+4xLTOlRdnXqYPylT56JQcjA2CB
hGBRJQFWVutrVtTXlbvT2OmUkRQT9+P5wr0c7fl+iOVXh2TwfaFeug9Fm8QWoGyP
GuKX1KO5JLQjcNTnZ3h3y9LIWHsCTCf2ltycUBguq8Mwzb5df2EkOVgFeLTfWyR2
Example #2
0
def create_account( syndicatemail_uid, syndicatemail_password, mail_server, password, ms_url, syndicate_user_id, syndicate_user_password, syndicate_user_privkey_str, syndicate_user_verifyingkey_str,
                    existing_volume_name, existing_volume_pubkey_pem, num_downloads=1, duration=3600, existing_gateway_name=None, existing_gateway_port=None, existing_gateway_pkey_pem=None ):
   
   global DEFAULT_GATEWAY_PORT, ALL_STORAGE_PACKAGES, VOLUME_STORAGE_ROOT, LOCAL_STORAGE_ROOT
   
   if storage.LOCAL_ROOT_DIR is None:
      # FIXME: remove this kludge
      fake_module = collections.namedtuple( "FakeModule", ["VOLUME_STORAGE_DIRS", "LOCAL_STORAGE_DIRS"] )
      this_module = fake_module( LOCAL_STORAGE_DIRS=LOCAL_STORAGE_DIRS, VOLUME_STORAGE_DIRS=VOLUME_STORAGE_DIRS )
      
      rc = storage.setup_local_storage( LOCAL_STORAGE_ROOT, ALL_STORAGE_PACKAGES + [this_module] )
      
   if existing_gateway_name is None:
      existing_gateway_name = make_default_gateway_name()
      
   if existing_gateway_port is None:
      existing_gateway_port = DEFAULT_GATEWAY_PORT
      
   # generate a SyndicateMail private key
   pubkey_pem, privkey_pem = keys.generate_key_pair()
   
   # create or load the gateway
   rc = make_gateway( pubkey_pem, syndicatemail_password, syndicate_user_id, syndicate_user_privkey_str, syndicate_user_verifyingkey_str, ms_url,
                      existing_volume_name, existing_gateway_name, existing_gateway_port, existing_gateway_pkey_pem )
   if not rc:
      raise Exception("Failed to create Gateway")
   
   gateway_rc = rc
   
   # create email address
   MS_host = urlparse( ms_url ).netloc
   email = contact.make_addr_str( syndicatemail_uid, existing_volume_name, MS_host, mail_server )
   
   log.info("SyndicateMail address is %s" % email )
   
   # cleanup Syndicate function
   def cleanup_syndicate():
      if gateway_rc != EXISTS:
         rc = delete_gateway( syndicate_user_id, syndicate_user_privkey_str, syndicate_user_verifyingkey_str, ms_url, existing_gateway_name )
         if not rc:
            log.critical("!!! cleanup failure: could not delete gateway %s !!!" % existing_gateway_name )
            
   
   # get the private key
   existing_gateway_pkey_pem = read_gateway_privkey( syndicatemail_password, existing_gateway_name )
   if existing_gateway_pkey_pem is None:
      log.critical("Failed to store gateway private key!")
      cleanup_syndicate()
      return False
      
   try:
      # open the Volume
      vol = SyndicateVolume(  gateway_name=existing_gateway_name,
                              gateway_port=existing_gateway_port,
                              oid_username=syndicate_user_id,
                              oid_password=syndicate_user_password,
                              ms_url=ms_url,
                              my_key_str=existing_gateway_pkey_pem,
                              volume_name=existing_volume_name,
                              storage_root=storage.local_path( GATEWAY_RUNTIME_STORAGE ) )
   
   except Exception, e:
      log.exception(e)
      log.critical("Failed to connect to Volume!")
      
      cleanup_syndicate()
      return False
Example #3
0
       privkey = CryptoKey.importKey( account_privkey_pem )
       existing_volume_pubkey_pem = volume_pubkey_pem
       
    else:
       raise Exception("No such account %s" % email )
    
 else:
    # set up storage
    need_storage_setup = True
    
    
 config['volume_pubkey_pem'] = existing_volume_pubkey_pem
 
 # set up local storage
 if need_storage_setup:
    rc = storage.setup_local_storage( account.LOCAL_STORAGE_ROOT, [] )
    if not rc:
       do_logout( config )
       raise Exception("Failed to set up local storage")
 
 # get account info
 account_info = account.read_account( password, email )
 if account_info is None:
    do_logout( config )
    raise Exception("Failed to read account information.")
 
 gateway_name = account_info.gateway_name
 gateway_port = account_info.gateway_port
 gateway_privkey_pem = account_info.gateway_privkey_pem
 volume_pubkey_pem = account_info.volume_pubkey_pem