Commit Graph

3017 Commits

Author SHA1 Message Date
TreeHugger Robot
5c6d177e45 Merge "Add comments to unit tests" 2019-03-06 01:59:11 +00:00
Adam Stone
77edbbe219 Merge changes I095f893b,I14d40676
* changes:
  Adds a VersionInfo message to SignedMessage
  Add UsageTableHeader metrics
2019-03-06 00:19:24 +00:00
Fred Gylys-Colwell
5f7803dedd Add comments to unit tests
Merge from Widevine repo of http://go/wvgerrit/73383

Partners have been requesting more explanation for what each test is
doing.  This is an attempt to clarify some of the tests.

Bug: 119640588
Test: unit tests
Change-Id: I270203b4e8fa7e65abb55297788e4d55856e7dcd
2019-03-03 21:16:55 -08:00
Srujan Gaddam
50e4d67415 Merge "Add log when LoadEntitledContentKeys fails" 2019-02-28 01:33:49 +00:00
Srujan Gaddam
8d54b99b75 Add log when LoadEntitledContentKeys fails
Test: CE CDM tests, Android unit/integration tests
Merge of http://go/wvgerrit/73464

LoadEntitledContentKeys result is logged in SelectKey when it fails.
Requested as part of http://go/wvgerrit/73144.

Change-Id: I063497144ff3370b817e12c0535580e54cfec1d8
2019-02-27 14:57:50 -08:00
Rahul Frias
e67d87bec1 Merge "Correction to logging when SRM version is queried" 2019-02-27 21:48:06 +00:00
Srujan Gaddam
99cea1b363 Merge "Separate key session SelectKey methods" 2019-02-27 01:18:18 +00:00
John Bruce
b3000dbcee Merge "Finer-Grained OEMCrypto Locking" 2019-02-26 22:57:20 +00:00
John W. Bruce
e10ac3b465 Finer-Grained OEMCrypto Locking
(This is a merge of http://go/wvgerrit/72867)

This patch replaces the previous static std::mutexes in CryptoSession
with shared_mutexes, allowing multiple readers to access the resources
they protect. For the shared fields, this means only Initialize(),
Terminate(), and the code that sets up the usage table headers needs
exclusive access. All other CryptoSession code is able to read these
fields in parallel.

For OEMCrypto, the static OEMCrypto lock is joined by a per-session
std::mutex, which are used in concert to enforce the OEMCrypto v15
threading guarantees.

On my machine this results in a noticeable increase in performance for
the parallel unit tests.

Bug: 70889998
Bug: 118584039
Test: CE CDM Unit Tests
Test: Android Unit Tests
Test: Jenkins Tests
Change-Id: Ie6332ae4926ed4f14af897685d37bfe63831b14f
2019-02-26 12:44:14 -08:00
Srujan Gaddam
6a8bd096f4 Separate key session SelectKey methods
Test: CE CDM tests, Android unit/integration tests
Bug: b/124773017
Merge of http://go/wvgerrit/73144

Since OEMCrypto supports one content key per entitlement key,
LoadEntitledContentKeys must be called every time we want to select a
key. EntitlementKeySession::SelectKey calls ContentKeySession::SelectKey
after loading the keys, which caches the key id from the previous call,
and if the key id hasn't changed, doesn't call SelectKey. This caching
is fine for content keys since we don't call LoadKeys every time, but
not fine for entitled keys since we do call LoadEntitledContentKeys
every time. So, we instead cache the current content key id per
entitlement key and only call LoadEntitledContentKeys and SelectKey if
the entitled content key id changes. Furthermore, the test
HandlesKeyRotationWithOnlyOneLicenseRequest is modified to complete
multiple decrypts per key to test this behavior.

Change-Id: I9d0d94e49da0fe1965beadbddec99d8dff744d73
2019-02-26 12:36:10 -08:00
Adam Stone
c891824a7a Adds a VersionInfo message to SignedMessage
[ Merge from http://go/wvgerrit/72724 ]

This adds a message that contains SDK and service version information
useful for debugging problems that occur because of different services.

BUG: 80536436

Test: Unit tests and manual GPlay testing.
Change-Id: I095f893b907ea7c2cd149155fb2cd4c7181e7bb2
2019-02-25 17:09:46 -08: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
John W. Bruce
85d8e961f8 Protect Session Map with a Recursive Mutex
(This is a merge of http://go/wvgerrit/72764)

Netflix has identified a calling pattern that causes this mutex to be
taken recursively. This is not guaranteed to be safe for Widevine's
old custom Lock implementation nor std::mutex. However, it is guaranteed
to be safe for std::recursive_mutex. This patch updates the mutex in use
accordingly.

In the long-term, this lock needs to be reconsidered, as already noted
by comments in the code. It would be great if the reconsidered locking
did not require a recursive-safe lock. The TODO for this has been spun
off into its own bug and the comment has been updated to point to this.

Bug: 120471929
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I34df64456de4b469b75caf25a33f0bc53a5da330
2019-02-21 16:07:16 -08:00
Fred Gylys-Colwell
d925048c35 Merge "Set max output buffer size in Mod Mock" 2019-02-21 22:30:46 +00:00
Fred Gylys-Colwell
36e845d00d Merge "Keep OEMCrypto testbed singleton after terminate" 2019-02-21 22:30:35 +00:00
Fred Gylys-Colwell
e03739585f Merge "Update build_and_run script" 2019-02-21 20:18:46 +00:00
Rahul Frias
d45ce337a3 Merge "Move WV unit/integration tests to /data/nativetest" 2019-02-21 20:04:47 +00:00
John Bruce
34553f649c Merge changes Iea5df62b,I346c04a5
* changes:
  Do Not Add Parallel Unit Tests
  Split CryptoSession Lock into Three
2019-02-21 19:37:15 +00:00
John Bruce
0144293022 Merge "Add Lock to ValueMetric" 2019-02-21 19:35:26 +00:00
Rahul Frias
088c5afa02 Move WV unit/integration tests to /data/nativetest
[ Merge of http://go/wvgerrit/73044 ]

The tests currently get copied to /data/bin. Changes in location
of system libraries causes test failures when tests are unable to
find dependent dynamic libraries.

Bug: 123879070
Test: WV unit/integration tests
Change-Id: I86edbe33b4753238fcf8b84243ac6e6c058ea145
2019-02-21 09:53:06 -08:00
Rahul Frias
4916cb1e9c Correction to logging when SRM version is queried
[ Merge of http://go/wvgerrit/72703 ]

SRM is an optional feature and whether it is implemented is upto the
discretion of OEMs. If it is not, avoid logging this information.

Bug: 124391178
Test: WV unit/integration tests
Change-Id: If8d2b1e0b59fb11825f832a5d4259b03c482fd6b
2019-02-20 18:13:07 -08:00
Fred Gylys-Colwell
6c4a10ea15 Update build_and_run script
Merge from Widevine repo of http://go/wvgerrit/73024

This updates the build_and_run_all_unit_tests.sh to only build a
predefined list of tests.  This prevents the accidental inclusion of
android.hardware.drm@1.2-service-lazy.widevine.rc.

Bug: b/123885511
Test: Unit tests build and extra library does not.
Change-Id: I4368817103720976de2b21de2591a0712944c8d0
2019-02-20 17:21:45 -08:00
Srujan Gaddam
007153889e Merge "Test to ensure rollback doesn't affect key duration" 2019-02-20 18:53:23 +00:00
John W. Bruce
d9de4c0304 Add Lock to ValueMetric
(This is a merge of http://go/wvgerrit/72723)

ValueMetric, unlike the other metrics, was not safe to call from
multiple threads. This patch adds internal locking to ValueMetric to
ensure its safety.

Bug: 124459322
Bug: 70889998
Bug: 118584039
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I55855ba8a5cdb2bbe1e15be7742304293245b5aa
2019-02-19 14:05:40 -08:00
John W. Bruce
42e21600a0 Do Not Add Parallel Unit Tests
(This is a merge of http://go/wvgerrit/71325)

Widevine CE CDM and the buildbot now have parallel operations unit
tests. These tests are not relevant on Android since it is not possible
to call into the Android CDM from multiple threads. However, there is
one change in CdmEngine that needs to be copied over to Android for
consistency's sake.

Bug: 70889998
Bug: 118584039
Test: Android Build
Change-Id: Iea5df62be256383e832b4fcfbd5ff5090e3f3b03
2019-02-19 13:59:16 -08:00
John W. Bruce
7e97ba4383 Split CryptoSession Lock into Three
(This is a merge of http://go/wvgerrit/71324)

This patch increases the granularity of the locking in CryptoSession
without substantially changing its locking semantics. Where before
there was a single |crypto_lock_| performing multiple duties, now
there are three locks:

1) |static_field_lock_|, which is used when needing to access the
   non-atomic static member fields of CryptoSession.
2) |oem_crypto_lock_|, which is used when needing to call into
   OEMCrypto.
3) |factory_lock_|, used only by the functions that interact with the
   CryptoSession factory.

All the code in CryptoSession has been updated to use these locks. It
has also been updated to only hold them for the minimal amount of time
necessary, as opposed to holding them for a whole function. This should
help some with the ability of CryptoSession calls to happen
concurrently. To assist in taking locks in a consistent manner, two
helper functions, |WithStaticFieldLock()| and |WithOecLock()| have been
added. Also, for the very common case of reading |initialized_|, the
accessor |IsInitialized()| will read the value safely.

While changing all the code to lock differently, I found that some
places in CryptoSession were *not* locking before accessing static state
or calling into OEMCrypto. I have made these callsites consistent with
the rest of CryptoSession.

As a result of taking locks for only the minimum time necessary, it is
no longer necessary for functions to make assumptions about whether the
lock will already be held before they are called. Locks should not be
held while calling helper functions, and code should always take a lock
for the brief time it is necessary to do so.

In tests, including the concurrent unit tests coming in the following
patch, this code did not perform substantially better or worse than the
code that preceded it, but the hope is that it will experience less
contention on devices that are more resource-constrained than my
desktop, such as older game consoles.

This patch appears to address some real threading issues. Hopefully, it
will also make it easier to maintain soundness in the future and to
reason about when code in CryptoSession needs to take a lock.

This is the first step to implementing the "Finer-Grained Locking in
CryptoSession" specification. A future patch will make some of these
locks reader-writer locks, to allow even greater parallelism.

Bug: 70889998
Bug: 118584039
Bug: 123319961
Test: CE CDM Unit Tests
Test: Android Unit Tests
Test: GTS
Test: Play Movies
Test: Netflix
Change-Id: I346c04a5d9875723db54af33ee91772bf49ca12f
2019-02-19 13:59:00 -08:00
Fred Gylys-Colwell
4389e262d1 Set max output buffer size in Mod Mock
Merge from Widevine repo of http://go/wvgerrit/72392

This adds the ability of the reference code to set the maximum output
buffer size error discussed in the Recoverable Errors section of
http://go/wvdelta15

Bug: http://b/120572363 Add Recoverable Errors (mod mock)
Change-Id: I688caca22929e29b3548c3f7d1df5de5bd37bfa1
2019-02-14 12:39:37 -08:00
Fred Gylys-Colwell
d20cf6c892 Keep OEMCrypto testbed singleton after terminate
Merge from Widevine repo of http://go/wvgerrit/72388

The unreleased oemcrypto test code has been modifed to keep a
singleton for the life of the process.  In order to do that, several
functions in the reference code have been made virtual, and some
initialization and termination has been moved from the constructor and
destructor to Initialize and Terminate.

Bug: http://b/120572363 Add Recoverable Errors (mod mock)
Test: unit tests
Change-Id: I300559195567a537c0700167514be0ea42363695
2019-02-13 21:51:59 -08:00
Fred Gylys-Colwell
b34c9db4c7 Update key control block logging
Merge from Widevine repo of http://go/wvgerrit/72386

This CL changes reference and testbed OEMCyrpto only.

Updates the logging of the key control block for testing by adding new
bits to log and cleaning up the format.

Also, update access to entitlement keys so that they can also have
their key control block logged in tests.

Test: reference and test code only.
Bug: http://b/113594182 Full Decrypt Path Testing - Top Level
Bug: http://b/68648263 Log Key Control Block
Change-Id: I259d6f29eceb9f097640aa50f43443e308797f69
2019-02-13 21:51:41 -08:00
Adam Stone
3448b2d4ec Merge changes I18139f67,Ib48361ef
* changes:
  Add device files error detail to metrics.
  Add error detail metric to some session methods
2019-02-13 18:31:21 +00:00
Adam Stone
5b49bf83a2 Add device files error detail to metrics.
[ Merge from http://go/wvgerrit/71923 ]

Plumb through the device files error detail and add the detail to
metrics.

Bug: http://b/115382201
Test: Unit tests, manual GPlay.
Change-Id: I18139f6712b6670be5fed863a97f9f03440745c7
2019-02-11 15:28:00 -08:00
Fred Gylys-Colwell
c54c2be6e8 Remove obsolete paragraph from docs
Merge from Widevine repo of http://go/wvgerrit/71743

Bug: 123436444 Update OEMCrypto threading documentation
Test: Doc change only
Change-Id: I186c803d5dfc20ce7e4fef6b9e16fd66c6dd3ad5
2019-02-11 10:09:10 -08:00
Adam Stone
605ff83103 Add error detail metric to some session methods
[ Merge from http://go/wvgerrit/71726 ]

Adds an error detail metric attribute to RestoreUsageSession and
RestoreOfflineSession. These metrics will now report an additional
attribute providing additional error detail for debugging.

BUG: http://b/115517916

Test: CDM Unit Tests. Manually tried GPlay.

Change-Id: Ib48361ef29d33a16150473d8967e4850bc0c623d
2019-02-08 12:51:12 -08:00
TreeHugger Robot
b56fd5e7bb Merge "Add a script to run the GTS and CTS media tests" 2019-02-08 20:22:39 +00:00
Peter Kalauskas
058e9a67d0 Add a script to run the GTS and CTS media tests
Test: Manual, use script
Change-Id: I16fe3cf6dbb0795b2397e8844480029403784d0b
2019-02-08 10:19:51 -08:00
Srujan Gaddam
6bd5c564d8 Test to ensure rollback doesn't affect key duration
Bug: b/78359032
Merge of http://go/wvgerrit/70544
Test: Android unit + integration tests/manual checking of system time to
make sure it's restored correctly

Integration tests are added to make sure that clock rollback of the
device system time does not affect key duration for both streaming and
offline licenses. These tests require root access as they modify system
time and restore them.

Change-Id: I3e1802205e2fc2056093c1e39b0ff6e0a8816abc
2019-02-07 17:26:32 -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
Peter Kalauskas
7af3070120 Fix typo in comment
Test: None
Change-Id: I36dd6e8beb195cf4e6548b2486c2eb1195659c52
2019-01-31 22:36:19 +00:00
Rahul Frias
1cc4f71975 Merge "Add recoverable errors" 2019-01-31 15:26:38 +00: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
Srujan Gaddam
137c472f7e Merge "Revert "Add relocs param to TerminateRuntime"" 2019-01-31 00:22:46 +00:00
Srujan Gaddam
252e437cc4 Revert "Add relocs param to TerminateRuntime"
This reverts commit ee45468c22.

Reason for revert: Segfaults occurring with 64-bit devices (B1 and C1) with the latest changes. The error condition points to SEGV_MAPERR, which combined with the build diff, leads me to believe this change caused the issue. b/123559319

Change-Id: I5255e14f74e2be229ffd8cd0765ca61a2a074139
2019-01-30 22:42:04 +00:00
Peter Kalauskas
afc46da6dc Merge "Add lazy service target to widevine" 2019-01-30 21:54:58 +00: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