mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
Update Intent API
This commit is contained in:
parent
bf7fb08bca
commit
f5b53b58f7
@ -146,7 +146,6 @@
|
|||||||
<!-- Keychain's own Actions -->
|
<!-- Keychain's own Actions -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.sufficientlysecure.keychain.action.ENCRYPT" />
|
<action android:name="org.sufficientlysecure.keychain.action.ENCRYPT" />
|
||||||
<action android:name="org.sufficientlysecure.keychain.action.ENCRYPT_FILE" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
@ -171,7 +170,6 @@
|
|||||||
<!-- Keychain's own Actions -->
|
<!-- Keychain's own Actions -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.sufficientlysecure.keychain.action.DECRYPT" />
|
<action android:name="org.sufficientlysecure.keychain.action.DECRYPT" />
|
||||||
<action android:name="org.sufficientlysecure.keychain.action.DECRYPT_FILE" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@
|
|||||||
|
|
||||||
<!-- btn_lowerCase: capitalized words, no punctuation -->
|
<!-- btn_lowerCase: capitalized words, no punctuation -->
|
||||||
<string name="btn_signToClipboard">Sign (Clipboard)</string>
|
<string name="btn_signToClipboard">Sign (Clipboard)</string>
|
||||||
<string name="btn_encryptToClipboard">Encrypt (Clipboard)</string>
|
<string name="btn_encryptToClipboard">Encrypt to Clipboard</string>
|
||||||
<string name="btn_encryptAndEmail">Encrypt (Email)</string>
|
<string name="btn_encryptAndSend">Encrypt and send…</string>
|
||||||
<string name="btn_signAndEmail">Sign (Email)</string>
|
<string name="btn_signAndSend">Sign and send…</string>
|
||||||
<string name="btn_encrypt">Encrypt</string>
|
<string name="btn_encrypt">Encrypt</string>
|
||||||
<string name="btn_sign">Sign</string>
|
<string name="btn_sign">Sign</string>
|
||||||
<string name="btn_decrypt">Decrypt</string>
|
<string name="btn_decrypt">Decrypt</string>
|
||||||
|
@ -74,19 +74,13 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
/* Intents */
|
/* Intents */
|
||||||
// without permission
|
// without permission
|
||||||
public static final String ACTION_DECRYPT = Constants.INTENT_PREFIX + "DECRYPT";
|
public static final String ACTION_DECRYPT = Constants.INTENT_PREFIX + "DECRYPT";
|
||||||
public static final String ACTION_DECRYPT_FILE = Constants.INTENT_PREFIX + "DECRYPT_FILE";
|
|
||||||
|
|
||||||
/* EXTRA keys for input */
|
/* EXTRA keys for input */
|
||||||
public static final String EXTRA_TEXT = "text";
|
public static final String EXTRA_TEXT = "text";
|
||||||
public static final String EXTRA_DATA = "data";
|
|
||||||
public static final String EXTRA_REPLY_TO = "reply_to";
|
|
||||||
public static final String EXTRA_SUBJECT = "subject";
|
|
||||||
|
|
||||||
private long mSignatureKeyId = 0;
|
private long mSignatureKeyId = 0;
|
||||||
|
|
||||||
private boolean mReturnResult = false;
|
private boolean mReturnResult = false;
|
||||||
private String mReplyTo = null;
|
|
||||||
private String mSubject = null;
|
|
||||||
private boolean mSignedOnly = false;
|
private boolean mSignedOnly = false;
|
||||||
private boolean mAssumeSymmetricEncryption = false;
|
private boolean mAssumeSymmetricEncryption = false;
|
||||||
|
|
||||||
@ -116,7 +110,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
private String mOutputFilename = null;
|
private String mOutputFilename = null;
|
||||||
|
|
||||||
private Uri mContentUri = null;
|
private Uri mContentUri = null;
|
||||||
private byte[] mDataBytes = null;
|
|
||||||
private boolean mReturnBinary = false;
|
private boolean mReturnBinary = false;
|
||||||
|
|
||||||
private long mUnknownSignatureKeyId = 0;
|
private long mUnknownSignatureKeyId = 0;
|
||||||
@ -310,7 +303,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
if (mDecryptImmediately
|
if (mDecryptImmediately
|
||||||
|| (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText()
|
|| (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText()
|
||||||
.length() > 0 || mDataBytes != null || mContentUri != null))) {
|
.length() > 0 || mContentUri != null))) {
|
||||||
decryptClicked();
|
decryptClicked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,7 +327,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
* Android's Action
|
* Android's Action
|
||||||
*/
|
*/
|
||||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||||
// When sending to APG Encrypt via share menu
|
// When sending to Keychain Encrypt via share menu
|
||||||
if ("text/plain".equals(type)) {
|
if ("text/plain".equals(type)) {
|
||||||
// Plain text
|
// Plain text
|
||||||
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
@ -348,83 +341,46 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
// Binary via content provider (could also be files)
|
// Binary via content provider (could also be files)
|
||||||
// override uri to get stream from send
|
// override uri to get stream from send
|
||||||
uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
action = ACTION_DECRYPT_FILE;
|
action = ACTION_DECRYPT;
|
||||||
}
|
}
|
||||||
} else if (Intent.ACTION_VIEW.equals(action)) {
|
} else if (Intent.ACTION_VIEW.equals(action)) {
|
||||||
// Android's Action when opening file associated to APG (see AndroidManifest.xml)
|
// Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
|
||||||
|
|
||||||
// override action
|
// override action
|
||||||
action = ACTION_DECRYPT_FILE;
|
action = ACTION_DECRYPT;
|
||||||
|
|
||||||
// EVERYTHING ELSE IS OLD CODE
|
|
||||||
// This gets the Uri, where an inputStream can be opened from
|
|
||||||
// mContentUri = intent.getData();
|
|
||||||
|
|
||||||
// TODO: old implementation of ACTION_VIEW. Is this used in K9?
|
|
||||||
// Uri uri = mIntent.getData();
|
|
||||||
// try {
|
|
||||||
// InputStream attachment = getContentResolver().openInputStream(uri);
|
|
||||||
// ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
|
||||||
// byte bytes[] = new byte[1 << 16];
|
|
||||||
// int length;
|
|
||||||
// while ((length = attachment.read(bytes)) > 0) {
|
|
||||||
// byteOut.write(bytes, 0, length);
|
|
||||||
// }
|
|
||||||
// byteOut.close();
|
|
||||||
// String data = new String(byteOut.toByteArray());
|
|
||||||
// mMessage.setText(data);
|
|
||||||
// } catch (FileNotFoundException e) {
|
|
||||||
// // ignore, then
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// // ignore, then
|
|
||||||
// }
|
|
||||||
|
|
||||||
// same as ACTION_DECRYPT_FILE but decrypt it immediately
|
|
||||||
// handleActionDecryptFile(intent);
|
|
||||||
// mDecryptImmediately = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String textData = extras.getString(EXTRA_TEXT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Actions
|
* Main Actions
|
||||||
*/
|
*/
|
||||||
if (ACTION_DECRYPT.equals(action)) {
|
if (ACTION_DECRYPT.equals(action) && textData != null) {
|
||||||
mDataBytes = extras.getByteArray(EXTRA_DATA);
|
Log.d(Constants.TAG, "textData null, matching text ...");
|
||||||
String textData = null;
|
Matcher matcher = PgpMain.PGP_MESSAGE.matcher(textData);
|
||||||
if (mDataBytes == null) {
|
if (matcher.matches()) {
|
||||||
Log.d(Constants.TAG, "EXTRA_DATA was null");
|
Log.d(Constants.TAG, "PGP_MESSAGE matched");
|
||||||
textData = extras.getString(EXTRA_TEXT);
|
textData = matcher.group(1);
|
||||||
|
// replace non breakable spaces
|
||||||
|
textData = textData.replaceAll("\\xa0", " ");
|
||||||
|
mMessage.setText(textData);
|
||||||
} else {
|
} else {
|
||||||
Log.d(Constants.TAG, "Got data from EXTRA_DATA");
|
matcher = PgpMain.PGP_SIGNED_MESSAGE.matcher(textData);
|
||||||
}
|
|
||||||
if (textData != null) {
|
|
||||||
Log.d(Constants.TAG, "textData null, matching text ...");
|
|
||||||
Matcher matcher = PgpMain.PGP_MESSAGE.matcher(textData);
|
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
Log.d(Constants.TAG, "PGP_MESSAGE matched");
|
Log.d(Constants.TAG, "PGP_SIGNED_MESSAGE matched");
|
||||||
textData = matcher.group(1);
|
textData = matcher.group(1);
|
||||||
// replace non breakable spaces
|
// replace non breakable spaces
|
||||||
textData = textData.replaceAll("\\xa0", " ");
|
textData = textData.replaceAll("\\xa0", " ");
|
||||||
mMessage.setText(textData);
|
mMessage.setText(textData);
|
||||||
} else {
|
|
||||||
matcher = PgpMain.PGP_SIGNED_MESSAGE.matcher(textData);
|
|
||||||
if (matcher.matches()) {
|
|
||||||
Log.d(Constants.TAG, "PGP_SIGNED_MESSAGE matched");
|
|
||||||
textData = matcher.group(1);
|
|
||||||
// replace non breakable spaces
|
|
||||||
textData = textData.replaceAll("\\xa0", " ");
|
|
||||||
mMessage.setText(textData);
|
|
||||||
|
|
||||||
mDecryptString = getString(R.string.btn_verify);
|
mDecryptString = getString(R.string.btn_verify);
|
||||||
// build new action bar
|
// build new action bar
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
} else {
|
} else {
|
||||||
Log.d(Constants.TAG, "Nothing matched!");
|
Log.d(Constants.TAG, "Nothing matched!");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mReplyTo = extras.getString(EXTRA_REPLY_TO);
|
} else if (ACTION_DECRYPT.equals(action) && uri != null) {
|
||||||
mSubject = extras.getString(EXTRA_SUBJECT);
|
|
||||||
} else if (ACTION_DECRYPT_FILE.equals(action)) {
|
|
||||||
// get file path from uri
|
// get file path from uri
|
||||||
String path = FileHelper.getPath(this, uri);
|
String path = FileHelper.getPath(this, uri);
|
||||||
|
|
||||||
@ -439,45 +395,16 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG,
|
Log.e(Constants.TAG,
|
||||||
"Direct binary data without actual file in filesystem is not supported. This is only supported by ACTION_DECRYPT_STREAM_AND_RETURN.");
|
"Direct binary data without actual file in filesystem is not supported. Please use the Remote Service API!");
|
||||||
Toast.makeText(this, R.string.error_onlyFilesAreSupported, Toast.LENGTH_LONG)
|
Toast.makeText(this, R.string.error_onlyFilesAreSupported, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
// end activity
|
// end activity
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(Constants.TAG,
|
||||||
|
"Include the extra 'text' or an Uri with setData() in your Intent!");
|
||||||
}
|
}
|
||||||
// } else if (ACTION_DECRYPT_AND_RETURN.equals(action)) {
|
|
||||||
// mReturnBinary = extras.getBoolean(EXTRA_BINARY, false);
|
|
||||||
//
|
|
||||||
// if (mContentUri == null) {
|
|
||||||
// mDataBytes = extras.getByteArray(EXTRA_DATA);
|
|
||||||
// String data = extras.getString(EXTRA_TEXT);
|
|
||||||
// if (data != null) {
|
|
||||||
// Matcher matcher = PgpMain.PGP_MESSAGE.matcher(data);
|
|
||||||
// if (matcher.matches()) {
|
|
||||||
// data = matcher.group(1);
|
|
||||||
// // replace non breakable spaces
|
|
||||||
// data = data.replaceAll("\\xa0", " ");
|
|
||||||
// mMessage.setText(data);
|
|
||||||
// } else {
|
|
||||||
// matcher = PgpMain.PGP_SIGNED_MESSAGE.matcher(data);
|
|
||||||
// if (matcher.matches()) {
|
|
||||||
// data = matcher.group(1);
|
|
||||||
// // replace non breakable spaces
|
|
||||||
// data = data.replaceAll("\\xa0", " ");
|
|
||||||
// mMessage.setText(data);
|
|
||||||
// mDecryptString = getString(R.string.btn_verify);
|
|
||||||
//
|
|
||||||
// // build new action bar
|
|
||||||
// invalidateOptionsMenu();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// mReturnResult = true;
|
|
||||||
// } else if (ACTION_DECRYPT_STREAM_AND_RETURN.equals(action)) {
|
|
||||||
// // TODO: Implement decrypt stream
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void guessOutputFilename() {
|
private void guessOutputFilename() {
|
||||||
@ -641,11 +568,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mDataBytes != null) {
|
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
||||||
inStream = new ByteArrayInputStream(mDataBytes);
|
|
||||||
} else {
|
|
||||||
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get decryption key for this inStream
|
// get decryption key for this inStream
|
||||||
@ -685,8 +608,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
data = data.replaceAll("(?m)^", "> ");
|
data = data.replaceAll("(?m)^", "> ");
|
||||||
data = "\n\n" + data;
|
data = "\n\n" + data;
|
||||||
intent.putExtra(EncryptActivity.EXTRA_TEXT, data);
|
intent.putExtra(EncryptActivity.EXTRA_TEXT, data);
|
||||||
intent.putExtra(EncryptActivity.EXTRA_SUBJECT, "Re: " + mSubject);
|
|
||||||
intent.putExtra(EncryptActivity.EXTRA_SEND_TO, mReplyTo);
|
|
||||||
intent.putExtra(EncryptActivity.EXTRA_SIGNATURE_KEY_ID, mSecretKeyId);
|
intent.putExtra(EncryptActivity.EXTRA_SIGNATURE_KEY_ID, mSecretKeyId);
|
||||||
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
|
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -768,13 +689,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
|
|||||||
} else {
|
} else {
|
||||||
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
|
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
|
||||||
|
|
||||||
if (mDataBytes != null) {
|
String message = mMessage.getText().toString();
|
||||||
data.putByteArray(KeychainIntentService.DECRYPT_CIPHERTEXT_BYTES, mDataBytes);
|
data.putByteArray(KeychainIntentService.DECRYPT_CIPHERTEXT_BYTES, message.getBytes());
|
||||||
} else {
|
|
||||||
String message = mMessage.getText().toString();
|
|
||||||
data.putByteArray(KeychainIntentService.DECRYPT_CIPHERTEXT_BYTES,
|
|
||||||
message.getBytes());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data.putLong(KeychainIntentService.ENCRYPT_SECRET_KEY_ID, mSecretKeyId);
|
data.putLong(KeychainIntentService.ENCRYPT_SECRET_KEY_ID, mSecretKeyId);
|
||||||
|
@ -72,22 +72,18 @@ import com.actionbarsherlock.view.MenuItem;
|
|||||||
public class EncryptActivity extends SherlockFragmentActivity {
|
public class EncryptActivity extends SherlockFragmentActivity {
|
||||||
|
|
||||||
/* Intents */
|
/* Intents */
|
||||||
// without permission
|
|
||||||
public static final String ACTION_ENCRYPT = Constants.INTENT_PREFIX + "ENCRYPT";
|
public static final String ACTION_ENCRYPT = Constants.INTENT_PREFIX + "ENCRYPT";
|
||||||
public static final String ACTION_ENCRYPT_FILE = Constants.INTENT_PREFIX + "ENCRYPT_FILE";
|
|
||||||
|
|
||||||
/* EXTRA keys for input */
|
/* EXTRA keys for input */
|
||||||
public static final String EXTRA_TEXT = "text";
|
public static final String EXTRA_TEXT = "text";
|
||||||
public static final String EXTRA_DATA = "data";
|
|
||||||
public static final String EXTRA_ASCII_ARMOUR = "ascii_armor";
|
// enables ASCII Armor for file encryption when uri is given
|
||||||
public static final String EXTRA_SEND_TO = "send_to";
|
public static final String EXTRA_ASCII_ARMOR = "ascii_armor";
|
||||||
public static final String EXTRA_SUBJECT = "subject";
|
|
||||||
|
// preselect ids, for internal use
|
||||||
public static final String EXTRA_SIGNATURE_KEY_ID = "signature_key_id";
|
public static final String EXTRA_SIGNATURE_KEY_ID = "signature_key_id";
|
||||||
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryption_key_ids";
|
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryption_key_ids";
|
||||||
|
|
||||||
private String mSubject = null;
|
|
||||||
private String mSendTo = null;
|
|
||||||
|
|
||||||
private long mEncryptionKeyIds[] = null;
|
private long mEncryptionKeyIds[] = null;
|
||||||
|
|
||||||
private EditText mMessage = null;
|
private EditText mMessage = null;
|
||||||
@ -116,7 +112,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
private EditText mPassPhrase = null;
|
private EditText mPassPhrase = null;
|
||||||
private EditText mPassPhraseAgain = null;
|
private EditText mPassPhraseAgain = null;
|
||||||
private CheckBox mAsciiArmour = null;
|
private CheckBox mAsciiArmor = null;
|
||||||
private Spinner mFileCompression = null;
|
private Spinner mFileCompression = null;
|
||||||
|
|
||||||
private EditText mFilename = null;
|
private EditText mFilename = null;
|
||||||
@ -127,9 +123,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
private String mOutputFilename = null;
|
private String mOutputFilename = null;
|
||||||
|
|
||||||
private boolean mAsciiArmorDemand = false;
|
private boolean mAsciiArmorDemand = false;
|
||||||
private boolean mOverrideAsciiArmour = false;
|
private boolean mOverrideAsciiArmor = false;
|
||||||
private Uri mStreamAndReturnUri = null;
|
|
||||||
private byte[] mData = null;
|
|
||||||
|
|
||||||
private boolean mGenerateSignature = false;
|
private boolean mGenerateSignature = false;
|
||||||
|
|
||||||
@ -201,26 +195,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
updateSource();
|
updateSource();
|
||||||
updateMode();
|
updateMode();
|
||||||
|
|
||||||
// if (mEncryptImmediately) {
|
|
||||||
// mSourcePrevious.setClickable(false);
|
|
||||||
// mSourcePrevious.setEnabled(false);
|
|
||||||
// mSourcePrevious.setVisibility(View.INVISIBLE);
|
|
||||||
//
|
|
||||||
// mSourceNext.setClickable(false);
|
|
||||||
// mSourceNext.setEnabled(false);
|
|
||||||
// mSourceNext.setVisibility(View.INVISIBLE);
|
|
||||||
//
|
|
||||||
// mSourceLabel.setClickable(false);
|
|
||||||
// mSourceLabel.setEnabled(false);
|
|
||||||
// }
|
|
||||||
|
|
||||||
updateActionBarButtons();
|
updateActionBarButtons();
|
||||||
|
|
||||||
// if (mEncryptImmediately
|
|
||||||
// && (mMessage.getText().length() > 0 || mData != null)
|
|
||||||
// && ((mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) || mSecretKeyId != 0)) {
|
|
||||||
// encryptClicked();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -250,40 +225,24 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
// handle like normal text encryption, override action and extras to later
|
// handle like normal text encryption, override action and extras to later
|
||||||
// execute ACTION_ENCRYPT in main actions
|
// execute ACTION_ENCRYPT in main actions
|
||||||
extras.putString(EXTRA_TEXT, sharedText);
|
extras.putString(EXTRA_TEXT, sharedText);
|
||||||
extras.putBoolean(EXTRA_ASCII_ARMOUR, true);
|
extras.putBoolean(EXTRA_ASCII_ARMOR, true);
|
||||||
action = ACTION_ENCRYPT;
|
action = ACTION_ENCRYPT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Files via content provider, override uri and action
|
// Files via content provider, override uri and action
|
||||||
uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
action = ACTION_ENCRYPT_FILE;
|
action = ACTION_ENCRYPT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (ACTION_ENCRYPT_AND_RETURN.equals(action)
|
if (extras.containsKey(EXTRA_ASCII_ARMOR)) {
|
||||||
// || ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) {
|
mAsciiArmorDemand = extras.getBoolean(EXTRA_ASCII_ARMOR, true);
|
||||||
// mEncryptImmediately = true;
|
mOverrideAsciiArmor = true;
|
||||||
// }
|
mAsciiArmor.setChecked(mAsciiArmorDemand);
|
||||||
//
|
|
||||||
// if (ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) {
|
|
||||||
// mGenerateSignature = true;
|
|
||||||
// mOverrideAsciiArmour = true;
|
|
||||||
// mAsciiArmorDemand = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (extras.containsKey(EXTRA_ASCII_ARMOUR)) {
|
|
||||||
mAsciiArmorDemand = extras.getBoolean(EXTRA_ASCII_ARMOUR, true);
|
|
||||||
mOverrideAsciiArmour = true;
|
|
||||||
mAsciiArmour.setChecked(mAsciiArmorDemand);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mData = extras.getByteArray(EXTRA_DATA);
|
String textData = extras.getString(EXTRA_TEXT);
|
||||||
String textData = null;
|
|
||||||
if (mData == null) {
|
|
||||||
textData = extras.getString(EXTRA_TEXT);
|
|
||||||
}
|
|
||||||
mSendTo = extras.getString(EXTRA_SEND_TO);
|
|
||||||
mSubject = extras.getString(EXTRA_SUBJECT);
|
|
||||||
long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
|
long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
|
||||||
long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
|
long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
|
||||||
|
|
||||||
@ -293,18 +252,18 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
/**
|
/**
|
||||||
* Main Actions
|
* Main Actions
|
||||||
*/
|
*/
|
||||||
// if (ACTION_ENCRYPT.equals(action) || ACTION_ENCRYPT_AND_RETURN.equals(action)
|
if (ACTION_ENCRYPT.equals(action) && textData != null) {
|
||||||
// || ACTION_GENERATE_SIGNATURE_AND_RETURN.equals(action)) {
|
// encrypt text based on given extra
|
||||||
if (ACTION_ENCRYPT.equals(action)) {
|
|
||||||
if (textData != null) {
|
mMessage.setText(textData);
|
||||||
mMessage.setText(textData);
|
|
||||||
}
|
|
||||||
mSource.setInAnimation(null);
|
mSource.setInAnimation(null);
|
||||||
mSource.setOutAnimation(null);
|
mSource.setOutAnimation(null);
|
||||||
while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
|
while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
|
||||||
mSource.showNext();
|
mSource.showNext();
|
||||||
}
|
}
|
||||||
} else if (ACTION_ENCRYPT_FILE.equals(action)) {
|
} else if (ACTION_ENCRYPT.equals(action) && uri != null) {
|
||||||
|
// encrypt file based on Uri
|
||||||
|
|
||||||
// get file path from uri
|
// get file path from uri
|
||||||
String path = FileHelper.getPath(this, uri);
|
String path = FileHelper.getPath(this, uri);
|
||||||
|
|
||||||
@ -319,16 +278,15 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG,
|
Log.e(Constants.TAG,
|
||||||
"Direct binary data without actual file in filesystem is not supported. This is only supported by ACTION_ENCRYPT_STREAM_AND_RETURN.");
|
"Direct binary data without actual file in filesystem is not supported by Intents. Please use the Remote Service API!");
|
||||||
Toast.makeText(this, R.string.error_onlyFilesAreSupported, Toast.LENGTH_LONG)
|
Toast.makeText(this, R.string.error_onlyFilesAreSupported, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
// end activity
|
// end activity
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
// } else if (ACTION_ENCRYPT_STREAM_AND_RETURN.equals(action)) {
|
} else {
|
||||||
// // TODO: Set mStreamAndReturnUri that is used later to encrypt a stream!
|
Log.e(Constants.TAG,
|
||||||
//
|
"Include the extra 'text' or an Uri with setData() in your Intent!");
|
||||||
// mStreamAndReturnUri = uri;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +349,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
private String guessOutputFilename(String path) {
|
private String guessOutputFilename(String path) {
|
||||||
// output in the same directory but with additional ending
|
// output in the same directory but with additional ending
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
String ending = (mAsciiArmour.isChecked() ? ".asc" : ".gpg");
|
String ending = (mAsciiArmor.isChecked() ? ".asc" : ".gpg");
|
||||||
String outputFilename = file.getParent() + File.separator + file.getName() + ending;
|
String outputFilename = file.getParent() + File.separator + file.getName() + ending;
|
||||||
|
|
||||||
return outputFilename;
|
return outputFilename;
|
||||||
@ -455,31 +413,19 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
mSourceLabel.setText(R.string.label_message);
|
mSourceLabel.setText(R.string.label_message);
|
||||||
|
|
||||||
if (mMode.getCurrentView().getId() == R.id.modeSymmetric) {
|
if (mMode.getCurrentView().getId() == R.id.modeSymmetric) {
|
||||||
// if (mEncryptImmediately) {
|
setActionbarButtons(true, R.string.btn_encryptAndSend, true,
|
||||||
// setActionbarButtons(true, R.string.btn_encrypt, false, 0);
|
|
||||||
// } else {
|
|
||||||
setActionbarButtons(true, R.string.btn_encryptAndEmail, true,
|
|
||||||
R.string.btn_encryptToClipboard);
|
R.string.btn_encryptToClipboard);
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
if (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0) {
|
if (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0) {
|
||||||
if (mSecretKeyId == 0) {
|
if (mSecretKeyId == 0) {
|
||||||
setActionbarButtons(false, 0, false, 0);
|
setActionbarButtons(false, 0, false, 0);
|
||||||
} else {
|
} else {
|
||||||
// if (mEncryptImmediately) {
|
setActionbarButtons(true, R.string.btn_signAndSend, true,
|
||||||
// setActionbarButtons(true, R.string.btn_sign, false, 0);
|
|
||||||
// } else {
|
|
||||||
setActionbarButtons(true, R.string.btn_signAndEmail, true,
|
|
||||||
R.string.btn_signToClipboard);
|
R.string.btn_signToClipboard);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if (mEncryptImmediately) {
|
setActionbarButtons(true, R.string.btn_encryptAndSend, true,
|
||||||
// setActionbarButtons(true, R.string.btn_encrypt, false, 0);
|
|
||||||
// } else {
|
|
||||||
setActionbarButtons(true, R.string.btn_encryptAndEmail, true,
|
|
||||||
R.string.btn_encryptToClipboard);
|
R.string.btn_encryptToClipboard);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -684,13 +630,8 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN);
|
intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN);
|
||||||
|
|
||||||
// choose default settings, target and data bundle by target
|
// choose default settings, target and data bundle by target
|
||||||
if (mStreamAndReturnUri != null) {
|
if (mEncryptTarget == Id.target.file) {
|
||||||
// mIntentDataUri is only defined when ACTION_ENCRYPT_STREAM_AND_RETURN is used
|
useAsciiArmor = mAsciiArmor.isChecked();
|
||||||
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_STREAM);
|
|
||||||
data.putParcelable(KeychainIntentService.ENCRYPT_PROVIDER_URI, mStreamAndReturnUri);
|
|
||||||
|
|
||||||
} else if (mEncryptTarget == Id.target.file) {
|
|
||||||
useAsciiArmor = mAsciiArmour.isChecked();
|
|
||||||
compressionId = ((Choice) mFileCompression.getSelectedItem()).getId();
|
compressionId = ((Choice) mFileCompression.getSelectedItem()).getId();
|
||||||
|
|
||||||
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE);
|
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE);
|
||||||
@ -707,19 +648,14 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
|
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
|
||||||
|
|
||||||
if (mData != null) {
|
String message = mMessage.getText().toString();
|
||||||
data.putByteArray(KeychainIntentService.ENCRYPT_MESSAGE_BYTES, mData);
|
if (signOnly) {
|
||||||
} else {
|
fixBadCharactersForGmail(message);
|
||||||
String message = mMessage.getText().toString();
|
|
||||||
// if (signOnly && !mEncryptImmediately) {
|
|
||||||
if (signOnly) {
|
|
||||||
fixBadCharactersForGmail(message);
|
|
||||||
}
|
|
||||||
data.putByteArray(KeychainIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes());
|
|
||||||
}
|
}
|
||||||
|
data.putByteArray(KeychainIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mOverrideAsciiArmour) {
|
if (mOverrideAsciiArmor) {
|
||||||
useAsciiArmor = mAsciiArmorDemand;
|
useAsciiArmor = mAsciiArmorDemand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,31 +691,18 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Id.target.email:
|
case Id.target.email:
|
||||||
// if (mEncryptImmediately) {
|
|
||||||
// Intent intent = new Intent();
|
|
||||||
// intent.putExtras(data);
|
|
||||||
// setResult(RESULT_OK, intent);
|
|
||||||
// finish();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
output = data.getString(KeychainIntentService.RESULT_ENCRYPTED_STRING);
|
output = data.getString(KeychainIntentService.RESULT_ENCRYPTED_STRING);
|
||||||
Log.d(Constants.TAG, "output: " + output);
|
Log.d(Constants.TAG, "output: " + output);
|
||||||
|
|
||||||
Intent emailIntent = new Intent(Intent.ACTION_SEND);
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||||
|
|
||||||
// Type is set to text/plain so that encrypted messages can
|
// Type is set to text/plain so that encrypted messages can
|
||||||
// be sent with Whatsapp, Hangouts, SMS etc...
|
// be sent with Whatsapp, Hangouts, SMS etc...
|
||||||
emailIntent.setType("text/plain");
|
sendIntent.setType("text/plain");
|
||||||
|
|
||||||
emailIntent.putExtra(Intent.EXTRA_TEXT, output);
|
sendIntent.putExtra(Intent.EXTRA_TEXT, output);
|
||||||
if (mSubject != null) {
|
startActivity(Intent.createChooser(sendIntent,
|
||||||
emailIntent.putExtra(Intent.EXTRA_SUBJECT, mSubject);
|
|
||||||
}
|
|
||||||
if (mSendTo != null) {
|
|
||||||
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { mSendTo });
|
|
||||||
}
|
|
||||||
startActivity(Intent.createChooser(emailIntent,
|
|
||||||
getString(R.string.title_sendEmail)));
|
getString(R.string.title_sendEmail)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -949,8 +872,8 @@ public class EncryptActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
mDeleteAfter = (CheckBox) findViewById(R.id.deleteAfterEncryption);
|
mDeleteAfter = (CheckBox) findViewById(R.id.deleteAfterEncryption);
|
||||||
|
|
||||||
mAsciiArmour = (CheckBox) findViewById(R.id.asciiArmour);
|
mAsciiArmor = (CheckBox) findViewById(R.id.asciiArmour);
|
||||||
mAsciiArmour.setChecked(Preferences.getPreferences(this).getDefaultAsciiArmour());
|
mAsciiArmor.setChecked(Preferences.getPreferences(this).getDefaultAsciiArmour());
|
||||||
|
|
||||||
mSelectKeysButton.setOnClickListener(new OnClickListener() {
|
mSelectKeysButton.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
12
README.md
12
README.md
@ -53,18 +53,14 @@ OpenPGP Keychain specific Intent actions:
|
|||||||
|
|
||||||
* ``org.sufficientlysecure.keychain.action.ENCRYPT``
|
* ``org.sufficientlysecure.keychain.action.ENCRYPT``
|
||||||
* To encrypt text use extra ``text`` (type: ``String``)
|
* To encrypt text use extra ``text`` (type: ``String``)
|
||||||
* To encrypt bytes use extra ``data`` (type: ``byte[]``)
|
* or set data ``Uri`` (``intent.setData()``) pointing to a file
|
||||||
* Enable ASCII Armor (encoding to Radix-64, 33% overhead) by adding the extra ``ascii_armor`` with value ``true``
|
* Enable ASCII Armor for file encryption (encoding to Radix-64, 33% overhead) by adding the extra ``ascii_armor`` with value ``true``
|
||||||
* ``org.sufficientlysecure.keychain.action.ENCRYPT_FILE``
|
|
||||||
* Include data ``Uri`` (``intent.setData()``) pointing to a file or content provider
|
|
||||||
* ``org.sufficientlysecure.keychain.action.DECRYPT``
|
* ``org.sufficientlysecure.keychain.action.DECRYPT``
|
||||||
* To decrypt text use extra ``text`` (type: ``String``)
|
* To decrypt text use extra ``text`` (type: ``String``)
|
||||||
* To decrypt bytes use extra ``data`` (type: ``byte[]``)
|
* or set data ``Uri`` (``intent.setData()``) pointing to a file
|
||||||
* ``org.sufficientlysecure.keychain.action.DECRYPT_FILE``
|
|
||||||
* Include data ``Uri`` (``intent.setData()``) pointing to a file or content provider
|
|
||||||
* ``org.sufficientlysecure.keychain.action.IMPORT_KEY``
|
* ``org.sufficientlysecure.keychain.action.IMPORT_KEY``
|
||||||
* Extras: ``key_bytes`` (type: ``byte[]``)
|
* Extras: ``key_bytes`` (type: ``byte[]``)
|
||||||
* or Uri in data with file schema
|
* or set data ``Uri`` (``intent.setData()``) pointing to a file
|
||||||
* ``org.sufficientlysecure.keychain.action.IMPORT_KEY_FROM_QR_CODE``
|
* ``org.sufficientlysecure.keychain.action.IMPORT_KEY_FROM_QR_CODE``
|
||||||
* without extras starts Barcode Scanner to get QR Code
|
* without extras starts Barcode Scanner to get QR Code
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user