Beispiel #1
0
def read_gateway_port():
   name_path = storage.local_path( GATEWAY_STORAGE_DIR, "gateway_port" )
   rc = storage.read_file( name_path, volume=None )
   try:
      rc = int(rc)
      return rc
   except:
      return None
Beispiel #2
0
def setup_syntool( syndicate_user_id, ms_url_api, syndicate_user_signingkey_str, syndicate_user_verifyingkey_str, signing_key_type, signing_key_name, setup_dirs=True ):
   # store user data in a convenient place, so we can blow it away later
   tmpdir = None
   if setup_dirs:
      tmpdir = tempfile.mkdtemp( dir=storage.local_path( LOCAL_TMP_DIR ) )
   
   syntool_conf = syntool.make_conf( syndicate_user_id, ms_url_api, setup_dirs=setup_dirs, gateway_keys=tmpdir, volume_keys=tmpdir, user_keys=tmpdir,
                                     signing_pkey_pem=syndicate_user_signingkey_str, verifying_pubkey_pem=syndicate_user_verifyingkey_str, signing_key_type=signing_key_type, signing_key_name=signing_key_name, debug=True )
   
   return tmpdir, syntool_conf
Beispiel #3
0
def volume_pubkey_path( volume_name ):
   global VOLUME_STORAGE_DIR
   return storage.local_path( VOLUME_STORAGE_DIR, pubkey_basename( volume_name ) )
Beispiel #4
0
def gateway_privkey_path( gateway_name ):
   global GATEWAY_STORAGE_DIR
   return storage.local_path( GATEWAY_STORAGE_DIR, privkey_basename( gateway_name ) )
Beispiel #5
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
Beispiel #6
0
def delete_gateway_port():
   name_path = storage.local_path( GATEWAY_STORAGE_DIR, "gateway_port" )
   return storage.delete_file( name_path, volume=None )
Beispiel #7
0
def write_gateway_port( gateway_port ):
   name_path = storage.local_path( GATEWAY_STORAGE_DIR, "gateway_port" )
   return storage.write_file( name_path, "%s" % gateway_port, volume=None )
Beispiel #8
0
def read_gateway_name():
   name_path = storage.local_path( GATEWAY_STORAGE_DIR, "gateway_name" )
   return storage.read_file( name_path, volume=None )
Beispiel #9
0
def write_gateway_name( gateway_name ):
   name_path = storage.local_path( GATEWAY_STORAGE_DIR, "gateway_name" )
   return storage.write_file( name_path, gateway_name, volume=None )
Beispiel #10
0
   print "------- create account --------"
   #def create_account( syndicatemail_uid, mail_server, password, ms_url, syndicate_user_id, syndicate_user_password, syndicate_user_privkey_str, syndicate_user_verifyingkey_str, num_downloads, duration,
   account_privkey_pem = create_account( "fakeuser", "poop", "t510", "yoink", "http://*****:*****@gmail.com", "sniff", testuser_signing_pkey_str, testuser_verifying_pubkey_str, volume_name, volume_pubkey_pem )
   assert account_privkey_pem is not None and account_privkey_pem != False, "create_account failed"
   
   print "------- read account --------"
   account_info = read_account( "poop", "fakeuser.mail.localhost%3A8080@t510" )
   assert account_info is not None, "read_account failed"
   
   import pprint 
   pp = pprint.PrettyPrinter()
   pp.pprint( account_info )
   
   print "------- load volume --------"
   
   from syndicate.volume import Volume 
   volume = Volume( volume_name=volume_name,
                    gateway_name=account_info.gateway_name,
                    gateway_port=account_info.gateway_port,
                    oid_username="******",
                    oid_password="******",
                    ms_url="http://*****:*****@t510", volume, "*****@*****.**", remove_gateway=True,
                        syndicate_user_privkey_str = testuser_signing_pkey_str, syndicate_user_verifykey_str = testuser_verifying_pubkey_str, test=True )
   
   assert rc, "delete_account failed"
Beispiel #11
0
def make_key_local_path( name ):
   global PRIVATE_STORAGE_DIR
   
   # NOTE: do NOT store this on the Volume
   return storage.local_path( PRIVATE_STORAGE_DIR, name )