From 009efb8e348a91ec083c3789e1c221af12708ffa Mon Sep 17 00:00:00 2001 From: Tripti Ghanghas Date: Mon, 3 Jun 2024 13:04:49 -0700 Subject: [PATCH 1/9] added sender client's id to bundleDto --- BundleClient/app/build.gradle | 2 +- .../java/com/ddd/client/bundlesecurity/BundleSecurity.java | 4 ++++ .../ddd/client/bundletransmission/BundleTransmission.java | 6 ++++-- bundle-core/pom.xml | 2 +- bundle-core/src/main/java/com/ddd/model/BundleDTO.java | 4 +++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/BundleClient/app/build.gradle b/BundleClient/app/build.gradle index 435aa60ae4..2c563fd926 100644 --- a/BundleClient/app/build.gradle +++ b/BundleClient/app/build.gradle @@ -77,7 +77,7 @@ dependencies { exclude group: 'com.google.protobuf', module:'protobuf-java' } // DDD common core - implementation 'com.ddd:bundle-core:0.0.1' + implementation 'com.ddd:bundle-core:0.0.2' } task prepareKotlinBuildScriptModel { diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java index b91ff74eb4..d366e51494 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java @@ -158,6 +158,10 @@ public String generateNewBundleId() throws SecurityExceptions.IDGenerationExcept return clientBundleGenerator.generateBundleID(); } + public String getClientId(){ + return client.getClientID(); + } + public UncompressedBundle encryptPayload(Payload payload, String bundleGenDirPath) { String bundleId = payload.getBundleId(); Log.d(HelloworldActivity.TAG, "encrypting payload in bundleId: " + bundleId); diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java b/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java index d6961f8a4d..f932d46098 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java @@ -234,8 +234,10 @@ private BundleDTO generateNewBundle(UncompressedPayload.Builder builder, File ta Bundle toSend = BundleUtils.compressBundle(uncompressedBundle, targetDir.getAbsolutePath()); this.applicationDataManager.notifyBundleSent(toSendBundlePayload); - System.out.println("[BT] Generated new bundle for transmission with bundle id: " + bundleId); - return new BundleDTO(bundleId, toSend); + + String clientId = bundleSecurity.getClientId(); + System.out.println("[BT] Generated new bundle for transmission with bundle id: " + bundleId + ", and clientId: " + clientId); + return new BundleDTO(clientId, bundleId, toSend); } public BundleDTO generateBundleForTransmission() { diff --git a/bundle-core/pom.xml b/bundle-core/pom.xml index e02702bc3a..1e38ab94fc 100644 --- a/bundle-core/pom.xml +++ b/bundle-core/pom.xml @@ -6,7 +6,7 @@ com.ddd bundle-core - 0.0.1 + 0.0.2 17 diff --git a/bundle-core/src/main/java/com/ddd/model/BundleDTO.java b/bundle-core/src/main/java/com/ddd/model/BundleDTO.java index afa69e35dd..e5d64e4cb8 100644 --- a/bundle-core/src/main/java/com/ddd/model/BundleDTO.java +++ b/bundle-core/src/main/java/com/ddd/model/BundleDTO.java @@ -1,6 +1,7 @@ package com.ddd.model; public class BundleDTO { + private String senderClientId; private String bundleId; private Bundle bundle; @@ -12,7 +13,8 @@ public Bundle getBundle() { return this.bundle; } - public BundleDTO(String bundleId, Bundle bundle) { + public BundleDTO(String senderClientId, String bundleId, Bundle bundle) { + this.senderClientId = senderClientId; this.bundleId = bundleId; this.bundle = bundle; } From a37f89ceb02966c79fdf1b135729cc35abf88e6f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 3 Jun 2024 20:06:27 +0000 Subject: [PATCH 2/9] Auto-format code --- .../java/com/ddd/client/bundlesecurity/BundleSecurity.java | 2 +- .../ddd/client/bundletransmission/BundleTransmission.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java index d366e51494..bfb0778622 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java @@ -158,7 +158,7 @@ public String generateNewBundleId() throws SecurityExceptions.IDGenerationExcept return clientBundleGenerator.generateBundleID(); } - public String getClientId(){ + public String getClientId() { return client.getClientID(); } diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java b/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java index f932d46098..3f2618498d 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java @@ -235,8 +235,10 @@ private BundleDTO generateNewBundle(UncompressedPayload.Builder builder, File ta Bundle toSend = BundleUtils.compressBundle(uncompressedBundle, targetDir.getAbsolutePath()); this.applicationDataManager.notifyBundleSent(toSendBundlePayload); - String clientId = bundleSecurity.getClientId(); - System.out.println("[BT] Generated new bundle for transmission with bundle id: " + bundleId + ", and clientId: " + clientId); + String clientId = bundleSecurity.getClientId(); + System.out.println( + "[BT] Generated new bundle for transmission with bundle id: " + bundleId + ", and clientId: " + + clientId); return new BundleDTO(clientId, bundleId, toSend); } From 3ec4b47bc13dfe5c2ed3d9e9dd10ac985ea334be Mon Sep 17 00:00:00 2001 From: Tripti Ghanghas Date: Wed, 5 Jun 2024 10:26:03 -0700 Subject: [PATCH 3/9] reverting clientId addition to bundleDto --- BundleClient/app/build.gradle | 2 +- .../com/ddd/client/bundlesecurity/BundleSecurity.java | 4 ---- .../ddd/client/bundletransmission/BundleTransmission.java | 8 ++------ .../app/src/main/java/com/ddd/utils/JarUtils.java | 1 - bundle-core/pom.xml | 2 +- bundle-core/src/main/java/com/ddd/model/BundleDTO.java | 5 ++--- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/BundleClient/app/build.gradle b/BundleClient/app/build.gradle index 2c563fd926..435aa60ae4 100644 --- a/BundleClient/app/build.gradle +++ b/BundleClient/app/build.gradle @@ -77,7 +77,7 @@ dependencies { exclude group: 'com.google.protobuf', module:'protobuf-java' } // DDD common core - implementation 'com.ddd:bundle-core:0.0.2' + implementation 'com.ddd:bundle-core:0.0.1' } task prepareKotlinBuildScriptModel { diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java index bfb0778622..b91ff74eb4 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java @@ -158,10 +158,6 @@ public String generateNewBundleId() throws SecurityExceptions.IDGenerationExcept return clientBundleGenerator.generateBundleID(); } - public String getClientId() { - return client.getClientID(); - } - public UncompressedBundle encryptPayload(Payload payload, String bundleGenDirPath) { String bundleId = payload.getBundleId(); Log.d(HelloworldActivity.TAG, "encrypting payload in bundleId: " + bundleId); diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java b/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java index 3f2618498d..d6961f8a4d 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundletransmission/BundleTransmission.java @@ -234,12 +234,8 @@ private BundleDTO generateNewBundle(UncompressedPayload.Builder builder, File ta Bundle toSend = BundleUtils.compressBundle(uncompressedBundle, targetDir.getAbsolutePath()); this.applicationDataManager.notifyBundleSent(toSendBundlePayload); - - String clientId = bundleSecurity.getClientId(); - System.out.println( - "[BT] Generated new bundle for transmission with bundle id: " + bundleId + ", and clientId: " + - clientId); - return new BundleDTO(clientId, bundleId, toSend); + System.out.println("[BT] Generated new bundle for transmission with bundle id: " + bundleId); + return new BundleDTO(bundleId, toSend); } public BundleDTO generateBundleForTransmission() { diff --git a/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java b/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java index cae8b673ed..cf1efb0d9d 100644 --- a/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java +++ b/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java @@ -20,7 +20,6 @@ import java.util.zip.CheckedInputStream; import android.util.Base64; - import com.ddd.datastore.filestore.FileStoreHelper; public class JarUtils { diff --git a/bundle-core/pom.xml b/bundle-core/pom.xml index 1e38ab94fc..e02702bc3a 100644 --- a/bundle-core/pom.xml +++ b/bundle-core/pom.xml @@ -6,7 +6,7 @@ com.ddd bundle-core - 0.0.2 + 0.0.1 17 diff --git a/bundle-core/src/main/java/com/ddd/model/BundleDTO.java b/bundle-core/src/main/java/com/ddd/model/BundleDTO.java index e5d64e4cb8..c15075159e 100644 --- a/bundle-core/src/main/java/com/ddd/model/BundleDTO.java +++ b/bundle-core/src/main/java/com/ddd/model/BundleDTO.java @@ -1,7 +1,7 @@ package com.ddd.model; public class BundleDTO { - private String senderClientId; + private String bundleId; private Bundle bundle; @@ -13,8 +13,7 @@ public Bundle getBundle() { return this.bundle; } - public BundleDTO(String senderClientId, String bundleId, Bundle bundle) { - this.senderClientId = senderClientId; + public BundleDTO(String bundleId, Bundle bundle) { this.bundleId = bundleId; this.bundle = bundle; } From 0b74abde3cb4056b1e75486e9e9ab6c8a7c300dd Mon Sep 17 00:00:00 2001 From: Tripti Ghanghas Date: Wed, 5 Jun 2024 12:24:14 -0700 Subject: [PATCH 4/9] added server_identity key in client bundle, refactored EncryptionHeader --- BundleClient/app/build.gradle | 2 +- .../client/bundlesecurity/BundleSecurity.java | 7 ++- .../client/bundlesecurity/ClientSecurity.java | 18 ++++---- bundle-core/pom.xml | 7 ++- .../java/com/ddd/model/EncryptionHeader.java | 43 +++---------------- bundleserver/pom.xml | 2 +- .../server/bundlesecurity/BundleSecurity.java | 6 ++- 7 files changed, 33 insertions(+), 52 deletions(-) diff --git a/BundleClient/app/build.gradle b/BundleClient/app/build.gradle index 435aa60ae4..2c563fd926 100644 --- a/BundleClient/app/build.gradle +++ b/BundleClient/app/build.gradle @@ -77,7 +77,7 @@ dependencies { exclude group: 'com.google.protobuf', module:'protobuf-java' } // DDD common core - implementation 'com.ddd:bundle-core:0.0.1' + implementation 'com.ddd:bundle-core:0.0.2' } task prepareKotlinBuildScriptModel { diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java index b91ff74eb4..66fd635613 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java @@ -170,9 +170,12 @@ public UncompressedBundle encryptPayload(Payload payload, String bundleGenDirPat paths = client.encrypt(payload.getSource().getAbsolutePath(), bundleGenDirPath, bundleId); EncryptedPayload encryptedPayload = new EncryptedPayload(bundleId, new File(paths[0])); - File source = new File(bundleGenDirPath + File.separator + bundleId); - EncryptionHeader encHeader = new EncryptionHeader(new File(paths[2]), new File(paths[3])); + EncryptionHeader encHeader = EncryptionHeader.builder() + .clientBaseKey(new File(paths[2])) + .clientIdentityKey(new File(paths[3])) + .serverIdentityKey(new File("")) + .build(); return new UncompressedBundle(bundleId, source, encHeader, encryptedPayload, new File(paths[1])); } catch (Exception e) { e.printStackTrace(); diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java index 2596b8e181..da568515b7 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java @@ -101,16 +101,18 @@ private ClientSecurity(int deviceID, String clientRootPath, String serverKeyPath private String[] writeKeysToFiles(String path, boolean writePvt) throws EncodingException, IOException { /* Create Directory if it does not exist */ SecurityUtils.createDirectory(path); - String[] clientKeypaths = { path + File.separator + SecurityUtils.CLIENT_IDENTITY_KEY, - path + File.separator + SecurityUtils.CLIENT_BASE_KEY }; + String[] identityKeyPaths = { path + File.separator + SecurityUtils.CLIENT_IDENTITY_KEY, + path + File.separator + SecurityUtils.CLIENT_BASE_KEY, + path + File.separator + SecurityUtils.SERVER_IDENTITY_KEY}; if (writePvt) { writePrivateKeys(path); } - SecurityUtils.createEncodedPublicKeyFile(ourIdentityKeyPair.getPublicKey().getPublicKey(), clientKeypaths[0]); - SecurityUtils.createEncodedPublicKeyFile(ourBaseKey.getPublicKey(), clientKeypaths[1]); - return clientKeypaths; + SecurityUtils.createEncodedPublicKeyFile(ourIdentityKeyPair.getPublicKey().getPublicKey(), identityKeyPaths[0]); + SecurityUtils.createEncodedPublicKeyFile(ourBaseKey.getPublicKey(), identityKeyPaths[1]); + SecurityUtils.createEncodedPublicKeyFile(theirIdentityKey.getPublicKey(), identityKeyPaths[2]); + return identityKeyPaths; } private void writePrivateKeys(String path) throws IOException { @@ -308,14 +310,12 @@ public String[] encrypt(String toBeEncPath, String encPath, String bundleID) thr inputStream.close(); /* Create Encryption Headers */ - String[] clientKeyPaths = createEncryptionHeader(encPath, bundleID); + String[] identityKeyPaths = createEncryptionHeader(encPath, bundleID); returnPaths.add(payloadPath); returnPaths.add(signPath); - for (String clientKeyPath : clientKeyPaths) { - returnPaths.add(clientKeyPath); - } + returnPaths.addAll(Arrays.asList(identityKeyPaths)); return returnPaths.toArray(new String[returnPaths.size()]); } diff --git a/bundle-core/pom.xml b/bundle-core/pom.xml index e02702bc3a..3b477fc459 100644 --- a/bundle-core/pom.xml +++ b/bundle-core/pom.xml @@ -6,7 +6,7 @@ com.ddd bundle-core - 0.0.1 + 0.0.2 17 @@ -20,6 +20,11 @@ picocli 4.7.5 + + org.projectlombok + lombok + 1.18.32 + \ No newline at end of file diff --git a/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java b/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java index 9a5e6b8bc3..7d81b3f010 100644 --- a/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java +++ b/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java @@ -1,46 +1,17 @@ package com.ddd.model; -import java.io.File; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import java.io.File; +@Data +@Getter +@Builder public class EncryptionHeader { private final File serverSignedPreKey; private final File serverIdentityKey; private final File serverRatchetKey; - - public File getServerSignedPreKey() { - return this.serverSignedPreKey; - } - - public File getServerIdentityKey() { - return this.serverIdentityKey; - } - - public File getServerRatchetKey() { - return this.serverRatchetKey; - } - - public EncryptionHeader(File serverSignedPreKey, File serverIdentityKey, File serverRatchetKey) { - this.serverSignedPreKey = serverSignedPreKey; - this.serverIdentityKey = serverIdentityKey; - this.serverRatchetKey = serverRatchetKey; - } - private File clientBaseKey; private File clientIdentityKey; - - public EncryptionHeader(File clientBaseKey, File clientIdentityKey) { - this.clientBaseKey = clientBaseKey; - this.clientIdentityKey = clientIdentityKey; - this.serverSignedPreKey = null; - this.serverIdentityKey = null; - this.serverRatchetKey = null; - } - - public File getClientBaseKey() { - return clientBaseKey; - } - - public File getClientIdentityKey() { - return clientIdentityKey; - } } diff --git a/bundleserver/pom.xml b/bundleserver/pom.xml index 4673e5a7db..55fed37548 100644 --- a/bundleserver/pom.xml +++ b/bundleserver/pom.xml @@ -71,7 +71,7 @@ com.ddd bundle-core - 0.0.1 + 0.0.2 com.google.code.gson diff --git a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java index a8aa55b06f..303241c155 100644 --- a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java +++ b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java @@ -182,8 +182,10 @@ public UncompressedBundle encryptPayload(String clientId, Payload payload, Strin EncryptedPayload encryptedPayload = new EncryptedPayload(bundleId, new File(paths[0])); File source = new File(bundleGenDirPath + File.separator + bundleId); - EncryptionHeader encHeader = - new EncryptionHeader(new File(paths[2]), new File(paths[3]), new File(paths[4])); + EncryptionHeader encHeader = EncryptionHeader.builder() + .serverSignedPreKey(new File(paths[2])) + .serverIdentityKey(new File(paths[3])) + .serverRatchetKey(new File(paths[4])).build(); return new UncompressedBundle( // TODO get encryption header, payload signature bundleId, source, encHeader, encryptedPayload, new File(paths[1])); From 53008a46e6b5efd842a84b84e5f0870d9cd375a1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 5 Jun 2024 19:28:01 +0000 Subject: [PATCH 5/9] Auto-format code --- .../com/ddd/client/bundlesecurity/BundleSecurity.java | 8 +++----- .../com/ddd/client/bundlesecurity/ClientSecurity.java | 2 +- .../src/main/java/com/ddd/model/EncryptionHeader.java | 1 + .../com/ddd/server/bundlesecurity/BundleSecurity.java | 6 ++---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java index 66fd635613..3eece15af5 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java @@ -171,11 +171,9 @@ public UncompressedBundle encryptPayload(Payload payload, String bundleGenDirPat EncryptedPayload encryptedPayload = new EncryptedPayload(bundleId, new File(paths[0])); File source = new File(bundleGenDirPath + File.separator + bundleId); - EncryptionHeader encHeader = EncryptionHeader.builder() - .clientBaseKey(new File(paths[2])) - .clientIdentityKey(new File(paths[3])) - .serverIdentityKey(new File("")) - .build(); + EncryptionHeader encHeader = + EncryptionHeader.builder().clientBaseKey(new File(paths[2])).clientIdentityKey(new File(paths[3])) + .serverIdentityKey(new File("")).build(); return new UncompressedBundle(bundleId, source, encHeader, encryptedPayload, new File(paths[1])); } catch (Exception e) { e.printStackTrace(); diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java index da568515b7..e493211337 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/ClientSecurity.java @@ -103,7 +103,7 @@ private String[] writeKeysToFiles(String path, boolean writePvt) throws Encoding SecurityUtils.createDirectory(path); String[] identityKeyPaths = { path + File.separator + SecurityUtils.CLIENT_IDENTITY_KEY, path + File.separator + SecurityUtils.CLIENT_BASE_KEY, - path + File.separator + SecurityUtils.SERVER_IDENTITY_KEY}; + path + File.separator + SecurityUtils.SERVER_IDENTITY_KEY }; if (writePvt) { writePrivateKeys(path); diff --git a/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java b/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java index 7d81b3f010..3543515f21 100644 --- a/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java +++ b/bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java @@ -5,6 +5,7 @@ import lombok.Getter; import java.io.File; + @Data @Getter @Builder diff --git a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java index 303241c155..21309ff679 100644 --- a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java +++ b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java @@ -182,10 +182,8 @@ public UncompressedBundle encryptPayload(String clientId, Payload payload, Strin EncryptedPayload encryptedPayload = new EncryptedPayload(bundleId, new File(paths[0])); File source = new File(bundleGenDirPath + File.separator + bundleId); - EncryptionHeader encHeader = EncryptionHeader.builder() - .serverSignedPreKey(new File(paths[2])) - .serverIdentityKey(new File(paths[3])) - .serverRatchetKey(new File(paths[4])).build(); + EncryptionHeader encHeader = EncryptionHeader.builder().serverSignedPreKey(new File(paths[2])) + .serverIdentityKey(new File(paths[3])).serverRatchetKey(new File(paths[4])).build(); return new UncompressedBundle( // TODO get encryption header, payload signature bundleId, source, encHeader, encryptedPayload, new File(paths[1])); From 31aa83f97bb3a8765e18d75b77fb5c1f35bd4860 Mon Sep 17 00:00:00 2001 From: Tripti Ghanghas Date: Wed, 5 Jun 2024 12:35:42 -0700 Subject: [PATCH 6/9] added server identity key path --- .../main/java/com/ddd/client/bundlesecurity/BundleSecurity.java | 2 +- BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java | 1 + bundle-core/src/main/java/com/ddd/model/BundleDTO.java | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java index 66fd635613..a525892d5a 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java @@ -174,7 +174,7 @@ public UncompressedBundle encryptPayload(Payload payload, String bundleGenDirPat EncryptionHeader encHeader = EncryptionHeader.builder() .clientBaseKey(new File(paths[2])) .clientIdentityKey(new File(paths[3])) - .serverIdentityKey(new File("")) + .serverIdentityKey(new File(paths[4])) .build(); return new UncompressedBundle(bundleId, source, encHeader, encryptedPayload, new File(paths[1])); } catch (Exception e) { diff --git a/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java b/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java index cf1efb0d9d..cae8b673ed 100644 --- a/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java +++ b/BundleClient/app/src/main/java/com/ddd/utils/JarUtils.java @@ -20,6 +20,7 @@ import java.util.zip.CheckedInputStream; import android.util.Base64; + import com.ddd.datastore.filestore.FileStoreHelper; public class JarUtils { diff --git a/bundle-core/src/main/java/com/ddd/model/BundleDTO.java b/bundle-core/src/main/java/com/ddd/model/BundleDTO.java index c15075159e..afa69e35dd 100644 --- a/bundle-core/src/main/java/com/ddd/model/BundleDTO.java +++ b/bundle-core/src/main/java/com/ddd/model/BundleDTO.java @@ -1,7 +1,6 @@ package com.ddd.model; public class BundleDTO { - private String bundleId; private Bundle bundle; From 2fa4573df5a02d65ec701d57c8752871e06a3e28 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 5 Jun 2024 19:41:24 +0000 Subject: [PATCH 7/9] Auto-format code --- .../com/ddd/client/bundlesecurity/BundleSecurity.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java index a525892d5a..b5a9172973 100644 --- a/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java +++ b/BundleClient/app/src/main/java/com/ddd/client/bundlesecurity/BundleSecurity.java @@ -171,11 +171,9 @@ public UncompressedBundle encryptPayload(Payload payload, String bundleGenDirPat EncryptedPayload encryptedPayload = new EncryptedPayload(bundleId, new File(paths[0])); File source = new File(bundleGenDirPath + File.separator + bundleId); - EncryptionHeader encHeader = EncryptionHeader.builder() - .clientBaseKey(new File(paths[2])) - .clientIdentityKey(new File(paths[3])) - .serverIdentityKey(new File(paths[4])) - .build(); + EncryptionHeader encHeader = + EncryptionHeader.builder().clientBaseKey(new File(paths[2])).clientIdentityKey(new File(paths[3])) + .serverIdentityKey(new File(paths[4])).build(); return new UncompressedBundle(bundleId, source, encHeader, encryptedPayload, new File(paths[1])); } catch (Exception e) { e.printStackTrace(); From 27c0dd3b383b04f441d903e08ea183a0af84f044 Mon Sep 17 00:00:00 2001 From: Tripti Ghanghas Date: Wed, 5 Jun 2024 14:53:33 -0700 Subject: [PATCH 8/9] added check on bundle processing on server to match serverIdentity key --- .../ddd/server/bundlesecurity/BundleSecurity.java | 8 ++++++++ .../ddd/server/bundlesecurity/ServerSecurity.java | 4 ++++ .../bundletransmission/BundleTransmission.java | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java index 21309ff679..a5c2ac813e 100644 --- a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java +++ b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/BundleSecurity.java @@ -198,4 +198,12 @@ public int isNewerBundle(String bundlePath, String lastReceivedBundleID) throws return this.serverSecurity.isNewerBundle(bundlePath, lastReceivedBundleID); } + public String getServerId() throws SecurityExceptions.IDGenerationException { + return serverSecurity.getServerId(); + } + + public boolean bundleServerIdMatchesCurrentServer(String receivedServerId) throws SecurityExceptions.IDGenerationException { + return receivedServerId.equals(getServerId()); + } + } diff --git a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/ServerSecurity.java b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/ServerSecurity.java index f612355afa..9faccc88f5 100644 --- a/bundleserver/src/main/java/com/ddd/server/bundlesecurity/ServerSecurity.java +++ b/bundleserver/src/main/java/com/ddd/server/bundlesecurity/ServerSecurity.java @@ -558,4 +558,8 @@ public int isNewerBundle(String bundlePath, String lastBundleID) throws IOExcept return BundleIDGenerator.compareBundleIDs(receivedBundleID, latestBundleID, BundleIDGenerator.UPSTREAM); } + public String getServerId() throws IDGenerationException { + return SecurityUtils.generateID(ourIdentityKeyPair.getPublicKey().serialize()); + } + }; diff --git a/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java b/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java index 309b758e17..df28519e11 100644 --- a/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java +++ b/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java @@ -11,6 +11,8 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.commons.io.FileUtils; import org.springframework.stereotype.Service; @@ -56,6 +58,7 @@ public class BundleTransmission { private ServerWindow serverWindow; private int WINDOW_LENGTH = 3; + private Logger logger = Logger.getLogger(this.getClass().getName()); public BundleTransmission(BundleSecurity bundleSecurity, ApplicationDataManager applicationDataManager, BundleRouting bundleRouting, @@ -80,6 +83,15 @@ public void processReceivedBundle(String transportId, Bundle bundle) throws Exce this.bundleGenServ.extractBundle(bundle, bundleRecvProcDir.getAbsolutePath()); String clientId = ""; try { + + String serverIdReceived = SecurityUtils.generateID( + uncompressedBundle.getSource() + File.separator + SecurityUtils.SERVER_IDENTITY_KEY); + if (!bundleSecurity.bundleServerIdMatchesCurrentServer(serverIdReceived)){ + logger.log(Level.WARNING, "Received bundle's serverIdentity didn't match with current server, " + + "ignoring bundle with bundleId: " + uncompressedBundle.getBundleId()); + return; + } + clientId = SecurityUtils.generateID( uncompressedBundle.getSource() + File.separator + SecurityUtils.CLIENT_IDENTITY_KEY); Optional opt = this.applicationDataManager.getLargestRecvdBundleId(clientId); From 62608832a5ae9aefa0b1705bc5a8437f7e9ff1db Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 5 Jun 2024 21:57:30 +0000 Subject: [PATCH 9/9] Auto-format code --- .../com/ddd/server/bundletransmission/BundleTransmission.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java b/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java index df28519e11..9d924950eb 100644 --- a/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java +++ b/bundleserver/src/main/java/com/ddd/server/bundletransmission/BundleTransmission.java @@ -86,7 +86,7 @@ public void processReceivedBundle(String transportId, Bundle bundle) throws Exce String serverIdReceived = SecurityUtils.generateID( uncompressedBundle.getSource() + File.separator + SecurityUtils.SERVER_IDENTITY_KEY); - if (!bundleSecurity.bundleServerIdMatchesCurrentServer(serverIdReceived)){ + if (!bundleSecurity.bundleServerIdMatchesCurrentServer(serverIdReceived)) { logger.log(Level.WARNING, "Received bundle's serverIdentity didn't match with current server, " + "ignoring bundle with bundleId: " + uncompressedBundle.getBundleId()); return;