Commit Graph

1135 Commits

Author SHA1 Message Date
Rahul Frias
dcfe0f3690 Merge "Remove references to internal documents" 2019-03-28 23:29:43 +00:00
Rahul Frias
4e745ff203 Remove references to internal documents
[ Merge of http://go/wvgerrit/75303 ]

Bug: 117181780
Test: WV unit/integration tests
Change-Id: Ica12e270a9ac5fbcff069aace807bb4651814ad7
2019-03-28 09:32:30 -07:00
Rahul Frias
a45deef63b Merge "Corrections for limited duration licenses" 2019-03-26 16:24:48 +00:00
Adam Stone
eeb09779aa Merge "Add extra OEMCrypto metrics" 2019-03-25 22:36:42 +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
Adam Stone
09c7473dea Add extra OEMCrypto metrics
[ Merge from http://go/wvgerrit/74924 ]

These were not previously being collected or were collected
insufficiently.

BUG: http://b/121090396 http://b/112919252
Test: Unit tests, Gplay, Nflix, GTS
Change-Id: I32b7206cbe6071519b4a483fbcd0920dc1a26961
2019-03-20 11:25:19 -07:00
John Bruce
a5bc8be7a0 Merge "Remove Passthrough When L3 is Used w/ Opaque Handles" 2019-03-19 18:50:29 +00:00
John Bruce
907630a018 Merge "Fix unconditional use of __attribute__." 2019-03-19 18:47:19 +00:00
Rahul Frias
1a16b7d5ca Merge "Add unit tests to remove usage entries" 2019-03-19 15:34:33 +00:00
Jacob Trimble
86f6fb0ef7 Fix unconditional use of __attribute__.
(This is a merge of http://go/wvgerrit/74844)

__attribute__ is not supported on all compilers, notably it's not
supported on MSVC.  Commenting out the variable should suppress the
warning this is trying to fix.

Test: Android CDM Build
Bug: 122953649
Change-Id: I0101df1cca271415a6444e5455eb0085676bcabf
2019-03-18 16:16:26 -07:00
Rahul Frias
8942f7682a Add unit tests to remove usage entries
[ Merge of http://go/wvgerrit/74343 ]

This replicates a Netflix test that adds secure stops and removes them
one at a time, while some of the sessions are still open. Usage
enties will be deleted at the time, but the usage header table
will not be shrunk if the last entry is in use. This happens later when
sessions are closed and the last usage entry is no longer in use.

Bug: 120894148
Test: WV unit/integration tests, CE CDM tests
Change-Id: Ib572950afc61754fe5f3c417e650d5d08503425a
2019-03-18 15:47:12 -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
Rahul Frias
fd420ccdc5 Merge "Enable CE CDM usage tests" 2019-03-16 01:15:08 +00:00
John W. Bruce
672a12dd8b Remove Passthrough When L3 is Used w/ Opaque Handles
(This is a merge of http://go/wvgerrit/74628)

There is some old legacy behavior in CryptoSession for supporting
Chromecast. When a platform tries to use a combination of L3 and opaque
handles, it silently substitutes the type "clear buffers" instead.

No platform uses this behavior anymore. In fact, the CE CDM contains
code that explicitly prevents this case from being triggered. That code
has broken in every one of the last 3 releases. To allow the CE CDM to
end that bug farm, this patch removes the behavior that no one wants.

Bug: 112703532
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I7f70483fac46c75637da5378c5a8b1bf7a2c2860
2019-03-15 16:04:28 -07:00
Rahul Frias
f9ad1dad69 Update usage entry before closing a session
[ Merge of http://go/wvgerrit/74443 ]

When deleting a usage entry, a crypto session may need to be closed
and reopened if a usage entry has previously been loaded. Before closing
this session, the usage entry/usage table header information should be
saved.

This is for completeness rather than correctness. Looking at code,
usage header and entry information are saved after the license
release has been generated. This change might be helpful in case
that changes in the future.

Bug: 115920873
Test: CE CDM unit tests, WV unit/integration tests
Change-Id: Ifc8f761497198247db31dab2f47e8323af783681
2019-03-12 15:21:58 -07:00
Rahul Frias
77ec11b8a8 Merge "Add UsageTableHeader metrics" 2019-03-12 18:41:00 +00:00
Rahul Frias
d8afbb3b51 Add UsageTableHeader metrics
[ Merge from http://go/wvgerrit/72183 ]

Adds basic metrics for the usage table header. This adds the last rev of
cdm_session.cpp that was merged to the wv repo.

Bug: http://b/112919252
Test: Unit tests. Manual GPlay
Change-Id: I9494caf6fcdfb3d335ea10fe8b712585e95c79e5
2019-03-08 14:00:01 -08:00
Rahul Frias
45638c74b3 Enable CE CDM usage tests
[ Merge of http://go/wvgerrit/74223 ]

Bug: 34949512
Bug: 109897011

Test: CE CDM unit tests, WV unit/integration tests
Change-Id: I4b8dca3cacbb66c87318c594f62d3e2a3e940308
2019-03-08 13:41:13 -08:00
John W. Bruce
84d9813b81 Add LOG_SILENT LogPriority Again
(This is a merge of http://go/wvgerrit/73743 and
http://go/wvgerrit/73903)

The CE CDM implements the ability to silence all logging with a "silent"
log level. However, under the covers, this assigned a value to g_cutoff
that was not a member of LogPriority, which fails some extremely strict
checks. This patch just adds a matching entry to LogPriority so that
"silent" is now a valid level in that enum.

A previous merge of this change broke builds on Elfin because it uses
stricter compiler settings that rejected the lack of LOG_SILENT in
certain switch statements. I've gone through the codebase and found
every switch on a LogLevel variable and updated it, of which only one
affects the Android build.

Bug: 118622359
Test: CE CDM Build
Test: Android Build
Test: Android Elfin Build Specifically
Change-Id: I6ba3556e0e70f5e7e1692754a8a2f54adae59a6b
2019-03-06 11:18:55 -08:00
John Bruce
def448a006 Merge "Revert "Add LOG_SILENT LogPriority"" 2019-03-06 19:03:02 +00:00
John Bruce
aa8d0a5d31 Revert "Add LOG_SILENT LogPriority"
This reverts commit 9a40a107f8.

Reason for revert: Elfin has stricter compiler settings than other platforms and breaks when this is checked in.

Change-Id: I169a43ff6b9d90101276690b1d3aae7865946eb0
2019-03-06 18:57:04 +00:00
John Bruce
aff6bfa8e3 Merge "Add Missing "override" to EntitlementKeySession::Type()" 2019-03-06 18:13:49 +00:00
John Bruce
4981ae6481 Merge "Fix Netflix Warnings" 2019-03-06 18:13:32 +00:00
John Bruce
12b78e4bd4 Merge "Add LOG_SILENT LogPriority" 2019-03-06 18:02:28 +00:00
John Bruce
89f75c34ff Merge "Restrict uses of BoringSSL." 2019-03-06 17:58:58 +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
John W. Bruce
f80ff74319 Add Missing "override" to EntitlementKeySession::Type()
(This is a merge of http://go/wvgerrit/73803)

While playing around with compiler settings, I found that
EntitlementKeySession::Type() is missing the `override` keyword.

Bug: 127498046
Test: CE CDM Build
Test: Android Build
Change-Id: I5a18dbbd425b0a493575a34b9f5f77b2d7c8f10d
2019-03-05 14:07:22 -08:00
John W. Bruce
c110804133 Fix Netflix Warnings
(This is a merge of the parts of http://go/wvgerrit/73763 that affect
the Widevine Android CDM.)

Netflix found some cases of benign shadowing & unused parameters through
having different warning settings than we do. No harm in fixing these.

Bug: 126864496
Bug: 126864495
Test: CE CDM Build
Test: Android Build
Change-Id: Ifb2a705a64071900b69aea17d6add46a36068ebb
2019-03-05 11:40:23 -08:00
John W. Bruce
9a40a107f8 Add LOG_SILENT LogPriority
(This is a merge of http://go/wvgerrit/73743)

The CE CDM implements the ability to silence all logging with a "silent"
log level. However, under the covers, this assigned a value to g_cutoff
that was not a member of LogPriority, which fails some extremely strict
checks. This patch just adds a matching entry to LogPriority so that
"silent" is now a valid level in that enum.

Bug: 118622359
Test: CE CDM Build
Test: Android Build
Change-Id: Idafb26b7c5f9a24a32c84da9b3c5595434ef07fe
2019-03-05 11:35:39 -08:00
John W. Bruce
e5380ca59f Restrict uses of BoringSSL.
(This is a merge of http://go/wvgerrit/71883)

This moves all the SSL code to privacy_crypto so we can use the
iOS-specific versions and not use any BoringSSL.  The iOS version
doesn't support OEM certificates.

Note that the tests still use BoringSSL.

Bug: 126559819
Test: build_and_run_all_unit_tests.sh
Change-Id: Ib0fad5d95b283b6cd6e02d8a08bcf248c5900bc4
2019-02-28 17:32:22 -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
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
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