From 8ad31e32519b42c3ae439baa52716792980c5638 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 17 Sep 2015 22:10:37 +0200 Subject: mime: skip trailing unsigned parts, and ignore nested signed data --- .../keychain/operations/InputDataOperation.java | 19 ++++++++++++++++--- .../keychain/operations/results/OperationResult.java | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java index 56e7d822d..d9e48af8a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -146,8 +146,8 @@ public class InputDataOperation extends BaseOperation { @Override public void startMultipart(BodyDescriptor bd) throws MimeException { if ("signed".equals(bd.getSubType())) { - if (mSignedDataResult != null) { - // recursive signed data is not supported! + if (mSignedDataUri != null) { + // recursive signed data is not supported, and will just be parsed as-is log.add(LogType.MSG_DATA_DETACHED_NESTED, 2); return; } @@ -185,6 +185,7 @@ public class InputDataOperation extends BaseOperation { } out.close(); + // continue to next body part the usual way parser.setFlat(); } @@ -259,6 +260,13 @@ public class InputDataOperation extends BaseOperation { return; } + // If mSignedDataUri is non-null, we already parsed a signature. If mSignedDataResult is non-null + // too, we are still in the same parsing stage, so this is trailing data - skip it! + if (mSignedDataUri != null && mSignedDataResult != null) { + log.add(LogType.MSG_DATA_DETACHED_TRAILING, 2); + return; + } + log.add(LogType.MSG_DATA_MIME_PART, 2); log.add(LogType.MSG_DATA_MIME_TYPE, 3, bd.getMimeType()); @@ -313,8 +321,13 @@ public class InputDataOperation extends BaseOperation { decryptResult = mSignedDataResult; } - in = mContext.getContentResolver().openInputStream(mSignedDataUri); + // the actual content is the signed data now (and will be passed verbatim, if parsing fails) + currentInputUri = mSignedDataUri; + in = mContext.getContentResolver().openInputStream(currentInputUri); + // reset signed data result, to indicate to the parser that it is in the inner part + mSignedDataResult = null; parser.parse(in); + } // if we found data, return success diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java index 3fb5be0ad..b1dcc9202 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java @@ -835,6 +835,7 @@ public abstract class OperationResult implements Parcelable { MSG_DATA_DETACHED_SIG (LogLevel.DEBUG, R.string.msg_data_detached_sig), MSG_DATA_DETACHED_RAW (LogLevel.DEBUG, R.string.msg_data_detached_raw), MSG_DATA_DETACHED_NESTED(LogLevel.WARN, R.string.msg_data_detached_nested), + MSG_DATA_DETACHED_TRAILING (LogLevel.WARN, R.string.msg_data_detached_trailing), MSG_DATA_DETACHED_UNSUPPORTED (LogLevel.WARN, R.string.msg_data_detached_unsupported), MSG_DATA_MIME_ERROR (LogLevel.ERROR, R.string.msg_data_mime_error), MSG_DATA_MIME_FILENAME (LogLevel.DEBUG, R.string.msg_data_mime_filename), -- cgit v1.2.3