Merge branch 'master' into improve-file-more

Conflicts:
	OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
	OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java
This commit is contained in:
mar-v-in
2014-08-01 05:29:40 +02:00
25 changed files with 297 additions and 204 deletions

View File

@@ -285,9 +285,9 @@ public class HkpKeyserver extends Keyserver {
// group 1 contains the full fingerprint (v4) or the long key id if available
// see http://bit.ly/1d4bxbk and http://bit.ly/1gD1wwr
String fingerprintOrKeyId = matcher.group(1);
String fingerprintOrKeyId = matcher.group(1).toLowerCase(Locale.US);
if (fingerprintOrKeyId.length() > 16) {
entry.setFingerprintHex(fingerprintOrKeyId.toLowerCase(Locale.US));
entry.setFingerprintHex(fingerprintOrKeyId);
entry.setKeyIdHex("0x" + fingerprintOrKeyId.substring(fingerprintOrKeyId.length()
- 16, fingerprintOrKeyId.length()));
} else {

View File

@@ -354,7 +354,7 @@ public class PgpKeyOperation {
subProgressPush(15, 25);
for (int i = 0; i < saveParcel.mAddUserIds.size(); i++) {
progress(R.string.progress_modify_adduid, (i-1) * (100 / saveParcel.mAddSubKeys.size()));
progress(R.string.progress_modify_adduid, (i-1) * (100 / saveParcel.mAddUserIds.size()));
String userId = saveParcel.mAddUserIds.get(i);
log.add(LogLevel.INFO, LogType.MSG_MF_UID_ADD, indent);
@@ -399,7 +399,7 @@ public class PgpKeyOperation {
subProgressPush(25, 40);
for (int i = 0; i < saveParcel.mRevokeUserIds.size(); i++) {
progress(R.string.progress_modify_revokeuid, (i-1) * (100 / saveParcel.mAddSubKeys.size()));
progress(R.string.progress_modify_revokeuid, (i-1) * (100 / saveParcel.mRevokeUserIds.size()));
String userId = saveParcel.mRevokeUserIds.get(i);
log.add(LogLevel.INFO, LogType.MSG_MF_UID_REVOKE, indent, userId);
@@ -522,7 +522,7 @@ public class PgpKeyOperation {
subProgressPush(50, 60);
for (int i = 0; i < saveParcel.mChangeSubKeys.size(); i++) {
progress(R.string.progress_modify_subkeychange, (i-1) * (100 / saveParcel.mAddSubKeys.size()));
progress(R.string.progress_modify_subkeychange, (i-1) * (100 / saveParcel.mChangeSubKeys.size()));
SaveKeyringParcel.SubkeyChange change = saveParcel.mChangeSubKeys.get(i);
log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_CHANGE,
indent, PgpKeyHelper.convertKeyIdToHex(change.mKeyId));
@@ -583,7 +583,7 @@ public class PgpKeyOperation {
subProgressPush(60, 70);
for (int i = 0; i < saveParcel.mRevokeSubKeys.size(); i++) {
progress(R.string.progress_modify_subkeyrevoke, (i-1) * (100 / saveParcel.mAddSubKeys.size()));
progress(R.string.progress_modify_subkeyrevoke, (i-1) * (100 / saveParcel.mRevokeSubKeys.size()));
long revocation = saveParcel.mRevokeSubKeys.get(i);
log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_REVOKE,
indent, PgpKeyHelper.convertKeyIdToHex(revocation));

View File

@@ -300,14 +300,14 @@ public class UncachedKeyRing {
revocation = zert;
// more revocations? at least one is superfluous, then.
} else if (revocation.getCreationTime().before(zert.getCreationTime())) {
log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, indent);
modified = PGPPublicKey.removeCertification(modified, revocation);
redundantCerts += 1;
log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, indent);
revocation = zert;
} else {
log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, indent);
modified = PGPPublicKey.removeCertification(modified, zert);
redundantCerts += 1;
log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, indent);
}
}
@@ -331,12 +331,13 @@ public class UncachedKeyRing {
indent, "0x" + Integer.toString(zert.getSignatureType(), 16));
modified = PGPPublicKey.removeCertification(modified, userId, zert);
badCerts += 1;
continue;
}
if (cert.getCreationTime().after(now)) {
// Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_TIME, indent);
modified = PGPPublicKey.removeCertification(modified, zert);
modified = PGPPublicKey.removeCertification(modified, userId, zert);
badCerts += 1;
continue;
}
@@ -344,7 +345,7 @@ public class UncachedKeyRing {
if (cert.isLocal()) {
// Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_LOCAL, indent);
modified = PGPPublicKey.removeCertification(modified, zert);
modified = PGPPublicKey.removeCertification(modified, userId, zert);
badCerts += 1;
continue;
}
@@ -387,35 +388,35 @@ public class UncachedKeyRing {
if (selfCert == null) {
selfCert = zert;
} else if (selfCert.getCreationTime().before(cert.getCreationTime())) {
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP,
indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, selfCert);
redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP,
indent, userId);
selfCert = zert;
} else {
modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP,
indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1;
}
// If there is a revocation certificate, and it's older than this, drop it
if (revocation != null
&& revocation.getCreationTime().before(selfCert.getCreationTime())) {
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_OLD,
indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, revocation);
revocation = null;
redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_OLD,
indent, userId);
}
break;
case PGPSignature.CERTIFICATION_REVOCATION:
// If this is older than the (latest) self cert, drop it
if (selfCert != null && selfCert.getCreationTime().after(zert.getCreationTime())) {
modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_OLD,
indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1;
continue;
}
// first revocation? remember it.
@@ -423,16 +424,16 @@ public class UncachedKeyRing {
revocation = zert;
// more revocations? at least one is superfluous, then.
} else if (revocation.getCreationTime().before(cert.getCreationTime())) {
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_DUP,
indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, revocation);
redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_DUP,
indent, userId);
revocation = zert;
} else {
modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_DUP,
indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1;
}
break;
@@ -442,9 +443,9 @@ public class UncachedKeyRing {
// If no valid certificate (if only a revocation) remains, drop it
if (selfCert == null && revocation == null) {
modified = PGPPublicKey.removeCertification(modified, userId);
log.add(LogLevel.ERROR, LogType.MSG_KC_UID_REMOVE,
indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId);
}
}

View File

@@ -535,6 +535,11 @@ public class KeychainIntentService extends IntentService
Intent importIntent = new Intent(this, KeychainIntentService.class);
importIntent.setAction(ACTION_IMPORT_KEYRING);
// TODO: don't use FileImportCache
// externalize import key into function
FileImportCache cache = new FileImportCache(this);
cache.writeCache(keyRings);
Bundle importData = new Bundle();
importIntent.putExtra(EXTRA_DATA, importData);
importIntent.putExtra(EXTRA_MESSENGER, mMessenger);

View File

@@ -139,7 +139,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements
Notify.showNotify(CertifyKeyActivity.this, getString(R.string.select_key_to_certify),
Notify.Style.ERROR);
} else {
initiateSigning();
initiateCertifying();
}
}
}
@@ -229,7 +229,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements
/**
* handles the UI bits of the signing process on the UI thread
*/
private void initiateSigning() {
private void initiateCertifying() {
// get the user's passphrase for this key (if required)
String passphrase = PassphraseCacheService.getCachedPassphrase(this, mMasterKeyId);
if (passphrase == null) {
@@ -238,7 +238,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements
@Override
public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
startSigning();
startCertifying();
}
}
}
@@ -246,15 +246,14 @@ public class CertifyKeyActivity extends ActionBarActivity implements
// bail out; need to wait until the user has entered the passphrase before trying again
return;
} else {
startSigning();
startCertifying();
}
}
/**
* kicks off the actual signing process on a background thread
*/
private void startSigning() {
private void startCertifying() {
// Bail out if there is not at least one user id selected
ArrayList<String> userIds = mUserIdsAdapter.getSelectedUserIds();
if (userIds.isEmpty()) {
@@ -279,7 +278,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements
// Message is received after signing is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
getString(R.string.progress_signing), ProgressDialog.STYLE_SPINNER) {
getString(R.string.progress_certifying), ProgressDialog.STYLE_SPINNER) {
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
@@ -333,7 +332,7 @@ public class CertifyKeyActivity extends ActionBarActivity implements
// Message is received after uploading is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL) {
getString(R.string.progress_uploading), ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);

View File

@@ -145,20 +145,20 @@ public class CreateKeyFinalFragment extends Fragment {
return;
}
if (mUploadCheckbox.isChecked()) {
if (result.getResult() == OperationResultParcel.RESULT_OK) {
if (result.getResult() == OperationResultParcel.RESULT_OK) {
if (mUploadCheckbox.isChecked()) {
// result will be displayed after upload
uploadKey(result);
} else {
// display result on error without finishing activity
// TODO: return result
result.createNotify(getActivity());
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
}
} else {
// TODO: return result
// display result on error without finishing activity
result.createNotify(getActivity());
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
}
}
}
@@ -196,9 +196,8 @@ public class CreateKeyFinalFragment extends Fragment {
intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING);
// set data uri as path to keyring
Uri blobUri = KeychainContract.KeyRingData.buildPublicKeyRingUri(
Long.toString(editKeyResult.mRingMasterKeyId)
);
Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(
editKeyResult.mRingMasterKeyId);
intent.setData(blobUri);
// fill values for this action
@@ -212,14 +211,15 @@ public class CreateKeyFinalFragment extends Fragment {
// Message is received after uploading is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL) {
getString(R.string.progress_uploading), ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
// TODO: return results
// TODO: not supported by upload?
// if (result.getResult() == OperationResultParcel.RESULT_OK) {
// TODO: return result
editKeyResult.createNotify(getActivity());
Notify.showNotify(getActivity(), R.string.key_send_success,
@@ -227,6 +227,10 @@ public class CreateKeyFinalFragment extends Fragment {
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
// } else {
// // display result on error without finishing activity
// editKeyResult.createNotify(getActivity());
// }
}
}
};

View File

@@ -30,8 +30,11 @@ import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Button;
import com.tokenautocomplete.TokenCompleteTextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;

View File

@@ -100,6 +100,7 @@ public class ImportKeysActivity extends ActionBarActivity {
public static final int VIEW_PAGER_HEIGHT = 64; // dp
private static final int ALL_TABS = -1;
private static final int TAB_KEYSERVER = 0;
private static final int TAB_QR_CODE = 1;
private static final int TAB_FILE = 2;
@@ -152,7 +153,7 @@ public class ImportKeysActivity extends ActionBarActivity {
}
Bundle serverBundle = null;
boolean serverOnly = false;
int showTabOnly = ALL_TABS;
if (ACTION_IMPORT_KEY.equals(action)) {
/* Keychain's own Actions */
@@ -216,7 +217,7 @@ public class ImportKeysActivity extends ActionBarActivity {
serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query);
serverBundle.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
// display server tab only
serverOnly = true;
showTabOnly = TAB_KEYSERVER;
mSwitchToTab = TAB_KEYSERVER;
// action: search immediately
@@ -229,11 +230,18 @@ public class ImportKeysActivity extends ActionBarActivity {
);
return;
}
} else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)
|| ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(action)) {
} else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
// NOTE: this only displays the appropriate fragment, no actions are taken
mSwitchToTab = TAB_FILE;
// no immediate actions!
startListFragment(savedInstanceState, null, null, null);
} else if (ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(action)) {
// NOTE: this only displays the appropriate fragment, no actions are taken
mSwitchToTab = TAB_FILE;
// display file tab only
showTabOnly = TAB_FILE;
// no immediate actions!
startListFragment(savedInstanceState, null, null, null);
} else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) {
@@ -261,10 +269,10 @@ public class ImportKeysActivity extends ActionBarActivity {
startListFragment(savedInstanceState, null, null, null);
}
initTabs(serverBundle, serverOnly);
initTabs(serverBundle, showTabOnly);
}
private void initTabs(Bundle serverBundle, boolean serverOnly) {
private void initTabs(Bundle serverBundle, int showTabOnly) {
mTabsAdapter = new PagerTabStripAdapter(this);
mViewPager.setAdapter(mTabsAdapter);
mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@@ -287,15 +295,34 @@ public class ImportKeysActivity extends ActionBarActivity {
}
});
mTabsAdapter.addTab(ImportKeysServerFragment.class,
serverBundle, getString(R.string.import_tab_keyserver));
if (!serverOnly) {
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
null, getString(R.string.import_tab_qr_code));
mTabsAdapter.addTab(ImportKeysFileFragment.class,
null, getString(R.string.import_tab_direct));
mTabsAdapter.addTab(ImportKeysKeybaseFragment.class,
null, getString(R.string.import_tab_keybase));
switch (showTabOnly) {
case ALL_TABS:
// show all tabs
mTabsAdapter.addTab(ImportKeysServerFragment.class,
serverBundle, getString(R.string.import_tab_keyserver));
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
null, getString(R.string.import_tab_qr_code));
mTabsAdapter.addTab(ImportKeysFileFragment.class,
null, getString(R.string.import_tab_direct));
mTabsAdapter.addTab(ImportKeysKeybaseFragment.class,
null, getString(R.string.import_tab_keybase));
break;
case TAB_KEYSERVER:
mTabsAdapter.addTab(ImportKeysServerFragment.class,
serverBundle, getString(R.string.import_tab_keyserver));
break;
case TAB_QR_CODE:
mTabsAdapter.addTab(ImportKeysQrCodeFragment.class,
null, getString(R.string.import_tab_qr_code));
break;
case TAB_FILE:
mTabsAdapter.addTab(ImportKeysFileFragment.class,
null, getString(R.string.import_tab_direct));
break;
case TAB_KEYBASE:
mTabsAdapter.addTab(ImportKeysKeybaseFragment.class,
null, getString(R.string.import_tab_keybase));
break;
}
// update layout after operations

View File

@@ -74,7 +74,7 @@ public class KeyListActivity extends DrawerActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_key_list_import:
case R.id.menu_key_list_add:
importKeys();
return true;
@@ -82,6 +82,12 @@ public class KeyListActivity extends DrawerActivity {
createKey();
return true;
case R.id.menu_key_list_import_existing_key:
Intent intentImportExisting = new Intent(this, ImportKeysActivity.class);
intentImportExisting.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN);
startActivityForResult(intentImportExisting, 0);
return true;
case R.id.menu_key_list_export:
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
return true;

View File

@@ -475,41 +475,40 @@ public class KeyListFragment extends LoaderFragment
}
}
{ // set edit button and revoked info, specific by key type
{ // set edit button and status, specific by key type
if (cursor.getInt(KeyListFragment.INDEX_HAS_ANY_SECRET) != 0) {
// this is a secret key
h.mStatus.setVisibility(View.GONE);
} else {
// this is a public key - show if it's revoked, expired, or verified
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
boolean isExpired = !cursor.isNull(INDEX_EXPIRY)
&& new Date(cursor.getLong(INDEX_EXPIRY)*1000).before(new Date());
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
boolean isExpired = !cursor.isNull(INDEX_EXPIRY)
&& new Date(cursor.getLong(INDEX_EXPIRY)*1000).before(new Date());
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
// Note: order is important!
if (isRevoked) {
h.mStatus.setImageDrawable(
getResources().getDrawable(R.drawable.status_signature_revoked_cutout));
h.mStatus.setColorFilter(getResources().getColor(R.color.android_red_light),
PorterDuff.Mode.SRC_ATOP);
h.mStatus.setVisibility(View.VISIBLE);
} else if (isExpired) {
h.mStatus.setImageDrawable(
getResources().getDrawable(R.drawable.status_signature_expired_cutout));
h.mStatus.setColorFilter(getResources().getColor(R.color.android_orange_light),
PorterDuff.Mode.SRC_ATOP);
h.mStatus.setVisibility(View.VISIBLE);
} else if (isVerified) {
// Note: order is important!
if (isRevoked) {
h.mStatus.setImageDrawable(
getResources().getDrawable(R.drawable.status_signature_revoked_cutout));
h.mStatus.setColorFilter(getResources().getColor(R.color.android_red_dark),
PorterDuff.Mode.SRC_ATOP);
h.mStatus.setVisibility(View.VISIBLE);
} else if (isExpired) {
h.mStatus.setImageDrawable(
getResources().getDrawable(R.drawable.status_signature_expired_cutout));
h.mStatus.setColorFilter(getResources().getColor(R.color.android_orange_dark),
PorterDuff.Mode.SRC_ATOP);
h.mStatus.setVisibility(View.VISIBLE);
} else if (isVerified) {
if (cursor.getInt(KeyListFragment.INDEX_HAS_ANY_SECRET) != 0) {
// this is a secret key
h.mStatus.setVisibility(View.GONE);
} else {
// this is a public key - show if it's verified
h.mStatus.setImageDrawable(
getResources().getDrawable(R.drawable.status_signature_verified_cutout));
h.mStatus.setColorFilter(getResources().getColor(R.color.android_green_light),
h.mStatus.setColorFilter(getResources().getColor(R.color.android_green_dark),
PorterDuff.Mode.SRC_ATOP);
h.mStatus.setVisibility(View.VISIBLE);
} else {
h.mStatus.setVisibility(View.GONE);
}
} else {
h.mStatus.setVisibility(View.GONE);
}
}

View File

@@ -36,6 +36,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.util.Log;
@@ -92,7 +93,7 @@ public class UploadKeyActivity extends ActionBarActivity {
intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING);
// set data uri as path to keyring
Uri blobUri = KeychainContract.KeyRingData.buildPublicKeyRingUri(mDataUri);
Uri blobUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
intent.setData(blobUri);
// fill values for this action
@@ -105,7 +106,7 @@ public class UploadKeyActivity extends ActionBarActivity {
// Message is received after uploading is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL) {
getString(R.string.progress_uploading), ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);

View File

@@ -89,8 +89,6 @@ public class ViewKeyActivity extends ActionBarActivity implements
private ImageView mStatusImage;
private View mStatusDivider;
public static final int REQUEST_CODE_LOOKUP_KEY = 0x00007006;
// NFC
private NfcAdapter mNfcAdapter;
private NfcAdapter.CreateNdefMessageCallback mNdefCallback;
@@ -145,20 +143,27 @@ public class ViewKeyActivity extends ActionBarActivity implements
switchToTab = intent.getExtras().getInt(EXTRA_SELECTED_TAB);
}
Uri dataUri = getDataUri();
if (dataUri == null) {
Log.e(Constants.TAG, "Data missing. Should be Uri of key!");
mDataUri = getIntent().getData();
if (mDataUri == null) {
Log.e(Constants.TAG, "Data missing. Should be uri of key!");
finish();
return;
}
if (mDataUri.getHost().equals(ContactsContract.AUTHORITY)) {
mDataUri = ContactHelper.dataUriFromContactUri(this, mDataUri);
}
loadData(dataUri);
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
initNfc(dataUri);
// Prepare the loaders. Either re-connect with an existing ones,
// or start new ones.
getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
initNfc(mDataUri);
mShowAdvancedTabs = false;
initTabs(dataUri);
initTabs(mDataUri);
// switch to tab selected by extra
mViewPager.setCurrentItem(switchToTab);
@@ -235,24 +240,6 @@ public class ViewKeyActivity extends ActionBarActivity implements
mSlidingTabLayout.setViewPager(mViewPager);
}
private Uri getDataUri() {
Uri dataUri = getIntent().getData();
if (dataUri != null && dataUri.getHost().equals(ContactsContract.AUTHORITY)) {
dataUri = ContactHelper.dataUriFromContactUri(this, dataUri);
}
return dataUri;
}
private void loadData(Uri dataUri) {
mDataUri = dataUri;
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
// Prepare the loaders. Either re-connect with an existing ones,
// or start new ones.
getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
@@ -273,14 +260,6 @@ public class ViewKeyActivity extends ActionBarActivity implements
startActivity(homeIntent);
return true;
}
case R.id.menu_key_view_update: {
updateFromKeyserver(mDataUri, mProviderHelper);
return true;
}
case R.id.menu_key_view_export_keyserver: {
uploadToKeyserver(mDataUri);
return true;
}
case R.id.menu_key_view_export_file: {
exportToFile(mDataUri, mExportHelper, mProviderHelper);
return true;
@@ -321,26 +300,6 @@ public class ViewKeyActivity extends ActionBarActivity implements
);
}
private void uploadToKeyserver(Uri dataUri) throws ProviderHelper.NotFoundException {
Intent uploadIntent = new Intent(this, UploadKeyActivity.class);
uploadIntent.setData(dataUri);
startActivityForResult(uploadIntent, 0);
}
private void updateFromKeyserver(Uri dataUri, ProviderHelper providerHelper)
throws ProviderHelper.NotFoundException {
byte[] blob = (byte[]) providerHelper.getGenericData(
KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri),
KeychainContract.Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
String fingerprint = PgpKeyHelper.convertFingerprintToHex(blob);
Intent queryIntent = new Intent(this, ImportKeysActivity.class);
queryIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT);
queryIntent.putExtra(ImportKeysActivity.EXTRA_FINGERPRINT, fingerprint);
startActivityForResult(queryIntent, REQUEST_CODE_LOOKUP_KEY);
}
private void deleteKey(Uri dataUri, ExportHelper exportHelper) {
// Message is received after key is deleted
Handler returnHandler = new Handler() {
@@ -515,19 +474,19 @@ public class ViewKeyActivity extends ActionBarActivity implements
// Note: order is important
if (isRevoked) {
mStatusText.setText(R.string.view_key_revoked);
mStatusText.setTextColor(getResources().getColor(R.color.android_red_light));
mStatusText.setTextColor(getResources().getColor(R.color.android_red_dark));
mStatusImage.setImageDrawable(
getResources().getDrawable(R.drawable.status_signature_revoked_cutout));
mStatusImage.setColorFilter(getResources().getColor(R.color.android_red_light),
mStatusImage.setColorFilter(getResources().getColor(R.color.android_red_dark),
PorterDuff.Mode.SRC_ATOP);
mStatusDivider.setVisibility(View.VISIBLE);
mStatusLayout.setVisibility(View.VISIBLE);
} else if (isExpired) {
mStatusText.setText(R.string.view_key_expired);
mStatusText.setTextColor(getResources().getColor(R.color.android_orange_light));
mStatusText.setTextColor(getResources().getColor(R.color.android_orange_dark));
mStatusImage.setImageDrawable(
getResources().getDrawable(R.drawable.status_signature_expired_cutout));
mStatusImage.setColorFilter(getResources().getColor(R.color.android_orange_light),
mStatusImage.setColorFilter(getResources().getColor(R.color.android_orange_dark),
PorterDuff.Mode.SRC_ATOP);
mStatusDivider.setVisibility(View.VISIBLE);
mStatusLayout.setVisibility(View.VISIBLE);

View File

@@ -33,11 +33,13 @@ import android.widget.ListView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Notify;
@@ -55,7 +57,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements
private View mActionCertify;
private View mActionCertifyText;
private ImageView mActionCertifyImage;
private View mActionCertifyDivider;
private View mActionUpdate;
private ListView mUserIds;
@@ -84,7 +86,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements
// make certify image gray, like action icons
mActionCertifyImage.setColorFilter(getResources().getColor(R.color.tertiary_text_light),
PorterDuff.Mode.SRC_IN);
mActionCertifyDivider = view.findViewById(R.id.view_key_action_certify_divider);
mActionUpdate = view.findViewById(R.id.view_key_action_update);
return root;
}
@@ -124,6 +126,15 @@ public class ViewKeyMainFragment extends LoaderFragment implements
editKey(mDataUri);
}
});
mActionUpdate.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
try {
updateFromKeyserver(mDataUri, new ProviderHelper(getActivity()));
} catch (NotFoundException e) {
Notify.showNotify(getActivity(), R.string.error_key_not_found, Notify.Style.ERROR);
}
}
});
mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0);
mUserIds.setAdapter(mUserIdsAdapter);
@@ -254,6 +265,20 @@ public class ViewKeyMainFragment extends LoaderFragment implements
}
}
private void updateFromKeyserver(Uri dataUri, ProviderHelper providerHelper)
throws ProviderHelper.NotFoundException {
byte[] blob = (byte[]) providerHelper.getGenericData(
KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri),
KeychainContract.Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
String fingerprint = PgpKeyHelper.convertFingerprintToHex(blob);
Intent queryIntent = new Intent(getActivity(), ImportKeysActivity.class);
queryIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT);
queryIntent.putExtra(ImportKeysActivity.EXTRA_FINGERPRINT, fingerprint);
startActivityForResult(queryIntent, 0);
}
private void certify(Uri dataUri) {
Intent signIntent = new Intent(getActivity(), CertifyKeyActivity.class);
signIntent.setData(dataUri);

View File

@@ -49,6 +49,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
import org.sufficientlysecure.keychain.ui.dialog.ShareNfcDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Notify;
@@ -70,6 +71,7 @@ public class ViewKeyShareFragment extends LoaderFragment implements
private View mKeyClipboardButton;
private View mNfcHelpButton;
private View mNfcPrefsButton;
private View mKeyUploadButton;
ProviderHelper mProviderHelper;
@@ -94,6 +96,7 @@ public class ViewKeyShareFragment extends LoaderFragment implements
mKeyClipboardButton = view.findViewById(R.id.view_key_action_key_clipboard);
mNfcHelpButton = view.findViewById(R.id.view_key_action_nfc_help);
mNfcPrefsButton = view.findViewById(R.id.view_key_action_nfc_prefs);
mKeyUploadButton = view.findViewById(R.id.view_key_action_upload);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mNfcPrefsButton.setVisibility(View.VISIBLE);
@@ -144,6 +147,12 @@ public class ViewKeyShareFragment extends LoaderFragment implements
showNfcPrefs();
}
});
mKeyUploadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
uploadToKeyserver();
}
});
return root;
}
@@ -345,4 +354,11 @@ public class ViewKeyShareFragment extends LoaderFragment implements
loadTask.execute();
}
private void uploadToKeyserver() {
Intent uploadIntent = new Intent(getActivity(), UploadKeyActivity.class);
uploadIntent.setData(mDataUri);
startActivityForResult(uploadIntent, 0);
}
}

View File

@@ -188,7 +188,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
case Certs.VERIFIED_SECRET:
vVerified.setImageResource(R.drawable.status_signature_verified_cutout);
vVerified.setColorFilter(
mContext.getResources().getColor(R.color.android_green_light),
mContext.getResources().getColor(R.color.android_green_dark),
PorterDuff.Mode.SRC_IN);
break;
case Certs.VERIFIED_SELF:
@@ -200,7 +200,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
default:
vVerified.setImageResource(R.drawable.status_signature_invalid_cutout);
vVerified.setColorFilter(
mContext.getResources().getColor(R.color.android_red_light),
mContext.getResources().getColor(R.color.android_red_dark),
PorterDuff.Mode.SRC_IN);
break;
}