Certify not sign a key, added as button, does not belong to menu

This commit is contained in:
Dominik Schürmann 2014-02-04 14:20:49 +01:00
parent 7eb34a48f4
commit d75ea3f9e5
19 changed files with 78 additions and 65 deletions

View File

@ -249,9 +249,9 @@
android:label="@string/title_key_server_preference"
android:windowSoftInputMode="stateHidden" />
<activity
android:name=".ui.SignKeyActivity"
android:name=".ui.CertifyKeyActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/title_sign_key" />
android:label="@string/title_certify_key" />
<activity
android:name=".ui.ImportKeysActivity"
android:label="@string/title_import_keys"

View File

@ -405,7 +405,7 @@ public class PgpKeyOperation {
updateProgress(R.string.progress_done, 100, 100);
}
public PGPPublicKeyRing signKey(long masterKeyId, long pubKeyId, String passphrase)
public PGPPublicKeyRing certifyKey(long masterKeyId, long pubKeyId, String passphrase)
throws PgpGeneralException, NoSuchAlgorithmException, NoSuchProviderException,
PGPException, SignatureException {
if (passphrase == null) {
@ -414,14 +414,14 @@ public class PgpKeyOperation {
PGPPublicKeyRing pubring = ProviderHelper
.getPGPPublicKeyRingByKeyId(mContext, pubKeyId);
PGPSecretKey signingKey = PgpKeyHelper.getCertificationKey(mContext, masterKeyId);
if (signingKey == null) {
PGPSecretKey certificationKey = PgpKeyHelper.getCertificationKey(mContext, masterKeyId);
if (certificationKey == null) {
throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
}
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.toCharArray());
PGPPrivateKey signaturePrivateKey = signingKey.extractPrivateKey(keyDecryptor);
PGPPrivateKey signaturePrivateKey = certificationKey.extractPrivateKey(keyDecryptor);
if (signaturePrivateKey == null) {
throw new PgpGeneralException(
mContext.getString(R.string.error_could_not_extract_private_key));
@ -429,7 +429,7 @@ public class PgpKeyOperation {
// TODO: SHA256 fixed?
JcaPGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(
signingKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256)
certificationKey.getPublicKey().getAlgorithm(), PGPUtil.SHA256)
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(

View File

@ -54,7 +54,6 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
import org.sufficientlysecure.keychain.util.HkpKeyServer;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
import android.app.IntentService;
@ -96,7 +95,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
public static final String ACTION_UPLOAD_KEYRING = Constants.INTENT_PREFIX + "UPLOAD_KEYRING";
public static final String ACTION_DOWNLOAD_AND_IMPORT_KEYS = Constants.INTENT_PREFIX + "QUERY_KEYRING";
public static final String ACTION_SIGN_KEYRING = Constants.INTENT_PREFIX + "SIGN_KEYRING";
public static final String ACTION_CERTIFY_KEYRING = Constants.INTENT_PREFIX + "SIGN_KEYRING";
/* keys for data bundle */
@ -163,8 +162,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
public static final String DOWNLOAD_KEY_LIST = "query_key_id";
// sign key
public static final String SIGN_KEY_MASTER_KEY_ID = "sign_key_master_key_id";
public static final String SIGN_KEY_PUB_KEY_ID = "sign_key_pub_key_id";
public static final String CERTIFY_KEY_MASTER_KEY_ID = "sign_key_master_key_id";
public static final String CERTIFY_KEY_PUB_KEY_ID = "sign_key_pub_key_id";
/*
* possible data keys as result send over messenger
@ -777,19 +776,19 @@ public class KeychainIntentService extends IntentService implements ProgressDial
} catch (Exception e) {
sendErrorToHandler(e);
}
} else if (ACTION_SIGN_KEYRING.equals(action)) {
} else if (ACTION_CERTIFY_KEYRING.equals(action)) {
try {
/* Input */
long masterKeyId = data.getLong(SIGN_KEY_MASTER_KEY_ID);
long pubKeyId = data.getLong(SIGN_KEY_PUB_KEY_ID);
long masterKeyId = data.getLong(CERTIFY_KEY_MASTER_KEY_ID);
long pubKeyId = data.getLong(CERTIFY_KEY_PUB_KEY_ID);
/* Operation */
String signaturePassPhrase = PassphraseCacheService.getCachedPassphrase(this,
masterKeyId);
PgpKeyOperation keyOperation = new PgpKeyOperation(this, this);
PGPPublicKeyRing signedPubKeyRing = keyOperation.signKey(masterKeyId, pubKeyId,
PGPPublicKeyRing signedPubKeyRing = keyOperation.certifyKey(masterKeyId, pubKeyId,
signaturePassPhrase);
// store the signed key in our local cache

View File

@ -56,7 +56,7 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
/**
* Signs the specified public key with the specified secret master key
*/
public class SignKeyActivity extends ActionBarActivity implements
public class CertifyKeyActivity extends ActionBarActivity implements
SelectSecretKeyLayoutFragment.SelectSecretKeyCallback {
private BootstrapButton mSignButton;
private CheckBox mUploadKeyCheckbox;
@ -72,7 +72,7 @@ public class SignKeyActivity extends ActionBarActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_key_activity);
setContentView(R.layout.certify_key_activity);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
@ -196,8 +196,8 @@ public class SignKeyActivity extends ActionBarActivity implements
String passphrase = PassphraseCacheService.getCachedPassphrase(this, mMasterKeyId);
if (passphrase == null) {
showPassphraseDialog(mMasterKeyId);
return; // bail out; need to wait until the user has entered the passphrase
// before trying again
// bail out; need to wait until the user has entered the passphrase before trying again
return;
} else {
startSigning();
}
@ -218,13 +218,13 @@ public class SignKeyActivity extends ActionBarActivity implements
// Send all information needed to service to sign key in other thread
Intent intent = new Intent(this, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_SIGN_KEYRING);
intent.setAction(KeychainIntentService.ACTION_CERTIFY_KEYRING);
// fill values for this action
Bundle data = new Bundle();
data.putLong(KeychainIntentService.SIGN_KEY_MASTER_KEY_ID, mMasterKeyId);
data.putLong(KeychainIntentService.SIGN_KEY_PUB_KEY_ID, mPubKeyId);
data.putLong(KeychainIntentService.CERTIFY_KEY_MASTER_KEY_ID, mMasterKeyId);
data.putLong(KeychainIntentService.CERTIFY_KEY_PUB_KEY_ID, mPubKeyId);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
@ -237,14 +237,12 @@ public class SignKeyActivity extends ActionBarActivity implements
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
Toast.makeText(SignKeyActivity.this, R.string.key_sign_success,
Toast.makeText(CertifyKeyActivity.this, R.string.key_sign_success,
Toast.LENGTH_SHORT).show();
// check if we need to send the key to the server or not
if (mUploadKeyCheckbox.isChecked()) {
/*
* upload the newly signed key to the key server
*/
// upload the newly signed key to the key server
uploadKey();
} else {
setResult(RESULT_OK);
@ -291,7 +289,7 @@ public class SignKeyActivity extends ActionBarActivity implements
super.handleMessage(message);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
Toast.makeText(SignKeyActivity.this, R.string.key_send_success,
Toast.makeText(CertifyKeyActivity.this, R.string.key_send_success,
Toast.LENGTH_SHORT).show();
setResult(RESULT_OK);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2011 Senecaso
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -127,7 +127,7 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
/* Scanning a fingerprint directly with Barcode Scanner */
getSupportActionBar().setSelectedNavigationItem(0);
loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[0]);
loadFromFingerprintUri(dataUri);
loadFromFingerprintUri(savedInstanceState, dataUri);
} else if (ACTION_IMPORT_KEY.equals(action)) {
/* Keychain's own Actions */
getSupportActionBar().setSelectedNavigationItem(1);
@ -248,7 +248,7 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
ft.commit();
}
public void loadFromFingerprintUri(Uri dataUri) {
public void loadFromFingerprintUri(Bundle savedInstanceState, Uri dataUri) {
String fingerprint = dataUri.toString().split(":")[1].toLowerCase(Locale.ENGLISH);
Log.d(Constants.TAG, "fingerprint: " + fingerprint);
@ -267,7 +267,7 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
loadFragment(ImportKeysServerFragment.class, args, mNavigationStrings[0]);
startListFragment(null, null, null, query);
startListFragment(savedInstanceState, null, null, query);
}
public void loadCallback(byte[] importData, Uri dataUri, String serverQuery, String keyServer) {

View File

@ -130,7 +130,7 @@ public class ImportKeysQrCodeFragment extends Fragment {
}
public void importFingerprint(Uri dataUri) {
mImportActivity.loadFromFingerprintUri(dataUri);
mImportActivity.loadFromFingerprintUri(null, dataUri);
}
private void importParts(String[] parts) {

View File

@ -75,6 +75,7 @@ public class ViewKeyActivity extends ActionBarActivity implements
private TextView mCreation;
private TextView mFingerprint;
private BootstrapButton mActionEncrypt;
private BootstrapButton mActionCertify;
private ListView mUserIds;
private ListView mKeys;
@ -91,6 +92,7 @@ public class ViewKeyActivity extends ActionBarActivity implements
mExportHelper = new ExportHelper(this);
// let the actionbar look like Android's contact app
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setIcon(android.R.color.transparent);
getSupportActionBar().setHomeButtonEnabled(true);
@ -105,9 +107,10 @@ public class ViewKeyActivity extends ActionBarActivity implements
mCreation = (TextView) findViewById(R.id.creation);
mExpiry = (TextView) findViewById(R.id.expiry);
mFingerprint = (TextView) findViewById(R.id.fingerprint);
mActionEncrypt = (BootstrapButton) findViewById(R.id.action_encrypt);
mUserIds = (ListView) findViewById(R.id.user_ids);
mKeys = (ListView) findViewById(R.id.keys);
mActionEncrypt = (BootstrapButton) findViewById(R.id.action_encrypt);
mActionCertify = (BootstrapButton) findViewById(R.id.action_certify);
loadData(getIntent());
}
@ -130,9 +133,6 @@ public class ViewKeyActivity extends ActionBarActivity implements
case R.id.menu_key_view_update:
updateFromKeyserver(mDataUri);
return true;
case R.id.menu_key_view_sign:
signKey(mDataUri);
return true;
case R.id.menu_key_view_export_keyserver:
uploadToKeyserver(mDataUri);
return true;
@ -196,19 +196,18 @@ public class ViewKeyActivity extends ActionBarActivity implements
@Override
public void onClick(View v) {
long keyId = ProviderHelper.getMasterKeyId(ViewKeyActivity.this, mDataUri);
encryptToContact(mDataUri);
}
});
mActionCertify.setOnClickListener(new OnClickListener() {
long[] encryptionKeyIds = new long[]{keyId};
Intent intent = new Intent(ViewKeyActivity.this, EncryptActivity.class);
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
// used instead of startActivity set actionbar based on callingPackage
startActivityForResult(intent, 0);
@Override
public void onClick(View v) {
certifyKey(mDataUri);
}
});
mUserIdsAdapter = new ViewKeyUserIdsAdapter(this, null, 0);
mUserIds.setAdapter(mUserIdsAdapter);
// mUserIds.setEmptyView(findViewById(android.R.id.empty));
// mUserIds.setClickable(true);
@ -219,11 +218,10 @@ public class ViewKeyActivity extends ActionBarActivity implements
// });
mKeysAdapter = new ViewKeyKeysAdapter(this, null, 0);
mKeys.setAdapter(mKeysAdapter);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
// Prepare the loaders. Either re-connect with an existing ones,
// or start new ones.
getSupportLoaderManager().initLoader(LOADER_ID_KEYRING, null, this);
getSupportLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
getSupportLoaderManager().initLoader(LOADER_ID_KEYS, null, this);
@ -405,8 +403,19 @@ public class ViewKeyActivity extends ActionBarActivity implements
startActivityForResult(queryIntent, Id.request.look_up_key_id);
}
private void signKey(Uri dataUri) {
Intent signIntent = new Intent(this, SignKeyActivity.class);
private void encryptToContact(Uri dataUri) {
long keyId = ProviderHelper.getMasterKeyId(ViewKeyActivity.this, dataUri);
long[] encryptionKeyIds = new long[]{keyId};
Intent intent = new Intent(ViewKeyActivity.this, EncryptActivity.class);
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
// used instead of startActivity set actionbar based on callingPackage
startActivityForResult(intent, 0);
}
private void certifyKey(Uri dataUri) {
Intent signIntent = new Intent(this, CertifyKeyActivity.class);
signIntent.setData(dataUri);
startActivity(signIntent);
}

View File

@ -60,7 +60,7 @@
android:layout_height="60dp"
android:layout_marginBottom="4dp"
android:layout_marginTop="14dp"
android:text="@string/btn_sign"
android:text="@string/btn_certify"
bootstrapbutton:bb_icon_left="fa-pencil"
bootstrapbutton:bb_type="info" />
</LinearLayout>

View File

@ -215,6 +215,15 @@
android:text="@string/key_view_action_encrypt"
bootstrapbutton:bb_icon_left="fa-lock"
bootstrapbutton:bb_type="info" />
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/action_certify"
android:layout_width="match_parent"
android:layout_height="60dp"
android:padding="4dp"
android:text="@string/key_view_action_certify"
bootstrapbutton:bb_icon_left="fa-pencil"
bootstrapbutton:bb_type="info" />
</LinearLayout>
</ScrollView>

View File

@ -64,10 +64,6 @@
android:title="@string/menu_export_key_to_server" />
</menu>
</item>
<item
android:id="@+id/menu_key_view_sign"
app:showAsAction="ifRoom"
android:title="@string/menu_sign_key" />
<item
android:id="@+id/menu_key_view_export_file"
app:showAsAction="never"

View File

@ -25,7 +25,7 @@
<string name="title_key_server_query">Schlüssel-Server abfragen</string>
<string name="title_send_key">Auf Schlüsselserver hochladen</string>
<string name="title_unknown_signature_key">Unbekannter Signaturschlüssel</string>
<string name="title_sign_key">Schlüssel signieren</string>
<string name="title_certify_key">Schlüssel signieren</string>
<string name="title_key_details">Schlüsseldetails</string>
<string name="title_help">Hilfe</string>
<!--section-->

View File

@ -22,7 +22,7 @@
<string name="title_key_not_found">Clave no encontrada</string>
<string name="title_key_server_query">Solicitar al servidor de claves</string>
<string name="title_unknown_signature_key">Clave de firma desconocida</string>
<string name="title_sign_key">Clave de firma</string>
<string name="title_certify_key">Clave de firma</string>
<string name="title_help">Ayuda</string>
<!--section-->
<string name="section_user_ids">IDs de usuario</string>

View File

@ -25,7 +25,7 @@
<string name="title_key_server_query">Interroger le serveur de clefs</string>
<string name="title_send_key">Téléverser vers le serveur de clefs</string>
<string name="title_unknown_signature_key">Clef de signature inconnue</string>
<string name="title_sign_key">Signer la clef</string>
<string name="title_certify_key">Signer la clef</string>
<string name="title_key_details">Détails sur la clef</string>
<string name="title_help">Aide</string>
<!--section-->

View File

@ -15,7 +15,7 @@
<string name="title_export_key">Esportare Chiave</string>
<string name="title_export_keys">Esportare Chiavi</string>
<string name="title_key_not_found">Chiave Non Trovata</string>
<string name="title_sign_key">Firma Chiave</string>
<string name="title_certify_key">Firma Chiave</string>
<string name="title_help">Aiuto</string>
<!--section-->
<string name="section_user_ids">ID Utente</string>

View File

@ -22,7 +22,7 @@
<string name="title_key_not_found">Sleutel niet gevonden</string>
<string name="title_key_server_query">Sleutelserver verzoek zenden</string>
<string name="title_unknown_signature_key">Onbekende handtekeningssleutel</string>
<string name="title_sign_key">Sleutel ondertekenen</string>
<string name="title_certify_key">Sleutel ondertekenen</string>
<string name="title_help">Help</string>
<!--section-->
<string name="section_user_ids">Gebruikers-id\'s</string>

View File

@ -25,7 +25,7 @@
<string name="title_key_server_query">Запросить сервер ключей</string>
<string name="title_send_key">Загрузить на сервер ключей</string>
<string name="title_unknown_signature_key">Неизвестная подпись</string>
<string name="title_sign_key">Ключ для подписи</string>
<string name="title_certify_key">Ключ для подписи</string>
<string name="title_key_details">Сведения о ключе</string>
<string name="title_help">Помощь</string>
<!--section-->

View File

@ -14,7 +14,7 @@
<string name="title_key_not_found">Anahtar Bulunamadı</string>
<string name="title_key_server_query">Anahtar Sunucusunu Sorgula</string>
<string name="title_unknown_signature_key">Bilinmeyen İmza Anahtarı</string>
<string name="title_sign_key">Anahtarı İmzala</string>
<string name="title_certify_key">Anahtarı İmzala</string>
<string name="title_key_details">Anahtar Detayları</string>
<string name="title_help">Yardım</string>
<!--section-->

View File

@ -25,7 +25,7 @@
<string name="title_key_server_query">Сервер запиту ключа</string>
<string name="title_send_key">Завантажити на сервер ключів</string>
<string name="title_unknown_signature_key">Невідомий підпис ключа</string>
<string name="title_sign_key">Підписати ключ</string>
<string name="title_certify_key">Підписати ключ</string>
<string name="title_key_details">Подробиці про ключ</string>
<string name="title_help">Довідка</string>
<!--section-->

View File

@ -26,7 +26,7 @@
<string name="title_key_server_query">Query Key Server</string>
<string name="title_send_key">Upload to Key Server</string>
<string name="title_unknown_signature_key">Unknown Signature Key</string>
<string name="title_sign_key">Sign Key</string>
<string name="title_certify_key">Certify Key</string>
<string name="title_key_details">Key Details</string>
<string name="title_help">Help</string>
@ -39,7 +39,7 @@
<string name="section_master_key">Master Key</string>
<string name="section_master_user_id">Master User ID</string>
<string name="section_actions">Actions</string>
<string name="section_signing_key">Your Key used for Signing</string>
<string name="section_certification_key">Your Key used for certification</string>
<string name="section_upload_key">Upload Key</string>
<string name="section_key_server">Key Server</string>
<string name="section_encrypt_and_or_sign">Encrypt and/or Sign</string>
@ -47,6 +47,7 @@
<!-- button -->
<string name="btn_sign">Sign</string>
<string name="btn_certify">Certify</string>
<string name="btn_decrypt">Decrypt</string>
<string name="btn_decrypt_verify">Decrypt and Verify</string>
<string name="btn_select_encrypt_keys">Select Recipients</string>
@ -126,7 +127,7 @@
<string name="label_name">Name</string>
<string name="label_comment">Comment</string>
<string name="label_email">Email</string>
<string name="label_send_key">Upload key to selected key server after signing</string>
<string name="label_send_key">Upload key to selected key server after certification</string>
<string name="label_fingerprint">Fingerprint</string>
<string name="select_keys_button_default">Select</string>
@ -406,6 +407,7 @@
<!-- Key view -->
<string name="key_view_action_encrypt">Encrypt to this contact</string>
<string name="key_view_action_certify">Certify User ID of this contact</string>
<!-- Navigation Drawer -->
<string name="nav_contacts">Contacts</string>