From b6b00268af77040d3070a835dcda6c7fe202509d Mon Sep 17 00:00:00 2001 From: Julian Knutsen Date: Sat, 23 Nov 2019 13:46:19 -0800 Subject: [PATCH] Remove ProtectedStorageEntry::updateSignature The only users were tests that can just pass a bad signature directly into the constructor. --- .../storage/payload/ProtectedStorageEntry.java | 7 +------ .../ProtectedMailboxStorageEntryTest.java | 15 +++++++-------- .../payload/ProtectedStorageEntryTest.java | 16 ++++++++++------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/storage/payload/ProtectedStorageEntry.java b/p2p/src/main/java/bisq/network/p2p/storage/payload/ProtectedStorageEntry.java index 1982052bc2b..87782af57a3 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/payload/ProtectedStorageEntry.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/payload/ProtectedStorageEntry.java @@ -47,7 +47,7 @@ public class ProtectedStorageEntry implements NetworkPayload, PersistablePayload private final byte[] ownerPubKeyBytes; transient private final PublicKey ownerPubKey; private final int sequenceNumber; - private byte[] signature; + private final byte[] signature; private long creationTimeStamp; public ProtectedStorageEntry(ProtectedStoragePayload protectedStoragePayload, @@ -146,11 +146,6 @@ public void backDate() { creationTimeStamp -= ((ExpirablePayload) protectedStoragePayload).getTTL() / 2; } - // TODO: only used in tests so find a better way to test and delete public API - public void updateSignature(byte[] signature) { - this.signature = signature; - } - public boolean isExpired(Clock clock) { return protectedStoragePayload instanceof ExpirablePayload && (clock.millis() - creationTimeStamp) > ((ExpirablePayload) protectedStoragePayload).getTTL(); diff --git a/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedMailboxStorageEntryTest.java b/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedMailboxStorageEntryTest.java index 74d466aa148..035e9e03d57 100644 --- a/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedMailboxStorageEntryTest.java +++ b/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedMailboxStorageEntryTest.java @@ -107,14 +107,13 @@ public void isValidForAddOperation_EntryReceiverPayloadReceiverMismatch() throws // TESTCASE: validForAddOperation() should fail if the signature isn't valid @Test - public void isValidForAddOperation_BadSignature() throws NoSuchAlgorithmException, CryptoException { + public void isValidForAddOperation_BadSignature() throws NoSuchAlgorithmException { KeyPair senderKeys = TestUtils.generateKeyPair(); KeyPair receiverKeys = TestUtils.generateKeyPair(); MailboxStoragePayload mailboxStoragePayload = buildMailboxStoragePayload(senderKeys.getPublic(), receiverKeys.getPublic()); - ProtectedStorageEntry protectedStorageEntry = buildProtectedMailboxStorageEntry(mailboxStoragePayload, senderKeys, receiverKeys.getPublic(), 1); - - protectedStorageEntry.updateSignature( new byte[] { 0 }); + ProtectedStorageEntry protectedStorageEntry = new ProtectedMailboxStorageEntry( + mailboxStoragePayload, senderKeys.getPublic(), 1, new byte[] { 0 }, receiverKeys.getPublic(), Clock.systemDefaultZone()); Assert.assertFalse(protectedStorageEntry.isValidForAddOperation()); } @@ -145,14 +144,14 @@ public void validForRemoveEntryOwnerPayloadOwnerMismatch() throws NoSuchAlgorith // TESTCASE: isValidForRemoveOperation() should fail if the signature is bad @Test - public void isValidForRemoveOperation_BadSignature() throws NoSuchAlgorithmException, CryptoException { + public void isValidForRemoveOperation_BadSignature() throws NoSuchAlgorithmException { KeyPair senderKeys = TestUtils.generateKeyPair(); KeyPair receiverKeys = TestUtils.generateKeyPair(); MailboxStoragePayload mailboxStoragePayload = buildMailboxStoragePayload(senderKeys.getPublic(), receiverKeys.getPublic()); - ProtectedStorageEntry protectedStorageEntry = buildProtectedMailboxStorageEntry(mailboxStoragePayload, receiverKeys, receiverKeys.getPublic(), 1); - - protectedStorageEntry.updateSignature(new byte[] { 0 }); + ProtectedStorageEntry protectedStorageEntry = + new ProtectedMailboxStorageEntry(mailboxStoragePayload, receiverKeys.getPublic(), + 1, new byte[] { 0 }, receiverKeys.getPublic(), Clock.systemDefaultZone()); Assert.assertFalse(protectedStorageEntry.isValidForRemoveOperation()); } diff --git a/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedStorageEntryTest.java b/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedStorageEntryTest.java index 1b5313977e7..b1e9727f032 100644 --- a/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedStorageEntryTest.java +++ b/p2p/src/test/java/bisq/network/p2p/storage/payload/ProtectedStorageEntryTest.java @@ -125,11 +125,13 @@ public void isValidForAddOperation_invalidMailboxPayloadReceiver() throws NoSuch // TESTCASE: validForAddOperation() should fail if the signature isn't valid @Test - public void isValidForAddOperation_BadSignature() throws NoSuchAlgorithmException, CryptoException { + public void isValidForAddOperation_BadSignature() throws NoSuchAlgorithmException { KeyPair ownerKeys = TestUtils.generateKeyPair(); - ProtectedStorageEntry protectedStorageEntry = buildProtectedStorageEntry(ownerKeys, ownerKeys, 1); - protectedStorageEntry.updateSignature( new byte[] { 0 }); + ProtectedStoragePayload protectedStoragePayload = new ProtectedStoragePayloadStub(ownerKeys.getPublic()); + ProtectedStorageEntry protectedStorageEntry = + new ProtectedStorageEntry(protectedStoragePayload, ownerKeys.getPublic(), + 1, new byte[] { 0 }, Clock.systemDefaultZone()); Assert.assertFalse(protectedStorageEntry.isValidForAddOperation()); } @@ -181,11 +183,13 @@ public void isValidForRemoveOperation_invalidMailboxPayloadReceiver() throws NoS // TESTCASE: isValidForRemoveOperation() should fail if the signature is bad @Test - public void isValidForRemoveOperation_BadSignature() throws NoSuchAlgorithmException, CryptoException { + public void isValidForRemoveOperation_BadSignature() throws NoSuchAlgorithmException { KeyPair ownerKeys = TestUtils.generateKeyPair(); - ProtectedStorageEntry protectedStorageEntry = buildProtectedStorageEntry(ownerKeys, ownerKeys, 1); - protectedStorageEntry.updateSignature(new byte[] { 0 }); + ProtectedStoragePayload protectedStoragePayload = new ProtectedStoragePayloadStub(ownerKeys.getPublic()); + ProtectedStorageEntry protectedStorageEntry = + new ProtectedStorageEntry(protectedStoragePayload, ownerKeys.getPublic(), + 1, new byte[] { 0 }, Clock.systemDefaultZone()); Assert.assertFalse(protectedStorageEntry.isValidForRemoveOperation()); }