Commit Graph

580 Commits

Author SHA1 Message Date
John W. Bruce
3d603eb12d Reject Embedded Keys Under 16 Bytes
(This is a merge of http://go/wvgerrit/60620)

The license code handles keys larger than 16 bytes correctly, but it
does not properly reject keys smaller than 16 bytes.

This patch adds unit tests not only for the new error case but also
the existing success cases which were not previously being tested. As
part of this, license_unittest was changed to use a Test Peer instead
of making the test fixture a friend class.

Bug: 111069024
Test: CE CDM unit tests
Test: Android unit tests
Change-Id: Idb2deb6fbe0aeb19b530f9818bebff480541f5c8
2018-10-08 10:05:34 -07:00
Jeff Tinker
44fe62b0a6 Remove spurious "No Widevine PSSH" error log message
This log message was printed if initialization data was
not provided, which is actually not an error condition.

bug:116045153
Change-Id: I5597286ddf33d5b6c17f69f9a6a7cdba469b46b6
2018-10-05 20:51:11 +00:00
Rahul Frias
adfc0093f5 Rename method CanUseKey for clarity
[ Merge of http://go/wvgerrit/60240 ]

Since the method is not a general purpose check and only verifies that
the key can be used for a given security level the method
has been renamed PolicyEngine::CanUseKeyForSecurityLevel.

Bug: 115701771
Test: WV unit/integration tests
Change-Id: Icd6789538bb709d2a48c67bbd7bc810f4b000e14
2018-09-19 09:46:08 -07:00
TreeHugger Robot
0c072a628c Merge "Change keys_ to key_statuses_" 2018-09-19 01:16:49 +00:00
Fred Gylys-Colwell
edb7de2923 Avoid dlclose
Merge from Widevine repo of http://go/wvgerrit/55462

Instead of calling dlclose on liboemcrypto.so after each terminate,
this CL keeps the library loaded.  Although the original bug
b/72831885 has been fixed, there is still some lingering worry about
possible hard-to-find resource leaks in dlclose.

For more context, see the discussion around the original bug
b/72831885. The fix that closed this bug has more discussion:
https://boringssl-review.googlesource.com/c/boringssl/+/25784 In
particular, we only fixed a known resource leak in boringssl, not in
any other libraries, and we added a patch that the borringssl team was
not very happy to include because it was not very thread safe.

bug: http://b/72831885 d2i_PKCS8_PRIV_KEY_INFO_bio returns null
test: unit tests on taimen.
Change-Id: I73b5e69bf300e03fe567b8e7e1d8e0e08b6bca37
2018-09-18 16:52:03 -07:00
Fred Gylys-Colwell
f97624e477 Change keys_ to key_statuses_
Merge from Widevine repo of http://go/wvgerrit/59980

This CL addresses review comments from http://go/ag/4454369.

Change-Id: I5fafafef9a2e9ccbeac3f8d18c3d6335e2de61e8
2018-09-18 16:47:08 -07:00
Fred Gylys-Colwell
f4258cc628 Send test name to server
Merge from Widevine repo of http://go/wvgerrit/59700

This CL sets the environment variable MODEL_NAME to be the current
unit test.  When running on a test platform, this environment variable
is used in the license request as model_name.

test: unit tests.
bug: 38004627

Change-Id: I347c5cec35942d68285cc01615b976097f37d214
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
562c14b5f1 Use InstallRootKeyCertificate for keybox and cert
Merge from Widevine repo of http://go/wvgerrit/55461

This CL allows provisioning 3.0 devices to install their OEM certs
from an initialization partition.  This method is already used for
keyboxes on Android -- we are just adding the ability to use it for
OEM certs, also.

Also, for v15, we require OEMCrypto to report a valid certificate in
the unit tests.

bug: 111725154
test: unit tests
Change-Id: I142c84a1a67bdb4cee943cfd12a632421901eb24
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
a0961a8834 Merge common code
Merge from Widevine repo of http://go/wvgerrit/57720

Now that we have oemcrypto mock split into reference and testbed code, it is
time to remove the part of testbed that is an exact copy of the reference code
and just use the reference code.

Test: unit tests
Bug: 76393338
Change-Id: I3831a3f0118221c21ff1c28e6b6101b27b889012
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
b849630a6f Fix generic crypto tests
Merge from Widevine repo of http://go/wvgerrit/56524

Test: unit tests, including generic crypto tests, pass.
Bug: 72354901 Fix Generic Crypto tests.
Change-Id: I39404424acb2d896afe06c461a02e3664c0f45de
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
5095bb746e Handle KEY_NOT_LOADED error
Merge from Widevine repo of http://go/wvgerrit/56523

In OEMCrypto v14, SelectKey can also return KEY_NOT_LOADED if the key
id is not found.  This was added to help with entitlement licenses.
However, SelectKey in crypto session converts this to an unknown
error.

In this CL we change that to a NO_CONTENT_KEY_3 error.  This is
probably only important because the generic crypto tests expect
NO_CONTENT_KEY_3 when we try to use an undefined key.

Test: existing unit tests pass, and some future unit tests pass.
Bug: 72354901 Turn on generic crypto tests
Change-Id: I3c0b7e6306cafd3feabc8aac7e47983c89194a26
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
790799ceaa Refactor provisioning tests
Merge from Widevine repo of http://go/wvgerrit/56522

This CL moves provisioning from core/test/cdm_engine_test.cpp to
test_base.cpp because other tests should also only be run when the
device has been provisioned.

It also adds a fake license server.  The license holder helps a test
create a license request and then generates a bare-bones license,
without actually sending anything to a real license server.

Test: more unit tests pass than before.
Bug: 72354901 Fix Generic Crypto tests.
Change-Id: Iec067a6a1fb91fa8fd7b904fdf36e90981e293a3
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
e635d4d384 Common test main
Merge from Widevine repo of http://go/wvgerrit/56521

This CL adds a common main routine for integration tests.  It sets a
default test configuration for the provisioning and license server
urls and certificates, and allows the user to set them on the command
line.

Test: current unit tests still pass.
Bug: 72354901 Fix Generic Crypto tests.
Change-Id: I604a3d9e15d50da5041794624c4571c0dcb091f5
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
4af5aaf18a Add test base that catches nonce flood
Merge from Widevine repo of http://go/wvgerrit/56520

This CL adds a test base that installs a test keybox and catches nonce
flood errors for all CDM tests.

In order to do this, a new class is added called a
CryptoSessionFactory.  The default factory just creates a new
CryptoSession.  All places in the code that create a new CryptoSession
now call the static method MakeCryptoSession, which uses the current
factory to create a CryptoSession.  If MakeCryptoSession is called and
there is no current factory, a default factory is created.

The CryptoSession constructor is now private, so that we do not
accidentally try to create one without using the factory.

For the new test base, we first create a special test
CryptoSessionFactory that creates a TestCryptoSession.  The test
factory catches the first call to MakeCryptoSession and injects an
installation of the test keybox after OEMCrypto_Initialize is called.

The TestCryptoSession injects a sleep statement and a retry whenever
it detects a nonce flood.

Test: current unit tests still pass.
bug: 72354901 Fix Generic Crypto tests.
bug: 111361440 Remove #ifdef from unit tests
Change-Id: I248e7f3c53721c04d2af412ef835e19bb4d15d9a
2018-09-18 16:33:11 -07:00
Fred Gylys-Colwell
d9c5e59e00 Rename OpenSSL to BoringSSL
Merge from Widevine repo of http://go/wvgerrit/55620

There were two places that explicitly referenced BoringSSL instead of
OpenSSL. (Not counting, of course, all the BoringSSL functions and
headers that still have "OpenSSL" in their names.) This change fixes one
to mention either library and the other to specifically mention
BoringSSL.

Bug: 70636815
Test: CE CDM Unit Tests
Change-Id: I8703e1c427c66953fcc565a4f8f85093c7180f46
2018-09-18 16:33:09 -07:00
Fred Gylys-Colwell
2c940856fd Allow clear lead to play before key policy loaded
Merge from Widevine repo of http://go/wvgerrit/56760

This CL backs out one restriction added in http://go/wvgerrit/42941.
In that CL, a sample would not be processed if the policy engine says
the key cannot be used for a given security level. The change relaxes
the check and does not run the verification if the sample is clear.

Bug: 112113797
Bug: 115758660
Test: GTS tests.  Unit tests.  Verified Play movies and Netflix.
Test: version number unit tests fail as expected.

Change-Id: I5238745c3d3d7f0eb7fae203f4579e8df4d0681b
2018-09-18 16:33:07 -07:00
Fred Gylys-Colwell
7bd1d0ea51 Update OEMCrypto L3 to v14
This CL updates the level 3 library to v14. It includes the following CLs:

http://go/wvgerrit/52941 Change initialization of TimeInfo object in L3
http://go/wvgerrit/50820 Use memmove instead of relocs memcpy
http://go/wvgerrit/49845 Use memmove or the relocs memcpy in entry_points
http://go/wvgerrit/48884 Merge back rollback changes from pi-dev
http://go/wvgerrit/47985 Deprecate all_obfuscated_symbols.h
http://go/wvgerrit/47720 Invalidate current key index when loading keys
http://go/wvgerrit/46206 Split mock into two -- step 3
http://go/wvgerrit/46205 Move some OEMCrypto types to common header - split the mock, step 2
http://go/wvgerrit/46204 Refactor utility code - split the mock, step 1
http://go/wvgerrit/44981 Fix pointer addresses of generation number
http://go/wvgerrit/47460 Address offline playback with rollbacked time
http://go/wvgerrit/46442 Convert union type-punning to memcpy in Level 3
http://go/wvgerrit/46441 Remove usage of strlen from Level 3
http://go/wvgerrit/41900 Increase size of RSA key for Level3
http://go/wvgerrit/41832 Remove LoadTestKeybox and test keybox code
http://go/wvgerrit/41826 Add prov 3.0 and remove prov 2.0 code
http://go/wvgerrit/44262 Fixed loading mac keys in mock and Level3
http://go/wvgerrit/43402 Add AES256 to Level 3
http://go/wvgerrit/43045 Add entitlement keys and V14 for Level3
http://go/wvgerrit/38800 Update LoadTestKeybox to take test keybox parameter
http://go/wvgerrit/42064 Test Carmicahel RSA Keys
http://go/wvgerrit/41701 Update print-version-strings

New version numbers:
level3/x86/libl3oemcrypto.cpp  Level3 Library 8162 May 21 2018 13:50:29
level3/arm/libl3oemcrypto.cpp  Level3 Library 8158 May 21 2018 13:52:17
level3/mips64/libl3oemcrypto.cpp Level3 Library 8161 May 21 2018 13:51:47
level3/arm64/libl3oemcrypto.cpp Level3 Library 8159 May 21 2018 13:50:47
level3/mips/libl3oemcrypto.cpp Level3 Library 8160 May 21 2018 13:51:51
level3/x86_64/libl3oemcrypto.cpp Level3 Library 8163 May 21 2018 13:51:19

Test: tested as part of http://go/ag/4674759
Change-Id: Ib2c09e4549e58ad57213168dac27b35543bd64c3
2018-09-09 11:37:50 -07:00
Fred Gylys-Colwell
60d010d18d Address review comments
Merge from Widevine repo of http://go/wvgerrit/54540

Addressing comments in http://go/ag/4448747

Test: tested as part of http://go/ag/4674759
Change-Id: I29005397efcc2e982e635581cc68c8293cea6243
2018-09-09 11:37:48 -07:00
Fred Gylys-Colwell
72e260da48 Clean merge of Client ID code
This CL cleans up some bad merges of client ID code, entitlement keys,
and concurrent session access. After this CL, core cdm code on
android should match that on widevine at the commit 2f916720 on branch
master.

CLs merged here are based on:
http://go/wvgerrit/50483 Protect sessions from concurrent access
http://go/wvgerrit/48860 Remove duplicate information from client identification
http://go/wvgerrit/49040 Revert revertion of Client ID Expansion
http://go/wvgerrit/46448 Test Entitlement Licenses

Test: tested as part of http://go/ag/4674759

Change-Id: I45854d6b034c247b16073a96d6ff3ea953ded3ae
2018-09-09 11:37:48 -07:00
Fred Gylys-Colwell
0099f8d08b Remove Remaining OPENSSL_VERSION_NUMBER Conditional Compiles
Some of http://go/wvgerrit/46251 from Widevine repo.
The rest was merged in the oemcrypto refactor.

When we standardized on BoringSSL, these conditional compilations that
had been added as a stopgap for OpenSSL became unneeded. However, they
were not noticed and removed at the time.

Bug: 72459799
Test: CE CDM Unit Tests
Test: tested as part of http://go/ag/4674759

Change-Id: I693f691ffcb255e03660edaa6743cd0fb9ef12c6
2018-09-09 11:37:48 -07:00
Fred Gylys-Colwell
b62a8f1652 Use GetDeviceID to determine SPOID's unique id
Merge from Widevine repo of http://go/wvgerrit/45940

Since the Level 3 OEMCrypto is being updated to Provisioning 3.0, its
SPOID would be derived from its OEM Certificate, breaking backwards
compatibility. This CL changes how we determine what unique id to use
for SPOIDs by checking to see if OEMCrypto_GetDeviceID is implemented,
and if so, using the id returned from that call. If not and the root
of trust is an OEM Cert, we continue to use that OEM Cert.

This allows Level 3 devices to keep the same SPOID when they undergo a
field update to Provisioning 3.0.

Also, the Level 3 OEMCrypto will share a single OEM certificate across
all devices with the same architecture.  Since the OEM Cert is not
unique, it cannot be used to derive a unique id.  By using the unique
id returned by OEMCrypto_GetDeviceID, we can generate a unique SPOID.

The id from OEMCrypto_GetDeviceID has always been required to be
unique for devices with keyboxes.  The functionality and use of this
function for Provisioning 3.0 devices was introduced in OEMCrypto API
version 14.1.

Test: tested as part of http://go/ag/4674759

Change-Id: I65af8246c9312c75c570a2d518caa3de633007c4
2018-09-09 11:37:48 -07:00
Fred Gylys-Colwell
de8d11b8de Remove WrongMessageTest
Merge from Widevine repo of http://go/wvgerrit/48841

This test is not providing value to the CDM, as it seems to exist
primarily to validate server behavior. However, it is not doing what
it says it is (the request is rejected because it is using unparseable
garbage data, not because its key ID is unknown) and according to
tinskip@, the behavior it claims to be testing is not valid. (The
licensing service will not fail just because the key ID is unknown.
Indeed, if the test data is fixed to use a valid payload with an
unknown key ID, the test fails because the server does not.)

Bug: 78640287
Test: CE CDM Unit Tests
Test: Android Unit Tests
Test: tested as part of http://go/ag/4674759

Change-Id: Idfcff15ab3d15fdfb6eb111b5dff68aa5a23fb37
2018-09-09 11:37:48 -07:00
Fred Gylys-Colwell
d36ab56575 Sync the definition of WidevinePssh data
Merge from Widevine repo of http://go/wvgerrit/43202

Sync the definition of WidevinePssh data with the latest in support of
entitlement keys.

bug: 73297961 Fix or remove sublicense support.
Test: tested as part of http://go/ag/4674759
Change-Id: Ia9faf82732854a705b4b14430169ce4c8ecbcfcd
2018-09-09 11:37:48 -07:00
Fred Gylys-Colwell
6000f834a0 Entitled Key Management
Merge from Widevine repo of http://go/wvgerrit/53883

Note: this CL does not modify license_key_status.cpp because the
previous CL already included those changes.

OEMCrypto v14 only supports one entitled key per entitlement key at a
time. Unfortunately, some partners have use cases that require using
old entitlement keys after the new keys have been loaded. Most
notably, when a key rotation occurs, the new PSSH will often be loaded
before the playback position catches up to the PSSH in the stream,
meaning that decryption will need to continue using the old keys for a
bit.

To fix this, EntitlementKeySession now caches the entitled keys when
they are loaded and only loads them under their matching entitlement
key when SelectKey() is called. This ensures that the right entitled
key is loaded for a given entitlement key before decryption.

The entitlement key integration tests have been updated to verify that
the old entitled keys still work even after loading new entitled keys.
Also, several places in the code that assumed loading new entitled
keys would wipe out the old keys have had to be modified.

Bug: 78652567
Test: CE CDM Unit Tests
Test: tested as part of http://go/ag/4674759
Change-Id: I6fac9dfe2b170ad68fb7cdb5bc8d6a2f35a20c2c
2018-09-09 11:36:49 -07:00
Fred Gylys-Colwell
d5bb64a60c Strip padding from entitlement keys.
Merge from Widevine repo of http://go/wvgerrit/47540

Bug: 77364593
Test: tested as part of http://go/ag/4674759

Change-Id: If1063d410153eb49584c94156e2d98af9e08c060
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
fc4186e4fd Add initial support for key rotation through ce cdm interface.
Merge from Widevine repo of http://go/wvgerrit/42941

Bug: 72168544
Test: tested as part of http://go/ag/4674759
Change-Id: I1a2d0f49371e5b3edf1d9dff85b85593f981d1f5
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
d17199fb83 Update comments on copying old usage entries
Merge from Widevine repo of http://go/wvgerrit/49003

CopyOldUsageEntry currently needs the old usage table to be loaded via
CreateOldUsageEntry. The CDM uses a workaround by creating a dummy old
entry, but the OEMCrypto code should be responsible for this. However,
since there have been several versions released with the current
OEMCrypto spec, the CDM code would have to still exist to support
implementations of that spec. Therefore, in order to avoid having to
support both a CDM with this workaround removed (as well as updating
the spec) and a CDM with it still in place, this workaround should be
canonicalized.

b/65730828
Test: tested as part of http://go/ag/4674759
Change-Id: I4619c551b79a53746683519d284663bf513ec38d
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
8639842ff5 Clarify that Properties::Init is called multiple times
Merge from Widevine repo of http://go/wvgerrit/53465

It may not be clear that Properties::Init is called multiple
times. This CL adds an explanation in the header file.  The function
itself is platform specific.

Test: tested as part of http://go/ag/4674759

Change-Id: I68010c594ec146e36161ae0f4f44d53caefa1896
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
0936f1b875 Improve SSL Error Handling in HttpSocket::Read()
Merge from Widevine repo of http://go/wvgerrit/53640

While HttpSocket supports both secure and insecure requests, the
error-handling code in HttpSocket::Read() was written assuming that
the insecure code path was previously taken. This resulted in spurious
and misleading error messages being printed when an SSL error
occurred, and it also meant that retryable SSL responses were not
being retried. Also, the code for detecting a closed connection was
technically incorrect, although a quirk of BoringSSL meant that it
happened to work well enough to go unnoticed.

This patch adds separate SSL error handling from the non-secure error
handling. It correctly checks for a closed connection. It will retry
retryable errors after a delay. And it prints the correct BoringSSL
error when an unrecoverable error occurs. There should be no change in
behavior for insecure connections.

Bug: 77338045
Test: CE CDM Unit Tests
Test: tested as part of http://go/ag/4674759

Change-Id: I8c45ca5771f22c11716d2e3649de91ab1acc1954
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
22d9160219 Revert of "Prevent race conditions between decrypt and close session"
Merge from Widevine repo of http://go/wvgerrit/50481
Original CL http://go/wvgerrit/47520

The original CL was not completely merged to master on Android, so
this CL only reverts the left-over bits.

The original fix was not sufficient to address all race conditions.  A
subsequent CL will address them.

Bug: 73781703
Bug: 79158083
Bug: 79262108
Test: tested as part of http://go/ag/4674759

Change-Id: Ib6c55ab5434e08fe61e0f65623ac8c7b2dc5aaa1
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
147f40a5ef Explicitly Pass NULL Character in ProvisioningServiceCertificateInvalidTest
Merge from Widevine repo of http://go/wvgerrit/53625

Passing the third parameter to std::string::insert() as an integer
technically makes for an ambiguous method call, as there are two
overloads that could accept these arguments. While baseline GCC and
Clang discern our intent here correctly, seawardt@ discovered that
XCode is more pedantic and requires that we pass the third parameter
as a char to disambiguate.

Test: WvCdmEnginePreProvTestUat.ProvisioningServiceCertificateInvalidTest
Test: tested as part of http://go/ag/4674759
Change-Id: I65a2506209215cd081c685faac26e08bae486d5e
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
1d594f3140 Assorted Key Session Code Cleanup
Merge from Widevine repo of http://go/wvgerrit/53202
and
Merge from Widevine repo of http://go/wvgerrit/53624

This change contains a variety of small tweaks to the
ContentKeySession and EntitlementKeySession classes that were
discovered while fixing b/78652567. There should be no change in
behavior from this patch. The fixes are:

1) Added missing headers and removed unnecessary headers.

2) Removed the unused keys_ member from EntitlementKeySession.

3) Renamed ContentKeySession's protected member function so that it is
not an overload of the public LoadKeys() function. This makes it
clearer what EntitlementKeySession::LoadKeys() is doing.

4) Added missing "virtual" and "OVERRIDE" keywords.

5) Added missing copyright headers.

6) Ran clang-format with Google style.

7) Correct missing OVERRIDE keywords.

Test: tested as part of http://go/ag/4674759

Change-Id: Icb0af886d7d3eb097b5dffbb716be6ac28f0916d
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
08c57e7a8e Support Dual PSSHs
Merge from Widevine repo of http://go/wvgerrit/48842

In order to work around a limitation of some versions of OEMCrypto,
the packager is going to start generating files with multiple Widevine
PSSH boxes. For backwards-compatibility, the first PSSH will be a
SINGLE-type PSSH while the ENTITLED_KEYS-type PSSH (if any) will come
later. In order to use entitlement licenses, then, the CDM needs to
change how it selects PSSHs from the init data blob.

Previously, the CDM always took the first Widevine PSSH it found. Now,
it must find all the Widevine PSSHs and select the appropriate PSSH
for the OEMCrypto implementation. ENTITLTED_KEYS will be used on OEC
v14 and later, if available, while SINGLE will be preferred on earlier
OEMCrypto versions.

As a side-effect of this, the CDM is now stricter about what PSSH
payloads it will accept. Previously, it would blindly accept the
payload of any PSSH where the wrapper was not malformed. Now, it
sometimes has to actually parse the payload, and therefore PSSHs that
have corrupted payloads will be rejected. This affected a few unit
tests which used PSSHs that were malformed. These tests have been
updated to use PSSHs that do not fail to parse.

Bug: 78142219
Test: CE CDM Unit Tests
Test: Android Unit Tests
Test: Android Google Play & Netflix
Test: tested as part of http://go/ag/4674759
Change-Id: Ia70d627a914299bfbae84b4cb46f100dc5c7a501
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
a242a32bba Implement Method to Release Licenses Without a Server Roundtrip
Merge from Widevine repo of http://go/wvgerrit/52480

Partners have asked for a way to release offline licenses without
using a release message. This is typically used by cable partners who
are caching licenses ahead of time and do not care about usage
statistics.

As part of implementing this request, CdmSession::DeleteLicense() was
renamed to reflect that it only deletes the *files* associated with a
license, and a new CdmSession::DeleteLicense() has been written that
also cleans up other related data.

Bug: 77955334
Test: CE CDM Unit Tests
Test: tested as part of http://go/ag/4674759
Change-Id: I00d6e20935c5fecb3ac9be6757c0f191d85c6bd6
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
240652afcf Do Not Unprovision Baked-In DRM Certs
Merge from Widevine repo of http://go/wvgerrit/49820

Devices with baked-in DRM certs cannot be reprovisioned. As such, we
must protect them against being unprovisioned. Currently, our unit
tests break such devices by attempting to unprovision them. This patch
adds code to block the Unprovision() call on these devices.

Bug: 69264798
Test: CE CDM Unit Tests
Test: tested as part of http://go/ag/4674759
Change-Id: I49322dcb2d3d5c7953e870eb91a9e0b978d4dabe
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
13a76d1236 Merge Forgotten Cleanup from CE CDM v3.5.0
This CL just updates some comments from the http://go/wvgerrit/51680.  Changes
in that CL made to oemcrypto are in the refactor CL.

Test: tested as part of http://go/ag/4674759

Change-Id: Ia619089e146ea635c5a73a53bc81973bb42b42f7
2018-09-02 11:45:16 -07:00
Fred Gylys-Colwell
947531a6a9 Refactor oemcrypto mock into stand alone reference code
Merge from Widevine repo of http://go/wvgerrit/46204
Refactor utility code - split the mock, step 1

Merge from Widevine repo of http://go/wvgerrit/46205
Move some OEMCrypto types to common header - split the mock, step 2

Merge from Widevine repo of http://go/wvgerrit/46206
Split mock into two -- step 3

Merge from Widevine repo of http://go/wvgerrit/47460
Split the mock into two -- step 3.5

The CL moves several files used by oemcrypto and cdm into a common
subdirectory, so that it may more easily be shared with partners.

The CORE_DISALLOW_COPY_AND_ASSIGN macro was moved to its own header in
the util/include directory.

This CL removes some references to the mock from other code, and puts
some constants and types, such as the definition of the keybox, into a
header in oemcrypto.

Test: tested as part of http://go/ag/4674759
bug: 76393338
Change-Id: I75b4bde7062ed8ee572c97ebc2f4da018f4be0c9
2018-09-02 11:45:16 -07:00
Rahul Frias
b8091eaa7d Merge "Delete usage information on insufficient resources" into pi-dev am: b4b02e7762
am: 4540d4eba3

Change-Id: I617db9b5b8ee69681036456d8e2a7b4711b2d926
2018-08-29 20:45:55 -07:00
Rahul Frias
299b100fc8 Delete usage information on insufficient resources
[ Merge of http://go/wvgerrit/58460 ]

If OEMCrypto runs out of space in the usage table header+entries adding
a new license or loading/using an existing one might fail. This CL makes
two modifications to handle this scenario.

* OEMCrypto_ERROR_INSUFFICIENT_RESOURCES will be returned from
  OEMCrypto_CreateNewUsageEntry or OEMCrypto_LoadUsageEntry. An attempt
  will be made to release a LRU entry from the usage table and retry
  the operation. This may be retried 3 times unless success
  occurs earlier.

* On initialization, the usage table header is loaded. If there are more than
  the minimum number of usage entries (200), an attempt is made to
  add a usage entry. If this fails, we are likely in an unrecoverable
  state. We then delete all offline licenses, usage information and
  recreate the usage table header. This will allow future playback
  attempts to succeed and offline licenses to be able to be downloaded
  but will lose all current offline licenses and secure stops.

Bug: 112486006
Test: WV unit/integration tests, GtsMediaDrmTest
      Playback tests using Netflix and Play movies.

Change-Id: I41a18d69a329f8a96c7b607d299ce73af3d56177
2018-08-29 17:38:43 -07:00
Rahul Frias
7b7d5edd7c Use new play license service URI
[ Merge of http://go/wvgerrit/54802 ]

BUG: 110954967
BUG: 110960064

Test: WV unit/integration tests.

Change-Id: I3c5263f304ec9c9734a6761cbd7db46ccb476e9e
2018-08-01 13:41:54 -07:00
John W. Bruce
c28cea3637 Add Missing Parameter to License Keys Unit-Test
(This is a merge of http://go/wvgerrit/55265)

Compiling with GCC 7 revealed that a function call in this test was
missing an argument. It meant to be passing the output protection level
to the function, but because of optional arguments, it was instead
passing it as the fourth argument.

Fixing this revealed that the test cases for the test were incorrect in
one case, which has been fixed to expect the correct results.
Thankfully, this part of the code does not appear to have been broken
while the tests had this hole.

Bug: 111648438
Test: build_and_run_all_unit_tests.sh
Change-Id: I6c13d5fecdccc4185ca5e8698fc845929ff16cb1
2018-07-19 12:49:40 -07:00
Rahul Frias
a20034e3a2 Recover when stored information is corrupted
[ Merge of http://go/wvgerrit/52040 ]

Information stored in files are serialized and protected by an MD5 hash.
When files cannot be read because the MD5 hash computed over it
fails verification, the file is deleted. This allows for recovery.

However if the protobuf deserialization fails we return an error
but do not delete the file. When errors of this sort occur
with usage information files, the CDM cannot recover.
removeAllSecureStops() will fail as well and new licenses
with PSTs cannot be processed. In order to recover the file will
be deleted when a protobuf deserialization error occurs.

Bug: 109765590
Test: WV unit, integration tests. GTS tests. Netflix and Play Movies playback
Change-Id: I408914924e644d5c22b2ba7865d3a7d598788ee6
2018-06-06 00:57:31 -07:00
Rahul Frias
d401baa236 Address deadlock
[ Merge of http://go/wvgerrit/51322 ]

This avoids taking the session_map_lock_ twice.

Bug: 80248149
Test: WV unit/integration tests, GtsMediaTestCases,
      2 days of netflix playback.

Change-Id: Iea1c7b7ba08d7d40c227d21c5abfce13c0a8b395
2018-05-28 12:41:19 -07:00
John W. Bruce
b305d99d3b Make Defensive Copies in CopyBufferInChunks
(This is a merge of http://go/wvgerrit/51084)

Nominally, OEMCrypto probably shouldn't modify the buffer descriptor we
pass into OEMCrypto_DecryptCENC(), but in practice, we know some
platforms do this, so we make defensive copies in
CryptoSession::DecryptInChunks() just in case. Turns out, some devices
also behave like this in OEMCrypto_CopyBuffer(), so we should also be
doing defensive copies in CryptoSession::CopyBufferInChunks().

Bug: 79779554
Test: ExoPlayer Demo App, played "Secure Subsample UHD (WebM, VP9)"
Test: build_and_run_all_unit_tests.sh
Change-Id: Ib46043a6cc0aa42d1d1cc85f5adb477c566363e9
2018-05-23 18:04:01 -07:00
Rahul Frias
e8c3a4afac Protect sessions from concurrent access.
Locks in earlier releases controlled access to sessions and the list
of sessions for each CdmEngine instance. This guarded against
concurrent access between session management (OpenSession,
CloseSession, etc), periodic timer calls and calls to Decrypt.

The list of sessions and locking was moved to a separate class
CdmSessionMap. This left open the possibility that a session
might be destructed, while being called to decrypt or invoked through the
timer. An attempt was made to add per-session locks in b/73781703
but this was found insufficient.

Per-session locks will be introduced in a future changelist, but for
now the coarser locks will be reintroduced.

Bug: 73781703
Bug: 79158083
Bug: 79262108
Bug: 79436509

Test: WV unit/integration tests, GTS GtsMediaTestCases tests and
      24 hours of continuous Netflix playback.

Change-Id: I30a3ede340192370dfe5c92c01b1c76df16b7123
2018-05-15 11:51:17 -07:00
Rahul Frias
dcab2b1355 Address concurrency failures between calls to decrypt and periodic timer
[ http://go/wvgerrit/50341 ]

The shared_ptr implementation was taken from a google3 implementation.
Updates to the reference counter needed to be atomic and were
platform dependent in the original code. These were not carried
over to this codebase. Race conditions between calls to decrypt and
the periodic timer, led to incorrect reference count values.
CdmSession objects were then destructed while references to
them still existed. Segfaults occurred when they were referenced.

Bug: 79431096

Test: WV unit/integration tests, GTS GtsMediaTestCases tests and
      24 hours of continuous Netflix playback.

Change-Id: I6008ddba869efcc58972e5ea8644a204f91410ab
2018-05-14 16:38:38 -07:00
Rahul Frias
0163607fa3 Revert of "Prevent race conditions between decrypt and close session"
[ Original CL http://ag/3890635,
  Merge of http://go/wvgerrit/50340 ]

The original fix was not sufficient to address all race conditions.
A subsequent CL will address them.

Bug: 73781703
Bug: 79158083
Bug: 79262108
Test: WV unit/integration tests, GTS GtsMediaTestCases tests and
      24 hours of continuous Netflix playback.

Change-Id: I869c22a250e2467b3d49935815e4157dc012fff5
2018-05-14 15:45:54 -07:00
Rahul Frias
184e0d0559 Address Cdm Extended Duration Test failures
[ Merge of http://go/wvgerrit/49980 ]

This CL
* corrects some of the test expectations
* switches test content used to test streaming with provider session tokens.
  The policy of the earlier test content had changed.
* adds some more information to log messages

Bug: 63819720
Test: WV unit, integration tests, WvCdmExtendedDuraionTest,
      GtsMediaDrmTest

Change-Id: I8fdbc9c38d6018cc6e884e1b95b2e9d26e7aa536
2018-05-11 14:27:45 -07:00
Rahul Frias
734b6b819e Merge "Allow a service certificate to be specified for provisioning" into pi-dev 2018-05-02 21:51:54 +00:00
Rahul Frias
9ba6493e1b Save usage information before closing a session
[ Merge of http://go/wvgerrit/48640 ]

Usage information is saved periodically, in order to avoid excessive
flash writes. This limits our session usage accuracy to
within a usage save period. Saving usage information when
closing a session is an improvement and addresses some failures
seen with Netflix compliance tests.

Bug: 74015553
Test: WV unit/integration tests
Change-Id: I680aad05922f334df0611ff3933082a512f7c002
2018-04-26 14:14:51 -07:00