Commit Graph

905 Commits

Author SHA1 Message Date
Alex Dale
ee56d93454 Creating a new RNG and replacing rand().
[ Merge of http://go/wvgerrit/84607 ]
[ Merge of http://go/wvgerrit/84608 ]

The primary goal is to replace the use of `rand()` with the random
number generators provided with the C++11 standard.

This simplified generator wraps some of the technical aspects of the
<random> library and provides an interface for uniformly distributed
integers.

As part of the `rand()` purge in the CDM, all uses of the C random int
function in `core()` have been removed.  Places that previously used
`rand()` now use `CdmRandom` facilities.

Test: Linux unittest and Android unittest
Bug: 130680365
Change-Id: Ica383870536ed462dbb80e630c2d66845e38b937
2019-08-26 14:39:50 -07:00
Alex Dale
ee995d5fae Replacing NULL with nullptr in core/
[ Merge of http://go/wvgerrit/84647 ]
[ Merge of http://go/wvgerrit/84648 ]

Replacing most instances of C's NULL with C++'s nullptr.  Also changed
how a NULL check is performed on smart pointers.  They provided an
implicit boolean operator for null checks, meaning the underlying
pointer does not need to be compared directly (as it was in some places
before).

Note that clang-format has performed additional changes to some of the
test files that have not yet been formatted.

Bug: 120602075
Test: Linux and Android unittests
Change-Id: I06ddebe34b0ea6dfecedb5527e7e808e32f5269a
2019-08-19 14:18:25 -07:00
Alex Dale
f4360552b7 Log cleanup and reformatting for core/ (Part 2-6)
[ Merge of http://go/wvgerrit/83423 ]
[ Merge of http://go/wvgerrit/83424 ]
[ Merge of http://go/wvgerrit/83425 ]
[ Merge of http://go/wvgerrit/83426 ]
[ Merge of http://go/wvgerrit/83427 ]

Types of cleanup:
  - Removed function / class prefixes from the logs.
  - Fixed log string format options to match the types passed
  - Corrected small spelling mistakes / typos
  - _Tried_ to make the log format more consistent
  - Added static_cast<int> conversion on enumerations when logged
  - Changed several LOGE to LOGW and vice versa
      - Used LOGE if the triggering condition stops the method/function
        from completing its task
      - Used LOGW if the triggering condition changes the expected
        outcome but does not stop the rest of the method/function's
        task
  - Changed several instances of `NULL` to `nullptr`
  - Ran clang-format on files after cleanup

This is part of a larger code quality effort in Widevine DRM.

Test: WV linux unittests and WV Android unit tests
Bug: 134460638
Bug: 134365840
Bug: 136123217
Change-Id: I958ec70ef99eef95c38dbebd7a1acd62ef304145
2019-08-08 13:24:42 -07:00
Alex Dale
79a28e5ddb Changed UsageTableHeader::Shrink to tolerate over shrinking.
[ Merge of http://go/wvgerrit/83804 ]

There is a private helper method in `UsageTableHeader` which is used by
other methods to shrink the table by removing a specified number of
entries.

Prior to this change, if `Shrink` was called to remove more entries
than there are, it would: 1) do nothing and 2) return `NO_ERROR`.
Obviously, at least one of those action should change.

Instead of doing nothing, it will simply remove all the entries from
the table and return `NO_ERROR`.  A warning will be logged that it was
requested to shrink by more entries than there are.

Four (4) new tests have been created to ensure that `Shrink()` works as
expected.

Test: Linux unit tests
Bug: 138242127
Change-Id: Idedd922bd883d7ae1b84ce8ec1255fdce00c0948
2019-07-31 12:06:58 -07:00
John W. Bruce
510804a295 Add Missing Header to CDM Engine Metrics Decorator
(This is a merge of http://go/wvgerrit/83324)

Bug: 134116645
Test: Build
Change-Id: I813381437201b9e7842ba491c36d58c9be4efdda
2019-07-24 15:09:25 -07:00
Alex Dale
182ca34fca Created an ArraySize utility function.
[ Merge of http://go/wvgerrit/82232 ]

The new function `ArraySize` will only work for compile-time fixed-length
arrays, and will provide compiler errors if the provided argument is not an
array.

This will replace the commonly used macro `N_ELEM()` which uses `sizeof()`.

Test: Linux unittest
Bug: 137041745
Change-Id: I0f5c268197a8062a99ccba43c73349e97f66eb02
2019-07-15 17:09:14 -07:00
Fred Gylys-Colwell
334d966f12 Merge "Unify log level for tests" 2019-07-11 02:19:25 +00:00
Fred Gylys-Colwell
b60f75805d Unify log level for tests
Merge from Widevine repo of http://go/wvgerrit/79463 and
http://go/wvgerrit/82383

Several tests explicitly set the log level. This CL unifies that a
little bit. When running the unit tests by hand, on android or for ce
cdm, the log level is 0 (ERROR) and can be incremented on the command
line using the "--verbose" switch.

When running on the desktop, you can set the environment variable
VERBOSE_LOG to "yes", and the log level is set to VERBOSE.  This is
done by the buildbot so you can see full logs in the build archive.

When running with the test bed (i.e. Mod Mock) you can edit the
options.txt file and set log_level to 0=ERROR up to 4=VERBOSE. if you
are using the run_current_tests script, you can create a file in the
linux directory called override_options.txt and add the line
log_level 4

This CL only changes test code.

bug: 124390006
Test: unit tests
Change-Id: I1e042004692750e218b8c4220bce3ec1e387004e
2019-07-10 14:02:45 -07:00
Alex Dale
7c6572a39e Merge "Log cleanup and reformatting for core/ (part 1)" 2019-07-10 01:26:16 +00:00
Rahul Frias
57f2a7fe31 Address request license test failures
[ Merge of http://go/wvgerrit/81743 and http://go/ag/7747989 ]

This fixes some failures in tests. A platform property has been added
which controls whether an offline license can be restored if a release
request has been previously made. This behaviour was introduced by
CE CDM in b/113167010 but is not permitted for android.

The tests failures addressed are
* ProvisioningTestWithServiceCertificate
* ReleaseRetryOfflineKeyTest
* ReleaseRetryL3OfflineKeyTest
* ReleaseRetryL3OfflineKeySessionUsageDisable

Bug: 119428680
Bug: 133684744
Test: WV unit/integration tests
Change-Id: I5beacecea32f26c8a319a6d73a45cc36f04d8aa1
2019-06-28 14:10:01 -07:00
John W. Bruce
435f839f7e Support CE CDM in OEMCrypto Testbed
(This is a merge of http://go/wvgerrit/81628. Although it is primarily
to support a CE CDM feature, this patch touched shared code and so must
be merged.)

The problem that has long stopped the OEMCrypto Testbed from working
with the CE CDM build is that the OEMCrypto Testbed sometimes accesses
the storage via the normal filesystem APIs rather than the FileSystem
abstraction. Furthermore, when doing this, it assumes that FileSystem
abstraction is just a wrapper around direct filesystem access and thus
it should use the same paths in both kinds of filesystem access.
However, this is not true on the CE CDM where FileSystem wraps an opaque
key/value store.

This patch adds a property that allows a platform to indicate if its
FileSystem base path represents a real file system path and sets it
appropriately. ("true" for all platforms except CE CDM) It also adds
code to the OEMCrypto Testbed that makes use of this property to modify
its behavior. When running on a device where the FileSystem base path is
not a real file system path, it will instead use the directory of the
current executable as its base path when accessing the filesystem
directly.

Bug: 129311942
Test: CE CDM Build with Fake L1
Test: Android Build
Change-Id: Iadb3cc57d3bbc8ce0d49224b7df31c46bd5ea56c
2019-06-24 11:52:23 -07:00
Alex Dale
cbc1fba713 Log cleanup and reformatting for core/ (part 1)
Merge from Widevine repo of http://go/wvgerrit/81265

Types of cleanup:
  - Removed function / class prefixes from the logs.
  - Fixed log string format options to match the types passed
  - Added static_cast conversion on enumerations
  - _Tried_ to make the log format more consistent (open to feedback)
  - Corrected small spelling mistakes

This set of changes is very large, splitting change across several
submissions.  This change:
  - core/src/buffer_reader.cpp
  - core/src/cdm_engine.cpp
  - core/src/cdm_session.cpp

Test: WV linux unittests
Bug: 134460638
Change-Id: I16c3297b8e94a99c2b8650b129d0f9e8d96b177f
2019-06-21 17:23:58 -07:00
Alex Dale
96c36fa25e Merge "Replace typedef with using statement in cdm/core/ files." 2019-06-10 15:44:00 +00:00
Alex Dale
ce0ea7b20b Replace typedef with using statement in cdm/core/ files.
[ Merge of http://go/wvgerrit/80805 ]

This change was used only where `typedef` was used for type aliasing,
and not for defining a new type (such as enums, structs, or function
pointer types).

Clang-format was used on the changed files.

Test: WV unit tests
Bug: 134437705
Change-Id: I730b9709a5ac773b3036daa79024caab665b3daa
2019-06-07 11:17:45 -07:00
Srujan Gaddam
dcf3f21289 Add query to CDM to get provisioning model
Bug: b/133855570
Tests: Android tests/CE CDM tests/Linux tests
Merge of http://go/wvgerrit/80163

Adds a query option to QueryStatus to get the provisioning model of the
OEMCrypto.

Change-Id: I1896984be6294a5ada9a97b63e6d9080297e92b0
2019-06-07 09:40:59 -07:00
Rahul Frias
a178eed57d Reformat wv core/src files
[ Merge of http://go/wvgerrit/80484 ]

Clang-format has been run on files in core/src. clang-format has been turned
off for some blocks but otherwise no other changes have been made.

Bug: 134365840
Test: WV unit/integration tests
Change-Id: I6e509f25136f84d37de3d920084302f0f2c23dc4
2019-06-04 11:26:18 -07:00
Rahul Frias
47c2068d6a Reformat wv core/include files
[ Merge of http://go/wvgerrit/80483 ]

Clang-format has been run on files in core/include

Bug: 134365840
Test: WV unit/integration tests
Change-Id: I890127f23f30f0e63f826d3638521b4cc12fb995
2019-06-03 13:53:31 -07:00
John W. Bruce
1d5b7cc8fe Take a Global Write Lock Before Calling OEMCrypto_GenerateNonce()
(This is a merge of http://go/wvgerrit/77803)

In OEMCrypto 15.2, OEMCrypto_GenerateNonce() is a Session Initialization
Function, which means the global OEMCrypto lock must be held before
calling it. There's no harm updating our code to behave this way now,
even before OEMCrypto 15.2 implementations are ready, since it's a
stricter guarantee than the current behavior.

Bug: 131327826
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: Icb6a86dea7298c99596fa9e3d90cec721ebcb8a6
2019-05-31 19:02:29 -07:00
Rahul Frias
6c9c4697f0 Merge "Return key request type none after key rotation" into qt-dev am: 999a466275 am: 4690da2bcb
am: 4c9a3a6f02

Change-Id: Iddcac699401f64d920fcb8ff73053410019ec028
2019-05-31 09:55:31 -07:00
Rahul Frias
4c9a3a6f02 Merge "Return key request type none after key rotation" into qt-dev am: 999a466275
am: 4690da2bcb

Change-Id: I45387edbb83f05dcadec53e4514cb97c68eae6c7
2019-05-31 09:33:36 -07:00
Rahul Frias
3c9175fec5 Return key request type none after key rotation
[ Merge of http://go/wvgerrit/80084 ]

Corrected the key type being returned after entitled keys from
init data are loaded. Made test changes to validate.

Bug: 133903028
Test: WV unit/integration tests
Change-Id: Icb44587f5c3aba3b0facae6d83dc9344d6b60833
2019-05-29 19:03:43 -07:00
Haibo Huang
e3e086e3f8 Using ::testing::DoAll
Without this statement, compilation failed with new googletest.

Test: build
Bug: 129498355
Change-Id: I9eb7b7a2634f20ef80a23b75c06fc84a2fa52dc3
(cherry picked from commit 9055e93a70)
2019-05-22 17:38:58 +00:00
Fred Gylys-Colwell
aa7f7d3ac4 Remove test keybox one more time
Merge from Widevine repo of http://go/wvgerrit/78883

Bug: 119316243
Test: unit tests
Change-Id: Ic6748a6e020c2a4058510fb5c6c5a821e57cc5fd
2019-05-22 00:25:56 +00:00
Haibo Huang
9055e93a70 Using ::testing::DoAll
Without this statement, compilation failed with new googletest.

Test: build
Bug: 129498355
Change-Id: I9eb7b7a2634f20ef80a23b75c06fc84a2fa52dc3
2019-05-20 00:18:22 +00:00
Robert Shih
fe8924f814 Add CdmKeyStatus kKeyStatusUsableInFuture am: 69c8f488ca am: 6a329e6c9a
am: e6ba3ec747

Change-Id: Iee17c92d9a3f3fd390e05bb0324ba04861236210
2019-05-16 20:07:33 -07:00
Fred Gylys-Colwell
e4c7bc38f8 Address review comments for OEMCrypto Build Information
Merge of http://go/wvgerrit/78683

There were some review comments in http://go/wvgerrit/78683 that came
in after the code was merged to the qt-dev branch.  This CL addresses
them on the master branch.

Test: unit tests.
Bug: 129070445
2019-05-16 18:32:16 +00:00
Robert Shih
69c8f488ca Add CdmKeyStatus kKeyStatusUsableInFuture
Bug: 116738851
Test: unit tests
Change-Id: I49728788e57905806b72e891f3654fbf0c8b1bc0
2019-05-15 15:16:05 -07:00
Rahul Frias
c9c3e6ab6f Merge "Single PSSH entitlement handling" into qt-dev am: 19c6e57269
am: f13e62fbe3

Change-Id: Ib06c9f6606fab960a132d1fb0876108cd7513c2d
2019-05-13 09:49:41 -07:00
Rahul Frias
f1bb063682 Merge "Key Status should reflect key container security level" into qt-dev am: 80f5e283ad
am: 555d7cdc83

Change-Id: Ib3c97a96e8482fafc888d71780daa047cc6428ac
2019-05-13 09:49:24 -07:00
Rahul Frias
19c6e57269 Merge "Single PSSH entitlement handling" into qt-dev 2019-05-13 16:26:16 +00:00
Rahul Frias
80f5e283ad Merge "Key Status should reflect key container security level" into qt-dev 2019-05-13 16:25:24 +00:00
Fred Gylys-Colwell
878e39c740 Report OEMCrypto Build Information in License Request am: 5ee5d00514
am: 23c3bc8ebc

Change-Id: I1006614f9eadc97e9287816723ec179851bf2e67
2019-05-10 06:30:12 -07:00
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
Fred Gylys-Colwell
5ee5d00514 Report OEMCrypto Build Information in License Request
Merge from Widevine repo of http://go/wvgerrit/78623

This updates the license request client identification to include
OEMCrypto build information.

Bug: 129070445
Test: ExoPlayer on crosshatch with mod mock
Change-Id: I0dbce0cca4e9810e14f60561e4e434f1dbcadfb6
2019-05-09 13:24:04 -07:00
Rahul Frias
da25bce428 Single PSSH entitlement handling
[ Merge of http://go/wvgerrit/78425 ]

This CL refactors code, corrects comments and adds additional
integration tests.

Bug: 128462397
Test: WV unit/integration tests, GPlay playback tests and GtsMediaDrmTests
Change-Id: I679960d44c45cf4ff13c27eb960e66ec63f491b5
2019-05-07 23:07:05 -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
TreeHugger Robot
862cb96e77 Merge "Handle key rotation" into qt-dev 2019-05-03 20:50:17 +00:00
Srujan Gaddam
cee0887d20 Call SelectKey regardless of entitled key mapping am: fce75c295b
am: 09366bb6ce

Change-Id: I9b73230d68eecf47dd5caab94100c5f9144e75da
2019-04-30 20:04:44 -07:00
Srujan Gaddam
fce75c295b Call SelectKey regardless of entitled key mapping
Bug: b/129426820
Test: CE CDM, Android unit/integration, Linux, ExoPlayer key rotation
playback with modmock and L3
Merge of http://go/wvgerrit/77608

http://go/ag/6543431 modified the entitlement key session to select the
entitled content key if it had just been loaded in so that there's a
valid current content key loaded in OEMCrypto. However, this did not
account for the case where you have two entitlement to entitled key
pairs. If OEMCrypto does not select the key when you switch from the
first pair to the second pair back to the first pair, OEMCrypto will
still be using the key from the second pair during decrypt. This CL
changes it so we SelectKey each time to make sure that we update the
current content key.

Change-Id: I764ec13deb87e14188707b811a44eff132eeb5a1
2019-04-30 10:51:33 -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
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