Commit graph

3659 commits

Author SHA1 Message Date
Tao Bao
a80ed221b8 Replace OTA keys when signing for A/B devices.
It replaces the package verification key (change of path due to
system_root_image flag), as well as the payload verification key.

Bug: 29397395
Change-Id: I10435072aaf4356f2d8b5e1b6e82eb9cead7ad62
(cherry picked from commit 24a7206430)
2016-06-23 22:12:31 -07:00
Alex Klyubin
9a41c93f41 Use Builder pattern for ApkVerifier parameters.
This should make it easier to add parameters/options without breaking
existing clients.

Bug: 27461702
Change-Id: Ia4577f78d703a6b91828dd08492c78d5e9afb110
2016-06-22 14:59:12 -07:00
Elliott Hughes
d8a52f9785 Remove --no_prereq flag from OTA script.
Bug: http://b/29393071
Test: aosp_flounder "make dist"
Change-Id: I9ec85210e118f7e525291e31ab4081a2bd10f998
2016-06-20 14:44:18 -07:00
Alex Klyubin
05f87de7a3 Let caller handle NoSuchAlgorithmException.
This surfaces relevant NoSuchAlgorithmExceptions to the caller instead
of rethrowing as other exception types. Some setups need to be able to
distringuish issues due to their own misconfiguration
(required crypto algorithm mising -- NoSuchAlgorithmException) from
issues with the APK being signed or verified.

Bug: 27461702
Change-Id: I993f73edb29b2cd4cc485734a89a924ec357ef19
2016-06-17 12:15:32 -07:00
Alex Klyubin
f31ced2e10 maxSdkVersion can be specified for APK verification.
This enables verification of APKs which are served to a specific
range of Android platform versions, or to replicate behavior of
particular platform versions.

Bug: 27461702
Change-Id: I44ab4c99419eb97d72c4ccd109137fe1efda577d
2016-06-17 10:02:47 -07:00
Alex Klyubin
21213cff9c Merge "Reject PKCS#7 SignerInfo with unsupported parameters." 2016-06-17 15:56:51 +00:00
Treehugger Robot
63fc2b6766 Merge "Remove obsolete MTD support from the releasetools scripts." 2016-06-17 04:47:47 +00:00
Elliott Hughes
305b088729 Remove obsolete MTD support from the releasetools scripts.
Bug: http://b/29250988
Change-Id: I653dc306485c6b35411840b53211d42eb6d19e34
2016-06-16 20:48:47 -07:00
Dan Willemsen
eb4431595c Remove build/libs
There's only a single library, libhost, and it's only used by acp and
atree in build/tools, move it there.

Bug: 28001743
Change-Id: Ie404d2793710de4e265a6fa95d462c32d4042623
2016-06-16 14:52:47 -07:00
Alex Klyubin
d7236da153 Reject PKCS#7 SignerInfo with unsupported parameters.
This addresses the TODO to mimic the behavior of Android when
verifying APK JAR signatures. Unfortunately, the behavior of Android
kept changing in interesting ways between different platform versions.
This is hard-coded as a big lookup.

Bug: 27461702
Change-Id: I49bc181ee05f774ef8ee041af870385b35212c23
2016-06-16 12:44:36 -07:00
Tao Bao
7c5dc578b3 Support wiping userdata for A/B OTA packages.
update_engine now accepts POWERWASH=1 to schedule a factory reset in
the post-install phase. Hook up with the --wipe_user_data flag in the
OTA script.

Bug: 28700985
Change-Id: Ie73876a61db90d124d2af588d674757376e9aabc
(cherry picked from commit 38ca0be399)
2016-06-15 23:19:52 -07:00
Alex Klyubin
1fb96c3ff5 Merge "Don't depend on Bouncy Castle." 2016-06-15 20:32:35 +00:00
Treehugger Robot
98b4f07dfc Merge "Faster and cleaner way to obtain UTF-8 encoded form." 2016-06-14 22:37:10 +00:00
Treehugger Robot
6c0c720389 Merge "Use more prebuilt build-tools" 2016-06-14 22:14:07 +00:00
Alex Klyubin
d4761a19b8 Faster and cleaner way to obtain UTF-8 encoded form.
Instead of specifying character encoding by name, the faster, cleaner,
and safer way is to use StandardCharsets.UTF_8.

Bug: 27461702
Change-Id: I897284d3ceeb44a21cc74de09a9b25f6aec8c205
2016-06-14 14:18:21 -07:00
Alex Klyubin
cf89865b95 Merge "APK JAR signature verifier." 2016-06-14 20:56:28 +00:00
Dan Willemsen
7c2d228701 Use more prebuilt build-tools
For acp, we've been using an old prebuilt in prebuilts/sdk, but it's not
part of the SDK. Instead, we'll use a prebuilt in the build-tools
repository.

For ijar, we've been using the host libstdc++ to workaround the lack of
libc++ on some unbundled branches. Instead, use a prebuilt that can use
libc++.

For ziptime, we've been disabling it on unbundled branches, due to the
lack of libc++. Instead, use a prebuilt version of ziptime that can use
the prebuilt libc++.

Change-Id: If80f845ea06f76e3fe6765964e77c864eaf303d0
2016-06-14 13:50:38 -07:00
Alex Klyubin
7f770c0963 Don't depend on Bouncy Castle.
This switches PKCS#7 SignedData generation code from Bouncy Castle to
OpenJDK's proprietary internal API. This is to avoid depending on a
huge library that's not really needed. In the longer term, it's best
to add our own implementation of PKCS#7 SignedData building, parsing,
and verification. This will give the code more power to mimic what the
Android platform does.

Bug: 27461702
Change-Id: I29f1ceea1293e35424fde69c0f2969d551345100
2016-06-14 11:20:49 -07:00
Dan Willemsen
e19d451f49 Add a libc++ version of ijar for prebuilt use
I'll remove the old version once we've moved over to the prebuilts.

Change-Id: Ifd8d396f8b653abbe958cd34e69831a6ca378649
2016-06-14 10:30:06 -07:00
Alex Klyubin
8b47001e9b APK JAR signature verifier.
This adds JAR signature verification to ApkVerifier.

Bug: 27461702
Change-Id: Id2b72bea7869be66268f6bc1387e1559ee02ff9d
2016-06-14 10:28:36 -07:00
Alex Klyubin
dca955a9bd Merge "More general OutputStreamDataSink." 2016-06-13 19:49:01 +00:00
Alex Klyubin
a85e0aa883 Merge "Fix inefficiency in APK entry data alignment." 2016-06-13 18:14:18 +00:00
Alex Klyubin
e54b2753e4 More general OutputStreamDataSink.
This replaces the less general DataSink which outputs into a
ByteArrayOutputStream with a more general DataSink which outputs into
an OutputStream.

Bug: 27461702
Change-Id: I9467f38c41f586b71f35edb3602fd6e57153184f
2016-06-13 10:19:26 -07:00
Alex Klyubin
ab2a3b0061 Fix inefficiency in APK entry data alignment.
26f00cda4b introduced a bug where an
APK entry's extra field is padded for alignment purposes when no
padding is necessary because the entry is aligned without any padding
bytes.

Bug: 27461702
Change-Id: Icb164dbaa26d9686412e2920318a9f40c5ce9751
2016-06-11 17:47:20 -07:00
Alex Deymo
d8d96ecdae Redirect subprocess stderr to stdout in verbose mode.
This patch uses subprocess.communicate instead of subprocess.wait to
prevent deadlock if any of the child processes outputs too much data,
and redirects the subprocess output to stdout when running in verbose
mode.

With this patch `ota_from_target_files -v` prints the delta_generator
output in stdout, and no output if '-v' is not passed.

Bug: None
TEST=ota_from_target_files -v ...

Change-Id: Id66e4f3360a6f91d61a3ce96d53afbccdaa19da5
2016-06-10 16:38:31 -07:00
Alex Klyubin
8740e9df19 APK Signature Scheme v2 APK verifier.
This adds the ApkVerifier class which verifies APKs using APK
Signature Scheme v2 only. In a follow-up commit this class will be
extended to verify APKs using JAR signature scheme when necessary.

The APK verifier is designed to not just verify an APK, but also
report errors, warnings, and information about signers in a structured
way, to enable tools to surface this information to users in various
ways.

Bug: 27461702
Change-Id: I10c6ba436021d86b6dbf6d3cf44494652adacb66
2016-06-08 08:23:30 -07:00
Alex Klyubin
ebe68ec237 Merge "Fix DSA APK signatures for API Level 8 and lower." 2016-06-08 15:17:42 +00:00
Treehugger Robot
c52d09e694 Merge "Switch some build tools to Soong" 2016-06-06 22:51:57 +00:00
Alex Klyubin
819b5354e0 Fix DSA APK signatures for API Level 8 and lower.
This modifies JAR signing code to produce DSA signatures which are
accepted by all Android platforms rather than only API Level 9 and
higher.

The issue is that by default Bouncy Castle uses OID 1.2.840.10040.4.3
(dsaWithSha1) in PKCS #7 CMS SignerInfo whereas Android accepts that
only since API Level 9. However, OID 1.2.840.10040.4.1 (dsa) is
accepted by all Android platforms.

Bug: 27461702
Change-Id: I24256a255bcdc2108bdb447557af7568a2c096e3
2016-06-06 15:05:08 -07:00
Dan Willemsen
56eb2f9f54 Switch some build tools to Soong
In preparation for including them in prebuilts/build-tools.

acp: We use a prebuilt in prebuilts/sdk, but it's not part of the sdk.

ijar: We use the host libstdc++ to workaround the lack of libc++ on
some unbundled branches.

ziptime: We disable this on unbundled builds, due to the lack of libc++.

Change-Id: Ib9766b1dbddd151c38ff27c529865200ab37fce1
2016-06-06 14:51:52 -07:00
Treehugger Robot
a571e83095 Merge "Remove dead rgb2565" 2016-06-06 21:35:47 +00:00
Alex Klyubin
7353eabd14 Merge "Improve efficiency of using the DataSource abstraction." 2016-06-06 21:07:52 +00:00
Dan Willemsen
08b12dc2c8 Remove dead rgb2565
Change-Id: I2397dc97768f24a7c416bff96dd983fc796cbb53
2016-06-06 13:32:11 -07:00
Alex Klyubin
1a39e8eb34 Merge "Switch signapk to apksigner-core." 2016-06-06 19:40:23 +00:00
Alex Klyubin
b02eefacbf Improve efficiency of using the DataSource abstraction.
This adds getByteBuffer and copyTo methods to the DataSource
abstraction. These methods enable the client to avoid unnecessary
copying of the data source's data.

Bug: 27461702
Change-Id: If4e9f902ea75c1ca5c7be0e20c0e7218faf9c504
2016-06-06 11:17:03 -07:00
Treehugger Robot
40623e2a99 Merge "Add --dir option to findleaves.py" 2016-05-28 00:53:47 +00:00
Colin Cross
9808645cd9 Add --dir option to findleaves.py
findleaves.py needs to be able to search multiple directories for
multiple filenames (Android.bp and Android.mk).  Add support for a new
--dir= option to specify one or more directories to search, and then
treat any remaining options as filenames.  If no directories are
specified, fall back to treating only the last option as a filename and
the rest as directories.

Change-Id: Ie879facd49192c6b4fafae070ad00eb21b1faa32
2016-05-27 16:05:10 -07:00
Alex Klyubin
fa1da6c311 Switch signapk to apksigner-core.
This switches signapk's APK signing from its own signing logic to that
offered by apksigner-core library. OTA update package signing logic
remains inside signapk codebase.

Bug: 27461702
Change-Id: Ibf8435c555fe3f2b621d5189e7ae44f79082c810
2016-05-27 14:45:51 -07:00
Alex Klyubin
ce4c9d7108 Merge "Improve DataSource interface." 2016-05-27 20:00:59 +00:00
Alex Klyubin
7b977ea0e9 Improve DataSource interface.
1. This adds way to obtain a DataSource which represents a region of
   data contained in the DataSource.
2. This fixes a design bug in "feed" method where the size parameter
   was an int instead of long.
3. This fixes a bug in ByteBufferDataSource where its mSize field was
   a long instead of an int (ByteBuffer's length cannot be more than
   2^31).

Bug: 27461702
Change-Id: Ib0812784beb581f19d2412e667b8bd018f0a3c78
2016-05-27 10:28:52 -07:00
Alex Klyubin
26f00cda4b Store entry alignment information in APK.
Data of uncompressed APK entries is often aligned to a multiple of 4
or 4096 in the APK to make it easier to mmap the data. Unfortunately,
the current method for achieving alignment suffers from two issues:
(1) the way it uses the Local File Header extra field is not compliant
with ZIP format (for example, this prevents older versions of Python's
zipfile from reading APKs: https://bugs.python.org/issue14315), and
(2) it does not store information about the alignment multiple in the
APK, making it harder/impossible to preserve the intended alignment
when rearranging entries in the APK.

This change solves these issues by switching to a different method for
aligning data of uncompressed APK entries. Same as before, alignment
is achieved using Local File Header entry field. What's different is
that alignment is achieved by placing a well-formed extensible data
field/block into the extra field. The new field/block contains the
alignment multiple (e.g., 4 or 4096) as well as the necessary padding
(if any). Compared to the original alignment method, the new method
uses 6 more bytes for each uncompressed entry.

Bug: 27461702
Change-Id: I8cffbecc50bf634b28fca5bc39eb23f671961cf9
2016-05-23 17:46:18 -07:00
Alex Klyubin
ac68c28831 Merge "Improve concurrency for JAR entry inspection requests." 2016-05-23 19:26:14 +00:00
Alex Klyubin
094caf99aa Merge "No need to JAR-sign OTA update packages." 2016-05-16 17:11:04 +00:00
Alex Klyubin
2af45bacb4 Improve concurrency for JAR entry inspection requests.
This moves the creation of potentially expensive objects from the
thread which creates JAR entry inspection requests, to the thread
which fulfills these requests, increasig concurrency opportunities.

Bug: 27461702
Change-Id: If753b2de7fb04ee5e2e4bbcb27d42269d7fa5def
2016-05-13 18:51:18 -07:00
Ian Rogers
86c3b72d9c Merge "Make Error Prone warnings in sync with Error Prone documenation." 2016-05-13 18:19:18 +00:00
Ian Rogers
6e52003b54 Make Error Prone warnings in sync with Error Prone documenation.
Use summary information from annotation within Error Prone to auto-generate
the warnings list.

Bug: 28681096
Change-Id: Ib3a5f734bd229726fcd7332eaa9e0e1bd1200c25
2016-05-13 10:18:18 -07:00
Mohamad Ayyash
465acf8631 Use fs_config files for mksquashfs
BUG: 27467028
Change-Id: I7648030ad4b31d70a5d439e9552fd2cbfe288b74
Signed-off-by: Mohamad Ayyash <mkayyash@google.com>
BUG: 28704419
2016-05-12 18:44:48 -07:00
Alex Klyubin
6975f03fd8 Merge "Offer an ApkSignerEngine implementation." 2016-05-12 18:43:08 +00:00
Alex Klyubin
0caa16a6d1 No need to JAR-sign OTA update packages.
This removes the logic for JAR signing from -w (whole-file signing)
mode. This mode is designed specifically for OTA update packages. When
such packages are verified, their JAR signatures are ignored. Thus,
there is no need to JAR-sign in -w mode.

For context, OTA update packages are protected by a special signature
residing in the ZIP End of Central Directory record (at the very end
of the file). This is the signature verified when update packages are
being applied to Android.

Change-Id: Ia852a11ed6774ce746087cdd7f028b191ef6bc8b
2016-05-12 11:32:43 -07:00
Alex Klyubin
e305f45f00 Offer an ApkSignerEngine implementation.
This adds an implementation of ApkSignerEngine to the apksigner-core
library.

Bug: 27461702
Change-Id: I5f977b98555ca507a0dfcd3e92eecb9758aa8370
2016-05-12 10:56:06 -07:00