com.google.ipc.invalidation.common.DigestFunction Java Examples

The following examples show how to use com.google.ipc.invalidation.common.DigestFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistenceUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (ValidationException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  Bytes mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<Bytes>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example #2
Source File: RegistrationManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public RegistrationManager(Logger logger, Statistics statistics, DigestFunction digestFn,
    RegistrationManagerStateP registrationManagerState) {
  this.logger = logger;
  this.statistics = statistics;
  this.desiredRegistrations = new SimpleRegistrationStore(digestFn);

  if (registrationManagerState == null) {
    // Initialize the server summary with a 0 size and the digest corresponding
    // to it.  Using defaultInstance would wrong since the server digest will
    // not match unnecessarily and result in an info message being sent.
    this.lastKnownServerSummary = ProtoWrapper.of(getRegistrationSummary());
  } else {
    this.lastKnownServerSummary =
      ProtoWrapper.of(registrationManagerState.getLastKnownServerSummary());
    desiredRegistrations.add(registrationManagerState.getRegistrationsList());
    for (RegistrationP regOp : registrationManagerState.getPendingOperationsList()) {
      pendingOperations.put(ProtoWrapper.of(regOp.getObjectId()), regOp.getOpType());
    }
  }
}
 
Example #3
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (InvalidProtocolBufferException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  ByteString mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<ByteString>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example #4
Source File: RegistrationManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public RegistrationManager(Logger logger, Statistics statistics, DigestFunction digestFn,
    RegistrationManagerStateP registrationManagerState) {
  this.logger = logger;
  this.statistics = statistics;
  this.desiredRegistrations = new SimpleRegistrationStore(digestFn);

  if (registrationManagerState == null) {
    // Initialize the server summary with a 0 size and the digest corresponding
    // to it.  Using defaultInstance would wrong since the server digest will
    // not match unnecessarily and result in an info message being sent.
    this.lastKnownServerSummary = ProtoWrapper.of(getRegistrationSummary());
  } else {
    this.lastKnownServerSummary =
      ProtoWrapper.of(registrationManagerState.getLastKnownServerSummary());
    desiredRegistrations.add(registrationManagerState.getRegistrationsList());
    for (RegistrationP regOp : registrationManagerState.getPendingOperationsList()) {
      pendingOperations.put(ProtoWrapper.of(regOp.getObjectId()), regOp.getOpType());
    }
  }
}
 
Example #5
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Deserializes a Ticl state blob. Returns either the parsed state or {@code null}
 * if it could not be parsed.
 */
public static PersistentTiclState deserializeState(Logger logger, byte[] stateBlobBytes,
    DigestFunction digestFn) {
  PersistentStateBlob stateBlob;
  try {
    // Try parsing the envelope protocol buffer.
    stateBlob = PersistentStateBlob.parseFrom(stateBlobBytes);
  } catch (InvalidProtocolBufferException exception) {
    logger.severe("Failed deserializing Ticl state: %s", exception.getMessage());
    return null;
  }

  // Check the mac in the envelope against the recomputed mac from the state.
  PersistentTiclState ticlState = stateBlob.getTiclState();
  ByteString mac = generateMac(ticlState, digestFn);
  if (!TypedUtil.<ByteString>equals(mac, stateBlob.getAuthenticationCode())) {
    logger.warning("Ticl state failed MAC check: computed %s vs %s", mac,
        stateBlob.getAuthenticationCode());
    return null;
  }
  return ticlState;
}
 
Example #6
Source File: RegistrationManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public RegistrationManager(Logger logger, Statistics statistics, DigestFunction digestFn,
    RegistrationManagerStateP registrationManagerState) {
  this.logger = logger;
  this.statistics = statistics;
  this.desiredRegistrations = new SimpleRegistrationStore(digestFn);

  if (registrationManagerState == null) {
    // Initialize the server summary with a 0 size and the digest corresponding
    // to it.  Using defaultInstance would wrong since the server digest will
    // not match unnecessarily and result in an info message being sent.
    this.lastKnownServerSummary = getRegistrationSummary();
  } else {
    this.lastKnownServerSummary = registrationManagerState.getNullableLastKnownServerSummary();
    if (this.lastKnownServerSummary == null) {
      // If no server summary is set, use a default with size 0.
      this.lastKnownServerSummary = getRegistrationSummary();
    }
    desiredRegistrations.add(registrationManagerState.getRegistrations());
    for (RegistrationP regOp : registrationManagerState.getPendingOperations()) {
      pendingOperations.put(regOp.getObjectId(), regOp.getOpType());
    }
  }
}
 
Example #7
Source File: RegistrationManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns a copy of the registration manager's state
 * <p>
 * Direct test code MUST not call this method on a random thread. It must be called on the
 * InvalidationClientImpl's internal thread.
 */

RegistrationManagerState getRegistrationManagerStateCopyForTest(DigestFunction digestFunction) {
  List<ObjectIdP> registeredObjects = new ArrayList<ObjectIdP>();
  for (ObjectIdP oid : desiredRegistrations.getElements(EMPTY_PREFIX, 0)) {
    registeredObjects.add(oid);
  }
  return new RegistrationManagerState(
      RegistrationSummary.newBuilder(getRegistrationSummary()).build(),
      RegistrationSummary.newBuilder(lastKnownServerSummary.getProto()).build(),
      registeredObjects);
}
 
Example #8
Source File: RegistrationManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns a copy of the registration manager's state
 * <p>
 * Direct test code MUST not call this method on a random thread. It must be called on the
 * InvalidationClientImpl's internal thread.
 */

RegistrationManagerState getRegistrationManagerStateCopyForTest(DigestFunction digestFunction) {
  List<ObjectIdP> registeredObjects = new ArrayList<ObjectIdP>();
  for (ObjectIdP oid : desiredRegistrations.getElements(EMPTY_PREFIX, 0)) {
    registeredObjects.add(oid);
  }
  return new RegistrationManagerState(
      RegistrationSummary.newBuilder(getRegistrationSummary()).build(),
      RegistrationSummary.newBuilder(lastKnownServerSummary.getProto()).build(),
      registeredObjects);
}
 
Example #9
Source File: TestableInvalidationClient.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the digest function used for computing digests for object registrations. */
DigestFunction getDigestFunctionForTest();
 
Example #10
Source File: TestableInvalidationClient.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the digest function used for computing digests for object registrations. */
DigestFunction getDigestFunctionForTest();
 
Example #11
Source File: SimpleRegistrationStore.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
SimpleRegistrationStore(DigestFunction digestFunction) {
  this.digestFunction = digestFunction;
  recomputeDigest();
}
 
Example #12
Source File: PersistenceUtils.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Serializes a Ticl state blob. */
public static byte[] serializeState(
    PersistentTiclState state, DigestFunction digestFn) {
  Bytes mac = generateMac(state, digestFn);
  return PersistentStateBlob.create(state, mac).toByteArray();
}
 
Example #13
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override

public DigestFunction getDigestFunctionForTest() {
  return this.digestFn;
}
 
Example #14
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns a message authentication code over {@code state}. */
private static ByteString generateMac(PersistentTiclState state, DigestFunction digestFn) {
  digestFn.reset();
  digestFn.update(state.toByteArray());
  return ByteString.copyFrom(digestFn.getDigest());
}
 
Example #15
Source File: PersistenceUtils.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Returns a message authentication code over {@code state}. */
private static Bytes generateMac(PersistentTiclState state, DigestFunction digestFn) {
  digestFn.reset();
  digestFn.update(state.toByteArray());
  return new Bytes(digestFn.getDigest());
}
 
Example #16
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Serializes a Ticl state blob. */

public static byte[] serializeState(PersistentTiclState state, DigestFunction digestFn) {
  ByteString mac = generateMac(state, digestFn);
  return CommonProtos2.newPersistentStateBlob(state, mac).toByteArray();
}
 
Example #17
Source File: SimpleRegistrationStore.java    From 365browser with Apache License 2.0 4 votes vote down vote up
SimpleRegistrationStore(DigestFunction digestFunction) {
  this.digestFunction = digestFunction;
  recomputeDigest();
}
 
Example #18
Source File: SimpleRegistrationStore.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
SimpleRegistrationStore(DigestFunction digestFunction) {
  this.digestFunction = digestFunction;
  recomputeDigest();
}
 
Example #19
Source File: InvalidationClientCore.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override

public DigestFunction getDigestFunctionForTest() {
  return this.digestFn;
}
 
Example #20
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override

public DigestFunction getDigestFunctionForTest() {
  return this.digestFn;
}
 
Example #21
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns a message authentication code over {@code state}. */
private static ByteString generateMac(PersistentTiclState state, DigestFunction digestFn) {
  digestFn.reset();
  digestFn.update(state.toByteArray());
  return ByteString.copyFrom(digestFn.getDigest());
}
 
Example #22
Source File: PersistenceUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Serializes a Ticl state blob. */

public static byte[] serializeState(PersistentTiclState state, DigestFunction digestFn) {
  ByteString mac = generateMac(state, digestFn);
  return CommonProtos2.newPersistentStateBlob(state, mac).toByteArray();
}
 
Example #23
Source File: TestableInvalidationClient.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Returns the digest function used for computing digests for object registrations. */
DigestFunction getDigestFunctionForTest();