Commit Graph

593 Commits

Author SHA1 Message Date
Fred Gylys-Colwell
b63085ab5a Layered Clock interface
Merge from Widevine repo of http://go/wvgerrit/131306
which is a
Merge of non OPK files from http://go/wvgerrit/129344
and http://go/wvgerrit/129563. The OPK files are squash merged
in the CL http://go/wvgerrit/131303.

This splits the clock interface into two layers so that we can save
the previous value.

Bug: 158719238
Change-Id: I473966eb9b0766d27372682e8ebfbcb53f546980
2021-10-13 21:20:55 +00:00
Jeff Tinker
b082f3fb0b Implement serialization version checking
Merge from Widevine repo of http://go/wvgerrit/125263
and http://go/wvgerrit/135749

Define a |major.minor| version in the
serialization layer and check for compatibility
between REE and TEE before accepting connections.

bug: 158857733
test: opk_all_tests
Change-Id: Iad44a1f50a27c6bca4959c6d41c9b361712dbde8
2021-10-13 21:20:55 +00:00
John W. Bruce
895d391121 Migrate tests to googletest 1.10+ API
(This is a cherry-pick of http://go/wvgerrit/135227 and
http://go/wvgerrit/135246 from the Widevine repo.)

Googletest has deprecated the TEST_CASE nomenclature in favor of the
International Software Testing Qualifications Board-compliant term
TEST_SUITE. See
https://google.github.io/googletest/primer.html#beware-of-the-nomenclature
for more info.

Bug: 156766290
Test: build_and_run_all_unit_tests.sh
Change-Id: Ib94d534d17677601c4c160eb6b8d4e4e07df85c9
2021-10-11 17:05:48 -07:00
TreeHugger Robot
fdea46d325 Merge "Fix -Wshorten-64-to-32 errors in BoringSSL interactions" 2021-10-06 21:54:09 +00:00
Fred Gylys-Colwell
7397f77343 Updates to OTA Keybox Reprovisioning
[ Cherry pick of http://ag/15847758 ]

Adjust OTA code to account for some design changes and
add integration tests.

Merge from Widevine repo of http://go/wvgerrit/133775
Change use_test_key to uint32_t type

Merge from Widevine repo of http://go/wvgerrit/133774
Cleanup CDM OKP info before tests.

Merge from Widevine repo of http://go/wvgerrit/133773
Change context for derivation in OTA keybox solution

Merge from Widevine repo of http://go/wvgerrit/133772
Updated OTA keybox key derivation.

Merge from Widevine repo of http://go/wvgerrit/133771
Use double provisioning step in integration tests

Merge from Widevine repo of http://go/wvgerrit/133770
Erase keybox on initialization for OEMCrypto testbed

Merge from Widevine repo of http://go/wvgerrit/133769
Add session id to OEMCrypto OTA functions

Merge from Widevine repo of http://go/wvgerrit/133768
Integration test for OTA Keybox reprovisioning

Merge from Widevine repo of http://go/wvgerrit/133767
Add test x509 cert for testing

Merge from Widevine repo of http://go/wvgerrit/133766
OTA Keybox basic functionality in testbed

Merge from Widevine repo of http://go/wvgerrit/133765
Update OTA test script to use newer build scripts

Merge from Widevine repo of http://go/wvgerrit/133764
Adjust comment stype for doxygen

Test: MediaDrmTest and Android unittests

Bug: 190505461
Bug: 190505461
Bug: 190505461
bug: 187646550
Bug: 187646550
Bug: 187646550
Bug: 187646550
Bug: 190505461
Bug: 187646550
Bug: 188228998
Bug: 190505461
Bug: 187646550
Change-Id: I41ff819a1fd8aca2e20adb25127fa0d9c4879b01
2021-10-01 15:00:33 -07:00
Rahul Frias
6afcbab5cf Wrapped OKP info into several classes.
[ Cherry pick of http://ag/15836995 ]
[ Merge of http://go/wvgerrit/133744 ]

This changes adds several small classes which contain and manage
system and engine information related to OTA keybox provisioning.
These classes closely map to the OKP device file messages.

Bug: 189232882
Test: Linux unit tests
Change-Id: Ia9334c38f9d7ea89b30d9ad05f0595570bb38658

Storing and loading OKP info.

[ Merge of http://go/wvgerrit/133763 and http://go/ag/15645333 ]

This change extends the DeviceFiles module to be able to store and
load OKP info.  Mild data validation is performed when storing and
loading the information.

Bug: 189232882
Test: Android unit tests
Change-Id: I077de3234157252f2255a4389bf82a8d5344a355

System OKP fallback policy.

[ Merge of http://go/wvgerrit/133783 and http://go/ag/15645334 ]

SystemFallbackPolicy provides a thread-safe interface for accessing
and modifying OKP info.

Bug: 189232882
Test: Android unit tests
Change-Id: I4e43e3bc047ed5fb6cb517b53e4094e812b70e1e

Engine OKP provisioner.

[ Merge of http://go/wvgerrit/133803 and http://go/ag/15645335 ]

The OtaKeyboxProvisioner provides a CdmEngine-specific context for
performing OTA keybox provisioning.  Utilizes the system-wide
SystemFallbackPolicy to relay provisioning status between engines.
The provisioner will handle message wrapping and unwrapping of the
raw OTA keybox request / response into the SignedProvisioningMessage
which is sent to/received from the provisioning server.

[ Partial merge of http://go/wvgerrit/125844 ]

Note: Includes partial CryptoSession changes from various CLs.
CryptoSession functionality has been stripped to reduce impact of
this CL.

Bug: 189232882
Test: Android unit tests
Change-Id: I282bf7d1887daefb2250af1bd595c4dc3dfcfb29

Integrated OKP into CDM Engine

[ Merge of http://go/wvgerrit/133804 and http://go/ag/15646376 ]

Extended the functionality of the CdmEngine to check if the device
requires OKP and to initialize OKP resources if required.  The
functionality of OpenSession() and GetProvisioningRequest() have been
the most affected.  If OKP is required, these methods will signal to
the app that provisioning is required and will return an OKP request.

Once a device is provisioned, the OKP data is cleared away and the
CdmEngine will resume normal operation.  Engines created after a
device is provisioned will immediately enter normal operations.
The exception is for CdmEngines which failed to perform OKP for some
reason and are still running.  Those apps will need to restart before
gaining access to L1 operations.

Bug: 187646550
Test: Android integration tests
Change-Id: Ia572a66a7b73479355758aa3d0c682691eaca0fc
2021-09-29 14:00:37 -07:00
Rahul Frias
3acc64a478 Added an OTA keybox provisioner.
[ Merge of http://go/wvgerrit/133729 ]
[ Cherry pick of http://ag/15836224 ]

The OtaKeyboxProvisioner is a system-wide provisioner for sharing the
provisioning workflow between CDM engines.

Bug: 189232882
Test: GtsMediaTestCases
Change-Id: I873af3087cc05e1831bdd1d2c14fb002b73e6902

Added keybox provisioning proto fields.

[ Merge of http://go/wvgerrit/133730 and http://go/ag/15113032 ]

This CL copies over the required license_protocol.proto changes that
are required for OTA keybox provisioning.  These fields are defined in
the server-side certificate_provisioning.proto, defined in
http://cl/377533774.

Note, changes are slightly different from server proto due to the RVC
version of license_protocol.proto being out of date with SC and newer
changes.

Bug: 189232882
Test: run_x86_64_tests
Change-Id: I55fcf6a7ac2ba4b6026b9acc63e822ff33c431d9

Added OTA keybox provisioning device files.

[ Merge of http://go/wvgerrit/133743 and http://go/ag/15421141 ]

This change adds a new set of proto messages/fields the CDM's device
files for recording device and engine information around OTA keybox
provisioning (OKP).

To make cleanup and thread protection possible, there is a single file
which will contain all the information for the device as a whole and
each CDM engine tied to an app/origin.

Bug: 189232882
Test: Linux unit tests
Change-Id: Iaf80cd6342f32657e04416750d9b278d935821a5

Client ID for OKP requests.

[ Merge of http://go/wvgerrit/133744 and http://go/ag/15645331 ]

Extended the CDM ClientIdentification class to support a subset of
client info used for OKP requests.

Bug: 189232882
Test: Android unit tests
Change-Id: I6aafb4f2164efe69bc733ece0a912f0e91893b91
2021-09-29 14:00:36 -07:00
Fred Gylys-Colwell
bac33dbc6e Use local provisioning server
Merge from Widevine repo of http://go/wvgerrit/133703 and
http://ag/14707867

[ Cherry-pick of http://ag/15835345 ]

In order to use a local provisioning server, we need to use a
different test keybox system id that is in the dev device database
instead of the production database. We also need to use a local
license server that uses the dev license server.

Bug: 187646550
Test: GtsMediaTestCases

Change-Id: Ice89143dd26de22757375a770c6bac716fcbc057

Add Keybox OTA Provisioning functions to OEMCrypto header

Merge from Widevine repo of http://go/wvgerrit/133704 and
http://go/ag/14707868

Bug: 188228998
Change-Id: Iff54bc2870e87bf7239e179e1d02fbcc8df6198f

Stub build changes to support OTA Keybox

Merge from Widevine repo of http://go/wvgerrit/133725 and
http://go/ag/14781459

This CL adds a new unit test file for testing OTA keybox
reprovisioning functionality. This new test is built when running the
dynamic adapter in the linux build, and in the Android build.

Bug: 187646550
Change-Id: I625513840188f95e74831ef2ea399e827e837439

Add OTA Keybox functions to dynamic adapter

Merge from Widevine repo of http://go/wvgerrit/125843
and http://go/ag/14781460

Bug: 187646550
Change-Id: Ief78ed10599c091690e0d7dc488ea71674c763b5

Refactor dynamic adapter keybox verification

Merge from Widevine repo of http://go/wvgerrit/133727
http://go/ag/14812524

The keybox validation needs to be done separately from initializing
the library so that we can support Keybox OTA Reprovisioning.

If L1 loads, but the keybox is missing, the initialization should
succeed. When the keybox is validated, the adapter should try to look
for a keybox on the filesystem. if none is found, it should either
return NEEDS PROVISIONING or an error.

Bug: 187646550
Change-Id: I34a8c365a5a5ca35c379bea827c85c749964744c

Update crypto session to use new OTA keybox functionality

Merge from Widevine repo of http://go/wvgerrit/133728 and
http://go/ag/14812525

This CL stubs out two new CryptoSession functions that call the new
OEMCrypto functions for OTA Keybox Provisioning. It builds!  Yay!

It also adds a boolean needs_keybox_provisioning that is set to true
when OEMCrypto reports that it needs a keybox. This should only happen
if there is no keybox installed and oemcrypto supports provisioning.

Bug: 187646550
Change-Id: Ide9533943125aa13b8899b652b118a0b410c882c
2021-09-29 14:00:36 -07:00
John W. Bruce
68187b9f02 Fix -Wshorten-64-to-32 errors in BoringSSL interactions
(This is a merge from the Widevine Repo of http://go/wvgerrit/134310.)

This patch fixes code that would trigger -Wshorten-64-to-32 by
implicitly narrowing a variable from 64 to 32 bits. Most of the time, it
does this by making the implicit conversion explicit. The cause of most
of these is that OpenSSL uses "int" for the length of things rather than
size_t. (While BoringSSL sometimes uses int and sometimes uses size_t.)

One exception is LogBoringSSLError(). We have a couple copies of this
function around, and they varied slightly. This patch brings them all
in-line, which conveniently also removes any code in them that would
deal with integer variables.

GetRandBytes() now takes a size_t and downcasts to BoringSSL's native
int internally, so that callers can pass in a size_t value as they would
expect.

There's also an interesting case in oec_session_util.cpp. Because
BoringSSL and OpenSSL disagree about the width of an error code, we have
to use the "auto" type for a temporary variable that holds an error, in
order to retain compatibility with both.

Bug: 194971260
Test: x86-64
Test: x86-64-openssl
Change-Id: I88bc62b4cda396f8a1eabd1a3cb7d1b03f47a33f
2021-09-27 18:17:04 -07:00
Rahul Frias
a3657ab200 Merge "Disable expiration for legacy DRM certificates" into sc-dev 2021-07-01 21:00:14 +00:00
Rahul Frias
151d0b15d3 Disable expiration for legacy DRM certificates
[ Merge of http://go/wvgerrit/128163 ]

In android S, we added a feature b/169740403 [Limited lifespan DRM
certificates with license preservation]

Due to uncertainties of when the provisioning service will
launch, we are disabling expiration for legacy DRM certificates.
If the feature does not launch in time, existing DRM certificates
will expire and be replaced. Offline licenses associated with these
expired DRM certificates will fail to load.

Expiration of legacy certificates will be reenabled at a later time.
The main portion of feature, the issuing of new DRM certificates with
expiration time will still be supported.

Bug: 192428783
Bug: 169740403
Test: WV unit/integration tests
Change-Id: I1d1184249848f215953a837f369528d3b74c9618
2021-07-01 19:24:02 +00:00
Rahul Frias
d30c5043d1 Merge "Correct an error reported when a license is restored and then released" into sc-dev 2021-07-01 19:17:21 +00:00
TreeHugger Robot
99c4d463d9 Merge "Allow delayed error code in generic crypto" into sc-dev 2021-06-30 21:06:17 +00:00
Rahul Frias
c882bd8230 Correct an error reported when a license is restored and then released
[ Merge of http://go/wvgerrit/128143 ]

Now reports LICENSE_STATE_ERROR rather than ERROR_DRM_GENERIC_PLUGIN
to make the cause of failure and suggested action more clear for app
developers. Also added an additional error log.

Bug: 190645000
Test: WV unit/integration tests
Change-Id: Ib23ca628c590316f90f497d8fdfbab24fd644d6f
2021-06-29 20:21:06 -07:00
Fred Gylys-Colwell
50a52710fa Allow delayed error code in generic crypto
Merge from Widevine repo of http://go/wvgerrit/127246

The unit tests WvGenericCryptoTest expected an error code to be
returned from SelectKey. But we allow an invalid key to be signaled
either at SelectKey or later when the decrypt operation occurs.

This CL just updates the tests.

Bug: 190745519
Test: ran tests on bonito
Change-Id: Ibacc92d6a6e708f2f104cb549b5845335f6c8cf5
2021-06-17 04:33:50 +00:00
Rahul Frias
8e92fef410 Address unit test failures
[ Merge of http://go/wvgerrit/126744 ]

* EngineMetrics previous_oemcrypto_initialization_failure is set only
  on a previous failure. Removing it from the list of expectations
  as we cannot be certain that it will or will not be set unless we
  know the previous state of the device.

* Corrected client_capabililties expectations in
  CdmLicenseTest.PrepareKeyRequestValidation

* Correct error expected in
  - WVDrmPluginTest.RejectsAtscProvisioningRequests
  - WVDrmPluginTest.RejectsAtscUnprovisionDeviceRequests

* Correct expectations
  - CdmSessionTest.InitWithBuiltInCertificate,
  - CdmSessionTest.InitWithCertificate
  - CdmSessionTest.ReInitFail,
  - CdmSessionTest.InitFailCryptoError

Bug: 181693982
Test: WV unit/integration tests
Change-Id: I2f1e1c38604d768e0532b30d8551c77ea45e63f4
2021-06-14 08:04:40 +00:00
Alex Dale
9c47be6aa8 Merge "New usage entries are moved lower after creation." into sc-dev 2021-05-26 22:31:03 +00:00
Fred Gylys-Colwell
20833734e1 Add fudge to duration tests
Merge from Widevine repo of http://go/wvgerrit/125046

Add some extra fudge to the termination time. This assumes that flaky
tests were caused by roundoff error.

Bug: 175741647
Change-Id: I9bcc86f9b9540e5985df647dd1b5c5d439556e2b
2021-05-25 20:26:43 +00:00
Alex Dale
884550333d New usage entries are moved lower after creation.
[ Merge of http://go/wvgerrit/124004 ]

When the CDM creates a new usage entry for an offline or streaming
license, the new entry is immediately moved to the lowest available
entry index that has been marked as vacant (kStorageTypeUnknown).

When a license is released, its meta data that is managed by the CDM
is cleared; however, the usage entry's index is marked vacant, but it
is not released.  This creates wasted entry space in the usage table.
Unfortunately, defragging the table is computationally expensive and
may not be able to actually free up much space depending on when it
is performed.

For a typical user, this will likely not be an issue as the table
can get quite large compared to the number of licenses an app uses
and the table is partially cleaned on each boot.

GTS tests, however, have reached a point where they fill the usage
table before all tests are complete.  This is causing many unexpected
failures for devices.  Most of these tests release their license, but
the CDM never reaches a state where it can clean up the table.

By moving newly created entries to the lowest available index directly
after creating the entries, the table never needs to grow unless all
entries are in use.  Clean up is now almost never required.

Bug: 180639135
Bug: 180638990
Bug: 180638530
Test: MediaDrmTest#testWidevineApi28
Change-Id: I1a68d90d51384094298b27037778747ce7435374
2021-05-24 12:51:44 -07:00
Alex Dale
023b06eded Check for open session when initializing usage table.
[ Merge of http://go/wvgerrit/122984 ]

There was an issue encountered by some vendors with how the usage
table was initialized on some devices.  Previously, the CDM would
open an OEMCrypto session first, then initialize the usage table
(loading existing or creating a new one).  On these devices,
OEMCrypto_CreateUsageTableHeader() and OEMCrypto_LoadUsageTableHeader()
would fail if there were any open sessions.

This CL changes the initialization process to create/load the usage
table before opening an OEMCrypto session.

This change also lays the ground work for another usage table fix
to address GTS tests failure.

In the process, several of the functions for the usage table have been
split up into smaller chunks of code.  This required additional changes
to the usage table unittest to keep them up to date.

Bug: 169195093
Bug: 180639135
Test: Linux unittests and MediaDrmTest
Change-Id: Ifbf35f5d8cff5b89fea9b16edb998c84803f4fbe
2021-05-19 10:39:51 -07:00
Rahul Frias
0921b04e41 Disallow the ability to load offline licenses more than once
[ Merge of http://go/wvgerrit/123263 ]

In b/65839890 we discovered that an android app loaded an offline
license more than once in a session. We did not intend to allow
this behavior but did not prohibit it. OEMCrypto v16 disallowed
this behavior at the OEMCrypto level but we worked around it
within the CDM to maintain the bad behavior. Now that we have confirmed
that the app no longer relies on that behavior, we are reverting
the CDM workaround.

Bug: 161865160
Test: WV unit/integration test, GtsMediaTestCases
      Amazon, Netflix, Google TV streaming and offline playback.
Change-Id: I31254e4c13b81587f88c6c684d08d5aa5c18e39d
2021-04-29 16:20:30 -07:00
TreeHugger Robot
03dff71bd8 Merge changes I6dd829f4,Id8384c58,I9228b9cc,I744a1e89 into sc-dev
* changes:
  Fix CDM Builds w/ OEMCrypto_ERROR_INVALID_ENTITLED_KEY_SESSION
  Fix unused param warnings in oemcrypto fuzz test
  Add http socket tests to other tests
  Turn on ODK tests in CE CDM test and fix test helper
2021-04-27 19:20:34 +00:00
Rahul Frias
4c4e746e57 Replace DeviceFiles::LicenseState with CdmOfflineLicenseState
[ Merge of http://go/wvgerrit/123003 ]

Bug: 160006474
Test: WV unit/integration tests
Change-Id: Ied813f58405fcac44f0543f715ab2175129bbf9c
2021-04-24 00:30:20 -07:00
Fred Gylys-Colwell
ebb7d45a25 Fix CDM Builds w/ OEMCrypto_ERROR_INVALID_ENTITLED_KEY_SESSION
Merge from Widevine repo of http://go/wvgerrit/108224

A recent Copybara merge to master broke CDM builds by introducing a
new OEMCrypto error code. This patch adds it to the test printers so
that the build can pass again.

Bug: 185597829
Test: CE CDM Build
Change-Id: I6dd829f4c618c9ebec937cf711ff57b7f1678994
2021-04-23 10:11:48 -07:00
Fred Gylys-Colwell
5a58b6d8d2 Add http socket tests to other tests
Merge from Widevine repo of http://go/wvgerrit/122224

This CL removes the separate main() in http_socket_test that
allowed the user to set the server on the command line.  I
don't think anybody was using this, and it conflicted with
our desire to include this suite of tests with the other CE
CDM tests running on Luci.

test: ran http_socket_test
bug: 118657876
Change-Id: I9228b9cc97a0af2afd1bb4a99bc40b88ce956d67
2021-04-23 10:11:48 -07:00
TreeHugger Robot
9c3c076cac Merge "Address review comments" into sc-dev 2021-04-17 03:49:56 +00:00
Alex Dale
d4b24490f2 Merge "Only one function for reporting usage support." into sc-dev 2021-04-16 19:47:10 +00:00
Rahul Frias
d59b009495 Merge "Address CE CDM test failures and code review comments" into sc-dev 2021-04-16 08:25:45 +00:00
Fred Gylys-Colwell
bcc1db9b69 Address review comments
Merge from Widevine repo of http://go/wvgerrit/122383

Fix a few grammar errors found in http://go/ag/14154405 and
http://go/ag/14150103.

Bug: 185536454
Test: comments changed only
Change-Id: Ied2af940d705fbfc4af60c1d76a051c8c163097f
2021-04-15 22:07:18 -07:00
Rahul Frias
d802baa4d4 Address CE CDM test failures and code review comments
The android CL ag/13947818 was submitted before some CE CDM test
failures were noticed and code review comments were received.

Bug: 184813991
Test: WV unit/integration test
Change-Id: Ic31ca5bc5e46994e01eca56248e6bdffedd779f3
2021-04-13 11:23:18 -07:00
Fred Gylys-Colwell
e998b08de7 Clean up duration tests
Merge from Widevine repo of http://go/wvgerrit/120903

Some comments in the duration tests had stale numbers in them. This
was fixed.

Also, the tests CdmUseCase_LicenseDuration were failing with a v16 CDM
and a v15 OEMCrypto because the exact cutoff time is different in
those two cases. That is exactly why specifying the license duration
is not recommended. The tests have been modified to handle both
acceptable behaviors.

Bug: 182237739
Change-Id: I05765beacfe69d02e7366bb3f651f0d5888ab3e5
2021-04-12 14:00:53 -07:00
Alex Dale
ca335b2c11 Only one function for reporting usage support.
[ Merge of http://go/wvgerrit/121567 ]

Replaced the two usage support functions GetUsageSupportType() and
UsageInformationSupport() into a single function HasUsageInfoSupport().

Since moving to only supporting a single usage info system (usage table
header + usage entries), the different usage support functions have
lost their purpose.

One version of the method works on an open session and will use a
cached value of the property if previously set.  The other can be
called without opening the session (as used for query calls).

This is part of larger fix for the usage table initialization process.

Bug: 169195093
Test: CE CDM unit tests
Change-Id: I637c24dd143e995dbb0f8848850e3c71ff1018eb
2021-04-09 01:34:57 -07:00
Rahul Frias
7c8d3e287e Correction to addition of LOCAL_LICENSE_KINDS to vendor/widevine
Remove incorrectly identified license files in http://go/ag/13998816

Bug: 68860345
Bug: 151177513
Bug: 151953481
Test: mm
Change-Id: I676a63598c8a7df11a1cef6d8bebcc9940c961dc
2021-04-08 07:56:48 +00:00
Bob Badour
ea0bd6030c Merge "[LSC] Add LOCAL_LICENSE_KINDS to vendor/widevine" into sc-dev 2021-03-26 06:45:39 +00:00
Alex Dale
50757c84ec Merge "Use new Base64 encode functions." into sc-dev 2021-03-26 05:19:31 +00:00
Bob Badour
376f47047c [LSC] Add LOCAL_LICENSE_KINDS to vendor/widevine
Added SPDX-license-identifier-Apache-2.0 legacy_by_exception_only to:
  Android.bp
  libwvdrmengine/Android.bp
  libwvdrmengine/vts/vendor_module/Android.bp

Added legacy_by_exception_only to:
  libwvdrmengine/cdm/Android.bp
  libwvdrmengine/cdm/core/src/Android.bp
  libwvdrmengine/cdm/core/test/Android.bp
  libwvdrmengine/cdm/metrics/src/Android.bp
  libwvdrmengine/cdm/test/integration-test.mk
  libwvdrmengine/cdm/test/unit-test.mk
  libwvdrmengine/level3/Android.bp
  libwvdrmengine/mediacrypto/Android.bp
  libwvdrmengine/mediacrypto/test/Android.mk
  libwvdrmengine/mediadrm/Android.bp
  libwvdrmengine/mediadrm/test/Android.mk
  libwvdrmengine/oemcrypto/odk/Android.bp
  libwvdrmengine/oemcrypto/odk/test/fuzzing/Android.bp
  libwvdrmengine/oemcrypto/odk/test/fuzzing/corpus_generator/Android.bp
  libwvdrmengine/oemcrypto/test/Android.mk
  libwvdrmengine/test/unit/Android.mk
  libwvdrmengine/tools/metrics_dump/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: I41ef520b6e394a7708f453a706e6ef1a5f46c36a
2021-03-25 09:52:52 -07:00
Alex Dale
d859c1ab17 Use new Base64 encode functions.
[ Merge of http://go/wvgerrit/119806 ]

This change replaces all calls for base64 encoding which first converts
a string to a vector.  The new base64 encoding function allow for
encoding binary data contained within strings.

Bug: 181732604
Test: Android unittests
Change-Id: Ibfe79dba99e6a2ee2f2a96e85b62fbd22519aea7
2021-03-23 14:49:58 -07:00
Rahul Frias
e538c96131 Save and retrieve key information from licenses and usage records
[ Merge of http://go/wvgerrit/120512 ]

Wrapped DRM private keys are loaded when a key request is made or when
offline/usage sessions are restored. They were earlier loaded when a
session was opened.

For streaming sessions, key material will be fetched from the default
or legacy certificates and loaded when a key request is made.

For offline and usage sessions, key material may be retrieved from
license or usage records if available. If not available, information
associated with the legacy certificate will be loaded.

Certificate and wrapped keys are also written out when an offline
license or usage record is saved.

Bug: 169740403
Test: WV unit/integration tests
      WvCdmRequestLicenseTest.ProvisioningWithExpiringCertTest
      WvCdmRequestLicenseTest.StreamingWithExpiringCertTest
      WvCdmRequestLicenseTest.RestoreOfflineKeysWithExpiringCertTest
Change-Id: Ice0154c632170c46da171cbbb23a97380c610a98
2021-03-23 13:06:55 -07:00
Rahul Frias
30ebbefb40 Add CLIENT_TOKEN_NOT_SET error code
[ Merge of http://go/wvgerrit/120511 ]

Bug: 169740403
Test: WV unit/integration test
Change-Id: Iba77c0b7e7f1bee1e96b0d08f0ab8e8591292012
2021-03-22 17:08:34 -07:00
Rahul Frias
1aa197ce4a Add certificate information to Usage Information
[ Merge of http://go/wvgerrit/120509 ]

Certificates and wrapped key material are stored in the usage information
file but apart from usage information records. Usage info records include
an identifier which indicates the associated certificate. Routines to
help with finding, inserting or removal of associated certificates have
been included. After a usage entry is deleted, a garbage collection
routine is run to remove any certificates not used by usage infomation
records.

Bug: 169740403
Test: WV unit/integration tests
Change-Id: I49075a7704a58c2488b73eb7c38b007958af566d
2021-03-22 17:07:25 -07:00
Rahul Frias
57ebb70fe7 Add certificate information to offline licenses
[ Merge of http://go/wvgerrit/120508 ]

Offline licenses will now store the DRM certificate information. This
allows for expired certificates to be deleted and replaced without
losing the ability to use offline licenses.

Bug: 169740403
Test: WV unit/integration tests
      DeviceFilesTest.RetrieveLicenses
      DeviceFilesTest.StoreLicenses
Change-Id: Ic0de6328d32e0000d1b58c81019e6c2227278cc4
2021-03-21 19:11:06 -07:00
Rahul Frias
b21be96b1b Verify DRM certificate validity
[ Merge of http://go/wvgerrit/120123 ]

DRM certificate creation and expiration times are now validated.

* New DRM (default) certificates will have an expiration time specified
by the provisioning service.

When stored, the client will include the time the certificate was
received. This allows for expiration calculation to occur when client
and provisioning service clocks are out of sync.

When read out, creation, expiration and acquisition times are
validated. The certificate is checked for expiry by making sure
that the time at the client since the license was acquired is not
greater than the expiration period. The time information stored at the
client may be tampered with. The license service will perform an
expiration check and reject the license request if tampered with.
The expiration time may be set to never expires/unlimited. This is not
a valid value for creation or acquisition time.

* Pre-existing (legacy) certificates from upgrading devices will not
have an expiration time set by the provisioning service. Instead
the client will calculate an expiration time 6 months with + or -
a random two month period in the future. This is stored along with the
certificate.

When read out, if no expiration time has been set by the client, one
will be calculated and written out. The certificate will be declared as
valid. If a client calculated expiration time is present, the
certificate will be validated. In case of tampering, the license service
can reject license requests and force reprovisioning when appropriate.

* ATSC certificates will continue to not have an expiration time.
No additional validation is required.

Other changes for non-ATSC licenses involve managing both default and
legacy certificate co-existance. When checking for DRM certificates,
the default certificate is attempted first. This is followed by a check
for the legacy certificate, if the default certificate is not present.

Bug: 169740403
Test: WV unit/integration tests
      DeviceFilesTest.StoreCertificateInvalidParams
      DeviceFilesTest.RetrieveAtscCertificate
      DeviceFilesTest.RetrieveAtscCertificateNotFound
      DeviceFilesTest.RetrieveCertificateInvalidParams
      DeviceFilesTest.RetrieveLegacyCertificateWithoutExpirationTime
      DeviceFilesTest.RetrieveLegacyCertificateWithClientExpirationTime
      DeviceFilesTest.RetrieveLegacyExpiredCertificateByClientExpirationTime
      DeviceFilesTest.RetrieveLegacyCertificateInvalidClientExpirationTime
      DeviceFilesTest.RetrieveCertificateWithoutKeyType
      DeviceFilesTest.RetrieveDefaultCertificate
      DeviceFilesTest.RetrieveDefaultCertificateNeverExpires
      DeviceFilesTest.HasCertificateAtsc
      DeviceFilesTest.HasCertificateDefault
      DeviceFilesTest.HasCertificateLegacy
      DeviceFilesTest.HasCertificateNone
      CertificateTest.StoreCertificateTest.DefaultAndLegacy/*
      CertificateTest.RetrieveLegacyCertificateTest.ErrorScenarios/*
      CertificateTest.RetrieveDefaultCertificateTest.ErrorScenarios/*

Change-Id: I7dbec7555fbd493c1ec61c6bb5d9428a2405b1fd
2021-03-19 02:49:20 -07:00
Rahul Frias
9a350eddbd Extract creation and expiration times from DRM cert
[ Merge of http://go/wvgerrit/119843 ]

Creation and expiration times are extracted from the device DRM
certificate. They are reported as
 * -1 if not set in the proto
 * 0 if unlimited
 * positive number otherwise

Bug: 169740403
Test: WV unit, integraiton tests
Change-Id: I9463954dfeb82b6a88ff5d608ed74d20f2424e83
2021-03-18 23:59:21 -07:00
TreeHugger Robot
6ee9f49e5c Merge "Address compilation warnings" into sc-dev 2021-03-13 02:43:45 +00:00
Alex Dale
16c704fa09 Android tests call exit() when complete.
[ Merge of http://go/wvgerrit/119804 ]

The coverage framework used by Android requires the process to call
exit() for coverage information to be dumped after the tests.

Android unit tests have been adapted to use the a new main module.
The core test_main.cpp used by integration tests has been updated to
call exit().

Bug: 138941105
Test: Linux and Android unittests
Change-Id: Ifffc7b8290c50dffe527738a36547c1d2fb90bd3
2021-03-12 16:22:20 -08:00
Rahul Frias
094fabed5a Address compilation warnings
[ Merge of http://go/wvgerrit/119523 ]

Bug: 182299187
Test: compile vendor/widevine/libwvdrmengine
Change-Id: I39d1b62a3237bfb9163a7e157b871f22e3fec394
2021-03-10 18:49:57 -08:00
Rahul Frias
0cf99f685f Update drm_certificate.proto
[ Merge of http://go/wvgerrit/118563 ]

Sync with the latest version of drm_certificate.proto to add in
certificate expiry time. Add in signed_drm_certificate.proto and remove
messages from device_certificate.proto.

SignedDrmDeviceCertificate and DrmDeviceCertificate are now named
SignedDrmCertificate and DrmCertificate. This necessitated non-proto
changes.

Bug: 169740403
Test: WV unit/integration tests
Change-Id: Ie5969ac7217a25eb075a41df59b77da2becd4545
2021-03-09 14:57:47 -08:00
Rahul Frias
9ab837c78a Integration test for license duration with renewal
This is a squash of several different CLs with chnages only affecting
duration_use_case_test.cpp

* Integration test for license duration with renewal

[ Merge of http://go/wvgerrit/117263 ]

Bug: 180067457

* Add test for infinite renewal

[ Merge of http://go/wvgerrit/107743 ]

This adds a test that verifies an infinite renewal is processed
correctly.

Bug: 162516965
Bug: 170355696
Bug: 169213621
Bug: 166728158

* Add more time to CdmUseCase_Streaming test

[ Merge of http://go/wvgerrit/114146 and http://go/wvgerrit/114147 ]

The duration tests CdmUseCase_Streaming.Case3 was flaky on the
buildbot for platforms with a real clock because there was only room
for 1 second of fudge at the end of playback -- i.e. the rental window
ended at 35s, but the last playback was 34s.

Bug: 175741647

* Set renewal server on command line for tests

[ Merge of http://go/wvgerrit/110903 ]

This CL adds the ability to set the renewal server on the command
line, and adds some comments to the build scripts' README file to
explain how to test a server rollout.

Bug: 173031207

* Change duration test fudge from 1 to 2

[ Merge of http://go/wvgerrit/112143 ]

Some duration tests are flakey. Let's see if this cleans them up
enough.

Bug: 175741647

* Correct some grammar

[ Merged from http://go/wvgerrit/111824 and http://go/wvgerrit/112063 ]

* Add license duration test

[ Merge of http://go/wvgerrit/109143 ]

This adds a license duration test that behaves the same as a rental
duration test. We do not encourage content providers to do this, but
it is reasonable that legacy licenses should work.

Bug: 172099147

* Shorten duration tests

[ Merge of http://go/wvgerrit/108664 ]

This CL tweaks some of the times in the duration use case tests so
that they take less time to run.

These changes the CdmUseCase test time from six and half hours to 3
and a quarter. A 50% savings!

Bug: 170746277

* Improve logging and edge cases in duration tests

[ Merge of http://go/wvgerrit/108663 ]

This cleans up some logging, and handles some edge cases on renewals
when the renewal request round trip overlaps the cutoff time.

Bug: 170746277

* Remove extra cutoff computations

[ Merge of http://go/wvgerrit/106783 ]

The duration tests originally tried to keep track of when the timer
would have gone off if the test was allowed to continue. This proved
impracticle, so the extra parameter has been removed. The tests still
closely match the documented use cases.

Bug: 169453960

* But not too lenient

[ Merge of http://go/wvgerrit/107943 ]

Previously, the duration tests were modified to allow playback to
continue in some cases. See the documentation or code for a list of
these cases. However, the tests had been modified to force playback to
continue in these cases.

This is not desired: in some cases, v15 devices can restrict playback
as requested. This CL changes the tests so that playback restriction
is allowed.  In other words, we no longer force older devices to fail
the test.

Bug: 169255315

* Make some integration tests lenient

[ Merge of http://go/wvgerrit/106843 ]

This allows devices that have OEMCrypto version < v16 or do not
support usage tables to continue playback for an offline license after
the playback window has expired.

Bug: 169582310
Test: duration_use_case_test.cpp

* Add Renewal Use Case tests

[ Merge of http://go/wvgerrit/105826 and http://go/wvgerrit/103784 ]

This CL adds several integration tests that match the duration use
cases with renewals. The test classes are designed for the core cdm,
but the test cases match those found in
oemcrypto/odk/test/odk_timer_test.cpp.

Test: tests pass except for documented bugs.
Bug: 161463952
Change-Id: Ib4775d48490cf150b89aeb2cc64e01a1428f0ab5
2021-03-08 15:36:49 -08:00
Rahul Frias
3176f5f66f An integration test for secure buffers
This is a squash of several different CLs with changes only affecting
policy_integration_test.cpp

* An integration test for secure buffers

[ Merge of http://go/wvgerrit/113905 ]

This extends the previous CL that loads a license that has a key that
requires a secure buffer. It now creates a secure buffer and tries to
decrypt to it.

Bug: 38004627

* Test loading license requiring secure buffer

[ Merge of http://go/wvgerrit/113903 ]

This adds a policy test to verify we can load a license that requires
hardware secure buffers.

Bug: 38004627
Test: WV  unit/integration tests
Change-Id: I1cc0b607ddf5b43fc6b7ba648f3c78d6163e14e9
2021-03-08 15:31:18 -08:00
Rahul Frias
616a9b38dc Return error when test initialization fails
[ Merge of http://go/wvgerrit/116243 ]

Currently if a command line argument is not understood, all tests are
skipped and the test suite passes.

Bug: 182058081
Test: WV unit/integration tests
Change-Id: I9725a9ed9446f15f08372e68c7a25dffd99c7cef
2021-03-08 15:25:50 -08:00