Remove pubkey storage, remove duplicate sig keys

This commit is contained in:
Manfred Karrer 2015-11-01 22:49:14 +01:00
parent 4883c90030
commit 07a9c7fd52
13 changed files with 101 additions and 139 deletions

View file

@ -317,7 +317,7 @@ public class P2PService {
log.trace("removeEntryFromMailbox");
ProtectedMailboxData mailboxData = mailboxMap.get(decryptedMessageWithPubKey);
if (mailboxData != null && mailboxData.expirablePayload instanceof ExpirableMailboxPayload) {
checkArgument(mailboxData.receiversPubKey.equals(keyRing.getStorageSignatureKeyPair().getPublic()),
checkArgument(mailboxData.receiversPubKey.equals(keyRing.getSignatureKeyPair().getPublic()),
"mailboxData.receiversPubKey is not matching with our key. That must not happen.");
removeMailboxData((ExpirableMailboxPayload) mailboxData.expirablePayload, mailboxData.receiversPubKey);
mailboxMap.remove(decryptedMessageWithPubKey);
@ -404,9 +404,9 @@ public class P2PService {
log.debug(throwable.toString());
log.info("We cannot send message to peer. Peer might be offline. We will store message in mailbox.");
log.trace("create MailboxEntry with peerAddress " + peerAddress);
PublicKey receiverStoragePublicKey = peersPubKeyRing.getStorageSignaturePubKey();
PublicKey receiverStoragePublicKey = peersPubKeyRing.getSignaturePubKey();
addMailboxData(new ExpirableMailboxPayload(sealedAndSignedMessage,
keyRing.getStorageSignatureKeyPair().getPublic(),
keyRing.getSignatureKeyPair().getPublic(),
receiverStoragePublicKey),
receiverStoragePublicKey);
UserThread.execute(() -> sendMailboxMessageListener.onStoredInMailbox());
@ -430,7 +430,7 @@ public class P2PService {
throw new AuthenticationException("You must be authenticated before adding data to the P2P network.");
try {
return dataStorage.add(dataStorage.getDataWithSignedSeqNr(expirablePayload, keyRing.getStorageSignatureKeyPair()), networkNode.getAddress());
return dataStorage.add(dataStorage.getDataWithSignedSeqNr(expirablePayload, keyRing.getSignatureKeyPair()), networkNode.getAddress());
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
return false;
@ -442,7 +442,7 @@ public class P2PService {
throw new AuthenticationException("You must be authenticated before adding data to the P2P network.");
try {
return dataStorage.add(dataStorage.getMailboxDataWithSignedSeqNr(expirableMailboxPayload, keyRing.getStorageSignatureKeyPair(), receiversPublicKey), networkNode.getAddress());
return dataStorage.add(dataStorage.getMailboxDataWithSignedSeqNr(expirableMailboxPayload, keyRing.getSignatureKeyPair(), receiversPublicKey), networkNode.getAddress());
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
return false;
@ -453,7 +453,7 @@ public class P2PService {
if (!authenticatedToFirstPeer)
throw new AuthenticationException("You must be authenticated before removing data from the P2P network.");
try {
return dataStorage.remove(dataStorage.getDataWithSignedSeqNr(expirablePayload, keyRing.getStorageSignatureKeyPair()), networkNode.getAddress());
return dataStorage.remove(dataStorage.getDataWithSignedSeqNr(expirablePayload, keyRing.getSignatureKeyPair()), networkNode.getAddress());
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
return false;
@ -464,7 +464,7 @@ public class P2PService {
if (!authenticatedToFirstPeer)
throw new AuthenticationException("You must be authenticated before removing data from the P2P network.");
try {
return dataStorage.removeMailboxData(dataStorage.getMailboxDataWithSignedSeqNr(expirableMailboxPayload, keyRing.getStorageSignatureKeyPair(), receiversPublicKey), networkNode.getAddress());
return dataStorage.removeMailboxData(dataStorage.getMailboxDataWithSignedSeqNr(expirableMailboxPayload, keyRing.getSignatureKeyPair(), receiversPublicKey), networkNode.getAddress());
} catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException e) {
log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
return false;
@ -642,7 +642,7 @@ public class P2PService {
checkNotNull(senderAddress, "senderAddress must not be null for mailbox messages");
log.trace("mailboxData.publicKey " + mailboxData.ownerStoragePubKey.hashCode());
log.trace("keyRing.getStorageSignatureKeyPair().getPublic() " + keyRing.getStorageSignatureKeyPair().getPublic().hashCode());
log.trace("keyRing.getStorageSignatureKeyPair().getPublic() " + keyRing.getSignatureKeyPair().getPublic().hashCode());
log.trace("keyRing.getMsgSignatureKeyPair().getPublic() " + keyRing.getSignatureKeyPair().getPublic().hashCode());
log.trace("keyRing.getMsgEncryptionKeyPair().getPublic() " + keyRing.getEncryptionKeyPair().getPublic().hashCode());

View file

@ -113,7 +113,7 @@ public class P2PServiceTest {
public void testAdversaryAttacks() throws InterruptedException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException {
p2PService3 = TestUtils.getAndAuthenticateP2PService(8003, encryptionService3, keyRing3, useLocalhost, seedNodes);
MockData origData = new MockData("mockData1", keyRing1.getStorageSignatureKeyPair().getPublic());
MockData origData = new MockData("mockData1", keyRing1.getSignatureKeyPair().getPublic());
p2PService1.addData(origData);
Assert.assertEquals(1, p2PService1.getDataMap().size());
@ -122,7 +122,7 @@ public class P2PServiceTest {
// p2PService3 is adversary
KeyPair msgSignatureKeyPairAdversary = keyRing3.getStorageSignatureKeyPair();
KeyPair msgSignatureKeyPairAdversary = keyRing3.getSignatureKeyPair();
// try to remove data -> fails
Assert.assertFalse(p2PService3.removeData(origData));

View file

@ -51,7 +51,7 @@ public class ProtectedDataStorageTest {
ProtectedExpirableDataStorage.CHECK_TTL_INTERVAL = 10 * 60 * 1000;
keyRing1 = new KeyRing(new KeyStorage(new File("temp_keyStorage1")));
storageSignatureKeyPair1 = keyRing1.getStorageSignatureKeyPair();
storageSignatureKeyPair1 = keyRing1.getSignatureKeyPair();
encryptionService1 = new EncryptionService(keyRing1);
networkNode1 = TestUtils.getAndStartSeedNode(8001, encryptionService1, keyRing1, useClearNet, seedNodes).getP2PService().getNetworkNode();
routing1 = new Routing(networkNode1, seedNodes);
@ -59,10 +59,10 @@ public class ProtectedDataStorageTest {
// for mailbox
keyRing2 = new KeyRing(new KeyStorage(new File("temp_keyStorage2")));
storageSignatureKeyPair2 = keyRing2.getStorageSignatureKeyPair();
storageSignatureKeyPair2 = keyRing2.getSignatureKeyPair();
encryptionService2 = new EncryptionService(keyRing2);
mockData = new MockData("mockData", keyRing1.getStorageSignatureKeyPair().getPublic());
mockData = new MockData("mockData", keyRing1.getSignatureKeyPair().getPublic());
Thread.sleep(sleepTime);
}
@ -130,7 +130,7 @@ public class ProtectedDataStorageTest {
@Test
public void testMultiAddRemoveProtectedData() throws InterruptedException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException {
MockData mockData = new MockData("msg1", keyRing1.getStorageSignatureKeyPair().getPublic());
MockData mockData = new MockData("msg1", keyRing1.getSignatureKeyPair().getPublic());
ProtectedData data = dataStorage1.getDataWithSignedSeqNr(mockData, storageSignatureKeyPair1);
Assert.assertTrue(dataStorage1.add(data, null));
@ -197,8 +197,8 @@ public class ProtectedDataStorageTest {
MockMessage mockMessage = new MockMessage("MockMessage");
SealedAndSignedMessage sealedAndSignedMessage = new SealedAndSignedMessage(encryptionService1.encryptAndSignMessage(keyRing1.getPubKeyRing(), mockMessage), null);
ExpirableMailboxPayload expirableMailboxPayload = new ExpirableMailboxPayload(sealedAndSignedMessage,
keyRing1.getStorageSignatureKeyPair().getPublic(),
keyRing2.getStorageSignatureKeyPair().getPublic());
keyRing1.getSignatureKeyPair().getPublic(),
keyRing2.getSignatureKeyPair().getPublic());
ProtectedMailboxData data = dataStorage1.getMailboxDataWithSignedSeqNr(expirableMailboxPayload, storageSignatureKeyPair1, storageSignatureKeyPair2.getPublic());
Assert.assertTrue(dataStorage1.add(data, null));