.keyPair(keyPair1).start();
futurePut2.awaitUninterruptibly();
assertTrue(futurePut2.isSuccess());
// verify overwrite
FutureGet futureGet = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).setVersionKey(vKey).start()
.awaitUninterruptibly();
assertEquals("data2", (String) futureGet.getData().object());
assertEquals(keyPair1.getPublic(), futureGet.getData().publicKey());
// try to overwrite without protection keys (expected to fail)
Data data2A = new Data("data2A").basedOn(bKey);
FuturePut futurePut2A = p1.put(lKey).setData(cKey, data2A).setDomainKey(dKey).setVersionKey(vKey)
.start();
futurePut2A.awaitUninterruptibly();
assertFalse(futurePut2A.isSuccess());
// verify that nothing changed
futureGet = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).setVersionKey(vKey).start()
.awaitUninterruptibly();
assertEquals("data2", (String) futureGet.getData().object());
assertEquals(keyPair1.getPublic(), futureGet.getData().publicKey());
// try to overwrite with wrong protection keys 2 (expected to fail)
Data data2B = new Data("data2B").basedOn(bKey).setProtectedEntry();
FuturePut futurePut2B = p1.put(lKey).setData(cKey, data2B).setDomainKey(dKey).setVersionKey(vKey)
.keyPair(keyPair2).start();
futurePut2B.awaitUninterruptibly();
assertFalse(futurePut2B.isSuccess());
// verify that nothing changed
futureGet = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).setVersionKey(vKey).start()
.awaitUninterruptibly();
assertEquals("data2", (String) futureGet.getData().object());
assertEquals(keyPair1.getPublic(), futureGet.getData().publicKey());
// change protection keys to protection keys 2, create meta data
Data data3 = new Data().setProtectedEntry().publicKey(keyPair2.getPublic()).duplicateMeta();
// use the old protection key 1 to sign the message
FuturePut futurePut3 = p1.put(lKey).setDomainKey(dKey).setVersionKey(vKey).putMeta()
.setData(cKey, data3).keyPair(keyPair1).start();
futurePut3.awaitUninterruptibly();
assertTrue(futurePut3.isSuccess());
// verify change
futureGet = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).setVersionKey(vKey).start()
.awaitUninterruptibly();
// data stays the same
assertEquals("data2", (String) futureGet.getData().object());
// should be new protection key
assertEquals(keyPair2.getPublic(), futureGet.getData().publicKey());
// overwrite with protection keys 2
Data data4 = new Data("data4").basedOn(bKey).setProtectedEntry();
FuturePut futurePut4 = p1.put(lKey).setData(cKey, data4).setDomainKey(dKey).setVersionKey(vKey)
.keyPair(keyPair2).start();
futurePut4.awaitUninterruptibly();
assertTrue(futurePut4.isSuccess());
// verify overwrite
futureGet = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).setVersionKey(vKey).start()
.awaitUninterruptibly();
assertEquals("data4", (String) futureGet.getData().object());
assertEquals(keyPair2.getPublic(), futureGet.getData().publicKey());
// try to overwrite without protection keys (expected to fail)
Data data5A = new Data("data5A").basedOn(bKey);
FuturePut futurePut5A = p1.put(lKey).setData(cKey, data5A).setDomainKey(dKey).setVersionKey(vKey)
.start();
futurePut5A.awaitUninterruptibly();
assertFalse(futurePut5A.isSuccess());
// verify that nothing changed
futureGet = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).setVersionKey(vKey).start()
.awaitUninterruptibly();
assertEquals("data4", (String) futureGet.getData().object());
assertEquals(keyPair2.getPublic(), futureGet.getData().publicKey());
// try to overwrite with wrong protection keys 1 (expected to fail)
Data data5B = new Data("data5B").basedOn(bKey).setProtectedEntry();
FuturePut futurePut5B = p1.put(lKey).setData(cKey, data5B).setDomainKey(dKey).setVersionKey(vKey)
.keyPair(keyPair1).start();
futurePut5B.awaitUninterruptibly();
assertFalse(futurePut5B.isSuccess());
// verify that nothing changed
futureGet = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).setVersionKey(vKey).start()
.awaitUninterruptibly();
assertEquals("data4", (String) futureGet.getData().object());
assertEquals(keyPair2.getPublic(), futureGet.getData().publicKey());
p1.shutdown().awaitUninterruptibly();
p2.shutdown().awaitUninterruptibly();
}