Commit Graph

141 Commits

Author SHA1 Message Date
Fred Gylys-Colwell
1735b367f3 Level 3 OEMCrypto library
This CL contains the level 3 oemcrypto library built for android.  I
used the toolchain from the mnc-emu-release branch because I'm having
problems with the toolchain on master.

This includes the security patch API, and several bug fixes to the library.

Current versions:
mips/libwvlevel3.a  Level3 Library Dec 17 2015 21:26:57
arm/libwvlevel3.a  Level3 Library Dec 17 2015 21:09:47
x86/libwvlevel3.a  Level3 Library Dec 17 2015 21:19:15

http://go/wvgerrit/16371 Level 3 OEMCrypto library
http://go/wvgerrit/16315 Security Patch Level - haystack version
http://go/wvgerrit/16282 Correctly handle null pointer in GetKeyData
http://go/wvgerrit/16294 Initialize data for generation number
http://go/wvgerrit/16280 Correctly handle bad RSA key

bug: 26089773
bug: 26092100
bug: 26086944
Change-Id: I3ea1b5d219dae0c88deafa742f61d67e97297902
2015-12-18 11:18:16 -08:00
Fred Gylys-Colwell
4a37b21a22 Close session before terminate
Merge from the widevine repo of http://go/wvgerrit/16362

A test class holds a default session that it expects to be able to
close in the tear down.  This was not true in the TimingTest because
it calls OEMCrypto_Terminate which closes all open sessions.

This CL closes the default session, and then reopens it again after
OEMCrypto_Initialize.

Change-Id: Ib4128ec3c0a33794c03aa934174cb6fff448483e
2015-12-16 17:26:26 -08:00
Fred Gylys-Colwell
ce6d392041 Unit Tests for Security Patch Level
Merge of widevine change http://go/wvgerrit/16249

This CL adds unit tests and reference code for the security patch
level, which is a new feature in OEMCrypto v11.  This CL also adjusts
the dynamic and static adapters to still run with devices that have a
v10 OEMCrypto.

The level 3 haystack code will be updated in a future CL.

bug: 26188985

Change-Id: I518ef46b4098cf3718fe0c0390bfb6825db4fb6b
2015-12-16 16:11:13 -08:00
Fred Gylys-Colwell
17faabee44 Fail early in oemcrypto unit tests
Merge from widevine of http://go/wvgerrit/16293

This CL adds ASSERT_NO_FATAL_FAILURE around many subroutines in the
oemcrypto unit tests.  This should help debug tradefed tests because
it will cause a test to stop after the first error.  This is important
for tests that are failing on OpenSession and then spewing garbage
into the log as every other ASSERT fails after that.

I also replaced the home-grown EXPECT_ALMOST with the standard
EXPECT_NEAR.  I also passed the file through clang-format to corect
whitespace problems.

Change-Id: I2c2c1c1dbeac234291dafc9fa8c23da8d270eb4e
2015-12-16 13:39:29 -08:00
Fred Gylys-Colwell
0dc746a380 OEMCrypto v11 Documentation and Headers
Merge from widevine repo of http://go/wvgerrit/16186

These are the OEMCrypto v11 documents and header files. I have updated
just enough code so that existing unit tests pass.  New unit tests,
the reference implementation, and the level 3 implementation are in
future CLs.

Change-Id: I9bbf1909e047f63a5877320a2d06740a3c4a3e32
2015-12-09 13:51:18 -08:00
Fred Gylys-Colwell
a99825b7aa Unit Test for OEMCrypto to Reject Future Key Control Block
Merge from widevine repo of http://go/wvgerrit/16250

The verification string in the key control block has an obvious
pattern that is incremented every time we update the API.  This CL
adds a unit test to make sure an implementation of OEMCrypto is not
casually accepting a future version of the key control block before
the API has even been defined.

Change-Id: I3f837f7346ef7de399441f5fcda9b13b65fa51f4
2015-12-09 09:58:36 -08:00
Fred Gylys-Colwell
6d7dcb8cba Updates to OEMCrytpo Mock
Squash merge from the widevine repo of several changes to oemcrypto
unit tests and the mock reference code.

http://go/wvgerrit/16264 Use unsigned int for count in usage table (more mock)
http://go/wvgerrit/16262 Use unsigned int for count in usage table (mock version)
http://go/wvgerrit/16247 Fix mock OEMCrypto_DeleteUsageTable
http://go/wvgerrit/16070 Fix OEMCrypto_GenerateRSASignature return values
http://go/wvgerrit/15991 Fix buffer overflow for 32-bit systems
http://go/wvgerrit/15993 Return Correct Value from OEMCrypto_RefreshKeys
http://go/wvgerrit/15880 Cast RSA_size() to int
http://go/wvgerrit/15831 Be strict about warnings for CE CDM

b/23729420
b/25221168

Change-Id: I97b91dfc672db8c586ae317977871b7d6afac4bb
2015-12-07 15:33:56 -08:00
Rahul Frias
072cf7e711 Add level 3 libs and address build warnings
* Fix strict aliasing error in gcc

  [ Merge of http://go/wvgerrit/15856 ]

  This also ensures the alignment of 64-bit memory access in a portable
  way, without using compiler-specific mechanisms like attributes or
  platform-specific mechanisms like memalign.

  (The aliasing error does not show up in clang.)

* Return kNotSupported for non-Widevine init data

  [ Merge of http://go/wvgerrit/15853 ]

  This also improves logging for the init data parser by including a
  verbose message for non-Widevine PSSHs and by using a new IsEOF()
  method to avoid misleading "Unable to read atom size" logs.

* Cast RSA_size() to int

  [ Merge of http://go/wvgerrit/15880 ]

  It has been suggested that this may be unsigned on some versions of
  OpenSSL or BoringSSL.

* Be strict about warnings for CE CDM

  [ Merge of http://go/wvgerrit/15831 ]

  * Enable all warnings and treat warnings as errors in the CE build.
  * Fix all existing warnings (mostly unused variables, consts, and
  functions, and one signed/unsigned comparison).
  * Exclude protobuf warnings rather than maintain a divergent copy.

* Fix release build errors

  [ Merge of http://go/wvgerrit/15855 ]

* Level 3 Build With Android Emulator

  [ Merge of http://go/wvgerrit/15778 ]

  This CL rebuilds the level 3 libraries with the android emulator
  sdk_phone_*.  This seems to avoid problems with the x86 build using
  incorrect compiler flags.

  These libraries work for arm, x86, mips, arm64, and x86_64.  The level
  3 library is disabled for mips64.

  Versions:
  level3/mips/libwvlevel3.a  Level3 Library Sep 30 2015 18:29:50
  level3/arm/libwvlevel3.a  Level3 Library Sep 28 2015 13:18:25
  level3/x86/libwvlevel3.a  Level3 Library Sep 28 2015 13:08:28

Change-Id: I1e50aa78bdc84ecb905f2e55297d4f48b140341c
2015-10-15 22:50:29 +00:00
Fred Gylys-Colwell
16f9a38a6b am 08198c7b: am 78583720: Clarify HDCP Type (mnc-dev branch)
* commit '08198c7bfa9c2d57fde2a616cc26b82189925822':
  Clarify HDCP Type (mnc-dev branch)
2015-10-03 15:40:00 +00:00
Fred Gylys-Colwell
a9fe9bb38c Variable Length Key ID Tests
Merge from Widevine repo of http://go/wvgerrit/14973 and
http://go/wvgerrit/14573.

Some devices were failing the variable length key id tests, so they
were removed from Android while we decided whether the tests are too
strict for future releases.

This CL re-instates the tests with the understanding that the maximum
key id length is 16 bytes, as discussed in b/24469550.  If we decide
that it is OK to have longer key ids, then another CL will be needed
to test with those lengths.

bug: 21935358

Change-Id: Ic6b776a8b119daac961c71280994fcc944984d8a
2015-09-28 12:58:17 -07:00
Fred Gylys-Colwell
7858372033 Clarify HDCP Type (mnc-dev branch)
Merge from widevine repo of http://go/wvgerrit/15735

This is a documentation only change.

This CL updates the docs for OEMCrypto to clarify that HDCP v2.2
should be type 1.  The document version number is rolled to 10.3.

See original document for version history:
https://docs.google.com/document/d/1pHSJ2IKL0axmQz2gmDZ7olxPWb_ZcULaJrYwDZAeS7k/edit#

bug: 24098055
Change-Id: If2dd677cd824482ab18eeed03a335d7b82adbcbe
2015-09-23 17:16:14 -07:00
Fred Gylys-Colwell
2057d49b3c Merge "Modify Code to Work with Clang/C++11" 2015-09-16 23:20:03 +00:00
Fred Gylys-Colwell
bf0c87e734 Modify Code to Work with Clang/C++11
Merge from widevine repo of http://go/wvgerrit/15659

The clang compiler is more strict about C++11. This is needed for
future Android work.

In particular, iostream no longer converts to bool automtically, so
those instances were replaced with ss.fail().

Arrays or structures that appear to be variable length need to be
placed last in a structure.  In oemcrypto_test a variable size
structure was replaced with an explicit buffer size, and a check was
added to make sure the buffer is not exceeded.

bug: 20893039
Change-Id: I5e25fc618dcf68262079c15554ee4ceae1858b8b
2015-09-16 15:58:33 -07:00
Fred Gylys-Colwell
914e13067f Add Support for Baked-In Certificates
Port from the widevine repo of http://go/wvgerrit/15628

This change enables easy support for baked-in certificates. Platforms
using this feature need only change the supports_keybox property to
false, replace keys.cpp with the file provided by Google, and make
sure the cert.bin provided by Google is preinstalled in the storage.

To enable this, new files defining storage for the embedded private
key were added to MockOEMCrypto. When supports_keybox is false, these
are referenced to get the embedded private key. As this code is mostly
shared with the existing test utility function that loads the test
certificate, the shared code was moved to a helper. Also, the behavior
of the MockOEMCrypto implementation OEMCrypto_LoadDeviceRSAKey when
supports_keybox is false was changed from erroring to validating that
the "wrapped private key" is actually the magic value 0xDEADBEEF.

Bug: 23554998
Change-Id: I8b5d7b4d37b8ec80bb4342e441625cbc5046df89
2015-09-16 13:35:10 -07:00
Fred Gylys-Colwell
150a6ea02a am c0455244: am 9a714edc: Merge "Fix RSA Key Padding in OEMCrypto Unit Tests" into mnc-dev
* commit 'c0455244631e8fd2627a5a95c9d956727b6a162c':
  Fix RSA Key Padding in OEMCrypto Unit Tests
2015-08-16 03:02:11 +00:00
Fred Gylys-Colwell
9a714edc6f Merge "Fix RSA Key Padding in OEMCrypto Unit Tests" into mnc-dev 2015-08-14 22:01:06 +00:00
Fred Gylys-Colwell
631d3e7a4c Relax test on forbidden signing [DO NOT MERGE]
Copy from widevine repo of http://go/wvgerrit/15390

Because some devices are failing oemcrypto unit tests related to
signing schemes that they do not support, we are relaxing the
requirement that they return the correct error code.

We are still requiring that the device does NOT sign with a forbidden
scheme.  However, it is OK if they do not return an error code from
OEMCrypto_GenerateRSASignature.   They will be required to return the
correct error code in the next release.

bug: 21668896
bug: 21708882

Change-Id: I1b8a410909b364d0086cba38eadca11aceaac5f6
2015-08-11 17:05:20 -07:00
Fred Gylys-Colwell
29e08f2166 Fix RSA Key Padding in OEMCrypto Unit Tests
Merge from widevine of http://go/wvgerrit/15371

incorrectly have leading 0x00 bytes added to all integers.  This
leading 0 should only be added to integers that had a leading byte
larger than 0x80 because those would be parsed as negative numbers.

bug: 23105200
Change-Id: I1dd01cc2b83a807bbdb78c079c6ce4e01d41f616
2015-08-11 13:52:50 -07:00
Fred Gylys-Colwell
b1ddcf1495 am 03f523ca: am e280ba6c: Merge "Add Short Key ID Test" into mnc-dev
* commit '03f523cab014cc3169d603d289dd51f9ca9ee71e':
  Add Short Key ID Test
2015-07-04 08:04:40 +00:00
Fred Gylys-Colwell
4b3c02267a Add Short Key ID Test
Merge from widevine repo of http://go/wvgerrit/14970

Even if devices cannot handle key ids with different lengths in the
same license, they should still handle keys with a shorter key id.

This is a partial fix for:
bug: 21935358

Change-Id: Ibc84f0b5d7d9bc5d24a2081f0581a2b256e51f44
2015-07-01 13:21:21 -07:00
Fred Gylys-Colwell
84efb88c28 Do not depend on wvcdm::Clock in OEC tests
Merge from widevine repo of http://go/wvgerrit/14669

This fixes two timing-related test failures when running the OEMCrypto
tests in the CE test suite.  The failures were caused by the TestHost
Clock implementation, which is a fake.  Since there is no clear reason
for OEMCrypto/mock to rely on wvcdm::Clock, this replaces it with
time(NULL).  Incidentally, this also makes the time source consistent
with the tests themselves, which were already using time(NULL).

Change-Id: I0fad51f14d45f99526146da05b757d4ba7b6aba0
2015-06-29 18:17:15 -07:00
Fred Gylys-Colwell
54bb6ea3c8 Add Comment to DecryptWithNearWrap
Merge from widevine repo of http://go/wvgerrit/14933

There was some confusion what the test DecryptWithNearWrap is
testing.  This CL adds some expanatory comments.

Change-Id: I9228830d81c089f80e0878f647e7e94c3e49896a
2015-06-29 18:16:21 -07:00
Fred Gylys-Colwell
666031026c Make MaxSessionsOpenCloseAPI10 More Lenient
Merge from widevine repo of http://go/wvgerrit/14870

OEMCrypto_GetMaxNumberOfSessions is not required to return a hard
limit for the number of sessions.  This CL adjusts the test to verify
we can open within 5% of the maximum number of sessions.

bug: 22029687
Change-Id: I6e72e39338cead8d547cdb194a32fb7e7dc53037
2015-06-24 17:49:06 -07:00
John "Juce" Bruce
256dd1a5b4 Merge "Re-Add MIPS to Android CDM Build" into mnc-dev 2015-06-20 00:33:01 +00:00
John "Juce" Bruce
da8e2beb28 Merge "Do Not Use GNU-Style Hashing on MIPS" into mnc-dev 2015-06-20 00:31:50 +00:00
John "Juce" Bruce
64d9be5615 Fix OEMCrypto Tests
(This is a merge of http://go/wvgerrit/14810)

By making this constant unsigned, all calculations in EXPECT_ALMOST
were cast to unsigned, leading to underflow problems when it was
subtracted from zero.

Change-Id: Iefc4e30604c45fec8b203375074b26fb12ec385f
2015-06-19 17:08:56 -07:00
John "Juce" Bruce
8443abc555 Re-Add MIPS to Android CDM Build
(This is a merge of http://go/wvgerrit/14795)

This change restores the ability to build the Widevine CDM for Android
for MIPS devices. It restores the precompiled binaries for MIPS and
re-adds MIPS to all makefiles.

This change includes a new build of the obfuscated binaries for
MIPS32r1 that were built using a MIPS device on the emulator.

level3/mips/libwvlevel3.a  Level3 Library Jun 19 2015 12:32:49

Bug: 19482469
Change-Id: Ifa1c299a5751f3772c42289d8333a2b8cec51f69
2015-06-19 16:34:08 -07:00
John "Juce" Bruce
123c469d3e Do Not Use GNU-Style Hashing on MIPS
(This is a merge of http://go/wvgerrit/14801)

The MIPS compiler does not support GNU hashing, which means this
compiler option needs to be excluded.

Bug: 19482469
Change-Id: I913f666a39eb535a33ebfbc49e5e7531115db5d4
2015-06-19 16:33:11 -07:00
Fred Gylys-Colwell
20b07afad9 Merge "Disable Flaky Key Id Length Tests" into mnc-dev 2015-06-19 22:27:26 +00:00
Fred Gylys-Colwell
592f8ad6db Disable Flaky Key Id Length Tests
Merge from widevine directory of http://go/wvgerrit/14784

These tests are not passing on multiple devices so I will disable them
until I am sure they are giving a clear signal.

bug: 21935358
Change-Id: I1e0cf01e64ea50b02d61d4b8334c0efb55e47d35
2015-06-19 13:29:52 -07:00
John "Juce" Bruce
6a773e3630 Be More Forgiving in EXPECT_ALMOST()
(This is a merge of http://go/wvgerrit/14776)

This change widens the range in EXPECT_ALMOST slightly, to allow for
slight timing errors in the tests.

Bug: 21489628
Change-Id: Ibb074c2d037566c307c0438efdda3841bc48f7ed
2015-06-18 19:00:06 -07:00
John "Juce" Bruce
57fd014f6d Fail Test if LoadOfflineLicense() Helper Fails
(This is a merge of http://go/wvgerrit/14775)

This change causes tests that call LoadOfflineLicense() to fail if
the session is still open after that call. Due to the way that gTest
handles ASSERT_*() macros, failures in LoadOfflineLicense() will leave
the session open, causing unexpected state and cascading failures
throughout the rest of the test. With this change, we will abort
sooner, reducing log noise.

Bug: 21489628
Change-Id: Ic35bc77bbc5f676f23deeefaacd1986e383538c8
2015-06-18 18:59:24 -07:00
Fred Gylys-Colwell
b879cc6c3a Merge "Fix QueryKeyControl Unit Test" into mnc-dev 2015-06-17 23:35:23 +00:00
Fred Gylys-Colwell
854a409ae6 Accept Other Error Codes in TestSignatureBoth
Merge from widevine of http://go/wvgerrit/14744

The OEMCrypto unit test TestSignatureBoth verifies that a cast
certificate cannot be used to derive session keys.  This CL relaxes
the requirement that DeriveKeysFromSessionKey returns a specific error
code instead of just failing.

bug: 21708882
Change-Id: I4163a9616122ad709bab76f488d030239029861c
2015-06-17 15:58:58 -07:00
Fred Gylys-Colwell
b6f096d08a Fix QueryKeyControl Unit Test
Merge from widevine repo of http://go/wvgerrit/14720

The QueryKeyControl test expects an error message that the output
buffer is too small.  However, it also gives a bad key id.  Some
devices were correctly returning key not found.  This corrects the key
id length so that the only error is that the buffer is too small.

bug: 21881768
Change-Id: I96f59ede42eeddc9849fbac1e52acecdb562df08
2015-06-17 15:53:12 -07:00
Fred Gylys-Colwell
f9453190fd Improve RSA performance in Level 3 OEMCrypto
Merge from widevine repo of http://go/wvgerrit/14668

This CL modifies the multiplication routine to avoid memory cache
misses.  This shows a 10-20% speed improvment in license requests on
an x86.

Level 3 library version:
level3/arm/libwvlevel3.a  Level3 Library Jun 15 2015 14:09:24
level3/x86/libwvlevel3.a  Level3 Library Jun 15 2015 14:09:10

bug: 18252910

Change-Id: I4429324374de46d1d710d5fcac80f7ed363c696c
2015-06-17 11:28:27 -07:00
Fred Gylys-Colwell
82bf03f062 Verify OEMCrypto supports Level 1
Merge from widevine repo of http://go/wvgerrit/14708

This CL adds a test to verify that oemcrypto is a level 1 device.  It
is part of oemcrypto_test_android.cpp, so it only applies to android
devices and to the widevine buildbot which also runs the android tests.

bug: 21814204

Change-Id: Icbcdd3496fb8a656891bd7c873c60cba23c9666a
2015-06-16 17:46:52 -07:00
Fred Gylys-Colwell
8bd1a40cd2 Verify Key Rewrapping Does Not Leave Key in Clear
Merge from widevine repo of http:/go/wvgerrit/14707

This CL adds a check to oemcrypto_test to verify that when a
certificate is rewrapped, it does not show up in the clear.  We can't
really verify that it is encrypted well, but we can check this.

bug: 21871738

Change-Id: I07c87c38a1e2a099a90a5be4e3350e91e09f6722
2015-06-16 11:16:46 -07:00
Fred Gylys-Colwell
bf484e95de Separate and Clarify Cast Reciever Tests
Merge from widevine of http://go/wvgerrit/14667

This CL updates oemcrypto_test.cpp so that devices that are not cast
recievers do not attempt to run those tests that are only needed by
cast recievers.

bug: 21708882
bug: 18948285

Change-Id: I75f9170cee13e66667db54c5f298ed5c6cf14a48
2015-06-15 11:22:46 -07:00
Fred Gylys-Colwell
30abdd58a0 Merge "Add Tests With Different Sized Key IDs" into mnc-dev 2015-06-05 17:40:12 +00:00
Fred Gylys-Colwell
177c59033e Add Tests With Different Sized Key IDs
Merge from widevine repo of http://go/wvgerrit/14550

This CL adds several tests with different sized key ids to
oemcrypto_test.

bug: 21643096
Change-Id: I62a89c557f3f746f09ee5a2fe5bdd3ca821448e4
2015-06-04 15:57:56 -07:00
Fred Gylys-Colwell
92958a0e6a Protect OEMCrypto Mock and Level 3 From Null Pointers
Merge from widevine repo of http://go/wvgerrit/14502

If any OEMCrypto session call is made after Terminate is called, then
there was a null pointer access.  This is protected by the oemcrypto
adapter, but could still be a problem in unit tests which by-pass the
adapter.

bug: 21642892

Level 3 versions:
level3/arm/libwvlevel3.a  Level3 Library May 29 2015 14:03:11
level3/x86/libwvlevel3.a  Level3 Library May 29 2015 14:03:12

Change-Id: I84fd098c2faea71a79bc21658485593e22a8e994
2015-06-04 15:54:08 -07:00
Fred Gylys-Colwell
9dfa85ae2a Replace some arrays with vectors and initialize
Merge from widevine side of http://go/wvgerrit/14462

This cleans up some tests in oemcrypto_test.cpp so that they use
vectors instead of arrays.  The two reasons this is needed are that
arrays are more likely to use up stack space, and that arrays on the
stack are not initialized.

The lack of initialization caused some negative tests to fail because
buffers that were reused from unencrypted data still contained values
that the test expected not to be there.

Change-Id: Ic1705b6bc581084a9fe3cd573adf34d8219a1a45
2015-05-29 13:53:08 -07:00
Fred Gylys-Colwell
994a7fc4c1 Update OEMCrypto Offset Tests
Merge from widevine repo of http://go/wvgerrit/14321

It is expected that OEMCrypto will only be given subsamples with a
block offset when there are multiple subsamples, so that the entire
sample may be decrypted after all calls are made.  This CL modifies
the existing tests so that the result of DecryptCTR is only checked
after all subsamples have been decrypted.

Also, the QueryKeyControl test has been modified so that failure does
not require a specific error code.

bug: 20757848
bug: 21063276
Change-Id: Ie2b12b287b0c9c661cd14111b2ae9eab004cd8b8
2015-05-29 13:50:20 -07:00
Fred Gylys-Colwell
6639965d30 Update padding scheme in mock
Merge from widevine repo of http://go/wvgerrit/14370

In order to run on android, we need the mock to compile with
BoringSSL, which uses a different function call for
RSA_padding_add_PKCS1_PSS.

Change-Id: I9cad4e7d5c1d4a3117fe7c0fc1e27590809a7ac3
2015-05-19 21:05:29 -07:00
Fred Gylys-Colwell
7fffdcdbd9 Print values in host byte order
Merge from widevine of http://go/wvgerrit/14361

In oemcrypto_test, we look at some control duration and control
bits. These are stored in network byte order.  However, it is easier
to read error messages if they are converted to host byte order before
printing them.

Change-Id: I116b5f43957351b0e40e05331c282c248128903c
2015-05-14 15:54:38 -07:00
Chih-Hung Hsieh
1c6b675f0c Use gcc to build unit tests until vendor code is fixed.
BUG: 20893039
Change-Id: I649dae16bbc748defc8eb92c879140fe950fe936
2015-05-06 16:44:47 -07:00
Fred Gylys-Colwell
48e84580e9 Close Unused Sessions in NonceFlood Unit Test
Merge from widevine of http://go/wvgerrit/14263

The unit test PreventNonceFlood3 opens 8 sessions and floods the nonce
table.  It then opens one more session after a pause to verify that it
can still request nonces.  However, there is no requirement that we
can open more than 8 sessions.  This CL reuses one of the already open
sessions to verify that we can continue generating nonces.

Change-Id: If35f146477bd21e381ec5375dde7ec7fdbe8f366
2015-05-01 15:55:34 -07:00
Fred Gylys-Colwell
c4d9c1036e Merge "Update unit test make files to use BoringSSL" 2015-04-22 17:35:25 +00:00
Fred Gylys-Colwell
d6da9518ec Merge "Annotate logcat with current running test (oemcrypto)" 2015-04-22 17:34:53 +00:00