Skip to content

Commit

Permalink
Remove ProtectedStorageEntry::updateSignature
Browse files Browse the repository at this point in the history
The only users were tests that can just pass a bad signature directly
into the constructor.
  • Loading branch information
julianknutsen committed Dec 4, 2019
1 parent 17f4b70 commit b6b0026
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit b6b0026

Please sign in to comment.