This commit is contained in:
Niels Andriesse 2019-06-05 13:33:54 +10:00
parent 063e0967df
commit 1498a2e382
2 changed files with 22 additions and 4 deletions

View File

@ -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
}

View File

@ -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)
}
}