Skip to content

Commit

Permalink
added server_identity key in client bundle, refactored EncryptionHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
triptighanghas committed Jun 5, 2024
1 parent 3ec4b47 commit 0b74abd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 52 deletions.
2 changes: 1 addition & 1 deletion BundleClient/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()]);
}

Expand Down
7 changes: 6 additions & 1 deletion bundle-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.ddd</groupId>
<artifactId>bundle-core</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand All @@ -20,6 +20,11 @@
<artifactId>picocli</artifactId>
<version>4.7.5</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
</dependency>

</dependencies>
</project>
43 changes: 7 additions & 36 deletions bundle-core/src/main/java/com/ddd/model/EncryptionHeader.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion bundleserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<dependency>
<groupId>com.ddd</groupId>
<artifactId>bundle-core</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]));

Expand Down

0 comments on commit 0b74abd

Please sign in to comment.