Skip to content

Commit

Permalink
ASAPPeer gets it keystore from outside now... Needed to use cryptogra…
Browse files Browse the repository at this point in the history
…phy on Android.
  • Loading branch information
thsc42 committed Sep 18, 2024
1 parent 39e9285 commit 0a8e1d6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/main/java/net/sharksystem/asap/ASAPPeer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.sharksystem.asap;

import net.sharksystem.SharkException;
import net.sharksystem.asap.crypto.ASAPKeyStore;
import net.sharksystem.fs.ExtraData;

import java.io.IOException;
Expand All @@ -18,6 +19,19 @@ public interface ASAPPeer extends

ASAPStorage getASAPStorage(CharSequence format) throws IOException, ASAPException;

/**
* Provide an ASAP keystore to the peer. Now, point-to-point encryption is possible.
* @param asapKeyStore
*/
void setASAPKeyStore(ASAPKeyStore asapKeyStore);

/**
* Get ASAP keystore. Throws an exception if not set
* @return ASAP keystore
* @throws ASAPException if no keystore present
*/
ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException;

/**
* ASAP peer are both: application host and potential router. Routing can be switched on or off.
* We tend to label this behaviour with different ages (stone. bronze, internet), see discussion there.
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/net/sharksystem/asap/ASAPPeerFS.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package net.sharksystem.asap;

import net.sharksystem.SharkException;
import net.sharksystem.asap.crypto.ASAPKeyStore;
import net.sharksystem.asap.engine.*;
import net.sharksystem.asap.utils.ASAPLogHelper;
import net.sharksystem.fs.ExtraData;
import net.sharksystem.utils.Log;

import javax.swing.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -162,6 +162,17 @@ public String toString() {
return this.getInternalPeer().getOwner().toString();
}

@Override
public void setASAPKeyStore(ASAPKeyStore asapKeyStore) {
this.getInternalPeer().setASAPKeyStore(asapKeyStore);
}

public ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException {
ASAPKeyStore keyStore = this.getInternalPeer().getASAPKeyStore();
if(keyStore == null) throw new ASAPSecurityException("no keystore set");
return keyStore;
}

@Override
public ExtraData getExtraData() throws SharkException, IOException {
return this.getInternalPeer().getExtraData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence urlTarget
void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence urlTarget, int era, byte[] messageAsBytes)
throws IOException, ASAPException;

void setASAPBasicKeyStorage(ASAPKeyStore ASAPKeyStore);
void setASAPKeyStore(ASAPKeyStore ASAPKeyStore);
ASAPKeyStore getASAPKeyStore();

ASAPCommunicationSetting getASAPCommunicationControl();

ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException;
ASAPKeyStore getAsapKeyStore() throws ASAPSecurityException;

ExtraData getExtraData() throws SharkException, IOException;

void setSecurityAdministrator(DefaultSecurityAdministrator securityAdministrator);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ASAPInternalPeerFS implements
private CharSequence owner;
private HashMap<CharSequence, EngineSetting> folderMap;
private final long maxExecutionTime;
private ASAPKeyStore ASAPKeyStore;
private ASAPKeyStore asapKeyStore;
private DefaultSecurityAdministrator defaultSecurityAdministrator = new DefaultSecurityAdministrator();
private InMemoASAPKeyStore inMemoASAPKeyStore;

Expand Down Expand Up @@ -348,7 +348,7 @@ public ASAPConnection handleConnection(
// TODO add white / black list.
ASAPSessionImpl asapConnection = new ASAPSessionImpl(
is, os, this, new ASAP_Modem_Impl(),
this, this.ASAPKeyStore,
this, this.asapKeyStore,
maxExecutionTime, this, this, encrypt, sign, connectionType);

StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -604,8 +604,12 @@ public void deactivateOnlineMessages() {


@Override
public void setASAPBasicKeyStorage(ASAPKeyStore ASAPKeyStore) {
this.ASAPKeyStore = ASAPKeyStore;
public void setASAPKeyStore(ASAPKeyStore asapKeyStore) {
this.asapKeyStore = asapKeyStore;
}

public ASAPKeyStore getASAPKeyStore() {
return this.asapKeyStore;
}

public void sendTransientASAPAssimilateMessage(CharSequence format, CharSequence uri, byte[] messageAsBytes)
Expand Down Expand Up @@ -688,7 +692,7 @@ public void handleUndecryptableMessage(

///////////////////////////////// SharkNet
@Override
public ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException {
public ASAPKeyStore getAsapKeyStore() throws ASAPSecurityException {
if(this.inMemoASAPKeyStore == null) {
this.inMemoASAPKeyStore = new InMemoASAPKeyStore(this.getOwner().toString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/sharksystem/asap/engine/Workbench.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void routeEncryptedMessage() throws IOException, ASAPException, Interrupt
String aliceFolder = WORKING_SUB_DIRECTORY + ALICE_PEER_NAME;
ExampleASAPChunkReceivedListener aliceChunkListener = new ExampleASAPChunkReceivedListener(aliceFolder);
ASAPInternalPeer alicePeer = ASAPInternalPeerFS.createASAPPeer(ALICE_PEER_NAME, aliceFolder, aliceChunkListener);
alicePeer.setASAPBasicKeyStorage(keyStorageAlice); // set keystore
alicePeer.setASAPKeyStore(keyStorageAlice); // set keystore
alicePeer.getASAPCommunicationControl().setSendEncryptedMessages(true); // send encrypted messages
ASAPEngine aliceChatEngine = alicePeer.createEngineByFormat(APPNAME); // create engine

Expand Down

0 comments on commit 0a8e1d6

Please sign in to comment.