mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
working encryption out of k9mail
This commit is contained in:
parent
24a53d548b
commit
4229b94270
@ -53,12 +53,28 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".SelectPublicKeyListActivity"
|
android:name=".SelectPublicKeyListActivity"
|
||||||
android:label="@string/title_selectRecipients"
|
android:label="@string/title_selectRecipients"
|
||||||
android:configChanges="keyboardHidden|orientation|keyboard"/>
|
android:configChanges="keyboardHidden|orientation|keyboard">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="org.thialfihar.android.apg.intent.SELECT_PUBLIC_KEYS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="text/*"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".SelectSecretKeyListActivity"
|
android:name=".SelectSecretKeyListActivity"
|
||||||
android:label="@string/title_selectSignature"
|
android:label="@string/title_selectSignature"
|
||||||
android:configChanges="keyboardHidden|orientation|keyboard"/>
|
android:configChanges="keyboardHidden|orientation|keyboard">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="org.thialfihar.android.apg.intent.SELECT_SECRET_KEY" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="text/*"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".EncryptActivity"
|
android:name=".EncryptActivity"
|
||||||
@ -68,6 +84,9 @@
|
|||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.thialfihar.android.apg.intent.ENCRYPT" />
|
<action android:name="org.thialfihar.android.apg.intent.ENCRYPT" />
|
||||||
<action android:name="org.thialfihar.android.apg.intent.ENCRYPT_FILE" />
|
<action android:name="org.thialfihar.android.apg.intent.ENCRYPT_FILE" />
|
||||||
|
<action android:name="org.thialfihar.android.apg.intent.ENCRYPT_AND_RETURN" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="text/*"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
@ -101,6 +101,9 @@ public class Apg {
|
|||||||
public static final String DECRYPT_FILE = "org.thialfihar.android.apg.intent.DECRYPT_FILE";
|
public static final String DECRYPT_FILE = "org.thialfihar.android.apg.intent.DECRYPT_FILE";
|
||||||
public static final String ENCRYPT_FILE = "org.thialfihar.android.apg.intent.ENCRYPT_FILE";
|
public static final String ENCRYPT_FILE = "org.thialfihar.android.apg.intent.ENCRYPT_FILE";
|
||||||
public static final String DECRYPT_AND_RETURN = "org.thialfihar.android.apg.intent.DECRYPT_AND_RETURN";
|
public static final String DECRYPT_AND_RETURN = "org.thialfihar.android.apg.intent.DECRYPT_AND_RETURN";
|
||||||
|
public static final String ENCRYPT_AND_RETURN = "org.thialfihar.android.apg.intent.ENCRYPT_AND_RETURN";
|
||||||
|
public static final String SELECT_PUBLIC_KEYS = "org.thialfihar.android.apg.intent.SELECT_PUBLIC_KEYS";
|
||||||
|
public static final String SELECT_SECRET_KEY = "org.thialfihar.android.apg.intent.SELECT_SECRET_KEY";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String EXTRA_DATA = "data";
|
public static final String EXTRA_DATA = "data";
|
||||||
@ -150,8 +153,8 @@ public class Apg {
|
|||||||
Pattern.DOTALL);
|
Pattern.DOTALL);
|
||||||
|
|
||||||
public static Pattern PGP_SIGNED_MESSAGE =
|
public static Pattern PGP_SIGNED_MESSAGE =
|
||||||
Pattern.compile(".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
|
Pattern.compile(".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
|
||||||
Pattern.DOTALL);
|
Pattern.DOTALL);
|
||||||
|
|
||||||
private static HashMap<Long, CachedPassPhrase> mPassPhraseCache =
|
private static HashMap<Long, CachedPassPhrase> mPassPhraseCache =
|
||||||
new HashMap<Long, CachedPassPhrase>();
|
new HashMap<Long, CachedPassPhrase>();
|
||||||
@ -1330,6 +1333,9 @@ public class Apg {
|
|||||||
String passPhrase, ProgressDialogUpdater progress,
|
String passPhrase, ProgressDialogUpdater progress,
|
||||||
boolean assumeSymmetric)
|
boolean assumeSymmetric)
|
||||||
throws IOException, GeneralException, PGPException, SignatureException {
|
throws IOException, GeneralException, PGPException, SignatureException {
|
||||||
|
if (passPhrase == null) {
|
||||||
|
passPhrase = "";
|
||||||
|
}
|
||||||
Bundle returnData = new Bundle();
|
Bundle returnData = new Bundle();
|
||||||
InputStream in = PGPUtil.getDecoderStream(inStream);
|
InputStream in = PGPUtil.getDecoderStream(inStream);
|
||||||
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
||||||
|
@ -496,7 +496,6 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
if (mSignedOnly) {
|
if (mSignedOnly) {
|
||||||
data = Apg.verifyText(this, in, out, this);
|
data = Apg.verifyText(this, in, out, this);
|
||||||
} else {
|
} else {
|
||||||
// TODO: check the pass phrase, may be null?
|
|
||||||
data = Apg.decrypt(this, in, out, size, Apg.getCachedPassPhrase(getSecretKeyId()),
|
data = Apg.decrypt(this, in, out, size, Apg.getCachedPassPhrase(getSecretKeyId()),
|
||||||
this, mAssumeSymmetricEncryption);
|
this, mAssumeSymmetricEncryption);
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ import android.widget.Toast;
|
|||||||
import android.widget.ViewFlipper;
|
import android.widget.ViewFlipper;
|
||||||
|
|
||||||
public class EncryptActivity extends BaseActivity {
|
public class EncryptActivity extends BaseActivity {
|
||||||
|
private Intent mIntent = null;
|
||||||
private String mSubject = null;
|
private String mSubject = null;
|
||||||
private String mSendTo = null;
|
private String mSendTo = null;
|
||||||
|
|
||||||
@ -265,11 +266,12 @@ public class EncryptActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Intent intent = getIntent();
|
mIntent = getIntent();
|
||||||
if (intent.getAction() != null &&
|
if (mIntent.getAction() != null &&
|
||||||
(intent.getAction().equals(Apg.Intent.ENCRYPT) ||
|
(mIntent.getAction().equals(Apg.Intent.ENCRYPT) ||
|
||||||
intent.getAction().equals(Apg.Intent.ENCRYPT_FILE))) {
|
mIntent.getAction().equals(Apg.Intent.ENCRYPT_FILE) ||
|
||||||
Bundle extras = intent.getExtras();
|
mIntent.getAction().equals(Apg.Intent.ENCRYPT_AND_RETURN))) {
|
||||||
|
Bundle extras = mIntent.getExtras();
|
||||||
if (extras == null) {
|
if (extras == null) {
|
||||||
extras = new Bundle();
|
extras = new Bundle();
|
||||||
}
|
}
|
||||||
@ -318,7 +320,8 @@ public class EncryptActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent.getAction().equals(Apg.Intent.ENCRYPT)) {
|
if (mIntent.getAction().equals(Apg.Intent.ENCRYPT) ||
|
||||||
|
mIntent.getAction().equals(Apg.Intent.ENCRYPT_AND_RETURN)) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
mMessage.setText(data);
|
mMessage.setText(data);
|
||||||
}
|
}
|
||||||
@ -327,7 +330,7 @@ public class EncryptActivity extends BaseActivity {
|
|||||||
while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
|
while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
|
||||||
mSource.showNext();
|
mSource.showNext();
|
||||||
}
|
}
|
||||||
} else if (intent.getAction().equals(Apg.Intent.ENCRYPT_FILE)) {
|
} else if (mIntent.getAction().equals(Apg.Intent.ENCRYPT_FILE)) {
|
||||||
mSource.setInAnimation(null);
|
mSource.setInAnimation(null);
|
||||||
mSource.setOutAnimation(null);
|
mSource.setOutAnimation(null);
|
||||||
while (mSource.getCurrentView().getId() != R.id.sourceFile) {
|
while (mSource.getCurrentView().getId() != R.id.sourceFile) {
|
||||||
@ -339,6 +342,13 @@ public class EncryptActivity extends BaseActivity {
|
|||||||
updateView();
|
updateView();
|
||||||
updateSource();
|
updateSource();
|
||||||
updateMode();
|
updateMode();
|
||||||
|
|
||||||
|
if (mMessage.getText().length() > 0 &&
|
||||||
|
((mEncryptionKeyIds != null &&
|
||||||
|
mEncryptionKeyIds.length > 0) ||
|
||||||
|
getSecretKeyId() > 0)) {
|
||||||
|
encryptClicked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openFile() {
|
private void openFile() {
|
||||||
@ -729,48 +739,56 @@ public class EncryptActivity extends BaseActivity {
|
|||||||
Toast.makeText(EncryptActivity.this,
|
Toast.makeText(EncryptActivity.this,
|
||||||
getString(R.string.errorMessage, error), Toast.LENGTH_SHORT).show();
|
getString(R.string.errorMessage, error), Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
String message = Strings.fromUTF8ByteArray(data.getByteArray(Apg.EXTRA_ENCRYPTED_MESSAGE));
|
String message = Strings.fromUTF8ByteArray(data.getByteArray(Apg.EXTRA_ENCRYPTED_MESSAGE));
|
||||||
switch (mEncryptTarget) {
|
switch (mEncryptTarget) {
|
||||||
case Id.target.clipboard: {
|
case Id.target.clipboard: {
|
||||||
ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
clip.setText(message);
|
clip.setText(message);
|
||||||
Toast.makeText(this, R.string.encryptionToClipboardSuccessful,
|
Toast.makeText(this, R.string.encryptionToClipboardSuccessful,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Id.target.email: {
|
||||||
|
if (mIntent.getAction() != null &&
|
||||||
|
mIntent.getAction().equals(Apg.Intent.ENCRYPT_AND_RETURN)) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtras(data);
|
||||||
|
setResult(RESULT_OK, intent);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Id.target.email: {
|
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||||
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
|
emailIntent.setType("text/plain; charset=utf-8");
|
||||||
emailIntent.setType("text/plain; charset=utf-8");
|
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
|
||||||
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
|
if (mSubject != null) {
|
||||||
if (mSubject != null) {
|
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
|
||||||
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
|
mSubject);
|
||||||
mSubject);
|
|
||||||
}
|
|
||||||
if (mSendTo != null) {
|
|
||||||
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
|
|
||||||
new String[] { mSendTo });
|
|
||||||
}
|
|
||||||
EncryptActivity.this.
|
|
||||||
startActivity(Intent.createChooser(emailIntent,
|
|
||||||
getString(R.string.title_sendEmail)));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (mSendTo != null) {
|
||||||
|
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
|
||||||
|
new String[] { mSendTo });
|
||||||
|
}
|
||||||
|
EncryptActivity.this.
|
||||||
|
startActivity(Intent.createChooser(emailIntent,
|
||||||
|
getString(R.string.title_sendEmail)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Id.target.file: {
|
case Id.target.file: {
|
||||||
Toast.makeText(this, R.string.encryptionSuccessful, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.encryptionSuccessful, Toast.LENGTH_SHORT).show();
|
||||||
if (mDeleteAfter.isChecked()) {
|
if (mDeleteAfter.isChecked()) {
|
||||||
setDeleteFile(mInputFilename);
|
setDeleteFile(mInputFilename);
|
||||||
showDialog(Id.dialog.delete_file);
|
showDialog(Id.dialog.delete_file);
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
// shouldn't happen
|
// shouldn't happen
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user