Stub key pair screen
parent
e2fe979cc1
commit
4148d598f9
@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/white"
|
||||||
|
android:fillViewport="true"
|
||||||
|
tools:context=".loki.KeyPairActivity">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="32dp"
|
||||||
|
android:layout_marginEnd="32dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/titleTextView"
|
||||||
|
style="@style/Signal.Text.Headline.Registration"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="40dp"
|
||||||
|
android:text="@string/activity_key_pair_title"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/subtitleTextView"
|
||||||
|
style="@style/Signal.Text.Body"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/activity_key_pair_subtitle"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/mnemonicTextView"
|
||||||
|
style="@style/Signal.Text.Body"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<com.dd.CircularProgressButton
|
||||||
|
android:id="@+id/nextButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:background="@color/signal_primary"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
app:cpb_colorIndicator="@color/white"
|
||||||
|
app:cpb_colorProgress="@color/textsecure_primary"
|
||||||
|
app:cpb_cornerRadius="4dp"
|
||||||
|
app:cpb_selectorIdle="@drawable/progress_button_state"
|
||||||
|
app:cpb_textIdle="@string/activity_key_pair_button_title" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
@ -1,13 +1,26 @@
|
|||||||
package org.thoughtcrime.securesms.loki
|
package org.thoughtcrime.securesms.loki
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import kotlinx.android.synthetic.main.activity_account_details.*
|
||||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||||
import org.thoughtcrime.securesms.R
|
import org.thoughtcrime.securesms.R
|
||||||
|
import org.whispersystems.signalservice.api.crypto.ProfileCipher
|
||||||
|
|
||||||
class AccountDetailsActivity : BaseActionBarActivity() {
|
class AccountDetailsActivity : BaseActionBarActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_account_details)
|
setContentView(R.layout.activity_account_details)
|
||||||
|
nextButton.setOnClickListener { continueIfPossible() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun continueIfPossible() {
|
||||||
|
val uncheckedName = nameEditText.text.toString()
|
||||||
|
val name = if (uncheckedName.isNotEmpty()) { uncheckedName.trim() } else { null }
|
||||||
|
if (name != null && name.toByteArray().size > ProfileCipher.NAME_PADDED_LENGTH) {
|
||||||
|
return nameEditText.input.setError("Too Long")
|
||||||
|
}
|
||||||
|
startActivity(Intent(this, KeyPairActivity::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import kotlinx.android.synthetic.main.activity_key_pair.*
|
||||||
|
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||||
|
import org.thoughtcrime.securesms.R
|
||||||
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||||
|
import org.whispersystems.libsignal.IdentityKeyPair
|
||||||
|
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
|
class KeyPairActivity : BaseActionBarActivity() {
|
||||||
|
private lateinit var languageFileDirectory: File
|
||||||
|
private var keyPair: IdentityKeyPair? = null
|
||||||
|
set(newValue) { field = newValue; updateMnemonic() }
|
||||||
|
private var mnemonic: String? = null
|
||||||
|
set(newValue) { field = newValue; updateMnemonicTextView() }
|
||||||
|
|
||||||
|
// region Lifecycle
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_key_pair)
|
||||||
|
setUpLanguageFileDirectory()
|
||||||
|
updateKeyPair()
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region General
|
||||||
|
private fun setUpLanguageFileDirectory() {
|
||||||
|
val languages = listOf( "english", "japanese", "portuguese", "spanish" )
|
||||||
|
val directory = File(applicationInfo.dataDir)
|
||||||
|
for (language in languages) {
|
||||||
|
val fileName = "$language.txt"
|
||||||
|
if (directory.list().contains(fileName)) { continue }
|
||||||
|
val inputStream = assets.open("mnemonic/$fileName")
|
||||||
|
val file = File(directory, fileName)
|
||||||
|
val outputStream = FileOutputStream(file)
|
||||||
|
val buffer = ByteArray(1024)
|
||||||
|
while (true) {
|
||||||
|
val count = inputStream.read(buffer)
|
||||||
|
if (count < 0) { break }
|
||||||
|
outputStream.write(buffer, 0, count)
|
||||||
|
}
|
||||||
|
inputStream.close()
|
||||||
|
outputStream.close()
|
||||||
|
}
|
||||||
|
languageFileDirectory = directory
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Updating
|
||||||
|
private fun updateKeyPair() {
|
||||||
|
IdentityKeyUtil.generateIdentityKeys(this)
|
||||||
|
keyPair = IdentityKeyUtil.getIdentityKeyPair(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateMnemonic() {
|
||||||
|
val hexEncodedPrivateKey = ("67982927" + "aaaabbbb" + "8926bfgd" + "0bfbba33" + "67982927" + "aaaabbbb" + "8926bfgd" + "0bfbba33").toUpperCase() // Hex.toString(keyPair!!.privateKey.serialize())
|
||||||
|
mnemonic = MnemonicCodec(languageFileDirectory).encode(hexEncodedPrivateKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateMnemonicTextView() {
|
||||||
|
mnemonicTextView.text = mnemonic!!
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
}
|
Loading…
Reference in New Issue