/** Picks out the byte strings of the applied deltas from a list of delta records. */ private static ImmutableList<ByteString> serializedAppliedDeltasOf( Iterable<WaveletDeltaRecord> deltaRecords) { ImmutableList.Builder<ByteString> serializedAppliedDeltas = ImmutableList.builder(); for (WaveletDeltaRecord deltaRecord : deltaRecords) { serializedAppliedDeltas.add(deltaRecord.getAppliedDelta().getByteString()); } return serializedAppliedDeltas.build(); }
/** * Verifies a single signature. * @param delta the payload that we're verifying the signature on. * @param signature the signature on the payload * @param domain the authority (domain name) that should have signed the * payload. * @throws SignatureException if the signature doesn't verify. */ private void verifySingleSignature(ByteStringMessage<ProtocolWaveletDelta> delta, ProtocolSignature signature, String domain) throws SignatureException, UnknownSignerException { verifier.verify(delta.getByteString().toByteArray(), signature, domain); }
@Override public boolean put(ByteStringMessage<ProtocolAppliedWaveletDelta> delta) { ByteString bytes = delta.getByteString(); deltaHistoryBytes.add(bytes); if (length.addAndGet(bytes.size()) >= lengthLimit) { return false; } return true; } });
@Override public Iterable<ProtocolSignature> sign(ByteStringMessage<ProtocolWaveletDelta> delta) { return ImmutableList.of(signer.sign(delta.getByteString().toByteArray())); }
@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(); }
private ProtocolSignedDelta getFakeSignedDelta() throws Exception { return ProtocolSignedDelta.newBuilder() .setDelta(getFakeDelta().getByteString()) .addSignature(getRealSignature()) .build(); }
private ProtocolSignedDelta getFakeSignedDelta() throws Exception { return ProtocolSignedDelta.newBuilder() .setDelta(getFakeDelta().getByteString()) .addSignature(getRealSignature()) .build(); }
/** * 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); }