From 1498a2e38247ac0b3b458f016626f0a960ff87f0 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 5 Jun 2019 13:33:54 +1000 Subject: [PATCH] WIP --- .../securesms/loki/KeyPairActivity.kt | 20 ++++++++++++++++++- .../securesms/loki/LokiPreKeyBundleStore.kt | 6 +++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt b/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt index bbcd24ca26..4bf03da6a5 100644 --- a/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/KeyPairActivity.kt @@ -1,13 +1,18 @@ package org.thoughtcrime.securesms.loki +import android.content.Intent import android.os.Bundle import kotlinx.android.synthetic.main.activity_key_pair.* import org.thoughtcrime.securesms.BaseActionBarActivity +import org.thoughtcrime.securesms.ConversationListActivity import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.crypto.IdentityKeyUtil +import org.thoughtcrime.securesms.database.Address +import org.thoughtcrime.securesms.database.DatabaseFactory +import org.thoughtcrime.securesms.database.IdentityDatabase +import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.libsignal.IdentityKeyPair import org.whispersystems.signalservice.loki.crypto.MnemonicCodec -import org.whispersystems.signalservice.loki.utilities.hexEncodedPrivateKey import java.io.File import java.io.FileOutputStream @@ -24,6 +29,7 @@ class KeyPairActivity : BaseActionBarActivity() { setContentView(R.layout.activity_key_pair) setUpLanguageFileDirectory() updateKeyPair() + nextButton.setOnClickListener { register() } } // endregion @@ -64,4 +70,16 @@ class KeyPairActivity : BaseActionBarActivity() { mnemonicTextView.text = mnemonic!! } // endregion + + // region Interaction + private fun register() { + val publicKey = keyPair!!.publicKey + val hexEncodedPublicKey = publicKey.fingerprint + DatabaseFactory.getIdentityDatabase(this).saveIdentity(Address.fromSerialized(hexEncodedPublicKey), publicKey, + IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true) + TextSecurePreferences.setLocalNumber(this, hexEncodedPublicKey) + TextSecurePreferences.setProfileName(this, "User McUserFace") // TODO: For debugging purposes + startActivity(Intent(this, ConversationListActivity::class.java)) + } + // endregion } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleStore.kt b/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleStore.kt index e7afe1a7b7..784dab423f 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleStore.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleStore.kt @@ -8,17 +8,17 @@ import org.whispersystems.signalservice.loki.messaging.LokiPreKeyBundleStoreProt class LokiPreKeyBundleStore(val context: Context) : LokiPreKeyBundleStoreProtocol { companion object { - private val fileLock = Object() + private val lock = Object() } override fun getPreKeyBundle(pubKey: String): PreKeyBundle? { - synchronized (fileLock) { + synchronized(lock) { return DatabaseFactory.getLokiPreKeyBundleDatabase(context).getPreKeyBundle(pubKey) } } override fun removePreKeyBundle(pubKey: String) { - synchronized (fileLock) { + synchronized(lock) { DatabaseFactory.getLokiPreKeyBundleDatabase(context).removePreKeyBundle(pubKey) } }