Stub key pair screen

This commit is contained in:
Niels Andriesse 2019-06-04 16:37:45 +10:00
parent e2fe979cc1
commit 4148d598f9
6 changed files with 160 additions and 10 deletions

View file

@ -441,6 +441,11 @@
android:windowSoftInputMode="stateUnchanged"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
<activity android:name=".loki.KeyPairActivity"
android:launchMode="singleTask"
android:theme="@style/TextSecure.LightRegistrationTheme"
android:windowSoftInputMode="stateUnchanged"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
<service android:enabled="true" android:name="org.thoughtcrime.securesms.service.WebRtcCallService"/>
<service android:enabled="true" android:name=".service.ApplicationMigrationService"/>

View file

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

View file

@ -1518,8 +1518,14 @@
<!-- EOF -->
<!-- Loki -->
<!-- Account details activity -->
<string name="activity_account_details_title">Create Your Loki Messenger Account</string>
<string name="activity_account_details_subtitle">Enter a name to be shown to your contacts</string>
<string name="activity_account_details_button_title">Next</string>
<!-- Key pair activity -->
<string name="activity_key_pair_title">Create Your Loki Messenger Account</string>
<string name="activity_key_pair_subtitle">Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device.</string>
<string name="activity_key_pair_button_title">Register</string>
</resources>

View file

@ -12,14 +12,11 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
import java.io.IOException;
import java.util.List;
import javax.inject.Inject;
@ -60,21 +57,19 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType {
if (!TextSecurePreferences.isPushRegistered(context)) return;
if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
Log.i(TAG, "Already have a signed pre key set");
Log.i(TAG, "Already have a signed pre key registered.");
return;
}
Log.i(TAG, "Registering new signed pre key...");
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
PreKeyUtil.generateSignedPreKey(context, identityKey, true);
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
ApplicationContext.getInstance(context)
.getJobManager()
.add(new CleanPreKeysJob());
ApplicationContext.getInstance(context).getJobManager().add(new CleanPreKeysJob());
}
/* Loki - Original Code
/* Loki - Original code
@Override
public void onRun() throws IOException {
if (!TextSecurePreferences.isPushRegistered(context)) return;
@ -101,7 +96,7 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType {
.getJobManager()
.add(new CleanPreKeysJob());
}
*/
*/
@Override
public boolean onShouldRetry(Exception exception) {

View file

@ -1,13 +1,26 @@
package org.thoughtcrime.securesms.loki
import android.content.Intent
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_account_details.*
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.R
import org.whispersystems.signalservice.api.crypto.ProfileCipher
class AccountDetailsActivity : BaseActionBarActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
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))
}
}

View file

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