@Override public ProtocolSignedDelta signDelta(ByteStringMessage<ProtocolWaveletDelta> delta) { // TODO: support extended address paths. For now, there will be exactly // one signature, and we don't support federated groups. Preconditions.checkState(delta.getMessage().getAddressPathCount() == 0); ProtocolSignedDelta.Builder signedDelta = ProtocolSignedDelta.newBuilder(); signedDelta.setDelta(delta.getByteString()); signedDelta.addAllSignature(waveSigner.sign(delta)); return signedDelta.build(); }
protected WaveletDeltaRecord createRecord() { HashedVersion targetVersion = HashedVersion.of(0, new byte[] {3, 2, 1}); HashedVersion resultingVersion = HashedVersion.of(2, new byte[] {1, 2, 3}); List<WaveletOperation> ops = ImmutableList.of(UTIL.noOp(), UTIL.addParticipant(TestingConstants.OTHER_PARTICIPANT)); TransformedWaveletDelta transformed = TransformedWaveletDelta.cloneOperations( TestingConstants.PARTICIPANT, resultingVersion, 1234567890, ops); ProtocolWaveletDelta serializedDelta = CoreWaveletOperationSerializer.serialize(transformed); ProtocolSignature signature = ProtocolSignature.newBuilder().setSignatureAlgorithm(SignatureAlgorithm.SHA1_RSA) .setSignatureBytes(ByteString.copyFrom(new byte[] {1, 2, 3})).setSignerId( ByteString.copyFromUtf8("somebody")).build(); ProtocolSignedDelta signedDelta = ProtocolSignedDelta.newBuilder().setDelta( ByteStringMessage.serializeMessage(serializedDelta).getByteString()).addAllSignature( ImmutableList.of(signature)).build(); ProtocolAppliedWaveletDelta delta = ProtocolAppliedWaveletDelta.newBuilder().setApplicationTimestamp(1234567890) .setHashedVersionAppliedAt(CoreWaveletOperationSerializer.serialize(targetVersion)) .setSignedOriginalDelta(signedDelta).setOperationsApplied(2).build(); return new WaveletDeltaRecord(targetVersion, ByteStringMessage.serializeMessage(delta), transformed); }
protected WaveletDeltaRecord createRecord() { HashedVersion targetVersion = HashedVersion.of(0, new byte[] {3, 2, 1}); HashedVersion resultingVersion = HashedVersion.of(2, new byte[] {1, 2, 3}); List<WaveletOperation> ops = ImmutableList.of(UTIL.noOp(), UTIL.addParticipant(TestingConstants.OTHER_PARTICIPANT)); TransformedWaveletDelta transformed = TransformedWaveletDelta.cloneOperations( TestingConstants.PARTICIPANT, resultingVersion, 1234567890, ops); ProtocolWaveletDelta serializedDelta = CoreWaveletOperationSerializer.serialize(transformed); ProtocolSignature signature = ProtocolSignature.newBuilder().setSignatureAlgorithm(SignatureAlgorithm.SHA1_RSA) .setSignatureBytes(ByteString.copyFrom(new byte[] {1, 2, 3})).setSignerId( ByteString.copyFromUtf8("somebody")).build(); ProtocolSignedDelta signedDelta = ProtocolSignedDelta.newBuilder().setDelta( ByteStringMessage.serializeMessage(serializedDelta).getByteString()).addAllSignature( ImmutableList.of(signature)).build(); ProtocolAppliedWaveletDelta delta = ProtocolAppliedWaveletDelta.newBuilder().setApplicationTimestamp(1234567890) .setHashedVersionAppliedAt(CoreWaveletOperationSerializer.serialize(targetVersion)) .setSignedOriginalDelta(signedDelta).setOperationsApplied(2).build(); return new WaveletDeltaRecord(targetVersion, ByteStringMessage.serializeMessage(delta), transformed); }
public void testFailedLocalWaveletRequest() throws Exception { ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(removeParticipantProtoDelta(localWavelet).toByteString()) .build(); try { .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); ProtocolSignedDelta addAgainDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(addParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) ProtocolSignedDelta rollbackDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder(doubleRemoveParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString())
public void testFailedLocalWaveletRequest() throws Exception { ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(removeParticipantProtoDelta(localWavelet).toByteString()) .build(); try { .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); ProtocolSignedDelta addAgainDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(addParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString()) ProtocolSignedDelta rollbackDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder(doubleRemoveParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())) .build().toByteString())
public void testSuccessfulLocalRequest() throws Exception { ProtocolSignedDelta addDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); localWavelet.submitRequest(localWaveletName, addDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 2); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); HashedVersion oldVersion = localWavelet.getCurrentVersion(); ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(removeParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())).build().toByteString()) .build(); localWavelet.submitRequest(localWaveletName, removeDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 4); assertTrue(localWavelet.isDeltaSigner(oldVersion, fakeSigner1)); assertFalse(localWavelet.isDeltaSigner(oldVersion, fakeSigner2)); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); }
public void testSuccessfulLocalRequest() throws Exception { ProtocolSignedDelta addDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(addParticipantProtoDelta(localWavelet).toByteString()) .build(); localWavelet.submitRequest(localWaveletName, addDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 2); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); HashedVersion oldVersion = localWavelet.getCurrentVersion(); ProtocolSignedDelta removeDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature2) .setDelta(ProtocolWaveletDelta.newBuilder(removeParticipantProtoDelta(localWavelet)) .setHashedVersion(serialize(localWavelet.getCurrentVersion())).build().toByteString()) .build(); localWavelet.submitRequest(localWaveletName, removeDelta); assertEquals(localWavelet.getCurrentVersion().getVersion(), 4); assertTrue(localWavelet.isDeltaSigner(oldVersion, fakeSigner1)); assertFalse(localWavelet.isDeltaSigner(oldVersion, fakeSigner2)); assertTrue(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner2)); assertFalse(localWavelet.isDeltaSigner( localWavelet.getCurrentVersion(), fakeSigner1)); }
private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, ImmutableList.copyOf(ops)); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); waveServer.submitRequest(name, protoDelta, new SubmitRequestListener() { @Override public void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, long applicationTimestamp) { // Wavelet was submitted. } @Override public void onFailure(String errorMessage) { fail("Could not submit callback"); } }); } }
private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, ImmutableList.copyOf(ops)); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); waveServer.submitRequest(name, protoDelta, new SubmitRequestListener() { @Override public void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, long applicationTimestamp) { // Wavelet was submitted. } @Override public void onFailure(String errorMessage) { fail("Could not submit callback"); } }); } }
public void testLocalEmptyDelta() throws Exception { ProtocolSignedDelta emptyDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder() .setAuthor(author.toString()) .setHashedVersion(serialize(localVersion0)) .build().toByteString()) .build(); try { localWavelet.submitRequest(localWaveletName, emptyDelta); fail("Should fail"); } catch (IllegalArgumentException e) { // Correct } }
public void testLocalEmptyDelta() throws Exception { ProtocolSignedDelta emptyDelta = ProtocolSignedDelta.newBuilder() .addSignature(fakeSignature1) .setDelta(ProtocolWaveletDelta.newBuilder() .setAuthor(author.toString()) .setHashedVersion(serialize(localVersion0)) .build().toByteString()) .build(); try { localWavelet.submitRequest(localWaveletName, emptyDelta); fail("Should fail"); } catch (IllegalArgumentException e) { // Correct } }
private ProtocolSignedDelta createProtocolSignedDelta(ProtocolWaveletOperation operation, HashedVersion protocolHashedVersion) { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setAuthor(AUTHOR) .setHashedVersion(CoreWaveletOperationSerializer.serialize(protocolHashedVersion)) .addOperation(operation) .build(); return ProtocolSignedDelta.newBuilder() .setDelta(delta.toByteString()) .addSignature(SIGNATURE) .build(); } }
private ProtocolSignedDelta createProtocolSignedDelta(ProtocolWaveletOperation operation, HashedVersion protocolHashedVersion) { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setAuthor(AUTHOR) .setHashedVersion(CoreWaveletOperationSerializer.serialize(protocolHashedVersion)) .addOperation(operation) .build(); return ProtocolSignedDelta.newBuilder() .setDelta(delta.toByteString()) .addSignature(SIGNATURE) .build(); } }
private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) throws Exception { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, Arrays.asList(ops)); addWaveletToUserView(name, user); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(name); wavelet.submitRequest(name, signedProtoDelta); }
/** * Build an applied delta message from a POJO delta. The delta is not signed. */ public static ByteStringMessage<ProtocolAppliedWaveletDelta> buildAppliedDelta(WaveletDelta delta, long applicationTimestamp) { ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); ByteStringMessage<ProtocolWaveletDelta> deltaBytes = ByteStringMessage.serializeMessage(protoDelta); ProtocolSignedDelta signedDelta = ProtocolSignedDelta.newBuilder().setDelta(deltaBytes.getByteString()).build(); return AppliedDeltaUtil.buildAppliedDelta(signedDelta, delta.getTargetVersion(), delta.size(), applicationTimestamp); }
private ProtocolSignedDelta getFakeSignedDelta() throws Exception { return ProtocolSignedDelta.newBuilder() .setDelta(getFakeDelta().getByteString()) .addSignature(getRealSignature()) .build(); }
private void submitDeltaToNewWavelet(WaveletName name, ParticipantId user, WaveletOperation... ops) throws Exception { HashedVersion version = V0_HASH_FACTORY.createVersionZero(name); WaveletDelta delta = new WaveletDelta(user, version, Arrays.asList(ops)); addWaveletToUserView(name, user); ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); // Submitting the request will require the certificate manager to sign the delta. We'll just // leave it unsigned. ProtocolSignedDelta signedProtoDelta = ProtocolSignedDelta.newBuilder().setDelta(protoDelta.toByteString()).build(); LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(name); wavelet.submitRequest(name, signedProtoDelta); }
/** * Build an applied delta message from a POJO delta. The delta is not signed. */ public static ByteStringMessage<ProtocolAppliedWaveletDelta> buildAppliedDelta(WaveletDelta delta, long applicationTimestamp) { ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); ByteStringMessage<ProtocolWaveletDelta> deltaBytes = ByteStringMessage.serializeMessage(protoDelta); ProtocolSignedDelta signedDelta = ProtocolSignedDelta.newBuilder().setDelta(deltaBytes.getByteString()).build(); return AppliedDeltaUtil.buildAppliedDelta(signedDelta, delta.getTargetVersion(), delta.size(), applicationTimestamp); }
private ProtocolSignedDelta getFakeSignedDelta() throws Exception { return ProtocolSignedDelta.newBuilder() .setDelta(getFakeDelta().getByteString()) .addSignature(getRealSignature()) .build(); }