Commit Graph

391 Commits

Author SHA1 Message Date
Rahul Frias
7d78609548 Key Status should reflect key container security level
[ Merge of http://go/wvgerrit/77506 ]

Callers of MediaDrm can register to be notified when key status
changes and if they are usable for decryption. A number of factors
are evaluated when making this determination. Key container security
level will now be included in the evaluation.

Bug: 78652608
Test: WV unit/integration test, GtsMediaDrmTest, Play movies playback
      testing.

Change-Id: I20243e5cb160f7957e3239e8d05f715ff0ee6dd6
2019-05-09 22:16:23 -07:00
Rahul Frias
4bd6f2bed0 Merge "Handle key rotation" into qt-dev am: 862cb96e77
am: 5b8fc4a05b

Change-Id: I0bbf6b0e12cde87c768d1b6408b7ef05801d7a3d
2019-05-03 23:00:50 -07:00
Rahul Frias
2e2e92280e Handle key rotation
[ Merge of http://go/wvgerrit/77049 ]

Entitlement PSSHs can now be provided in follow on key generation
requests to cause keys to be rotated without needing a license
exchange.

Bug: 128462397
Test: WV unit/integration tests, Netflix and GPlay tests,
      GtsMediaDrmTests

Change-Id: I6ed0901a35c498240f42e405a522d82ea8dce2f7
2019-04-23 13:54:51 -07:00
John W. Bruce
125856238c Rename WvGenericOperationsTest.
(This is a merge of http://go/wvgerrit/76043)

This renames the tests to be *GenericCrypto* to match the OEMCrypto
tests and ensures these tests are skipped when the device doesn't
support generic crypto.

Test: Android Unit Tests
Bug: 126392281
Change-Id: Ib16ca8c57ed5d99dde802d4d9a63eced0fa807a5
2019-04-19 22:22:59 +00:00
John W. Bruce
5ea429ee2b Don't Use StringStream When It's Overkill
(This is a merge of http://go/wvgerrit/76063)

Now that we have C++11, many places that do string formatting or parsing
can be replaced with std::to_string() or one of the std::sto*() family
of functions. This patch updates places that do simple stringifying or
parsing to use these functions. Some parts of the code are left
untouched because they were using StringStream to do more complex
actions, such as constructing more complex output or checking the status
of the parsing.

Bug: 120599938
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I482dc234ecd7c6014fa9b6874387ff51e04b772f
2019-04-17 17:46:31 -07:00
Rahul Frias
a45deef63b Merge "Corrections for limited duration licenses" 2019-03-26 16:24:48 +00:00
Rahul Frias
43efc6d84a Corrections for limited duration licenses
[ Merge of http://go/wvgerrit/74627 ]

Limited duration licenses (where license duration is unlimited and
playback window is set to a small value) did not work correctly when
the initial decrypt call occured before the license was received.

Bug: 109653883
Test: WV unit/integration tests
Change-Id: I0738e97db525b239455e2ac93ab0bedd6611b311
2019-03-23 00:53:26 -07:00
Fred Gylys-Colwell
d641797e05 Use hex for FDPT hash
Merge from Widevine repo of http://go/wvgerrit/75123
Merge from Widevine repo of http://go/wvgerrit/75114

This changes the encoding for the hash to be hex instead of base64.

Also, the bad frame number is initialized to 0 to make it easier to
debug. And the FDPT test app now uses the correct byte order.

Bug: 129100318
Test: unit tests, FDPT test app.
Change-Id: I296bab990125a4e18bec92f3316e8289a3b25a6b
2019-03-22 17:14:27 -07:00
Robert Shih
d54634baa4 hidl: return BAD_VALUE from RemoveOfflineLicense when keyset is not found
Bug: 127828539
Test: VtsHalDrmV1_2TargetTest
Change-Id: Ia567be076a9460546c59c2a38231e18bb0549ce3
2019-03-18 15:24:22 -07:00
Adam Stone
741645a4be Add UsageTableHeader metrics
[ Merge from http://go/wvgerrit/72183 ]

Adds basic metrics for the usage table header.

Bug: http://b/112919252
Test: Unit tests. Manual GPlay
Change-Id: I14d406766d8b2aba3b6e4f1a02c75eedc674b011
2019-02-25 17:09:31 -08:00
Adam Stone
05599927b9 Switch to using shared_ptr for Session Metrics
[ Merge from http://go/wvgerrit/71443 ]

The assumption that the metrics will always outlive the CdmSession
instance appears not to always hold (at least in a non-android
multi-threaded solution). The shared_ptr ensures that the metrics
are available even in these rare race conditions.

BUG: http://b/123321465
Test: CDM unit tests. Also http://go/wvgerrit/71264 parallel tests.
Change-Id: Iaa6a8f6c0fdc46a911789759d6e1228d849aa237
2019-02-04 10:19:06 -08:00
Adam Stone
9f31068de6 Merge "Add a metric decorator around cdm engine" 2019-02-04 17:55:35 +00:00
Rahul Frias
c9f7085f92 Merge "Enable provider client token test" 2019-02-01 21:44:02 +00:00
John Bruce
f8e46ebb34 Merge "Add a Reader-Writer Lock" 2019-02-01 19:32:43 +00:00
Fred Gylys-Colwell
4287df7d3d Merge "Revert "Remove Test Keybox Again"" 2019-02-01 19:23:31 +00:00
Rahul Frias
f83e813ea8 Enable provider client token test
[ Merge of http://go/wvgerrit/71907 ]

The client token needed to be enabled in the license request.

Bug: 123369846
Bug: 123370099
Test: WV unit/integration tests
Change-Id: I4d3e944b1d79010977c119291594878c406b00c5
2019-02-01 11:17:45 -08:00
Adam Stone
46eecb6b80 Add a metric decorator around cdm engine
[ Merge from http://go/wvgerrit/69105 ]

This adds a metric collecting decorator class around cdm engine. This
implementation uses a templated decorator. The decorator enables:

1) Wrapping the CDM Engine methods to capture timing and error
information.
2) Allows use of a mock CDM Engine for testing.

Test: Unit tests. GPlay manual testing and GTS tests.
BUG: http://b/64724336
Change-Id: I5e4a0f552974fab1939bc7ab02719a1f5849cf3f
2019-02-01 10:32:44 -08:00
Rahul Frias
272e60db27 Add recoverable errors
[ Merge of http://go/wvgerrit/71326 ]

Nonce flood, frame size, session and system invalidation errors
will now bubble up to the app. OEMCrypto v15 returns
OEMCrypto_ERROR_BUFFER_TOO_LARGE, OEMCrypto_ERROR_SESSION_LOST_STATE,
OEMCrypto_ERROR_SYSTEM_INVALIDATED and a variety of nonce errors.
These will be reported to HIDL as OUTPUT_TOO_LARGE_ERROR,
ERROR_DRM_SESSION_LOST_STATE, ERROR_DRM_INVALID_STATE and
ERROR_DRM_RESOURCE_CONTENTION.

Bug: 120572706
Test: Unit/Integration tests
Change-Id: Ida177300046327ce81592a273028ef6c3a0d9fd9
2019-01-31 00:44:02 -08:00
Fred Gylys-Colwell
fca89868f8 Revert "Remove Test Keybox Again"
This reverts commit 408509efdc.

Reason for revert: just kidding. We want to run the tests on 
old devices, too.

Change-Id: I920fa825380638122f638e057bcfbe98b5f7b301
2019-01-30 19:17:06 +00:00
John W. Bruce
a1b5b42d55 Add a Reader-Writer Lock
(This is a merge of http://go/wvgerrit/70666)

We need a reader-writer lock implementation in order to make use of the
new threading guarantees in OEMCrypto v15. However, we do not have
access to an STL reader-writer lock due to only being on C++11. This
patch adds a home-grown reader-writer lock, as well as tests to verify
that its behavior is sound.

Bug: 70889998
Bug: 118584039
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: Iaddcefb50e72452fbd27d04879eacf775484e675
2019-01-29 13:41:38 -08:00
Edwin Wong
54104c7a22 Implement MediaDrm offline license support in Widevine hidl service.
Merged from http://go/wvgerrit/69723.

The new APIs are getOfflineLicenseIds, getOfflineLicenseState and
removeOfflineLicense. These methods are currently stubbed out in
Widevine hidl service. This CL completes the implementation.

Test: unit tests - libwvdrmdrmplugin_hidl_test

Test: GTS
  --test com.google.android.media.gts.MediaDrmTest#testWidevineApi29

bug: 117570686
Change-Id: I96ffb75f453e36e931effefd3664b5faa8d69d30
2019-01-29 13:41:08 -08:00
Rahul Frias
19c4996b3c Merge "Modified return values for Restore operations" 2019-01-28 21:31:54 +00:00
John Bruce
d21695d395 Merge "Add a cross-platform argument parser." 2019-01-28 18:29:10 +00:00
John Bruce
fcfa61c71f Merge "Misc Windows fixes." 2019-01-28 17:49:28 +00:00
John Bruce
9372b9fb54 Merge "Segfault When Running Jenkins Tests... Sometimes" 2019-01-26 17:31:32 +00:00
Fred Gylys-Colwell
1e9c85c00d Merge changes Ibd8951c7,I9a13dbae
* changes:
  Add mutex lock around InstallTestRootOfTrust
  Remove Test Keybox Again
2019-01-26 01:09:28 +00:00
Fred Gylys-Colwell
03c10789f9 Add mutex lock around InstallTestRootOfTrust
Merge from Widevine repo of http://go/wvgerrit/71323

When running multithreaded tests, we need to make sure there are no other
OEMCrypto calls between OEMCrypto_Initialize and the installation of the test
keybox.

bug: 123319961
test: ran juce's threading test
Change-Id: Ibd8951c764f6538da4afa9ad146a6a72064eb13a
2019-01-26 01:05:38 +00:00
Jacob Trimble
9a66a6f590 Add a cross-platform argument parser.
(This is a merge of http://go/wvgerrit/70343)

Instead of using the POSIX-specific getopt(), this uses a manual
string comparison so it works on Windows.

Test: Android Unit Tests
Bug: 122953649
Change-Id: If009f8b3bfc8581d252da0f5ed55293c46d70bc6
2019-01-25 15:44:28 -08:00
Jacob Trimble
b3dd9c3711 Misc Windows fixes.
(This is a merge of http://go/wvgerrit/70324)

- Add build settings for Windows.
- Conditionally add pthread.
- Add dummy DLLMain method.
- Fix #if checks for Windows.
- Remove designated initializers which aren't supported in MSVC.
- Remove variable length array.

Test: Android Unit Tests
Bug: 122953649
Change-Id: I14f16e7ce4b3ff17ee0139ea6c2f7243ae999aa1
2019-01-25 15:05:00 -08:00
John W. Bruce
dfc5909d0c Segfault When Running Jenkins Tests... Sometimes
(This is a merge of http://go/wvgerrit/71330)

The Service Certificate unit tests actually relied on the ability to
call Properties::Init() multiple times to clear previous mutable state.
Unfortunately, they didn't check the return code that could have told
them their mutable state wasn't being cleared and instead proceeded to
use a pointer which — depending on compiler — could be totally valid and
allow the test to pass or could be invalid and cause a segfault. You can
read the bug for a fuller explanation of the mechanics.

The fix is twofold. First, the tests will now assert out if insertion
into the property set map fails, preventing segfaults. Second, a helper
has been added to Properties that allows tests interested in
re-initializing Properties to do so. The default behavior for most tests
remains the same: Properties can only be initialized once and subsequent
calls to Properties::Init() are ignored.

This patch also fixed a few formatting issues I noticed.

Bug: 123099779
Test: Jenkins Unit Tests w/ GCC
Test: CE CDM Unit Tests w/ GCC & Clang
Change-Id: Ifd29f3ddf5cff934933cf47b92ecd12ab0a4a938
2019-01-25 14:48:00 -08:00
Srujan Gaddam
d203bea228 Fix entry range for INSUFFICIENT_RESOURCES tests
Bug: b/121214641
Merge of http://go/wvgerrit/70768
Tests: usage_table_header_unittests (with and without hardcoded values)

DeleteEntry fails if the last entry is in use, since it cannot shrink
the table any further via swapping. The LoadEntry_LoadUsageEntry...
tests test to see that after deleting an entry x amount of times, the
usage table can load an entry. If the entry we want to load is within x
positions of the last entry of the usage table, the method cannot
succeed for the aforementioned reason.

Change-Id: Iccdaf538cb4bcbd34855f36c71aceaeb93b4a770
2019-01-25 11:32:13 -08:00
Fred Gylys-Colwell
408509efdc Remove Test Keybox Again
Merge from Widevine repo of http://go/wvgerrit/69563

This CL also disables unit tests that depend on the old test keybox when run
against OEMCrypto v13 or earlier.

Unit tests that require a particular API level have been
removed.  This requirement for Android is tested in GTS tests.

Bug: 119316243
Test: unit tests
Change-Id: I9a13dbaee1693ecea906fd0184a8e2590dc5beed
2019-01-24 11:59:02 -08:00
John Bruce
85e2c6a026 Merge "Simplify How Request ID Indices are Generated" 2019-01-24 05:27:18 +00:00
John Bruce
dfeaa49cb7 Merge "Implement HttpSocket for Windows." 2019-01-24 05:24:49 +00:00
Rahul Frias
869fd8b0d6 Merge "Return error codes when storing or retrieving licenses" 2019-01-23 19:12:25 +00:00
Rahul Frias
8b61a03b5f Return error codes when storing or retrieving licenses
[ Merge of http://go/wvgerrit/70386 ]

This allows error codes from device files to be added as sub-errors when
errors such as GET_LICENSE_ERROR are encountered.

Bug: 112357085
Bug: 115382201
Test: WV unit/integration tests

Change-Id: I505a87086ce584efc7e482984c0f132ac5329e16
2019-01-23 18:16:53 +00:00
John W. Bruce
ca00dc7ae4 Simplify How Request ID Indices are Generated
(This is a merge of http://go/wvgerrit/70667)

Request ID Index generation has historically worked by incrementing a
shared variable in one place and reading it in another place and
trusting the fact that CdmLicense calls these operations in a certain
order and only once per session to give each session a unique value.
This patch cleans this up a bit, having each session store the current
Request ID Index at the same time as it stores its Request ID Base. This
guarantees that each CryptoSession will receive a unique but stable
combination of Base and ID rather than relying on the calling pattern.

Since all this generation happens during the same function, the full
Request ID can be generated up-front and stored, making
GenerateRequestId() no longer necessary.

This patch also simplifies the threading story around this shared state
by using a std::atomic<uint64_t>. Bringing the code that interacts with
the shared state together into one place and replacing it with atomic
operations will simplify locking around this code when CryptoSession
locking is revamped in a future patch.

Bug: 70889998
Bug: 118584039
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I12d2f6501f872f1973e5a9af5125ca03f23e5a56
2019-01-23 09:52:46 -08:00
Rahul Frias
675b934406 Modified return values for Restore operations
[ Merge of http://go/wvgerrit/70543 ]

RestoreOfflineLicense and RestoreLicenseForRelease now return
CdmResponseType errors rather than a boolean. These error codes
can now be used when gathering metrics.

Bug: 115517916
Test: WV unit/integration tests
Change-Id: If4784d2cdd9825948c5dec31d3e60058ea06b61d
2019-01-17 00:09:38 -08:00
Jacob Trimble
39028534fa Implement HttpSocket for Windows.
(This is a merge of http://go/wvgerrit/70304)

Test: build_and_run_all_unit_tests
Bug: 122953649
Change-Id: I6f201f460a0779a23e72db2bbc5d22e3f47cdd42
2019-01-16 20:06:37 -08:00
Srujan Gaddam
92e123d8ea Merge "Fix handling of INSUFFICIENT_RESOURCES in LoadEntry" 2019-01-17 03:33:49 +00:00
John Bruce
0c194ff115 Merge "Re-enable Binary Provisioning Test Again" 2019-01-17 00:30:42 +00:00
John W. Bruce
777abaef01 Add some platform abstractions.
(This is a merge of http://go/wvgerrit/70303)

This adds a platform.h file to abstract some of the differences
between Windows and POSIX platforms.  This includes ntohl, setenv,
and ssize_t.

Bug: 122953649
Test: Android Unit Tests
Change-Id: I3235f3f284b53d24d7365ff3f4a06dcd9b403697
2019-01-16 11:06:55 -08:00
John W. Bruce
e12a837e14 Re-enable Binary Provisioning Test Again
(This is a merge of http://go/wvgerrit/70384)

It turns out the reason the binary provisioning unit test was failing is
because the test base class was setting the property to turn on binary
provisioning before calling Init(), however all current Init()
implementations overwrite the value of that field. As such, the tests
weren't actually using binary provisioning. With that fixed, everything
passes; the binary provisioning flow doesn't appear to actually be
broken.

This is the exact same commit as was previously reverted,
cf5464d7a2fbecd1938ae0700199145b7b61c3c3. However, a pending patch fixes
the multiple runs of Properties::Init() that lead to the inconsistent
failures of the previous patch. (See http://go/wvgerrit/70383)

Bug: 112046733
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I79fc2c8d4d24505b46cab0e21eef85a37d66748d
2019-01-15 16:28:01 -08:00
Srujan Gaddam
13b5c48512 Fix handling of INSUFFICIENT_RESOURCES in LoadEntry
Bug: b/121214641
Merge of http://go/wvgerrit/69703
Test: Android + Linux unit tests

LoadEntry attempts to handle INSUFFICIENT_RESOURCES by deleting an entry
and retrying, but it's possible that the randomly-generated number of
the entry to be deleted might match the entry we want to load. In this
case, we have wasted a retry, since the code just continues on to the
next iteration. This is changed to generate a number different from the
entry to load. Furthermore, if the number of usage entries is 1, we
break since there are no more entries to delete besides the one we want
to load. The code is also changed to call srand in the creation of the
usage_table_header, since without it, rand() would produce the same
values, and similarly, our random generation is changed to use a simple
mod. Tests are modified to reflect these changes.

Change-Id: I95e125b8adbd85d0189f9d40ca15f3fe69e6d6b9
2019-01-11 11:39:54 -08:00
John Bruce
38c45a66a3 Revert "Re-enable Binary Provisioning Test"
(The matching reversion in the Widevine Repository is
http://go/wvgerrit/69923)

This reverts commit c207ef8ea6.

Reason for revert: Widevine Buildbot failures

Change-Id: Ied9e36f9eaa94bb7e9cd13b8dff7a2cbdca07a07
2019-01-09 18:55:06 +00:00
John W. Bruce
c207ef8ea6 Re-enable Binary Provisioning Test
(This is a merge of http://go/wvgerrit/69843)

It turns out the reason the binary provisioning unit test was failing is
because the test base class was setting the property to turn on binary
provisioning before calling Init(), however all current Init()
implementations overwrite the value of that field. As such, the tests
weren't actually using binary provisioning. With that fixed, everything
passes; the binary provisioning flow doesn't appear to actually be
broken.

Bug: 112046733
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I7413f7fb2227e596fb610d6ddc5b95cda2f406b8
2019-01-08 18:08:26 -08:00
Rahul Frias
589a3cf27e Add decrypt hash support
[ Merge of http://go/wvgerrit/68083 ]

Add ability to query decrypt hash support, set a hash computed over a frame
and retrieve the last error at a later point.

Bug: 34080802
Test: WV unit/integration tests. New tests added to cdm_engine_test,
      libwvdrmdrmplugin_hidl_test and request_license_test.

Change-Id: I7548c8798c873a6af3e1cfc0df57c117e1e474a6
2019-01-07 10:14:25 -08:00
Edwin Wong
47c2b65cba Cleanup unaligned code.
Merge from: http://go/wvgerrit/69211

Cleanup unaligned code while working on b/117570686 and remove
a duplicate break statement.

Test: unit tests
  ./run_all_unit_tests.sh

Bug: 121971420
Change-Id: I0ca1dc0fe54e7fe3a87aa7c8dac7ef9da04e90b2
2018-12-24 18:31:12 -08:00
Adam Stone
0a64d25067 Add a field indicating online vs offline licenses.
Import of http://go/wvgerrit/68188

This adds an attribute to metrics indicating if the license was online
or offline.

Also, added a unit test for CdmEngineMetricsImpl.

Test: Unit tests. GPlay manual. GTS tests.
Bug: 115523917

Change-Id: Id315c643048914a2c51904451f9665987bc87eb7
2018-12-21 13:09:29 -08:00
Rahul Frias
65c64292b7 Merge "Enforce OEMCrypto insufficient resources error reporting" 2018-12-12 16:47:11 +00:00