Add autocrypt key transfer api method
This commit is contained in:
parent
5db00cd924
commit
be58f2ff4c
|
@ -929,6 +929,10 @@
|
||||||
android:configChanges="keyboardHidden|keyboard"
|
android:configChanges="keyboardHidden|keyboard"
|
||||||
android:label="@string/title_backup" />
|
android:label="@string/title_backup" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".remote.ui.RemoteDisplayTransferCodeActivity"
|
||||||
|
android:theme="@style/Theme.Keychain.Transparent"/>
|
||||||
|
|
||||||
<!-- Usb interceptor activity -->
|
<!-- Usb interceptor activity -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.UsbEventReceiverActivity"
|
android:name=".ui.UsbEventReceiverActivity"
|
||||||
|
|
|
@ -27,6 +27,7 @@ import android.os.Build;
|
||||||
import org.sufficientlysecure.keychain.pgp.DecryptVerifySecurityProblem;
|
import org.sufficientlysecure.keychain.pgp.DecryptVerifySecurityProblem;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.remote.ui.RemoteBackupActivity;
|
import org.sufficientlysecure.keychain.remote.ui.RemoteBackupActivity;
|
||||||
|
import org.sufficientlysecure.keychain.remote.ui.RemoteDisplayTransferCodeActivity;
|
||||||
import org.sufficientlysecure.keychain.remote.ui.RemoteErrorActivity;
|
import org.sufficientlysecure.keychain.remote.ui.RemoteErrorActivity;
|
||||||
import org.sufficientlysecure.keychain.remote.ui.RemoteImportKeysActivity;
|
import org.sufficientlysecure.keychain.remote.ui.RemoteImportKeysActivity;
|
||||||
import org.sufficientlysecure.keychain.remote.ui.RemotePassphraseDialogActivity;
|
import org.sufficientlysecure.keychain.remote.ui.RemotePassphraseDialogActivity;
|
||||||
|
@ -42,6 +43,7 @@ import org.sufficientlysecure.keychain.remote.ui.dialog.RemoteSelectIdKeyActivit
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity;
|
import org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity;
|
||||||
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
public class ApiPendingIntentFactory {
|
public class ApiPendingIntentFactory {
|
||||||
|
|
||||||
|
@ -193,6 +195,13 @@ public class ApiPendingIntentFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PendingIntent createDisplayTransferCodePendingIntent(Passphrase autocryptTransferCode) {
|
||||||
|
Intent intent = new Intent(mContext, RemoteDisplayTransferCodeActivity.class);
|
||||||
|
intent.putExtra(RemoteDisplayTransferCodeActivity.EXTRA_TRANSFER_CODE, autocryptTransferCode);
|
||||||
|
|
||||||
|
return createInternal(null, intent);
|
||||||
|
}
|
||||||
|
|
||||||
private PendingIntent createInternal(Intent data, Intent intent) {
|
private PendingIntent createInternal(Intent data, Intent intent) {
|
||||||
// re-attach "data" for pass through. It will be used later to repeat pgp operation
|
// re-attach "data" for pass through. It will be used later to repeat pgp operation
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ import org.sufficientlysecure.keychain.service.BackupKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
|
import org.sufficientlysecure.keychain.util.Numeric9x4PassphraseUtil;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
@ -811,6 +812,36 @@ public class OpenPgpService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Intent autocryptKeyTransferImpl(Intent data, OutputStream outputStream) {
|
||||||
|
try {
|
||||||
|
long[] masterKeyIds = data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
|
||||||
|
|
||||||
|
Passphrase autocryptTransferCode = Numeric9x4PassphraseUtil.generateNumeric9x4Passphrase();
|
||||||
|
CryptoInputParcel inputParcel = CryptoInputParcel.createCryptoInputParcel(autocryptTransferCode);
|
||||||
|
|
||||||
|
BackupKeyringParcel input = BackupKeyringParcel.createExportAutocryptSetupMessage(masterKeyIds);
|
||||||
|
BackupOperation op = new BackupOperation(this, mKeyRepository, null);
|
||||||
|
ExportResult pgpResult = op.execute(input, inputParcel, outputStream);
|
||||||
|
|
||||||
|
PendingIntent displayTransferCodePendingIntent =
|
||||||
|
mApiPendingIntentFactory.createDisplayTransferCodePendingIntent(autocryptTransferCode);
|
||||||
|
|
||||||
|
if (pgpResult.success()) {
|
||||||
|
Intent result = new Intent();
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_INTENT, displayTransferCodePendingIntent);
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
// should not happen normally...
|
||||||
|
String errorMsg = getString(pgpResult.getLog().getLast().mType.getMsgId());
|
||||||
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, errorMsg);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Timber.d(e);
|
||||||
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Intent updateAutocryptPeerImpl(Intent data) {
|
private Intent updateAutocryptPeerImpl(Intent data) {
|
||||||
try {
|
try {
|
||||||
AutocryptPeerDataAccessObject autocryptPeerDao = new AutocryptPeerDataAccessObject(getBaseContext(),
|
AutocryptPeerDataAccessObject autocryptPeerDao = new AutocryptPeerDataAccessObject(getBaseContext(),
|
||||||
|
@ -1030,6 +1061,9 @@ public class OpenPgpService extends Service {
|
||||||
case OpenPgpApi.ACTION_BACKUP: {
|
case OpenPgpApi.ACTION_BACKUP: {
|
||||||
return backupImpl(data, outputStream);
|
return backupImpl(data, outputStream);
|
||||||
}
|
}
|
||||||
|
case OpenPgpApi.ACTION_AUTOCRYPT_KEY_TRANSFER: {
|
||||||
|
return autocryptKeyTransferImpl(data, outputStream);
|
||||||
|
}
|
||||||
case OpenPgpApi.ACTION_UPDATE_AUTOCRYPT_PEER: {
|
case OpenPgpApi.ACTION_UPDATE_AUTOCRYPT_PEER: {
|
||||||
return updateAutocryptPeerImpl(data);
|
return updateAutocryptPeerImpl(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Schürmann & Breitmoser GbR
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.remote.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
|
||||||
|
import org.sufficientlysecure.keychain.ui.widget.PrefixedEditText;
|
||||||
|
import org.sufficientlysecure.keychain.util.Numeric9x4PassphraseUtil;
|
||||||
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
|
|
||||||
|
public class RemoteDisplayTransferCodeActivity extends FragmentActivity {
|
||||||
|
public static final String EXTRA_TRANSFER_CODE = "transfer_code";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
DisplayTransferCodeDialogFragment frag = new DisplayTransferCodeDialogFragment();
|
||||||
|
frag.setArguments(getIntent().getExtras());
|
||||||
|
frag.show(getSupportFragmentManager(), "displayTransferCode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DisplayTransferCodeDialogFragment extends DialogFragment {
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final Activity activity = getActivity();
|
||||||
|
|
||||||
|
Passphrase transferCode = getArguments().getParcelable(EXTRA_TRANSFER_CODE);
|
||||||
|
|
||||||
|
ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity);
|
||||||
|
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
|
View view = LayoutInflater.from(theme).inflate(R.layout.api_display_transfer_code, null, false);
|
||||||
|
alert.setView(view);
|
||||||
|
alert.setPositiveButton(R.string.button_got_it, (dialog, which) -> dismiss());
|
||||||
|
|
||||||
|
TextView[] transferCodeTextViews = new TextView[9];
|
||||||
|
transferCodeTextViews[0] = view.findViewById(R.id.transfer_code_block_1);
|
||||||
|
transferCodeTextViews[1] = view.findViewById(R.id.transfer_code_block_2);
|
||||||
|
transferCodeTextViews[2] = view.findViewById(R.id.transfer_code_block_3);
|
||||||
|
transferCodeTextViews[3] = view.findViewById(R.id.transfer_code_block_4);
|
||||||
|
transferCodeTextViews[4] = view.findViewById(R.id.transfer_code_block_5);
|
||||||
|
transferCodeTextViews[5] = view.findViewById(R.id.transfer_code_block_6);
|
||||||
|
transferCodeTextViews[6] = view.findViewById(R.id.transfer_code_block_7);
|
||||||
|
transferCodeTextViews[7] = view.findViewById(R.id.transfer_code_block_8);
|
||||||
|
transferCodeTextViews[8] = view.findViewById(R.id.transfer_code_block_9);
|
||||||
|
|
||||||
|
setTransferCode(transferCodeTextViews, transferCode);
|
||||||
|
|
||||||
|
return alert.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTransferCode(TextView[] view, Passphrase transferCode) {
|
||||||
|
CharBuffer transferCodeChars = CharBuffer.wrap(transferCode.getCharArray()).asReadOnlyBuffer();
|
||||||
|
if (!Numeric9x4PassphraseUtil.isNumeric9x4Passphrase(transferCodeChars)) {
|
||||||
|
throw new IllegalStateException("Illegal passphrase format!");
|
||||||
|
}
|
||||||
|
|
||||||
|
PrefixedEditText prefixedEditText = (PrefixedEditText) view[0];
|
||||||
|
prefixedEditText.setHint("34");
|
||||||
|
prefixedEditText.setPrefix(transferCodeChars.subSequence(0, 2));
|
||||||
|
prefixedEditText.setText(transferCodeChars.subSequence(2, 4));
|
||||||
|
|
||||||
|
for (int i = 1; i < 9; i++) {
|
||||||
|
view[i].setText(transferCodeChars.subSequence(i*5, i*5+4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
super.onDismiss(dialog);
|
||||||
|
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
tools:layout_marginTop="24dp"
|
||||||
|
>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
android:elevation="4dp"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
tools:targetApi="lollipop">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:src="@mipmap/ic_launcher"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:text="@string/app_name"
|
||||||
|
style="?android:textAppearanceLarge"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_title_select_key"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="36dp"
|
||||||
|
android:layout_marginBottom="22dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:text="Your transfer code:" />
|
||||||
|
|
||||||
|
<include layout="@layout/transfer_code_display" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
2
extern/openpgp-api-lib
vendored
2
extern/openpgp-api-lib
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit bfb355c5bfa57245f50efd747a4f297eda57254a
|
Subproject commit 3631265b348a02ea3c79f4f38f6c031a82298ed5
|
Loading…
Reference in a new issue