Skip to content

Commit 0a8e1d6

Browse files
committed
ASAPPeer gets it keystore from outside now... Needed to use cryptography on Android.
1 parent 39e9285 commit 0a8e1d6

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

src/main/java/net/sharksystem/asap/ASAPPeer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.sharksystem.asap;
22

33
import net.sharksystem.SharkException;
4+
import net.sharksystem.asap.crypto.ASAPKeyStore;
45
import net.sharksystem.fs.ExtraData;
56

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

1920
ASAPStorage getASAPStorage(CharSequence format) throws IOException, ASAPException;
2021

22+
/**
23+
* Provide an ASAP keystore to the peer. Now, point-to-point encryption is possible.
24+
* @param asapKeyStore
25+
*/
26+
void setASAPKeyStore(ASAPKeyStore asapKeyStore);
27+
28+
/**
29+
* Get ASAP keystore. Throws an exception if not set
30+
* @return ASAP keystore
31+
* @throws ASAPException if no keystore present
32+
*/
33+
ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException;
34+
2135
/**
2236
* ASAP peer are both: application host and potential router. Routing can be switched on or off.
2337
* We tend to label this behaviour with different ages (stone. bronze, internet), see discussion there.

src/main/java/net/sharksystem/asap/ASAPPeerFS.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package net.sharksystem.asap;
22

33
import net.sharksystem.SharkException;
4+
import net.sharksystem.asap.crypto.ASAPKeyStore;
45
import net.sharksystem.asap.engine.*;
56
import net.sharksystem.asap.utils.ASAPLogHelper;
67
import net.sharksystem.fs.ExtraData;
78
import net.sharksystem.utils.Log;
89

9-
import javax.swing.*;
1010
import java.io.IOException;
1111
import java.util.ArrayList;
1212
import java.util.Collection;
@@ -162,6 +162,17 @@ public String toString() {
162162
return this.getInternalPeer().getOwner().toString();
163163
}
164164

165+
@Override
166+
public void setASAPKeyStore(ASAPKeyStore asapKeyStore) {
167+
this.getInternalPeer().setASAPKeyStore(asapKeyStore);
168+
}
169+
170+
public ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException {
171+
ASAPKeyStore keyStore = this.getInternalPeer().getASAPKeyStore();
172+
if(keyStore == null) throw new ASAPSecurityException("no keystore set");
173+
return keyStore;
174+
}
175+
165176
@Override
166177
public ExtraData getExtraData() throws SharkException, IOException {
167178
return this.getInternalPeer().getExtraData();

src/main/java/net/sharksystem/asap/engine/ASAPInternalPeer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence urlTarget
150150
void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence urlTarget, int era, byte[] messageAsBytes)
151151
throws IOException, ASAPException;
152152

153-
void setASAPBasicKeyStorage(ASAPKeyStore ASAPKeyStore);
153+
void setASAPKeyStore(ASAPKeyStore ASAPKeyStore);
154+
ASAPKeyStore getASAPKeyStore();
154155

155156
ASAPCommunicationSetting getASAPCommunicationControl();
156157

157-
ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException;
158+
ASAPKeyStore getAsapKeyStore() throws ASAPSecurityException;
158159

159160
ExtraData getExtraData() throws SharkException, IOException;
160161

161162
void setSecurityAdministrator(DefaultSecurityAdministrator securityAdministrator);
163+
162164
}

src/main/java/net/sharksystem/asap/engine/ASAPInternalPeerFS.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ASAPInternalPeerFS implements
2424
private CharSequence owner;
2525
private HashMap<CharSequence, EngineSetting> folderMap;
2626
private final long maxExecutionTime;
27-
private ASAPKeyStore ASAPKeyStore;
27+
private ASAPKeyStore asapKeyStore;
2828
private DefaultSecurityAdministrator defaultSecurityAdministrator = new DefaultSecurityAdministrator();
2929
private InMemoASAPKeyStore inMemoASAPKeyStore;
3030

@@ -348,7 +348,7 @@ public ASAPConnection handleConnection(
348348
// TODO add white / black list.
349349
ASAPSessionImpl asapConnection = new ASAPSessionImpl(
350350
is, os, this, new ASAP_Modem_Impl(),
351-
this, this.ASAPKeyStore,
351+
this, this.asapKeyStore,
352352
maxExecutionTime, this, this, encrypt, sign, connectionType);
353353

354354
StringBuilder sb = new StringBuilder();
@@ -604,8 +604,12 @@ public void deactivateOnlineMessages() {
604604

605605

606606
@Override
607-
public void setASAPBasicKeyStorage(ASAPKeyStore ASAPKeyStore) {
608-
this.ASAPKeyStore = ASAPKeyStore;
607+
public void setASAPKeyStore(ASAPKeyStore asapKeyStore) {
608+
this.asapKeyStore = asapKeyStore;
609+
}
610+
611+
public ASAPKeyStore getASAPKeyStore() {
612+
return this.asapKeyStore;
609613
}
610614

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

689693
///////////////////////////////// SharkNet
690694
@Override
691-
public ASAPKeyStore getASAPKeyStore() throws ASAPSecurityException {
695+
public ASAPKeyStore getAsapKeyStore() throws ASAPSecurityException {
692696
if(this.inMemoASAPKeyStore == null) {
693697
this.inMemoASAPKeyStore = new InMemoASAPKeyStore(this.getOwner().toString());
694698
}

src/test/java/net/sharksystem/asap/engine/Workbench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void routeEncryptedMessage() throws IOException, ASAPException, Interrupt
115115
String aliceFolder = WORKING_SUB_DIRECTORY + ALICE_PEER_NAME;
116116
ExampleASAPChunkReceivedListener aliceChunkListener = new ExampleASAPChunkReceivedListener(aliceFolder);
117117
ASAPInternalPeer alicePeer = ASAPInternalPeerFS.createASAPPeer(ALICE_PEER_NAME, aliceFolder, aliceChunkListener);
118-
alicePeer.setASAPBasicKeyStorage(keyStorageAlice); // set keystore
118+
alicePeer.setASAPKeyStore(keyStorageAlice); // set keystore
119119
alicePeer.getASAPCommunicationControl().setSendEncryptedMessages(true); // send encrypted messages
120120
ASAPEngine aliceChatEngine = alicePeer.createEngineByFormat(APPNAME); // create engine
121121

0 commit comments

Comments
 (0)