Ejemplo n.º 1
0
   def get( self, volume_name_or_id_str ):
   
      # get the gateway, but we'll check for ourselves whether or not the gateway needs authentication
      gateway, volume, timing = response_begin( self, volume_name_or_id_str, fail_if_no_auth_header=False )
      if volume == None:
         return

      if volume.need_gateway_auth() and gateway == None:
         response_user_error( self, 403 )
         return 
   
      root = storage.get_volume_root( volume )
      
      if root == None:
         response_user_error( self, 404 )
         return

      # request for volume metadata
      volume_metadata = ms_pb2.ms_volume_metadata();
      
      root.protobuf( volume_metadata.root )
      volume.protobuf( volume_metadata )
      
      data = volume_metadata.SerializeToString()

      response_end( self, 200, data, "application/octet-stream", timing )
      return
Ejemplo n.º 2
0
    def get(self, volume_name_or_id_str):

        # get the gateway, but we'll check for ourselves whether or not the gateway needs authentication
        gateway, volume, timing = response_begin(self,
                                                 volume_name_or_id_str,
                                                 fail_if_no_auth_header=False)
        if volume == None:
            return

        if volume.need_gateway_auth() and gateway == None:
            response_user_error(self, 403)
            return

        root = storage.get_volume_root(volume)

        if root == None:
            response_user_error(self, 404)
            return

        # request for volume metadata
        volume_metadata = ms_pb2.ms_volume_metadata()

        root.protobuf(volume_metadata.root)
        volume.protobuf(volume_metadata)

        data = volume_metadata.SerializeToString()

        response_end(self, 200, data, "application/octet-stream", timing)
        return
Ejemplo n.º 3
0
def register_complete( gateway ):
   """
   Complete a gateway's registration, generating a shared session password.
   Only call this method once the given gateway has authenticated!
   Generate and return a serialized ms_registration_metadata protobuf.
   """
   
   # generate a session password
   # TODO: lock this operation, so we put the gateway and generate the password atomically?
   session_pass = gateway.regenerate_session_password()
   gateway_fut = gateway.put_async()
   futs = [gateway_fut]

   registration_metadata = ms_pb2.ms_registration_metadata()

   # registration information
   registration_metadata.session_password = session_pass
   registration_metadata.session_expires = gateway.session_expires
   gateway.protobuf_cert( registration_metadata.cert, need_closure=True )
   
   # find all Volumes
   volume = storage.read_volume( gateway.volume_id )
   
   if volume == None:
      return (404, None)
   
   root = storage.get_volume_root( volume )
   
   if root == None:
      return (404, None)

   # add volume and contents
   protobuf_volume( registration_metadata.volume, volume, root )

   # add sealed private key, if given earlier 
   if gateway.encrypted_gateway_private_key != None:
      registration_metadata.encrypted_gateway_private_key = gateway.encrypted_gateway_private_key
   
   # add flow control data
   registration_metadata.resolve_page_size = RESOLVE_MAX_PAGE_SIZE
   registration_metadata.max_connections = MAX_NUM_CONNECTIONS
   registration_metadata.max_batch_request_size = MAX_BATCH_REQUEST_SIZE
   registration_metadata.max_batch_async_request_size = MAX_BATCH_ASYNC_REQUEST_SIZE
   registration_metadata.max_transfer_time = MAX_TRANSFER_TIME
   
   # sign and serialize!
   registration_metadata.signature = ""
   
   data = registration_metadata.SerializeToString()
   
   registration_metadata.signature = volume.sign_message( data )
   
   data = registration_metadata.SerializeToString()
   
   # save the gateway
   storage.wait_futures( futs )
   
   gateway.FlushCache( gateway.g_id )
   volume.FlushCache( volume.volume_id )
   
   return (200, data)
Ejemplo n.º 4
0
def register_complete(gateway):
    """
   Complete a gateway's registration, generating a shared session password.
   Only call this method once the given gateway has authenticated!
   Generate and return a serialized ms_registration_metadata protobuf.
   """

    # generate a session password
    # TODO: lock this operation, so we put the gateway and generate the password atomically?
    session_pass = gateway.regenerate_session_password()
    gateway_fut = gateway.put_async()
    futs = [gateway_fut]

    registration_metadata = ms_pb2.ms_registration_metadata()

    # registration information
    registration_metadata.session_password = session_pass
    registration_metadata.session_expires = gateway.session_expires
    gateway.protobuf_cert(registration_metadata.cert, need_closure=True)

    # find all Volumes
    volume = storage.read_volume(gateway.volume_id)

    if volume == None:
        logging.error("No such volume %s" % gateway.volume_id)
        return (404, None)

    root = storage.get_volume_root(volume)

    if root is None:
        logging.error("BUG: no root for volume %s" % volume.name)
        return (500, None)

    # add volume and contents
    protobuf_volume(registration_metadata.volume, volume, root)

    # add sealed private key, if given earlier
    if gateway.encrypted_gateway_private_key != None:
        registration_metadata.encrypted_gateway_private_key = gateway.encrypted_gateway_private_key

    # add flow control data
    registration_metadata.resolve_page_size = RESOLVE_MAX_PAGE_SIZE
    registration_metadata.max_connections = MAX_NUM_CONNECTIONS
    registration_metadata.max_batch_request_size = MAX_BATCH_REQUEST_SIZE
    registration_metadata.max_batch_async_request_size = MAX_BATCH_ASYNC_REQUEST_SIZE
    registration_metadata.max_transfer_time = MAX_TRANSFER_TIME

    # sign and serialize!
    registration_metadata.signature = ""

    data = registration_metadata.SerializeToString()

    registration_metadata.signature = volume.sign_message(data)

    data = registration_metadata.SerializeToString()

    # save the gateway
    storage.wait_futures(futs)

    gateway.FlushCache(gateway.g_id)
    volume.FlushCache(volume.volume_id)

    return (200, data)