Skip to content

Commit 771e8ef

Browse files
committed
Prepare SharkNetMessage to be used in SN2 Android App
1 parent 62f9ebc commit 771e8ef

File tree

12 files changed

+113
-106
lines changed

12 files changed

+113
-106
lines changed

src/net/sharksystem/asap/ASAPPeer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package net.sharksystem.asap;
22

33
import net.sharksystem.asap.protocol.*;
4-
import net.sharksystem.asap.sharknet.SharkNetMessageListener;
5-
import net.sharksystem.crypto.BasicCryptoParameters;
4+
import net.sharksystem.crypto.BasicKeyStore;
65

76
import java.io.IOException;
8-
import java.io.InputStream;
97
import java.io.OutputStream;
108
import java.util.Set;
119

@@ -104,11 +102,11 @@ void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence urlTarget
104102
void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence urlTarget, byte[] messageAsBytes)
105103
throws IOException, ASAPException;
106104

107-
void setASAPBasicKeyStorage(BasicCryptoParameters basicCryptoParameters);
105+
void setASAPBasicKeyStorage(BasicKeyStore basicKeyStore);
108106

109107
ASAPCommunicationSetting getASAPCommunicationControl();
110108

111-
BasicCryptoParameters getBasicCryptoParameters() throws ASAPSecurityException;
109+
BasicKeyStore getBasicCryptoParameters() throws ASAPSecurityException;
112110

113111
void setSecurityAdministrator(DefaultSecurityAdministrator securityAdministrator);
114112
}

src/net/sharksystem/asap/ASAPPeerFS.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import net.sharksystem.Utils;
44
import net.sharksystem.asap.management.ASAPManagementMessageHandler;
55
import net.sharksystem.asap.protocol.*;
6-
import net.sharksystem.asap.sharknet.SharkNet;
7-
import net.sharksystem.asap.sharknet.SharkNetMessageListener;
86
import net.sharksystem.asap.util.Helper;
97
import net.sharksystem.asap.util.Log;
108
import net.sharksystem.crypto.ASAPCryptoAlgorithms;
119
import net.sharksystem.crypto.BasicCryptoKeyStorage;
12-
import net.sharksystem.crypto.BasicCryptoParameters;
10+
import net.sharksystem.crypto.BasicKeyStore;
1311
import net.sharksystem.crypto.ASAPCommunicationCryptoSettings;
1412

1513
import java.io.*;
@@ -24,7 +22,7 @@ public class ASAPPeerFS implements
2422
private CharSequence owner;
2523
private HashMap<CharSequence, EngineSetting> folderMap;
2624
private final long maxExecutionTime;
27-
private BasicCryptoParameters basicCryptoParameters;
25+
private BasicKeyStore basicKeyStore;
2826
private DefaultSecurityAdministrator defaultSecurityAdministrator = new DefaultSecurityAdministrator();
2927
private BasicCryptoKeyStorage basicCryptoKeyStorage;
3028

@@ -298,7 +296,7 @@ public Set<CharSequence> getFormats() {
298296
public ASAPConnection handleConnection(InputStream is, OutputStream os) {
299297
ASAPPersistentConnection asapConnection = new ASAPPersistentConnection(
300298
is, os, this, new ASAP_Modem_Impl(),
301-
this, this.basicCryptoParameters,
299+
this, this.basicKeyStore,
302300
maxExecutionTime, this, this);
303301

304302
StringBuilder sb = new StringBuilder();
@@ -560,8 +558,8 @@ public void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence ur
560558
}
561559

562560
@Override
563-
public void setASAPBasicKeyStorage(BasicCryptoParameters basicCryptoParameters) {
564-
this.basicCryptoParameters = basicCryptoParameters;
561+
public void setASAPBasicKeyStorage(BasicKeyStore basicKeyStore) {
562+
this.basicKeyStore = basicKeyStore;
565563
}
566564

567565
public void sendOnlineASAPAssimilateMessage(CharSequence format, CharSequence urlTarget,
@@ -620,7 +618,7 @@ public void handleUndecryptableMessage(
620618

621619
///////////////////////////////// SharkNet
622620
@Override
623-
public BasicCryptoParameters getBasicCryptoParameters() throws ASAPSecurityException {
621+
public BasicKeyStore getBasicCryptoParameters() throws ASAPSecurityException {
624622
if(this.basicCryptoKeyStorage == null) {
625623
this.basicCryptoKeyStorage = new BasicCryptoKeyStorage(this.getOwner().toString());
626624
}

src/net/sharksystem/asap/protocol/ASAPCryptoMessage.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import net.sharksystem.asap.ASAPException;
44
import net.sharksystem.asap.ASAPSecurityException;
5-
import net.sharksystem.crypto.BasicCryptoParameters;
5+
import net.sharksystem.crypto.BasicKeyStore;
66
import net.sharksystem.crypto.ASAPCryptoAlgorithms;
77
import net.sharksystem.utils.ASAPSerialization;
88

@@ -12,7 +12,7 @@ class ASAPCryptoMessage {
1212
private boolean encrypted;
1313
private boolean sign;
1414
private CharSequence recipient;
15-
private BasicCryptoParameters basicCryptoParameters;
15+
private BasicKeyStore basicKeyStore;
1616
private byte cmd;
1717

1818
private OutputStream effectiveOS;
@@ -21,26 +21,26 @@ class ASAPCryptoMessage {
2121
private InputStreamCopy inputStreamCopy;
2222
private ASAPCryptoAlgorithms.EncryptedMessagePackage encryptedMessagePackage;
2323

24-
ASAPCryptoMessage(BasicCryptoParameters basicCryptoParameters) {
25-
this.basicCryptoParameters = basicCryptoParameters;
24+
ASAPCryptoMessage(BasicKeyStore basicKeyStore) {
25+
this.basicKeyStore = basicKeyStore;
2626
}
2727

2828
ASAPCryptoMessage(byte cmd, OutputStream os, boolean sign, boolean encrypted,
2929
CharSequence recipient,
30-
BasicCryptoParameters basicCryptoParameters)
30+
BasicKeyStore basicKeyStore)
3131
throws ASAPSecurityException {
3232

3333
this.cmd = cmd;
3434
this.realOS = os;
3535
this.effectiveOS = os; // still this one
36-
this.basicCryptoParameters = basicCryptoParameters;
36+
this.basicKeyStore = basicKeyStore;
3737
this.recipient = recipient;
3838
this.encrypted = encrypted;
3939
this.sign = sign;
4040

4141
if(encrypted || sign) {
4242
// we need some basic crypto parameters
43-
if(basicCryptoParameters == null) {
43+
if(basicKeyStore == null) {
4444
throw new ASAPSecurityException("cannot encrypt or sign without cryptp parameters / key store");
4545
}
4646
this.setupCopyOutputStream();
@@ -56,7 +56,7 @@ class ASAPCryptoMessage {
5656

5757
if(sign) {
5858
// signing needs a private key - check of available
59-
if(basicCryptoParameters.getPrivateKey() == null) {
59+
if(basicKeyStore.getPrivateKey() == null) {
6060
throw new ASAPSecurityException("asap message is to be signed but no private key - fatal, give up");
6161
}
6262
}
@@ -85,7 +85,7 @@ public void finish() throws ASAPSecurityException {
8585
// get message as bytes
8686
byte[] asapMessageAsBytes = this.outputStreamCopy.toByteArray();
8787
// produce signature
88-
byte[] signatureBytes = ASAPCryptoAlgorithms.sign(asapMessageAsBytes, this.basicCryptoParameters);
88+
byte[] signatureBytes = ASAPCryptoAlgorithms.sign(asapMessageAsBytes, this.basicKeyStore);
8989

9090
if(this.encrypted) {
9191
// have to store it - message and signature will be encrypted
@@ -105,7 +105,7 @@ public void finish() throws ASAPSecurityException {
105105
byte[] asapMessageAsBytes = this.outputStreamCopy.toByteArray();
106106

107107
ASAPCryptoAlgorithms.writeEncryptedMessagePackage(
108-
asapMessageAsBytes, this.recipient, this.basicCryptoParameters, this.realOS);
108+
asapMessageAsBytes, this.recipient, this.basicKeyStore, this.realOS);
109109
}
110110
}
111111

@@ -159,7 +159,7 @@ public boolean verify(String sender, InputStream is) throws IOException, ASAPExc
159159
byte[] signatureBytes = ASAPSerialization.readByteArray(is);
160160
// debug break
161161
boolean wasVerified =
162-
ASAPCryptoAlgorithms.verify(signedData, signatureBytes, sender, this.basicCryptoParameters);
162+
ASAPCryptoAlgorithms.verify(signedData, signatureBytes, sender, this.basicKeyStore);
163163

164164
return wasVerified;
165165
}
@@ -185,12 +185,12 @@ public boolean initDecryption(byte cmd, InputStream is) throws IOException, ASAP
185185
ASAPCryptoAlgorithms.parseEncryptedMessagePackage(is);
186186
// ASAPCryptoAlgorithms.parseEncryptedMessagePackage(copyStream);
187187

188-
if(this.basicCryptoParameters == null) {
188+
if(this.basicKeyStore == null) {
189189
System.out.println(this.getLogStart() + "no keystore set: cannot handle encrypted messages");
190190
return false;
191191
}
192192

193-
if(this.basicCryptoParameters.isOwner(this.encryptedMessagePackage.getRecipient())) {
193+
if(this.basicKeyStore.isOwner(this.encryptedMessagePackage.getRecipient())) {
194194
return true;
195195
}
196196

@@ -215,7 +215,7 @@ public InputStream doDecryption() throws ASAPSecurityException {
215215
}
216216

217217
byte[] decryptedBytes =
218-
ASAPCryptoAlgorithms.decryptPackage(this.encryptedMessagePackage, this.basicCryptoParameters);
218+
ASAPCryptoAlgorithms.decryptPackage(this.encryptedMessagePackage, this.basicKeyStore);
219219

220220
return new ByteArrayInputStream(decryptedBytes);
221221
}

src/net/sharksystem/asap/protocol/ASAPPersistentConnection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import net.sharksystem.asap.*;
44
import net.sharksystem.asap.util.Log;
5-
import net.sharksystem.crypto.BasicCryptoParameters;
5+
import net.sharksystem.crypto.BasicKeyStore;
66

77
import java.io.IOException;
88
import java.io.InputStream;
@@ -26,11 +26,11 @@ public class ASAPPersistentConnection extends ASAPProtocolEngine
2626

2727
public ASAPPersistentConnection(InputStream is, OutputStream os, ASAPPeer asapPeer,
2828
ASAP_1_0 protocol, ASAPUndecryptableMessageHandler unencryptableMessageHandler,
29-
BasicCryptoParameters basicCryptoParameters,
29+
BasicKeyStore basicKeyStore,
3030
long maxExecutionTime, ASAPConnectionListener asapConnectionListener,
3131
ThreadFinishedListener threadFinishedListener) {
3232

33-
super(is, os, protocol, unencryptableMessageHandler, basicCryptoParameters);
33+
super(is, os, protocol, unencryptableMessageHandler, basicKeyStore);
3434

3535
this.asapPeer = asapPeer;
3636
this.maxExecutionTime = maxExecutionTime;
@@ -176,7 +176,7 @@ private synchronized void checkRunningOnlineMessageSender() {
176176
}
177177

178178
public void run() {
179-
ASAP_1_0 protocol = new ASAP_Modem_Impl(this.basicCryptoParameters, this.undecryptableMessageHandler);
179+
ASAP_1_0 protocol = new ASAP_Modem_Impl(this.basicKeyStore, this.undecryptableMessageHandler);
180180

181181
try {
182182
// let engine write their interest - at least management interest is sent which als introduces

src/net/sharksystem/asap/protocol/ASAPProtocolEngine.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import net.sharksystem.asap.ASAPException;
44
import net.sharksystem.asap.ASAPUndecryptableMessageHandler;
5-
import net.sharksystem.crypto.BasicCryptoParameters;
5+
import net.sharksystem.crypto.BasicKeyStore;
66

77
import java.io.IOException;
88
import java.io.InputStream;
@@ -15,16 +15,16 @@ public abstract class ASAPProtocolEngine {
1515
protected final InputStream is;
1616
protected final OutputStream os;
1717
protected final ASAPUndecryptableMessageHandler undecryptableMessageHandler;
18-
protected final BasicCryptoParameters basicCryptoParameters;
18+
protected final BasicKeyStore basicKeyStore;
1919

2020
public ASAPProtocolEngine(InputStream is, OutputStream os, ASAP_1_0 protocol,
2121
ASAPUndecryptableMessageHandler undecryptableMessageHandler,
22-
BasicCryptoParameters basicCryptoParameters) {
22+
BasicKeyStore basicKeyStore) {
2323
this.is = is;
2424
this.os = os;
2525
this.protocol = protocol;
2626
this.undecryptableMessageHandler = undecryptableMessageHandler;
27-
this.basicCryptoParameters = basicCryptoParameters;
27+
this.basicKeyStore = basicKeyStore;
2828
}
2929

3030
/**

src/net/sharksystem/asap/protocol/ASAP_Modem_Impl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import net.sharksystem.asap.ASAPSecurityException;
55
import net.sharksystem.asap.ASAPUndecryptableMessageHandler;
66
import net.sharksystem.crypto.ASAPCryptoAlgorithms;
7-
import net.sharksystem.crypto.BasicCryptoParameters;
7+
import net.sharksystem.crypto.BasicKeyStore;
88
import net.sharksystem.crypto.ASAPCommunicationCryptoSettings;
99
import net.sharksystem.utils.ASAPSerialization;
1010

@@ -15,7 +15,7 @@
1515
import java.util.List;
1616

1717
public class ASAP_Modem_Impl implements ASAP_1_0 {
18-
private final BasicCryptoParameters signAndEncryptionKeyStorage;
18+
private final BasicKeyStore signAndEncryptionKeyStorage;
1919
private final ASAPUndecryptableMessageHandler unencryptableMessageHandler;
2020

2121
public ASAP_Modem_Impl() {
@@ -26,11 +26,11 @@ public ASAP_Modem_Impl(ASAPUndecryptableMessageHandler unencryptableMessageHandl
2626
this(null, unencryptableMessageHandler);
2727
}
2828

29-
public ASAP_Modem_Impl(BasicCryptoParameters signAndEncryptionKeyStorage) {
29+
public ASAP_Modem_Impl(BasicKeyStore signAndEncryptionKeyStorage) {
3030
this(signAndEncryptionKeyStorage, null);
3131
}
3232

33-
public ASAP_Modem_Impl(BasicCryptoParameters signAndEncryptionKeyStorage,
33+
public ASAP_Modem_Impl(BasicKeyStore signAndEncryptionKeyStorage,
3434
ASAPUndecryptableMessageHandler unencryptableMessageHandler) {
3535
this.signAndEncryptionKeyStorage = signAndEncryptionKeyStorage;
3636
this.unencryptableMessageHandler = unencryptableMessageHandler;
@@ -194,7 +194,7 @@ public ASAP_PDU_1_0 readPDU(InputStream is) throws IOException, ASAPException {
194194
System.out.println(this.getLogStart() + "no handler for unencryptable messages found");
195195
}
196196
// throw exception anyway - could not create PDU
197-
throw new ASAPSecurityException("encryptable message received");
197+
throw new ASAPSecurityException("unencryptable message received");
198198
}
199199
}
200200

0 commit comments

Comments
 (0)