@Override public void submitRequest(WaveletName waveletName, ProtocolWaveletDelta delta, final SubmitRequestListener listener) { Preconditions.checkState(initialized, "Wave server not yet initialized"); if (delta.getOperationCount() == 0) { listener.onFailure("Empty delta at version " + delta.getHashedVersion().getVersion()); return; } // The serialised version of this delta happens now. This should be the only place, ever! ProtocolSignedDelta signedDelta = certificateManager.signDelta(ByteStringMessage.serializeMessage(delta)); submitDelta(waveletName, delta, signedDelta, new SubmitResultListener() { @Override public void onFailure(FederationError errorMessage) { listener.onFailure(errorMessage.getErrorMessage()); } @Override public void onSuccess(int operationsApplied, ProtocolHashedVersion hashedVersionAfterApplication, long applicationTimestamp) { listener.onSuccess(operationsApplied, CoreWaveletOperationSerializer.deserialize(hashedVersionAfterApplication), applicationTimestamp); } }); }
/** * Creates an applied delta message from a signed protocol delta and * application metadata. * * @param signedDelta the original delta * @param appliedAtVersion version at which the delta applied * @param operationsApplied number of ops in the delta * @param applicationTimestamp timestamp of application */ public static ByteStringMessage<ProtocolAppliedWaveletDelta> buildAppliedDelta( ProtocolSignedDelta signedDelta, HashedVersion appliedAtVersion, int operationsApplied, long applicationTimestamp) { ProtocolAppliedWaveletDelta.Builder appliedDeltaBuilder = ProtocolAppliedWaveletDelta .newBuilder() .setSignedOriginalDelta(signedDelta) .setOperationsApplied(operationsApplied) .setApplicationTimestamp(applicationTimestamp); // TODO(soren): Only set hashedVersionAppliedAt when different from the // signed delta's target version if we rev the protocol. appliedDeltaBuilder.setHashedVersionAppliedAt( CoreWaveletOperationSerializer.serialize(appliedAtVersion)); return ByteStringMessage.serializeMessage(appliedDeltaBuilder.build()); }
private ByteStringMessage<ProtocolWaveletDelta> getFakeDelta() throws Exception { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setHashedVersion(getProtocolHashedVersion()) .setAuthor("bob@initech-corp.com") .build(); return ByteStringMessage.serializeMessage(delta); }
private ByteStringMessage<ProtocolWaveletDelta> getFakeDelta() throws Exception { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setHashedVersion(getProtocolHashedVersion()) .setAuthor("bob@initech-corp.com") .build(); return ByteStringMessage.serializeMessage(delta); }
/** * 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); }
/** * 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); }
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 testSignature() throws Exception { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setHashedVersion(getProtocolHashedVersion()) .setAuthor("bob@example.com") .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); }
public void testSignature() throws Exception { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setHashedVersion(getProtocolHashedVersion()) .setAuthor("bob@example.com") .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); }
public void testSignature_authorNotMatching() throws Exception { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setHashedVersion(getProtocolHashedVersion()) .setAuthor("bob@someotherdomain.com") .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_authorNotMatching() throws Exception { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setHashedVersion(getProtocolHashedVersion()) .setAuthor("bob@someotherdomain.com") .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("bob@example.com") .build(); ByteStringMessage<ProtocolWaveletDelta> canonicalDelta = ByteStringMessage.serializeMessage(delta); manager = new CertificateManagerImpl(config, 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); } }
public void testSignature_missingSignerInfo() throws Exception { ProtocolWaveletDelta delta = ProtocolWaveletDelta.newBuilder() .setHashedVersion(getProtocolHashedVersion()) .setAuthor("bob@example.com") .build(); ByteStringMessage<ProtocolWaveletDelta> canonicalDelta = ByteStringMessage.serializeMessage(delta); manager = new CertificateManagerImpl(config, 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); } }