diff options
author | Shane Farmer <safarmer@google.com> | 2017-09-29 11:59:25 -0700 |
---|---|---|
committer | Shane Farmer <safarmer@google.com> | 2017-12-12 16:25:26 -0800 |
commit | 3ff44436a10d512e25d072d51ea84bfb85d69365 (patch) | |
tree | 93a0575c30f671ae9e30e99c63b06a4eda42cbe4 /tools/aapt2/optimize/MultiApkGenerator.cpp | |
parent | 67e8a3074d7ef42734d44f3a8d87635e201bd660 (diff) |
AAPT2: Remove signatures from multi-APK artifacts.
Remove signer files (.SF and public key) as well as the original
manifest file from any output artifacts. Since the artifacts are not
signed, we want to remove the original signature and manifest. The APK
signer tool will add these back later.
Updated the context wrapper to enable verbose mode to be cleared. This
lets us have more specific log messages when splitting an APK as at this
point the artifacts and filters are more interesting than the files removed.
Test: Manually split an APK and verified the filles were removed while
leaving the other META-INF entries.
Test: Unit tests
Change-Id: Ia59993b5570f802130c6e3ba42398a00821061ea
Diffstat (limited to 'tools/aapt2/optimize/MultiApkGenerator.cpp')
-rw-r--r-- | tools/aapt2/optimize/MultiApkGenerator.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/aapt2/optimize/MultiApkGenerator.cpp b/tools/aapt2/optimize/MultiApkGenerator.cpp index da3b8792be69..e2d738aec5a2 100644 --- a/tools/aapt2/optimize/MultiApkGenerator.cpp +++ b/tools/aapt2/optimize/MultiApkGenerator.cpp @@ -17,6 +17,7 @@ #include "MultiApkGenerator.h" #include <algorithm> +#include <regex> #include <string> #include "androidfw/StringPiece.h" @@ -125,6 +126,16 @@ class ContextWrapper : public IAaptContext { int min_sdk_ = -1; }; +class SignatureFilter : public IPathFilter { + bool Keep(const std::string& path) override { + static std::regex signature_regex(R"regex(^META-INF/.*\.(RSA|DSA|EC|SF)$)regex"); + if (std::regex_search(path, signature_regex)) { + return false; + } + return !(path == "META-INF/MANIFEST.MF"); + } +}; + MultiApkGenerator::MultiApkGenerator(LoadedApk* apk, IAaptContext* context) : apk_(apk), context_(context) { } @@ -209,6 +220,7 @@ bool MultiApkGenerator::FromBaseApk(const MultiApkGeneratorOptions& options) { diag.Note(DiagMessage() << "Writing output: " << out); } + filters.AddFilter(util::make_unique<SignatureFilter>()); if (!apk_->WriteToArchive(&wrapped_context, table.get(), options.table_flattener_options, &filters, writer.get(), manifest.get())) { return false; |