Merge branch 'master' of github.com:open-keychain/open-keychain

This commit is contained in:
Dominik Schürmann
2015-11-13 17:36:25 +01:00
7 changed files with 45 additions and 15 deletions

View File

@@ -635,6 +635,8 @@ public abstract class OperationResult implements Parcelable {
MSG_EK_ERROR_NOT_FOUND (LogLevel.ERROR, R.string.msg_ek_error_not_found), MSG_EK_ERROR_NOT_FOUND (LogLevel.ERROR, R.string.msg_ek_error_not_found),
// decryptverify // decryptverify
MSG_DC_ASKIP_BAD_FLAGS (LogLevel.DEBUG, R.string.msg_dc_askip_bad_flags),
MSG_DC_ASKIP_UNAVAILABLE (LogLevel.DEBUG, R.string.msg_dc_askip_unavailable),
MSG_DC_ASKIP_NO_KEY (LogLevel.DEBUG, R.string.msg_dc_askip_no_key), MSG_DC_ASKIP_NO_KEY (LogLevel.DEBUG, R.string.msg_dc_askip_no_key),
MSG_DC_ASKIP_NOT_ALLOWED (LogLevel.DEBUG, R.string.msg_dc_askip_not_allowed), MSG_DC_ASKIP_NOT_ALLOWED (LogLevel.DEBUG, R.string.msg_dc_askip_not_allowed),
MSG_DC_ASYM (LogLevel.DEBUG, R.string.msg_dc_asym), MSG_DC_ASYM (LogLevel.DEBUG, R.string.msg_dc_asym),

View File

@@ -591,6 +591,18 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
// get subkey which has been used for this encryption packet // get subkey which has been used for this encryption packet
secretEncryptionKey = secretKeyRing.getSecretKey(subKeyId); secretEncryptionKey = secretKeyRing.getSecretKey(subKeyId);
if (!secretEncryptionKey.canEncrypt()) {
secretEncryptionKey = null;
log.add(LogType.MSG_DC_ASKIP_BAD_FLAGS, indent + 1);
continue;
}
if (!secretEncryptionKey.getSecretKeyType().isUsable()) {
secretEncryptionKey = null;
log.add(LogType.MSG_DC_ASKIP_UNAVAILABLE, indent + 1);
continue;
}
/* secret key exists in database and is allowed! */ /* secret key exists in database and is allowed! */
asymmetricPacketFound = true; asymmetricPacketFound = true;

View File

@@ -117,7 +117,7 @@ public class PgpHelper {
} }
} }
public static String getPgpContent(@NonNull CharSequence input) { public static String getPgpMessageContent(@NonNull CharSequence input) {
Log.dEscaped(Constants.TAG, "input: " + input); Log.dEscaped(Constants.TAG, "input: " + input);
Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(input); Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(input);
@@ -141,4 +141,18 @@ public class PgpHelper {
} }
} }
public static String getPgpKeyContent(@NonNull CharSequence input) {
Log.dEscaped(Constants.TAG, "input: " + input);
Matcher matcher = PgpHelper.PGP_PUBLIC_KEY.matcher(input);
if (matcher.matches()) {
String text = matcher.group(1);
text = fixPgpMessage(text);
Log.dEscaped(Constants.TAG, "input fixed: " + text);
return text;
}
return null;
}
} }

View File

@@ -701,24 +701,17 @@ public class OpenPgpService extends RemoteService {
Intent result = new Intent(); Intent result = new Intent();
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
// return public key if requested by defining a output stream boolean requestedKeyData = outputStream != null;
if (outputStream != null) { if (requestedKeyData) {
boolean requestAsciiArmor = boolean requestAsciiArmor = data.getBooleanExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, false);
data.getBooleanExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, false);
ArmoredOutputStream arOutStream = null;
try { try {
if (requestAsciiArmor) { if (requestAsciiArmor) {
arOutStream = new ArmoredOutputStream(outputStream); outputStream = new ArmoredOutputStream(outputStream);
keyRing.encode(arOutStream);
} else {
keyRing.encode(outputStream);
} }
keyRing.encode(outputStream);
} finally { } finally {
try { try {
if (arOutStream != null) {
arOutStream.close();
}
outputStream.close(); outputStream.close();
} catch (IOException e) { } catch (IOException e) {
Log.e(Constants.TAG, "IOException when closing OutputStream", e); Log.e(Constants.TAG, "IOException when closing OutputStream", e);

View File

@@ -200,7 +200,7 @@ public class DecryptActivity extends BaseActivity {
} }
// clean up ascii armored message, fixing newlines and stuff // clean up ascii armored message, fixing newlines and stuff
String cleanedText = PgpHelper.getPgpContent(text); String cleanedText = PgpHelper.getPgpMessageContent(text);
if (cleanedText == null) { if (cleanedText == null) {
return null; return null;
} }

View File

@@ -29,6 +29,9 @@ import android.view.ViewGroup;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.FileHelper; import org.sufficientlysecure.keychain.util.FileHelper;
public class ImportKeysFileFragment extends Fragment { public class ImportKeysFileFragment extends Fragment {
@@ -78,12 +81,16 @@ public class ImportKeysFileFragment extends Fragment {
String sendText = ""; String sendText = "";
if (clipboardText != null) { if (clipboardText != null) {
sendText = clipboardText.toString(); sendText = clipboardText.toString();
sendText = PgpHelper.getPgpKeyContent(sendText);
if (sendText == null) {
Notify.create(mImportActivity, "Bad data!", Style.ERROR).show();
return;
}
mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(sendText.getBytes(), null)); mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(sendText.getBytes(), null));
} }
} }
}); });
return view; return view;
} }

View File

@@ -1150,6 +1150,8 @@
<string name="msg_ek_error_not_found">"Key not found!"</string> <string name="msg_ek_error_not_found">"Key not found!"</string>
<!-- Messages for DecryptVerify operation --> <!-- Messages for DecryptVerify operation -->
<string name="msg_dc_askip_bad_flags">"Key is not an encryption key, skipping…"</string>
<string name="msg_dc_askip_unavailable">"Key not available, skipping…"</string>
<string name="msg_dc_askip_no_key">"Data not encrypted with known key, skipping…"</string> <string name="msg_dc_askip_no_key">"Data not encrypted with known key, skipping…"</string>
<string name="msg_dc_askip_not_allowed">"Data not encrypted with allowed key, skipping…"</string> <string name="msg_dc_askip_not_allowed">"Data not encrypted with allowed key, skipping…"</string>
<string name="msg_dc_asym">"Found block of asymmetrically encrypted data for key %s"</string> <string name="msg_dc_asym">"Found block of asymmetrically encrypted data for key %s"</string>