Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication Protocols for Self-Sovereign Identity #72

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
8a7d9cb
Rename various dialogs + implement channels in FireMissilesDialog
InvictusRMC Apr 25, 2021
41be417
Add CommunicationManager initialization
InvictusRMC Apr 25, 2021
19e74b1
Add communication singleton class
InvictusRMC Apr 25, 2021
1cf3082
Make DatabaseFragment compatible with new Communication
InvictusRMC Apr 25, 2021
f914697
Add Requests screen
InvictusRMC Apr 25, 2021
26401a6
Add Requests resources
InvictusRMC Apr 25, 2021
25b9840
Make bottomnav accessible
InvictusRMC Apr 25, 2021
2515876
Add notifications + implement channels
InvictusRMC Apr 25, 2021
04863f9
Remove unnecessary white space + change adapter updating
InvictusRMC Apr 25, 2021
2ba9d14
Add NewAttestationValueDialog
InvictusRMC Apr 25, 2021
01dcc6e
Add html parsing method + apply dialog package definitions
InvictusRMC Apr 25, 2021
5ea68eb
Move dialogs to seperate package
InvictusRMC Apr 25, 2021
b0977d1
clean up verification fragment
InvictusRMC Apr 25, 2021
044005e
Cleanup database fragment
InvictusRMC Apr 25, 2021
ffba377
Use correct peer in FireMissileDialog
InvictusRMC Apr 25, 2021
f3e7576
Only update adapter when necessary
InvictusRMC Apr 25, 2021
b960e61
Cleanup peers fragment
InvictusRMC Apr 25, 2021
a767abb
Update coroutines version + add legacy dependency
InvictusRMC Apr 25, 2021
73eb5f7
Update resource files
InvictusRMC Apr 29, 2021
cedaa52
Update CommunicationManager imports
InvictusRMC Apr 29, 2021
c5b710c
Add encoding logic
InvictusRMC Apr 29, 2021
42dfba5
Update dabase fragment
InvictusRMC Apr 29, 2021
ea6ad09
Update attestation dialogs
InvictusRMC Apr 29, 2021
e5e90b6
Remove unnecessary imports
InvictusRMC Apr 29, 2021
2cc14bb
Update request fragment
InvictusRMC Apr 29, 2021
9c3e357
Ad QR code dependency
InvictusRMC Apr 29, 2021
bc73b61
Update verification fragment
InvictusRMC Apr 29, 2021
3456472
Refactor packages
InvictusRMC Apr 29, 2021
b4784e2
Add secondary QR code + clean up DatabaseFragment
InvictusRMC Apr 30, 2021
05155dd
Add unload when seting new rendezvoustoken
InvictusRMC Apr 30, 2021
d489ce7
Add searching state to firemissilesdialog
InvictusRMC Apr 30, 2021
f8cd97b
Show correct QR code in PresentAttestationDialog
InvictusRMC Apr 30, 2021
2a529b0
Update package definitions
InvictusRMC Apr 30, 2021
4e83062
Make ScanIntent find presented peer
InvictusRMC Apr 30, 2021
882cad5
Update package definitions
InvictusRMC Apr 30, 2021
966ed49
Make VerificationFragment locate peer
InvictusRMC Apr 30, 2021
b1c80a5
Add resources
InvictusRMC Apr 30, 2021
153de3d
Add Revocation screen
InvictusRMC May 5, 2021
c7d5391
Add resource files for revocation + add to bottom nav
InvictusRMC May 5, 2021
7203f4a
Add active verification of attestations
InvictusRMC May 5, 2021
02133fb
Add rendezvoustoken to attestation handling
InvictusRMC May 5, 2021
57d772b
Remove unnecessary debug print statement
InvictusRMC May 5, 2021
b6daaf5
Add rendezvous token dialog
InvictusRMC May 5, 2021
fd02fe2
Add QRCodeUtil class
InvictusRMC May 5, 2021
647a8f6
Add string resources + settings icon
InvictusRMC May 5, 2021
26332f1
Add presentation logic
InvictusRMC May 10, 2021
f9a28b3
Clean up callbacks
InvictusRMC May 10, 2021
c9223fd
Rename dialogs
InvictusRMC May 13, 2021
04e821c
Add attribute name and value to verification dialog
InvictusRMC May 13, 2021
84a8dd1
Update database item equals
InvictusRMC May 13, 2021
c8c3318
Add sentitem equals
InvictusRMC May 13, 2021
0281565
Update resources
InvictusRMC May 13, 2021
fd8cd6f
Make attribute value nullable
InvictusRMC May 13, 2021
7dbd6b6
Use navigator navigate up + rename reference
InvictusRMC May 13, 2021
eb02490
Account for animation duration scale + allow change without activity …
InvictusRMC May 13, 2021
4d29b55
simplify function callback
InvictusRMC May 13, 2021
e25fdb5
Add debug option to sent attestation fragment + add refresh view
InvictusRMC May 13, 2021
9a57742
Add sign date to SentItem
InvictusRMC May 13, 2021
870ac68
Add refresh view + improve QR code efficiency in DatabaseFragment
InvictusRMC May 13, 2021
4d5a86e
Improve AuthorityConfirmationDialog structure + use navigate up
InvictusRMC May 13, 2021
fb1b29e
Add loop loading to request fragment + improve item updating
InvictusRMC May 13, 2021
38adc9c
Add revocation update callback to main activity
InvictusRMC May 13, 2021
0177162
Set animation scale on dialog create
InvictusRMC May 13, 2021
78792e1
Change request item equals
InvictusRMC May 13, 2021
b0c1c06
Rename dialog reference in peers fragment
InvictusRMC May 13, 2021
1196614
Apply import refactor changes
InvictusRMC May 14, 2021
6019fd8
Add identity deletion modal
InvictusRMC May 14, 2021
7019638
Use metadata consts
InvictusRMC May 17, 2021
a2052f4
Use consts in QRCodeUtil
InvictusRMC May 17, 2021
8f173de
Rename value dialog + make navigation consistent with expected behavi…
InvictusRMC May 17, 2021
fd7bfcb
Add attestation callback + add authorities through peers fragment
InvictusRMC May 17, 2021
fad61ff
Merge branch 'master' of github.com:Tribler/trustchain-superapp into …
InvictusRMC May 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.ipv8.android.keyvault.AndroidCryptoProvider
import nl.tudelft.ipv8.android.messaging.bluetooth.BluetoothLeDiscovery
import nl.tudelft.ipv8.android.peerdiscovery.NetworkServiceDiscovery
import nl.tudelft.ipv8.attestation.schema.SchemaManager
import nl.tudelft.ipv8.attestation.common.AuthorityManager
import nl.tudelft.ipv8.attestation.common.SchemaManager
import nl.tudelft.ipv8.attestation.communication.CommunicationManager
import nl.tudelft.ipv8.attestation.identity.store.IdentitySQLiteStore
import nl.tudelft.ipv8.attestation.revocation.AuthoritySQLiteStore
import nl.tudelft.ipv8.attestation.trustchain.*
import nl.tudelft.ipv8.attestation.trustchain.store.TrustChainSQLiteStore
import nl.tudelft.ipv8.attestation.trustchain.store.TrustChainStore
import nl.tudelft.ipv8.attestation.trustchain.validation.TransactionValidator
import nl.tudelft.ipv8.attestation.trustchain.validation.ValidationResult
import nl.tudelft.ipv8.attestation.wallet.AttestationCommunity
import nl.tudelft.ipv8.attestation.wallet.AttestationSQLiteStore
import nl.tudelft.ipv8.attestation.wallet.cryptography.bonehexact.BonehPrivateKey
import nl.tudelft.ipv8.attestation.wallet.store.AttestationSQLiteStore
import nl.tudelft.ipv8.keyvault.PrivateKey
import nl.tudelft.ipv8.keyvault.defaultCryptoProvider
import nl.tudelft.ipv8.messaging.tftp.TFTPCommunity
Expand All @@ -48,6 +51,7 @@ import nl.tudelft.trustchain.gossipML.RecommenderCommunity
import nl.tudelft.trustchain.gossipML.db.RecommenderStore
import nl.tudelft.trustchain.peerchat.community.PeerChatCommunity
import nl.tudelft.trustchain.peerchat.db.PeerChatStore
import nl.tudelft.trustchain.ssi.Communication

import nl.tudelft.trustchain.voting.VotingCommunity
import nl.tudelft.gossipML.sqldelight.Database as MLDatabase
Expand All @@ -70,7 +74,6 @@ class TrustChainApplication : Application() {
createEuroTokenCommunity(),
createTFTPCommunity(),
createDemoCommunity(),
createWalletCommunity(),
createMarketCommunity(),
createCoinCommunity(),
createVotingCommunity(),
Expand All @@ -86,6 +89,7 @@ class TrustChainApplication : Application() {
.setServiceClass(TrustChainService::class.java)
.init()

initCommunicationManager()
initWallet()
initTrustChain()
}
Expand All @@ -100,6 +104,26 @@ class TrustChainApplication : Application() {
}
}

private fun initCommunicationManager() {
val driver: SqlDriver = AndroidSqliteDriver(Database.Schema, this, "wallet.db")
val database = Database(driver)
val authorityStore = AuthoritySQLiteStore(database)
val attestationStore = AttestationSQLiteStore(database)
val identityStore = IdentitySQLiteStore(database)

val authorityManager = AuthorityManager(authorityStore)
val communicationManager = CommunicationManager(
IPv8Android.getInstance(),
attestationStore,
identityStore,
authorityManager,
::storePseudonym,
::loadPseudonym
)

Communication.Factory(communicationManager)
}

private fun initTrustChain() {
val ipv8 = IPv8Android.getInstance()
val trustchain = ipv8.getOverlay<TrustChainCommunity>()!!
Expand Down Expand Up @@ -170,18 +194,6 @@ class TrustChainApplication : Application() {
)
}

private fun createWalletCommunity(): OverlayConfiguration<AttestationCommunity> {
val driver: SqlDriver = AndroidSqliteDriver(Database.Schema, this, "wallet.db")
val database = Database(driver)
val store = AttestationSQLiteStore(database)
val randomWalk = RandomWalk.Factory()

return OverlayConfiguration(
AttestationCommunity.Factory(store),
listOf(randomWalk)
)
}

private fun createDiscoveryCommunity(): OverlayConfiguration<DiscoveryCommunity> {
val randomWalk = RandomWalk.Factory()
val randomChurn = RandomChurn.Factory()
Expand Down Expand Up @@ -339,6 +351,23 @@ class TrustChainApplication : Application() {
}
}

private fun loadPseudonym(name: String): PrivateKey? {
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
val privateKey = prefs.getString(name, null)
return if (privateKey == null) {
null
} else {
AndroidCryptoProvider.keyFromPrivateBin(privateKey.hexToBytes())
}
}

private fun storePseudonym(name: String, privateKey: PrivateKey) {
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
prefs.edit()
.putString(name, privateKey.keyToBin().toHex())
.apply()
}

companion object {
private const val PREF_PRIVATE_KEY = "private_key"
private const val PREF_ID_METADATA_KEY = "id_metadata"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nl.tudelft.trustchain.common

import android.os.Bundle
import android.view.View
import androidx.annotation.MenuRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
Expand All @@ -9,6 +10,7 @@ import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import nl.tudelft.trustchain.common.databinding.ActivityBaseBinding
import nl.tudelft.trustchain.common.util.viewBinding

Expand All @@ -19,6 +21,8 @@ abstract class BaseActivity : AppCompatActivity() {
AppBarConfiguration(setOf())
}

protected lateinit var bottomNavigation: BottomNavigationView

/**
* The resource ID of the navigation graph.
*/
Expand All @@ -39,6 +43,7 @@ abstract class BaseActivity : AppCompatActivity() {

setContentView(binding.root)

bottomNavigation = binding.bottomNavigation
navController.setGraph(navigationGraph)

// Setup ActionBar
Expand Down
7 changes: 5 additions & 2 deletions ig-ssi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ dependencies {

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

implementation 'androidmads.library.qrgenearator:QRGenearator:1.0.4'

// Logging
implementation 'io.github.microutils:kotlin-logging:1.7.7'
implementation 'com.github.tony19:logback-android:2.0.0'

implementation 'com.github.MattSkala:recyclerview-itemadapter:0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

// Testing
testImplementation 'junit:junit:4.12'
Expand Down
69 changes: 69 additions & 0 deletions ig-ssi/src/main/java/nl/tudelft/trustchain/ssi/Communication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package nl.tudelft.trustchain.ssi

import nl.tudelft.ipv8.attestation.communication.CommunicationChannel
import nl.tudelft.ipv8.attestation.communication.CommunicationManager

const val DEFAULT_PSEUDONYM = "MY_PEER"
val DEFAULT_RENDEZVOUS_TOKEN = null

object Communication {

private var communicationManager: CommunicationManager? = null
private var activePseudonym: String? = null
private var activeRendezvousToken: String? = null

val pseudonymLock = Object()
val tokenLock = Object()

fun getInstance(): CommunicationManager {
return communicationManager
?: throw IllegalStateException("CommunicationManager is not initialized.")
}

fun load(
pseudonym: String = getActivePseudonym(),
rendezvous: String? = getActiveRendezvousToken()
): CommunicationChannel {
var rendezvousToken = rendezvous
if (rendezvousToken == "") {
rendezvousToken = DEFAULT_RENDEZVOUS_TOKEN
}
if (rendezvousToken != activeRendezvousToken) {
setActiveRendezvousToken(rendezvousToken)
}
return getInstance().load(pseudonym, rendezvousToken)
}

fun getActivePseudonym(): String {
return activePseudonym
?: throw java.lang.IllegalStateException("ActivePseudonym is not initialized.")
}

fun getActiveRendezvousToken(): String? {
return activeRendezvousToken
}

fun setActivePseudonym(pseudonym: String) {
synchronized(pseudonymLock) {
this.activePseudonym = pseudonym
}
}

fun setActiveRendezvousToken(token: String?) {
if (activeRendezvousToken != token)
synchronized(tokenLock) {
val manager = getInstance()
manager.unload(getActivePseudonym())
this.activeRendezvousToken = token
this.load()
}
}

class Factory(communicationManager: CommunicationManager) {
init {
Communication.communicationManager = communicationManager
activePseudonym = DEFAULT_PSEUDONYM
communicationManager.load(getActivePseudonym())
}
}
}
Loading