Skip to content

Commit f23b763

Browse files
committed
Make trust level feed entries private
Encrypting entries related to trust level
1 parent 9e348f6 commit f23b763

3 files changed

Lines changed: 80 additions & 40 deletions

File tree

android/tinySSB/app/src/main/assets/web/prod/contacts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ function show_contact_details(id) {
220220
function changeTrustLevel(contactID, value) {
221221
console.log("Supposed to set contact " + contactID + "'s Trust Level to " + value);
222222
let ch = tremola.chats[recps2nm([myId])];
223-
let tips = JSON.stringify(ch.timeline.get_tips())
223+
let tips = JSON.stringify([])
224+
225+
if (typeof ch.timeline.get_tips === 'function') {
226+
tips = JSON.stringify(ch.timeline.get_tips())
227+
}
228+
224229
console.log("Tips: " + JSON.stringify(tips))
225230
backend("contacts:setTrust " + contactID + " " + value + " " + tips);
226231
}

android/tinySSB/app/src/main/assets/web/tremola.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -550,38 +550,6 @@ function b2f_new_event(e) { // incoming SSB log event: we get map with three ent
550550
}
551551

552552
if (e.public) {
553-
if (e.public[0] == 'TRT' && e.header.fid == myId) {
554-
ch = tremola.chats[recps2nm([myId])];
555-
556-
load_chat_list();
557-
if (!(ch.timeline instanceof Timeline))
558-
ch.timeline = Timeline.fromJSON(ch.timeline)
559-
560-
// console.log("new post 1 ", ch)
561-
if (!(e.header.ref in ch.posts)) { // new post
562-
var a = e.public;
563-
var p = {
564-
"key": e.header.ref, "from": e.header.fid, "body": "Set contact: " + a[2] + "'s trust level to " + a[3],
565-
"when": a[4] * 1000, "prev": a[1]
566-
};
567-
// console.log("new post 2 ", JSON.stringify(p))
568-
// console.log("time: ", a[3])
569-
ch["posts"][e.header.ref] = p;
570-
// console.log(`chat add tips ${a[1]}`)
571-
ch.timeline.add(e.header.ref, a[1])
572-
if (ch["touched"] < e.header.tst)
573-
ch["touched"] = e.header.tst
574-
if (curr_scenario == "posts" && curr_chat == conv_name) {
575-
load_chat(conv_name); // reload all messages (not very efficient ...)
576-
ch.lastRead = Object.keys(ch.posts).length; // Date.now();
577-
}
578-
set_chats_badge(conv_name)
579-
} else {
580-
console.log(`post ${e.header.ref} known already?`)
581-
}
582-
// if (curr_scenario == "chats") // the updated conversation could bubble up
583-
load_chat_list();
584-
}
585553
if (e.public[0] == 'TAV') { // text and voice
586554
// console.log("new post 0 ", tremola)
587555
var conv_name = "ALL";
@@ -654,6 +622,38 @@ function b2f_new_event(e) { // incoming SSB log event: we get map with three ent
654622
if (e.confid) {
655623
var a = e.confid;
656624
var rcpts = null;
625+
if (e.confid[0] == 'TRT') {
626+
ch = tremola.chats[recps2nm([myId])];
627+
628+
load_chat_list();
629+
if (!(ch.timeline instanceof Timeline))
630+
ch.timeline = Timeline.fromJSON(ch.timeline)
631+
632+
// console.log("new post 1 ", ch)
633+
if (!(e.header.ref in ch.posts)) { // new post
634+
var a = e.confid;
635+
var p = {
636+
"key": e.header.ref, "from": e.header.fid, "body": "Set contact: " + a[2] + "'s trust level to " + a[3],
637+
"when": a[4] * 1000, "prev": a[1]
638+
};
639+
// console.log("new post 2 ", JSON.stringify(p))
640+
// console.log("time: ", a[3])
641+
ch["posts"][e.header.ref] = p;
642+
// console.log(`chat add tips ${a[1]}`)
643+
ch.timeline.add(e.header.ref, a[1])
644+
if (ch["touched"] < e.header.tst)
645+
ch["touched"] = e.header.tst
646+
if (curr_scenario == "posts" && curr_chat == conv_name) {
647+
load_chat(conv_name); // reload all messages (not very efficient ...)
648+
ch.lastRead = Object.keys(ch.posts).length; // Date.now();
649+
}
650+
set_chats_badge(conv_name)
651+
} else {
652+
console.log(`post ${e.header.ref} known already?`)
653+
}
654+
// if (curr_scenario == "chats") // the updated conversation could bubble up
655+
load_chat_list();
656+
}
657657
if (a[0] == 'TAV')
658658
rcpts = a[5];
659659
else if (a[0] == 'DLV' || a[0] == 'ACK')

android/tinySSB/app/src/main/java/nz/scuttlebutt/tremolavossbol/WebAppInterface.kt

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,31 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
485485
Bipf.list_append(lst, tst)
486486
Bipf.list_append(lst, Bipf.mkNone()) //placeholder for voice
487487

488-
val body = Bipf.encode(lst)
489-
if (body != null) {
490-
act.tinyNode.publish_public_content(body)
488+
//encrypt the entry such that only I can read it
489+
val recps = Bipf.mkList()
490+
val keys: MutableList<ByteArray> = mutableListOf()
491+
val me = act.idStore.identity.toRef()
492+
Bipf.list_append(recps, Bipf.mkString(me))
493+
keys.add(me.deRef())
494+
Bipf.list_append(lst, recps)
495+
496+
val body_clear = Bipf.encode(lst)
497+
val encrypted = body_clear!!.let { act.idStore.identity.encryptPrivateMessage(it, keys) }
498+
499+
val body_encr = Bipf.encode(Bipf.mkBytes(encrypted))
500+
501+
//test if entry can be decrypted
502+
val clear = encrypted?.let { act.idStore.identity.decryptPrivateMessage(it) }
503+
if (clear != null) {
504+
val clearList = Bipf.decode(clear)
505+
if (clearList != null) {
506+
val clearJson = Bipf.bipf_list2JSON(clearList)
507+
Log.d("trust_contact", clearJson.toString())
508+
}
491509
}
510+
511+
if (body_encr != null)
512+
act.tinyNode.publish_public_content(body_encr)
492513
reloadContactsTrustLevel()
493514
}
494515

@@ -501,11 +522,23 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
501522
if (lastSeq != null) {
502523
for (i in lastSeq downTo 1) {
503524
var entry = userFeed.read_content(lastSeq)
504-
val entryType = entry?.let { getFromEntry(it, 0) }
525+
//decode the entry using Bipf decode
526+
val decodedEntry = entry?.let { Bipf.decode(it) }
527+
Log.d("decodedEntry", decodedEntry.toString())
528+
529+
//get bytes from the decoded entry
530+
val entryBytes = decodedEntry?.let {it.getBytes()}
531+
Log.d("entryBytes", entryBytes.toString())
532+
533+
//decrypt the bytes to get the clear text
534+
val clear = entryBytes?.let { act.idStore.identity.decryptPrivateMessage(it) }
535+
Log.d("clear", clear.toString())
536+
537+
val entryType = clear?.let { getFromEntry(it, 0) }
505538
if (entryType == "TRT") {
506-
if (entry is ByteArray) {
507-
val contactID = getFromEntry(entry, 2)
508-
val trustLevel = getFromEntry(entry, 3)
539+
if (clear is ByteArray) {
540+
val contactID = getFromEntry(clear, 2)
541+
val trustLevel = getFromEntry(clear, 3)
509542
if (contactID != null && trustLevel != null) {
510543
contactsTrustLevel[contactID.toString()] = trustLevel.toString().toInt()
511544
}
@@ -663,6 +696,8 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
663696
hdr.put("fid", "@" + fid.toBase64() + ".ed25519")
664697
hdr.put("ref", mid.toBase64())
665698
hdr.put("seq", seq)
699+
Log.d("decrypted log entry", hdr.toString())
700+
Log.d("decrypted log entry", param.toString())
666701
return "{header:${hdr.toString()}, confid:${param.toString()}}"
667702
}
668703
}

0 commit comments

Comments
 (0)