Beispiel #1
0
def pack_auth_db():
    """Packs an entire AuthDB into a blob, signing it using app's private key.

  Returns:
    Tuple (blob, name of a key used to sign it, base64 encoded signature).
  """
    # Grab the snapshot.
    state, snapshot = replication.new_auth_db_snapshot()

    # Serialize to binary proto message.
    req = replication_pb2.ReplicationPushRequest()
    req.revision.primary_id = app_identity.get_application_id()
    req.revision.auth_db_rev = state.auth_db_rev
    req.revision.modified_ts = utils.datetime_to_timestamp(state.modified_ts)
    replication.auth_db_snapshot_to_proto(snapshot, req.auth_db)
    req.auth_code_version = version.__version__
    auth_db_blob = req.SerializeToString()

    # Sign it using primary's private keys. sign_blob is limited to 8KB only, so
    # hash the body first and sign the digest.
    key_name, sig = signature.sign_blob(hashlib.sha512(auth_db_blob).digest())
    sig = base64.b64encode(sig)

    logging.debug('AuthDB blob size is %d bytes', len(auth_db_blob))
    return auth_db_blob, key_name, sig
Beispiel #2
0
def pack_auth_db():
    """Packs an entire AuthDB into a blob (serialized protobuf message).

  Returns:
    Tuple (AuthReplicationState, blob).
  """
    # Grab the snapshot.
    state, snapshot = replication.new_auth_db_snapshot()

    # Serialize to binary proto message.
    req = replication_pb2.ReplicationPushRequest()
    req.revision.primary_id = app_identity.get_application_id()
    req.revision.auth_db_rev = state.auth_db_rev
    req.revision.modified_ts = utils.datetime_to_timestamp(state.modified_ts)
    replication.auth_db_snapshot_to_proto(snapshot, req.auth_db)
    req.auth_code_version = version.__version__
    auth_db_blob = req.SerializeToString()

    logging.debug('AuthDB blob size is %d bytes', len(auth_db_blob))
    return state, auth_db_blob
Beispiel #3
0
def publish_authdb_change(state):
  """Publishes AuthDB change notification to the topic.

  Args:
    state: AuthReplicationState with version info.
  """
  if utils.is_local_dev_server():
    return

  msg = replication_pb2.ReplicationPushRequest()
  msg.revision.primary_id = app_identity.get_application_id()
  msg.revision.auth_db_rev = state.auth_db_rev
  msg.revision.modified_ts = utils.datetime_to_timestamp(state.modified_ts)

  blob = msg.SerializeToString()
  key_name, sig = signature.sign_blob(blob)

  pubsub.publish(topic_name(), blob, {
    'X-AuthDB-SigKey-v1': key_name,
    'X-AuthDB-SigVal-v1': base64.b64encode(sig),
  })