private ByteStringMessage<ProtocolWaveletDelta> getFakeDelta() throws Exception {
   ProtocolWaveletDelta delta =
       ProtocolWaveletDelta.newBuilder()
           .setHashedVersion(getProtocolHashedVersion())
           .setAuthor("*****@*****.**")
           .build();
   return ByteStringMessage.serializeMessage(delta);
 }
Esempio n. 2
0
 @Override
 public int compare(
     ByteStringMessage<ProtocolAppliedWaveletDelta> first,
     ByteStringMessage<ProtocolAppliedWaveletDelta> second) {
   if (first == null && second != null) {
     return -1;
   }
   if (first != null && second == null) {
     return 1;
   }
   if (first == null && second == null) {
     return 0;
   }
   try {
     return Long.valueOf(getVersionAppliedAt(first.getMessage()).getVersion())
         .compareTo(getVersionAppliedAt(second.getMessage()).getVersion());
   } catch (InvalidProtocolBufferException e) {
     throw new IllegalStateException("Invalid applied delta added to history", e);
   }
 }
Esempio n. 3
0
 /** Return a dummy ProtocolAppliedWaveleetDelta instance used as a range boundary. */
 private static ByteStringMessage<ProtocolAppliedWaveletDelta> emptyAppliedDeltaAtVersion(
     final long version) {
   ProtocolAppliedWaveletDelta delta =
       ProtocolAppliedWaveletDelta.newBuilder()
           .setApplicationTimestamp(0)
           .setOperationsApplied(0)
           .setSignedOriginalDelta(
               ProtocolSignedDelta.newBuilder()
                   .setDelta(emptyDeltaAtVersion(version).toByteString()))
           .build();
   return ByteStringMessage.fromMessage(delta);
 }
  /*
   * TESTS
   */
  public void testSignature() throws Exception {
    ProtocolWaveletDelta delta =
        ProtocolWaveletDelta.newBuilder()
            .setHashedVersion(getProtocolHashedVersion())
            .setAuthor("*****@*****.**")
            .build();
    ByteStringMessage<ProtocolWaveletDelta> canonicalDelta =
        ByteStringMessage.serializeMessage(delta);

    ProtocolSignedDelta signedDelta = manager.signDelta(canonicalDelta);

    manager.storeSignerInfo(getSignerInfo().toProtoBuf());
    ByteStringMessage<ProtocolWaveletDelta> compare = manager.verifyDelta(signedDelta);

    assertEquals(canonicalDelta, compare);
  }
Esempio n. 5
0
  /**
   * Commit an applied delta to this wavelet container.
   *
   * @param appliedDelta to commit
   * @param transformedDelta of the applied delta
   * @return result of the application
   */
  protected DeltaApplicationResult commitAppliedDelta(
      ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta, WaveletDelta transformedDelta) {

    ProtocolWaveletDelta transformedProtocolDelta =
        WaveletOperationSerializer.serialize(transformedDelta, currentVersion);
    transformedDeltas.add(transformedProtocolDelta);
    deserializedTransformedDeltas.add(new VersionedWaveletDelta(transformedDelta, currentVersion));
    appliedDeltas.add(appliedDelta);

    HashedVersion newVersion =
        HASHED_HISTORY_VERSION_FACTORY.create(
            appliedDelta.getByteArray(), currentVersion, transformedDelta.getOperations().size());
    currentVersion = newVersion;

    return new DeltaApplicationResult(
        appliedDelta, transformedProtocolDelta, WaveletOperationSerializer.serialize(newVersion));
  }
  public void testSignature_authorNotMatching() throws Exception {
    ProtocolWaveletDelta delta =
        ProtocolWaveletDelta.newBuilder()
            .setHashedVersion(getProtocolHashedVersion())
            .setAuthor("*****@*****.**")
            .build();
    ByteStringMessage<ProtocolWaveletDelta> canonicalDelta =
        ByteStringMessage.serializeMessage(delta);

    ProtocolSignedDelta signedDelta = manager.signDelta(canonicalDelta);

    manager.storeSignerInfo(getSignerInfo().toProtoBuf());

    try {
      manager.verifyDelta(signedDelta);
      fail("expected exception, but didn't get it");
    } catch (SignatureException e) {
      // expected
    }
  }
  public void testSignature_missingSignerInfo() throws Exception {
    ProtocolWaveletDelta delta =
        ProtocolWaveletDelta.newBuilder()
            .setHashedVersion(getProtocolHashedVersion())
            .setAuthor("*****@*****.**")
            .build();
    ByteStringMessage<ProtocolWaveletDelta> canonicalDelta =
        ByteStringMessage.serializeMessage(delta);
    manager = new CertificateManagerImpl(false, getSigner(), getVerifier(store, false), store);
    ProtocolSignedDelta signedDelta = manager.signDelta(canonicalDelta);

    try {
      manager.verifyDelta(signedDelta);
      fail("expected UnknownSignerException, but didn't get it");
    } catch (UnknownSignerException e) {
      // expected
    } catch (Exception e) {
      fail("expected UnknownSignerExeception, but got " + e);
    }
  }