Skip to content

Commit cdaaf2a

Browse files
committed
ready to start debugging sn channels - towards a working version
1 parent a1947c1 commit cdaaf2a

File tree

16 files changed

+180
-44
lines changed

16 files changed

+180
-44
lines changed
0 Bytes
Binary file not shown.

.idea/render.experimental.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
230 Bytes
Binary file not shown.

app/libs/ASAPCertificate_0.1.0.jar

22 Bytes
Binary file not shown.

app/src/main/java/net/sharksystem/asap/sharknet/android/SNChannelAddMessageActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import net.sharksystem.android.ASAPChannelIntent;
1313
import net.sharksystem.asap.ASAPException;
1414
import net.sharksystem.asap.sharknet.InMemoSNMessage;
15-
import net.sharksystem.asap.sharknet.SNMessage;
1615
import net.sharksystem.crypto.BasicKeyStore;
1716

1817
import java.io.IOException;
@@ -63,7 +62,7 @@ public void onAddClick(View view) {
6362
CharSequence sender =
6463
SNChannelsComponent.getSharkNetChannelComponent().getOwnerID();
6564
Set<CharSequence> recipients = new HashSet<>();
66-
recipients.add("Alice"); // TODO must come from GUI
65+
recipients.add(sender); // TODO must come from GUI
6766
boolean sign = true; // TODO must come from GUI
6867
boolean encrypt = true; // TODO must come from GUI
6968
BasicKeyStore basicKeyStore =
@@ -80,7 +79,7 @@ public void onAddClick(View view) {
8079
serializedMessage, true);
8180

8281
} catch (ASAPException | IOException e) {
83-
Log.d(this.getLogStart(), "problems when sending makan message: "
82+
Log.d(this.getLogStart(), "problems when sending message in SNChannel: "
8483
+ e.getLocalizedMessage());
8584
}
8685
}

app/src/main/java/net/sharksystem/asap/sharknet/android/SNChannelViewContentAdapter.java

Lines changed: 88 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
import net.sharksystem.R;
1212
import net.sharksystem.asap.ASAPChannel;
1313
import net.sharksystem.asap.ASAPException;
14+
import net.sharksystem.asap.ASAPSecurityException;
1415
import net.sharksystem.asap.sharknet.InMemoSNMessage;
1516
import net.sharksystem.asap.sharknet.SNMessage;
17+
import net.sharksystem.asap.util.DateTimeHelper;
1618
import net.sharksystem.crypto.BasicKeyStore;
1719
import net.sharksystem.makan.Makan;
1820
import net.sharksystem.makan.android.MakanApp;
1921

2022
import java.io.IOException;
23+
import java.sql.Timestamp;
2124
import java.text.DateFormat;
25+
import java.util.Set;
2226

2327
public class SNChannelViewContentAdapter extends
2428
RecyclerView.Adapter<SNChannelViewContentAdapter.MyViewHolder> {
@@ -45,13 +49,21 @@ public SNChannelViewContentAdapter.MyViewHolder onCreateViewHolder(
4549
}
4650

4751
public class MyViewHolder extends RecyclerView.ViewHolder {
52+
private final TextView encryptedTextView;
53+
private final TextView verifiedTextView;
54+
private final TextView identityAssuranceTextView;
55+
private final TextView recipientsTextView;
4856
public TextView dateTextView, messageTextView, senderTextView;
4957

5058
public MyViewHolder(View view) {
5159
super(view);
5260
dateTextView = (TextView) view.findViewById(R.id.sn_channel_message_row_date);
5361
messageTextView = (TextView) view.findViewById(R.id.sn_channel_message_row_message);
5462
senderTextView = (TextView) view.findViewById(R.id.sn_channel_message_row_sender);
63+
encryptedTextView = (TextView) view.findViewById(R.id.sn_channel_message_row_encrypted);
64+
verifiedTextView = (TextView) view.findViewById(R.id.sn_channel_message_row_verified);
65+
identityAssuranceTextView = (TextView) view.findViewById(R.id.sn_channel_message_row_identityassurance);
66+
recipientsTextView = (TextView) view.findViewById(R.id.sn_channel_message_row_recipients);
5567
}
5668
}
5769

@@ -75,32 +87,85 @@ public void onBindViewHolder(SNChannelViewContentAdapter.MyViewHolder holder, in
7587
public static SharkNetMessage parseMessage(byte[] message, String sender, String uri,
7688
CharSequence ownerID, BasicKeyStore basicKeyStore) throws IOException, ASAPException {
7789
*/
78-
CharSequence sender;
7990
BasicKeyStore basicKeyStore =
8091
SNChannelsComponent.getSharkNetChannelComponent().getBasicKeyStore();
8192

82-
SNMessage snMessage =
83-
InMemoSNMessage.parseMessage(asapMessage, basicKeyStore);
84-
85-
// produce SNMessage
86-
String date = "dummy Date";
87-
String content = "dummy message";
88-
sender = "dummy Sender";
89-
90-
holder.dateTextView.setText(date);
91-
/*
92-
holder.dateTextView.setText(
93-
DateFormat.getInstance().format(message.getSentDate()));
94-
*/
95-
96-
holder.messageTextView.setText(content);
97-
holder.senderTextView.setText(sender);
98-
99-
/*
100-
holder.messageTextView.setText(message.getContentAsString());
101-
holder.senderTextView.setText(PersonsStorageAndroidComponent.
102-
getPersonsStorage().getPersonName(message.getSenderID()));
103-
*/
93+
SNMessage snMessage = null;
94+
try {
95+
snMessage = InMemoSNMessage.parseMessage(asapMessage, basicKeyStore);
96+
}
97+
catch(ASAPSecurityException e) {
98+
// could not be parsed
99+
Log.d(LOGSTART, "could not parse SNMessage " + position);
100+
return;
101+
}
102+
103+
CharSequence recipients2View;
104+
105+
Set<CharSequence> recipients = snMessage.getRecipients();
106+
if(recipients == null || recipients.isEmpty()) {
107+
recipients2View = "anybody";
108+
} else {
109+
StringBuilder sb = new StringBuilder();
110+
111+
boolean firstRound = true;
112+
for (CharSequence recipientID : recipients) {
113+
if (firstRound) {
114+
firstRound = false;
115+
sb.append("to: ");
116+
} else {
117+
sb.append("|");
118+
}
119+
120+
CharSequence recipientName = null;
121+
try {
122+
sb.append(SNChannelsComponent.getSharkNetChannelComponent().
123+
getPersonName(recipientID));
124+
}
125+
catch(ASAPException e) {
126+
// no name found
127+
sb.append(recipientID);
128+
}
129+
}
130+
131+
recipients2View = sb.toString();
132+
}
133+
134+
CharSequence encrypted2View = "E2E encrypted: no";
135+
if(snMessage.encrypted()) {
136+
encrypted2View = "E2E encrypted: yes";
137+
}
138+
139+
// assume defaults at first
140+
CharSequence sender2View = "from: unknown";
141+
CharSequence content2View = "decrypted message";
142+
CharSequence verified2View = "verified: no";
143+
CharSequence timestamp2View = "time: unknown";
144+
CharSequence iA2View = "iA: unknown";
145+
146+
147+
// do we have an decrypted message?
148+
if(snMessage.couldBeDecrypted()) {
149+
byte[] snContent = snMessage.getContent();
150+
content2View = String.valueOf(snMessage);
151+
152+
Timestamp creationTime = snMessage.getCreationTime();
153+
timestamp2View = DateTimeHelper.long2DateString(creationTime.getTime());
154+
155+
sender2View = "from: " + snMessage.getSender();
156+
157+
if(snMessage.verified()) {
158+
verified2View = "verified";
159+
}
160+
}
161+
162+
holder.dateTextView.setText(timestamp2View);
163+
holder.messageTextView.setText(content2View);
164+
holder.senderTextView.setText(sender2View);
165+
holder.encryptedTextView.setText(encrypted2View);
166+
holder.verifiedTextView.setText(verified2View);
167+
holder.identityAssuranceTextView.setText(iA2View);
168+
holder.recipientsTextView.setText(recipients2View);
104169

105170
} catch (Throwable e) {
106171
Log.e(LOGSTART, "cannot access message storage (yet?)");

app/src/main/java/net/sharksystem/asap/sharknet/android/SNChannelsComponent.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.util.Log;
66

77
import net.sharksystem.asap.ASAPChannel;
8-
import net.sharksystem.asap.ASAPChunkReceivedListener;
98
import net.sharksystem.asap.ASAPException;
109
import net.sharksystem.asap.ASAPMessages;
1110
import net.sharksystem.asap.ASAPStorage;
@@ -15,41 +14,49 @@
1514
import net.sharksystem.asap.android.apps.ASAPComponentNotYetInitializedException;
1615
import net.sharksystem.asap.android.apps.ASAPMessageReceivedListener;
1716
import net.sharksystem.crypto.BasicKeyStore;
17+
import net.sharksystem.sharknet.android.PersonsStorage;
1818
import net.sharksystem.sharknet.android.OwnerFactory;
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
2222
import java.util.Collection;
2323

24-
public class SNChannelsComponent implements ASAPApplicationComponent, ASAPMessageReceivedListener {
24+
public class SNChannelsComponent implements
25+
ASAPApplicationComponent, ASAPMessageReceivedListener, PersonsStorage {
2526
public static final CharSequence APP_NAME = "SharkNet";
2627
private static final String KEY_NAME_SN_CHANNEL_NAME = "snChannelName";
2728
private static SNChannelsComponent instance;
2829
private final ASAPApplicationComponentHelper asapComponentHelper;
2930
private final BasicKeyStore basicKeyStore;
3031
private final OwnerFactory ownerFactory;
32+
private final PersonsStorage personsStorage;
3133

3234
public SNChannelsComponent(ASAPApplication asapApplication,
33-
BasicKeyStore basicKeyStore, OwnerFactory ownerFactory) {
35+
BasicKeyStore basicKeyStore, OwnerFactory ownerFactory,
36+
PersonsStorage personsStorage) {
3437

3538
// set up component helper
3639
this.asapComponentHelper = new ASAPApplicationComponentHelper();
3740
this.asapComponentHelper.setASAPApplication(asapApplication);
3841
this.basicKeyStore = basicKeyStore;
3942
this.ownerFactory = ownerFactory;
43+
this.personsStorage = personsStorage;
4044
}
4145

4246
/**
4347
* Is to be called during system setup from overall ASAPApplication
4448
* @param asapApplication
4549
*/
4650
public static void initialize(ASAPApplication asapApplication,
47-
BasicKeyStore basicKeyStore, OwnerFactory ownerFactory) {
51+
BasicKeyStore basicKeyStore,
52+
OwnerFactory ownerFactory,
53+
PersonsStorage personsStorage) {
4854
try {
4955
SNChannelsComponent.instance = new SNChannelsComponent(
5056
asapApplication,
5157
basicKeyStore,
52-
ownerFactory
58+
ownerFactory,
59+
personsStorage
5360
);
5461

5562
// add chunk received listener
@@ -156,4 +163,8 @@ private String getLogStart() {
156163
return this.getClass().getSimpleName() + ": ";
157164
}
158165

166+
@Override
167+
public CharSequence getPersonName(CharSequence peerID) throws ASAPException {
168+
return this.personsStorage.getPersonName(peerID);
169+
}
159170
}

app/src/main/java/net/sharksystem/persons/android/PersonsStorageAndroidComponent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import net.sharksystem.sharknet.android.AndroidASAPKeyStorage;
2424
import net.sharksystem.sharknet.android.Owner;
2525
import net.sharksystem.sharknet.android.OwnerFactory;
26+
import net.sharksystem.sharknet.android.PersonsStorage;
2627

2728
import java.io.File;
2829
import java.io.FileInputStream;
@@ -37,7 +38,7 @@
3738
import java.util.Set;
3839

3940
public class PersonsStorageAndroidComponent extends ASAPPKIImpl
40-
implements ASAPApplicationComponent /*InMemoPersonsStorageImpl*/ {
41+
implements ASAPApplicationComponent, PersonsStorage /*InMemoPersonsStorageImpl*/ {
4142

4243
public static final String SN_ANDROID_DEFAULT_SIGNING_ALGORITHM = "SHA256withRSA/PSS";
4344
private static final String PERSONS_STORAGE_FILE_NAME = "sn2_personsStorageFile";

app/src/main/java/net/sharksystem/sharknet/android/InitActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ protected void onCreate(Bundle savedInstanceState) {
2828

2929
if(launchFirstActivity) {
3030
// leave - we have no business here
31-
Intent intent = new Intent(this, MakanListActivity.class);
32-
// Intent intent = new Intent(this, SNChannelsListActivity.class);
31+
// Intent intent = new Intent(this, MakanListActivity.class);
32+
Intent intent = new Intent(this, SNChannelsListActivity.class);
3333
this.startActivity(intent);
3434
} else {
3535
setContentView(R.layout.init);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.sharksystem.sharknet.android;
2+
3+
import net.sharksystem.asap.ASAPException;
4+
5+
public interface PersonsStorage {
6+
/**
7+
* @param peerID
8+
* @return clear name of person with ID
9+
* @throws ASAPException if not found
10+
*/
11+
CharSequence getPersonName(CharSequence peerID) throws ASAPException;
12+
}

0 commit comments

Comments
 (0)