Commit Graph

905 Commits

Author SHA1 Message Date
Rahul Frias
5151daec19 Avoid setting OEMCrypto_Algorithm enum vars with invalid values
[ Merge of http://go/wvgerrit/106203 ]

CdmSigningAlgorithm are converted into OEMCrypto_Algorithm enums
before being passed as parameters to OEMCrypto generic crypto functions.
The OEMCrypto_Algorithm variables should never be set to values not
specified in the enum declaration.

These private methods have also been moved to the anonymous namespace.

Bug: 168774486
Test: WV unit/integration tests
Change-Id: Ie570a3cf4447b6c133076baa0909d562824c8e4a
2020-10-22 16:39:19 -07:00
Rahul Frias
6a1f050ffc Update Widevine Copyright header for core CDM
[ Merge of http://go/wvgerrit/108064 ]

The Widevine License Agreement has been renamed to use inclusive
language. This covers files in the core directory.

Bug: 168562298
Test: verified compilation (comment only change)
Change-Id: I8ae5a10cbfdf7faae6a2735e57b33729763f10b8
2020-10-21 12:05:05 -07:00
Alex Dale
471e8c900d Merge "Query analog output capabilities." 2020-10-19 23:01:32 +00:00
John Bruce
cc715b479d Merge changes I9432dd26,Id52b8c38
* changes:
  Allow 1 or 2 GetOEMPublicCertificate Calls in Metrics Tests
  Fix TimeRollbackPrevention Test
2020-10-19 19:35:40 +00:00
Alex Dale
fb847c4704 Query analog output capabilities.
[ Merge of http://go/wvgerrit/107763 ]

This CL enables the ability to query the CDM for the analog output
capabilites of the device.  Due to the number of possibilities that
OEMCrypto can report, two queries are exposed:
- Output capabilities: None, Supported, CGMS-C, Unknown
- Can disable: True, False, Unknown

Bug: 168322023
Test: Android integration test
Change-Id: I8036a89237d698f170d2c1901c41d1d6b708c917
2020-10-15 17:46:13 -07:00
Rahul Frias
bab666ecdc Merge "Avoid passing device ID when unused" 2020-10-11 23:34:17 +00:00
John W. Bruce
25489dfa5b Allow 1 or 2 GetOEMPublicCertificate Calls in Metrics Tests
(This is a merge of http://go/wvgerrit/107263.)

The CryptoSessionMetricsTest suite assumed that GetOEMPublicCertificate
would only be called once, but in practice, it may be called twice,
since the first call can return OEMCrypto_ERROR_SHORT_BUFFER. This patch
updates the tests to accept 1 or 2 calls.

This patch also updates a few EXPECTs on vector lengths that should have
been ASSERTs, to avoid problems when later accessing the vector.

Bug: 169111969
Test: jenkins/ce_cdm_tests
Test: build_and_run_all_unit_tests.sh
Change-Id: I9432dd2694c7181ab57ed55f66ff6c8be0c867f9
2020-10-06 14:42:54 -07:00
Rahul Frias
6d8e447696 Delay license state evaluation for offline licenses am: 8543b4c903 am: 9f2363e076
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12646162

Change-Id: I0158e6b1dc2560ff28ff9379533a428f2970efeb
2020-09-23 03:03:08 +00:00
Rahul Frias
8543b4c903 Delay license state evaluation for offline licenses
[ Merge of http://go/wvgerrit/106325 and http://go/ag/12644840 ]

When offline licenses are restored, licenses and any renewals are processed.
License state evaluation occurs and notifications are sent to listeners.
If the license is expired, which is likely if a renewal is present,
the license state will transition to expired. Transitions out of
expired state are not allowed and the renewal has no effect.

If we work around this by allowing transitions out of expired state,
listeners will get notifications that keys have expired and then that are
usable soon after. To avoid delivering erroneous notifications we delay
evaluation of license state while the license and renewal are being processed.
Evaluation occurs at the last stage of license restoration when playback
information from the usage table is being restored.

This only need to occur for when licenses are being restored. In other
cases when a license or renewal is received, license state evaluation
and event listener notification needs to occur immediately.

Bug: 166131956

Test: WV unit/integration tests, GtsMediaTestCases tests
Change-Id: Ic8ade25316c5e20cc88de9225c43c24b28f21ac4
2020-09-22 15:36:35 -07:00
Fred Gylys-Colwell
5eb94cc6c6 Sign unused renewal so that offline renewal may be loaded am: 80667cbac3 am: f5896158c1
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12629547

Change-Id: I431e1f6607dd162809098798c20e28a35f1b88f8
2020-09-22 22:00:43 +00:00
Fred Gylys-Colwell
80667cbac3 Sign unused renewal so that offline renewal may be loaded
Merge from Widevine repo of http://go/wvgerrit/105347

When reloading an offline license that has an offline renewal, we sign
a unused renewal so that the ODK library can update its clock values.

Test: WV unit/integration tests, GtsMediaTestCases tests
Bug: 166131956
Change-Id: Ib1445fd85222489f21221e00729d4989cb49a331
2020-09-22 02:44:05 +00:00
Rahul Frias
0761dd8920 Avoid passing device ID when unused
[ Merge of http://go/wvgerrit/105743 ]

Device ID is no longer reported directly in provisioning/license
request or used by ClientIdentification. It does not need to be passed
in during initialization.

Bug: 168085721
Test: WV unit/integration tests
Change-Id: I483eac963c3f40784e42e1a2b917fcc96aa76a05
2020-09-17 23:35:15 -07:00
Edwin Wong
051e879438 Rename metrics.proto to wv_metrics.proto.
Merge from http://go/wvgerrit/105767

To avoid conflict with metrics.proto in
frameworks/av/drm/libmediadrm/proto.
This is in preparation of moving metrics_dump tool
to build under Android.

bug: 161783052
Test: unit test
Test: Play Movies & Tv and Netflix streaming
Change-Id: I2406b66db4d61cca7c6260ea8847a555d96c8d42
2020-09-10 12:26:28 -07:00
Alex Dale
7686e28e15 Merge "Enabled log formatting warnings." 2020-09-09 04:13:02 +00:00
Alex Dale
1defd1c7fc Merge "Correctly handle local display only for SRM version." 2020-09-09 03:38:48 +00:00
Alex Dale
f22cd20466 Enabled log formatting warnings.
[ Merge of http://go/wvgerrit/105025 ]

Clang and GCC allow for warnings against the arguments for printf-like
functions (e.i. LOGx).  These validate that the format type specified
in the format string match the corresponding argument type.

Most of the time, format specifer errors are benign; hence why they
haven't been seen as an error so far.  However, with the enabling of
specifier warnings and the enabling of warnings as errors on certain
platforms, these existing errors need to be addressed.

This CL enables format specifier warnings for most of the Widevine
code, with the OEMCrypto L3 implementation which has a single error
which requires a fix in the haystack code before being fixed in the
Widevine branch.

Strict format string warnings are not enabled for non-LP64 systems.

Bug: 137583127
Test: Compiled for Linux and Android
Change-Id: I051398332d31a20457b86563a90ad8f6d428445f
2020-09-08 15:46:15 -07:00
Rahul Frias
315bf42c4f Do not store information for kLicenseTypeTemporary
[ Merge of http://go/wvgerrit/105624 ]

Temporary licenses do not allow for license information to be stored
in any form, whether it is usage information or persisting license
information. Information should not be stored even if can_persist is
set to true and a PST is specified as those are suggestions rather than
a requirement.

Bug: 167684104
Test: WV unit/integration tests
Change-Id: I141a2bd5de4d86f0e5f31fc8f0ea9e20710d6469
2020-09-07 18:50:13 -07:00
Alex Dale
b96b58628c Correctly handle local display only for SRM version.
[ Merge of http://go/wvgerrit/105343 ]

If a device only supports local display (eliminating the need for an
SRM version), then the CDM should treat this as no SRM version.

Bug: 166009716
Test: License request integration test
Change-Id: I2d9c3f98735563df6d7c7a287abab41bf0a8c513
2020-09-02 21:36:37 -07:00
Edwin Wong
c64903759d Merge "Convert Android.mk to Android.bp" 2020-08-21 17:13:00 +00:00
Edwin Wong
307cf378a9 Convert Android.mk to Android.bp
This CL builds the Widevine drm services and libraries.
Soong makefile conversion for unit and integration
tests will be in a different CL.

This doc may help with the review:
https://docs.google.com/document/d/1lK3X9RFPwbbwewLNlS4TfSMhxIlPuAkHRnGcgwWpChU/edit?usp=sharing

Test: build
Test: Play Movies and Netflix streaming
Test: unit tests
  build_and_run_all_tests.sh
Test: gts
  ANDROID_BUILD_TOP= ./android-gts/tools/gts-tradefed run gts -m GtsMediaTestCases -t com.google.android.media.gts.MediaDrmTest

  atest GtsExoPlayerTestCases:com.google.android.exoplayer.gts.DashTest

Test: vts
  ANDROID_BUILD_TOP= PATH="$PWD/android-vts/tools:$PATH" vts-tradefed run commandAndExit vts --module VtsHalDrmV1_3Target

Bug: 162321744
Change-Id: I50c0fb2e8f28dfe7901587e3d3203542943e23b1
2020-08-19 14:54:47 -07:00
TreeHugger Robot
9ca0979e7f Merge "Test renewal against same and different server" 2020-08-19 20:47:27 +00:00
Fred Gylys-Colwell
7604158d6f Test renewal against same and different server
Merge from Widevine repo of http://go/wvgerrit/102843

The test WvCdmEngineTest.LicenseRenewal is split into two tests. One
test verifies that the renewal may be fetched from the server
specified in the license. The second test verifies that the renewal
may be fetched from the same server that the license was fetched from.

These might be the same server, but when we run against an
experimental server, a staging server, or UAT Nightly, these
will be different.

Test: ran the tests
Bug: 141438127
Change-Id: Ia11441bd2ba0c6ddb264ee38bfcb5060b9ddb476
2020-08-19 20:45:33 +00:00
John W. Bruce
7f028d25c8 Fix Undefined Behavior Around Enums
(This is a cherry-pick of http://go/wvgerrit/104184.)

UBSan has detected several places where our code tripped over what is
technically Undefined Behavior when handling enums, although in practice
any compiler would still generate safe code.

Some of these were places a variable was not being initialized and thus
was filled with garbage data. These have been fixed.

Understanding the rest depends on a bit of C++ trivia I had certainly
never heard before: An enum that doesn't specify its backing type will
frequently have a gap between the range of values the compiler will let
it take (which is limited only by the size of the backing type assigned
by the C++ standard) and the range of values for which the C++ standard
defines the behavior. (which is limited by the minimum number of bits
needed to hold the largest valid enumeration entry) So, for example, an
enum containing ten entries numbered 0 through 9 would be stored in
memory as an int and could thus take any value in the range of an int.
But it only takes 4 bits to represent the numbers 0 through 9. The
largest number that can be represented in 4 bits is 15. So reading the
value of a variable of this enum type when its stored value is outside
the range 0 to 15 is undefined behavior.

An enum that specifies its backing type is not subject to this because
it is defined behavior to access any value representable in the backing
type if one was explicitly specified.

If you think this sounds a bit silly, you'll be happy to know it doesn't
apply from C++17 onwards and most compilers generate code that handles
the undefined behavior values correctly.

Nonetheless, to appease UBSan and protect us from any compilers that
actually rely on this undefined behavior for optimizations, I have
defined backing types for all our enums. I have defaulted to the type
the compiler was already using (int32) and have deviated only where an
enum exists to be compared to or filled from a protobuf field and that
field in the protobuf is unsigned, in which case I used a uint32.

In the case of the CE CDM exported API, this also required changing our
enums from C-style to C++-style.

Bug: 163080356
Test: CE CDM Build & Unit Tests Pass even with UBSan
Test: Android Build & Tests
Change-Id: Id7e0064129e7c4d2827bb4a94825d144eeaacec8
2020-08-18 18:02:36 -07:00
Rahul Frias
17e0562098 Merge "Log OEMCrypto_CloseSession error" 2020-08-13 01:49:35 +00:00
Alex Dale
aa7ed24123 Merge "Log X-Google fields on failed HTTP requests." 2020-08-10 20:34:12 +00:00
Alex Dale
be2e32d09e Merge "Handle unlimited usage table capacity." 2020-08-07 20:35:43 +00:00
Rahul Frias
49e53ffdfe Log OEMCrypto_CloseSession error
[ Merge of http://go/wvgerrit/103643 ]

Bug: 161417560
Test: WV unit/integration test
Change-Id: I2d7e3b90e2e34e7854dea7aac865f8577d113aab
2020-08-05 02:20:28 -07:00
Rahul Frias
79eabb0989 Allow offline licenses to be loaded and restored in the same session
[ Merge of http://go/wvgerrit/103243 ]

Include review comments from wv gerrit CL.

Bug: 161551490
Test: WV unit integration tests, GtsMediaTestCases and
      WidevineConcurrentDrmCertificatesTest#testConcurrentDrmCertificates,
      MediaDrmTest#testMultipleLoadKeys on a redfin
Change-Id: Ie9b41a2e68b95692f9353578f6955637411d4dfc
2020-08-04 15:02:06 -07:00
Alex Dale
147c9e0afa Log X-Google fields on failed HTTP requests.
[ Merge of http://go/wvgerrit/103395 ]

To help with debugging failures in HTTP requests during unit tests,
this CL adds logging for Google's debugging response header fields.
These fields are of the type "X-Google-*" or "x-google-*" and provide
information such as the service name, server cell, error details, and
other details that can help isolate the cause of failure on the
server's end.

An additional unittest has been created to test the parser for the
header fields.

Tests that are known to exprience HTTP failures have been extended
to include logs for these fields should they be present.

Bug: 137619348
Test: Linux unit tests and Jenkins test
Change-Id: I69959af2ba91510f345bbb02cf7ca35c3f1119da
2020-07-30 17:24:11 -07:00
Alex Dale
99335a6aa8 DO NOT MERGE Handle unlimited usage table capacity.
[ Merge of http://go/wvgerrit/103684 ]
[ Cherry pick of http://ag/12221244 ]

The OEMCrypto method for usage table capacity can return zero to
indicate that the usage table size is not explicitly limited.  The
CDM must handle this case with regard to the CDM's usage table
management and information querying.

The usage table initialization tests are extended to include cases
where the table does not have a defined limit.

AddEntry() was missing call to update the usage table header after
creating a new usage entry.  This call is now included and required
additional changes to the usage table unit tests.

Bug: 160560364
Test: Android unit tests
Change-Id: Ica5d181092d2938d24deba5005a211ca883cb0f0
2020-07-29 17:45:21 -07:00
Alex Dale
def1a778b6 Handle unlimited usage table capacity.
[ Merge of http://go/wvgerrit/102945 ]

The OEMCrypto method for usage table capacity can return zero to
indicate that the usage table size is not explicitly limited.  The
CDM must handle this case with regard to the CDM's usage table
management and information querying.

The usage table initialization tests are extended to include cases
where the table does not have a defined limit.

AddEntry() was missing call to update the usage table header after
creating a new usage entry.  This call is now included and required
additional changes to the usage table unit tests.

Bug: 160560364
Test: Android unit tests
Change-Id: Ica5d181092d2938d24deba5005a211ca883cb0f0
2020-07-27 15:36:25 -07:00
Rahul Frias
c8cff5274c Allow offline licenses to be loaded and restored in the same session am: 3709a4f419 am: 693d58e17d am: e37249c1de
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12209028

Change-Id: I53f56740230c5e085f6210d5149cc4a77d475a8d
2020-07-26 18:48:36 +00:00
Rahul Frias
3709a4f419 Allow offline licenses to be loaded and restored in the same session
[ Merge of http://go/wvgerrit/103243 ]

In v16, OEMCrypto specifications required that an error be returned if
multiple attempts are made to load an offline license into a session.
This caused the GTS test testConcurrentDrmCertificates to fail. It was
introduced to verify that a license could retrieved and loaded into a
session and then restored. This was based on an app use case.

Ideally we would like to disallow a this behavior but need to make sure
it is not being used by apps.

For now this will be allowed. If detected, the CDM will reintialize the
OEMCrypto session and allow the license to be restored.

Bug: 161551490
Test: WV unit integration tests, GtsMediaTestCases and
      WidevineConcurrentDrmCertificatesTest#testConcurrentDrmCertificates,
      MediaDrmTest#testMultipleLoadKeys on a redfin
Change-Id: I0834e4419c3a6dccfd77aaea3afa3d65c2c0c742
2020-07-24 07:27:19 -07:00
Rahul Frias
d6c8348229 Merge "Correct WV log spam" 2020-07-24 06:33:23 +00:00
Robert Shih
41c6222c49 PolicyTimersV16: override base class HasRenewalDelayExpired am: d9112ff7e1 am: 035254e828 am: 6c6cbc95df
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12184963

Change-Id: I183964f4454b2718623cfaf471bdd92a5394322e
2020-07-24 00:16:41 +00:00
Rahul Frias
b02c9fc8ca Correct WV log spam
[ Merge of http://go/wvgerrit/102923 ]

Avoid logging an error, on first boot, when trying to retrieve a
certificate that does not yet exist.

Bug: 161201883
Test: WV unit/integration tests
Change-Id: I293f9766a7f2024107d0db45a874a9478b0c3959
2020-07-23 15:00:37 -07:00
Robert Shih
d9112ff7e1 PolicyTimersV16: override base class HasRenewalDelayExpired
Base class uses license_start_time_ which is not updated on renewals.

Merge of http://go/wvgerrit/103123

Bug: 161023174
Bug: 161621246
Test: WidevineDashPolicyTests#testL1RenewalDelay5S
Test: WidevineDashPolicyTests#testL1RenewalDelay13S
Change-Id: I16056d492bea4dd721984998b5cf38409fe3b055
2020-07-23 21:06:29 +00:00
TreeHugger Robot
37afd55f2e Merge "Start rental clock when nonce-free offline license loaded" into rvc-d1-dev am: d24b3d4bd2 am: 84c1ff91ae am: e8cf28340a
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12184965

Change-Id: I5d7b3212ef4d0c6f92793fb9b071dc83b2148d36
2020-07-21 11:05:22 +00:00
TreeHugger Robot
d24b3d4bd2 Merge "Start rental clock when nonce-free offline license loaded" into rvc-d1-dev 2020-07-21 10:24:53 +00:00
Fred Gylys-Colwell
fdc024c9c0 Adjust nonce for v15 servers am: 7f347cd59f am: 940a771969 am: 08fe6b1690
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12173751

Change-Id: I4d55319169d3e2709568ff51336cce0ad6b04345
2020-07-21 08:53:50 +00:00
Fred Gylys-Colwell
b90f88072f Start rental clock when nonce-free offline license loaded
Merge from Widevine repo of http://go/wvgerrit/103107

When an offline license is reloaded, if it does not have a usage entry
to indicate when the rental clock was started, the start time defaults
to 0 in the ODK library (in OEMCrypto). This CL changes the code to
start the rental clock in this case. It does this by signing a dummy
message, which triggers the ODK library to start the rental clock.

Bug: 161585265
Bug: 161023174
Test: GTS tests. http://go/forrest-run/L55100000642199761
Change-Id: I4cf555b2fb43009ffb62e7b2c1a37265c3f70bfe
2020-07-20 23:11:48 +00:00
Fred Gylys-Colwell
7f347cd59f Adjust nonce for v15 servers
Merge from Widevine repo of http://go/wvgerrit/102783

When OEMCrypto is v16, but the license server is v15, we should not
create a new nonce for a license renewal. However, the request does
need a nonce or the license server will not generate a valid key
control block. So we should use the nonce that came from the original
license.

Bug: 160676790
Test: tested playback using netflix
Test: GTS tests. http://go/forrest-run/L55100000642199761
Change-Id: Ie1644b5abe0662387edf01f6110d82f70a64df6c
2020-07-20 23:11:41 +00:00
Alex Dale
7ce8950c0f Usage table LRU only retrieves a single entry.
[ Merge of http://go/wvgerrit/102167 ]

After changes made to how the usage table is defragged by the CDM,
it was determined that there is no use in selecting more than a single
entry from the usage table to evict.  The only failure that can occur
when evicting an entry is if the last entry is in use, in that case,
evicting other entries will still result in a failure.

This change cleans up the LRU algorithm and test cases to reflect
the new functionality.

Bug: 155230578
Test: Linux unit tests
Change-Id: I817c039670d9f72c0e4f6c3fdac45c98ed5b6b21
2020-07-14 18:37:11 -07:00
Alex Dale
1d136b4f94 Merge "Re-enabling parallel license tests for L1 and ModMock." 2020-07-10 00:17:53 +00:00
Alex Dale
cf6cf5f4e8 Re-enabling parallel license tests for L1 and ModMock.
[ Merge of http://go/wvgerrit/102108 ]

Several tests that make parallel license requests were disabled due
to a flaky server failure unrelated to CDM code.  Most of these tests
are now re-enabled to ensure the multi-threaded license requests is
functional on V16.

These tests remains disabled for L3 due to continued flakiness.

Added a lock around the initialization of the SSL library to prevent
issues with license requests getting garbled.

Bug: 137619348
Test: Linux and Android unit tests
Change-Id: Idffaa6039b2bde12613bb5033af32d1af6704c76
2020-07-08 16:44:00 -07:00
John Bruce
5a27d24742 Merge "Memory Leak in CertificateProvisioningTest" 2020-07-08 19:56:04 +00:00
John W. Bruce
5f232c5436 Memory Leak in CertificateProvisioningTest
(This is a merge of http://go/wvgerrit/102084.)

No one was claiming ownership of the metrics object in
CertificateProvisioningTest, resulting in a leak. This patch makes the
test hold onto ownership.

Bug: 159486086
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I84710782b7a60d6bd3a7eda981de4f0af877fc39
2020-07-07 15:07:16 -07:00
Robert Shih
2ac3a6b623 GetDecryptHashSupport: recognize OEMCrypto_ERROR_NOT_IMPLEMENTED am: da09f4abca am: 0db8b90cdb am: 2009155f7e am: deb11efb5f
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12036417

Change-Id: I6df47d941ecea3ad046c90f19bd355767d0e15ab
2020-07-07 00:34:36 +00:00
Robert Shih
da09f4abca GetDecryptHashSupport: recognize OEMCrypto_ERROR_NOT_IMPLEMENTED
[ Merge of http://go/wvgerrit/102383 ]

Bug: 153297118
Bug: 160182693
Test: MediaDrmTest#testDecryptHashError
Change-Id: I107668cdd1ab0acda717f184496e569a4f9a8653
2020-06-29 22:19:26 +00:00
John Bruce
38a8b631be Merge "Rework Device File Matchers to Avoid Buffer Overflow" 2020-06-25 21:58:58 +00:00