diff --git a/libwvdrmengine/Android.mk b/libwvdrmengine/Android.mk index e7930bfa..0ae5ae4d 100644 --- a/libwvdrmengine/Android.mk +++ b/libwvdrmengine/Android.mk @@ -91,6 +91,7 @@ LOCAL_STATIC_LIBRARIES := libcrypto LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/oemcrypto/include \ LOCAL_HEADER_LIBRARIES := \ @@ -100,15 +101,16 @@ LOCAL_SHARED_LIBRARIES := \ liblog SRC_DIR := cdm/src +UTIL_SRC_DIR := cdm/util/src CORE_SRC_DIR := cdm/core/src LOCAL_SRC_FILES := \ $(CORE_SRC_DIR)/properties.cpp \ - $(CORE_SRC_DIR)/string_conversions.cpp \ - $(SRC_DIR)/clock.cpp \ - $(SRC_DIR)/file_store.cpp \ - $(SRC_DIR)/file_utils.cpp \ - $(SRC_DIR)/lock.cpp \ - $(SRC_DIR)/log.cpp \ + $(UTIL_SRC_DIR)/string_conversions.cpp \ + $(UTIL_SRC_DIR)/clock.cpp \ + $(UTIL_SRC_DIR)/file_store.cpp \ + $(UTIL_SRC_DIR)/file_utils.cpp \ + $(UTIL_SRC_DIR)/lock.cpp \ + $(UTIL_SRC_DIR)/log.cpp \ $(SRC_DIR)/properties_android.cpp \ $(SRC_DIR)/timer.cpp \ @@ -160,6 +162,7 @@ LOCAL_C_INCLUDES := \ frameworks/native/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediacrypto/include \ @@ -217,6 +220,7 @@ LOCAL_C_INCLUDES := \ frameworks/native/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/include_hidl \ vendor/widevine/libwvdrmengine/include \ diff --git a/libwvdrmengine/cdm/Android.mk b/libwvdrmengine/cdm/Android.mk index 31923902..585b898b 100644 --- a/libwvdrmengine/cdm/Android.mk +++ b/libwvdrmengine/cdm/Android.mk @@ -9,6 +9,7 @@ LOCAL_CFLAGS := -DDYNAMIC_ADAPTER LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/oemcrypto/include \ diff --git a/libwvdrmengine/cdm/core/include/buffer_reader.h b/libwvdrmengine/cdm/core/include/buffer_reader.h index 92da9cd8..0ccac377 100644 --- a/libwvdrmengine/cdm/core/include/buffer_reader.h +++ b/libwvdrmengine/cdm/core/include/buffer_reader.h @@ -9,7 +9,7 @@ #include #include -#include "wv_cdm_types.h" +#include "disallow_copy_and_assign.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/core/include/cdm_engine.h b/libwvdrmengine/cdm/core/include/cdm_engine.h index d713e08b..a7a72d9e 100644 --- a/libwvdrmengine/cdm/core/include/cdm_engine.h +++ b/libwvdrmengine/cdm/core/include/cdm_engine.h @@ -13,6 +13,7 @@ #include "certificate_provisioning.h" #include "clock.h" #include "crypto_session.h" +#include "disallow_copy_and_assign.h" #include "file_store.h" #include "initialization_data.h" #include "lock.h" diff --git a/libwvdrmengine/cdm/core/include/cdm_session.h b/libwvdrmengine/cdm/core/include/cdm_session.h index 113c9e96..f8c79b6f 100644 --- a/libwvdrmengine/cdm/core/include/cdm_session.h +++ b/libwvdrmengine/cdm/core/include/cdm_session.h @@ -10,6 +10,7 @@ #include #include "crypto_session.h" +#include "disallow_copy_and_assign.h" #include "device_files.h" #include "file_store.h" #include "initialization_data.h" diff --git a/libwvdrmengine/cdm/core/include/cdm_session_map.h b/libwvdrmengine/cdm/core/include/cdm_session_map.h index 7fa06b81..ac0bacdf 100644 --- a/libwvdrmengine/cdm/core/include/cdm_session_map.h +++ b/libwvdrmengine/cdm/core/include/cdm_session_map.h @@ -10,6 +10,8 @@ #include #include "cdm_session.h" +#include "disallow_copy_and_assign.h" +#include "lock.h" #include "shared_ptr.h" #include "wv_cdm_types.h" diff --git a/libwvdrmengine/cdm/core/include/certificate_provisioning.h b/libwvdrmengine/cdm/core/include/certificate_provisioning.h index edf8a737..6f3b00ea 100644 --- a/libwvdrmengine/cdm/core/include/certificate_provisioning.h +++ b/libwvdrmengine/cdm/core/include/certificate_provisioning.h @@ -8,6 +8,7 @@ #include #include "crypto_session.h" +#include "disallow_copy_and_assign.h" #include "license_protocol.pb.h" #include "metrics_collections.h" #include "oemcrypto_adapter.h" diff --git a/libwvdrmengine/cdm/core/include/client_identification.h b/libwvdrmengine/cdm/core/include/client_identification.h index da878b1f..76fcde5e 100644 --- a/libwvdrmengine/cdm/core/include/client_identification.h +++ b/libwvdrmengine/cdm/core/include/client_identification.h @@ -8,6 +8,7 @@ // ClientIdentification fills in the ClientIdentification portion // of the License or Provisioning request messages. +#include "disallow_copy_and_assign.h" #include "license_protocol.pb.h" #include "wv_cdm_types.h" diff --git a/libwvdrmengine/cdm/core/include/crypto_session.h b/libwvdrmengine/cdm/core/include/crypto_session.h index 82fadb5d..54aeec59 100644 --- a/libwvdrmengine/cdm/core/include/crypto_session.h +++ b/libwvdrmengine/cdm/core/include/crypto_session.h @@ -10,6 +10,7 @@ #include #include "OEMCryptoCENC.h" +#include "disallow_copy_and_assign.h" #include "key_session.h" #include "lock.h" #include "metrics_collections.h" diff --git a/libwvdrmengine/cdm/core/include/device_files.h b/libwvdrmengine/cdm/core/include/device_files.h index 377c9e0c..82ceeb16 100644 --- a/libwvdrmengine/cdm/core/include/device_files.h +++ b/libwvdrmengine/cdm/core/include/device_files.h @@ -12,6 +12,7 @@ #include #include "device_files.pb.h" +#include "disallow_copy_and_assign.h" #include "scoped_ptr.h" #include "wv_cdm_types.h" diff --git a/libwvdrmengine/cdm/core/include/entitlement_key_session.h b/libwvdrmengine/cdm/core/include/entitlement_key_session.h index 7cdad259..ec3c2f42 100644 --- a/libwvdrmengine/cdm/core/include/entitlement_key_session.h +++ b/libwvdrmengine/cdm/core/include/entitlement_key_session.h @@ -31,4 +31,4 @@ class EntitlementKeySession : public ContentKeySession { } // namespace wvcdm -#endif // WVCDM_CORE_ENTITLEMENT_KEY_SESSSION_H_ \ No newline at end of file +#endif // WVCDM_CORE_ENTITLEMENT_KEY_SESSSION_H_ diff --git a/libwvdrmengine/cdm/core/include/key_session.h b/libwvdrmengine/cdm/core/include/key_session.h index d8c3c737..285c60f3 100644 --- a/libwvdrmengine/cdm/core/include/key_session.h +++ b/libwvdrmengine/cdm/core/include/key_session.h @@ -43,4 +43,4 @@ typedef std::map SubLicenseSessionMap; } // namespace wvcdm -#endif // WVCDM_CORE_KEY_SESSSION_H_ \ No newline at end of file +#endif // WVCDM_CORE_KEY_SESSSION_H_ diff --git a/libwvdrmengine/cdm/core/include/license.h b/libwvdrmengine/cdm/core/include/license.h index d215b39f..2c906449 100644 --- a/libwvdrmengine/cdm/core/include/license.h +++ b/libwvdrmengine/cdm/core/include/license.h @@ -7,6 +7,7 @@ #include +#include "disallow_copy_and_assign.h" #include "initialization_data.h" #include "license_protocol.pb.h" #include "scoped_ptr.h" diff --git a/libwvdrmengine/cdm/core/include/license_key_status.h b/libwvdrmengine/cdm/core/include/license_key_status.h index 06cf6adc..b52a641a 100644 --- a/libwvdrmengine/cdm/core/include/license_key_status.h +++ b/libwvdrmengine/cdm/core/include/license_key_status.h @@ -8,6 +8,7 @@ #include #include "crypto_session.h" +#include "disallow_copy_and_assign.h" #include "license_protocol.pb.h" #include "wv_cdm_types.h" diff --git a/libwvdrmengine/cdm/core/include/policy_engine.h b/libwvdrmengine/cdm/core/include/policy_engine.h index 85ac3798..9bd0f95e 100644 --- a/libwvdrmengine/cdm/core/include/policy_engine.h +++ b/libwvdrmengine/cdm/core/include/policy_engine.h @@ -8,6 +8,7 @@ #include #include +#include "disallow_copy_and_assign.h" #include "license_key_status.h" #include "license_protocol.pb.h" #include "scoped_ptr.h" diff --git a/libwvdrmengine/cdm/core/include/privacy_crypto.h b/libwvdrmengine/cdm/core/include/privacy_crypto.h index 66a629c3..6258bd80 100644 --- a/libwvdrmengine/cdm/core/include/privacy_crypto.h +++ b/libwvdrmengine/cdm/core/include/privacy_crypto.h @@ -26,6 +26,7 @@ #include +#include "disallow_copy_and_assign.h" #include "wv_cdm_types.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/core/include/properties.h b/libwvdrmengine/cdm/core/include/properties.h index 2987f87f..49dd1c28 100644 --- a/libwvdrmengine/cdm/core/include/properties.h +++ b/libwvdrmengine/cdm/core/include/properties.h @@ -9,6 +9,7 @@ #include #include "cdm_client_property_set.h" +#include "disallow_copy_and_assign.h" #include "lock.h" #include "scoped_ptr.h" #include "wv_cdm_types.h" diff --git a/libwvdrmengine/cdm/core/include/scoped_ptr.h b/libwvdrmengine/cdm/core/include/scoped_ptr.h index 0cca1b05..cfff35f8 100644 --- a/libwvdrmengine/cdm/core/include/scoped_ptr.h +++ b/libwvdrmengine/cdm/core/include/scoped_ptr.h @@ -8,7 +8,7 @@ #ifndef WVCDM_CORE_SCOPED_PTR_H_ #define WVCDM_CORE_SCOPED_PTR_H_ -#include "wv_cdm_types.h" +#include "disallow_copy_and_assign.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/core/include/service_certificate.h b/libwvdrmengine/cdm/core/include/service_certificate.h index 532e4a5a..1b4de7f1 100644 --- a/libwvdrmengine/cdm/core/include/service_certificate.h +++ b/libwvdrmengine/cdm/core/include/service_certificate.h @@ -15,6 +15,7 @@ #include +#include "disallow_copy_and_assign.h" #include "license_protocol.pb.h" #include "privacy_crypto.h" #include "wv_cdm_types.h" diff --git a/libwvdrmengine/cdm/core/include/usage_table_header.h b/libwvdrmengine/cdm/core/include/usage_table_header.h index f38a96ef..6b3ca861 100644 --- a/libwvdrmengine/cdm/core/include/usage_table_header.h +++ b/libwvdrmengine/cdm/core/include/usage_table_header.h @@ -10,6 +10,7 @@ #include "crypto_session.h" #include "device_files.h" +#include "disallow_copy_and_assign.h" #include "file_store.h" #include "lock.h" #include "metrics_collections.h" diff --git a/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h b/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h index ab4e0786..1713d172 100644 --- a/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h +++ b/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h @@ -5,6 +5,7 @@ #ifndef WVCDM_CORE_WV_CDM_EVENT_LISTENER_H_ #define WVCDM_CORE_WV_CDM_EVENT_LISTENER_H_ +#include "disallow_copy_and_assign.h" #include "wv_cdm_types.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/core/include/wv_cdm_types.h b/libwvdrmengine/cdm/core/include/wv_cdm_types.h index bead3941..a8cbc36b 100644 --- a/libwvdrmengine/cdm/core/include/wv_cdm_types.h +++ b/libwvdrmengine/cdm/core/include/wv_cdm_types.h @@ -155,7 +155,7 @@ enum CdmResponseType { /* previously RESTORE_OFFLINE_LICENSE_ERROR_1 = 112 */ RESTORE_OFFLINE_LICENSE_ERROR_2 = 113, NOT_INITIALIZED_ERROR = 114, /* prior to pi, SESSION_INIT_ERROR_1 = 114 */ - REINIT_ERROR = 115, /* prior to pi, SESSION_INIT_ERROR_2 = 115 */ + REINIT_ERROR = 115, /* prior to pi, SESSION_INIT_ERROR_2 = 115 */ /* previously SESSION_INIT_GET_KEYBOX_ERROR = 116 */ SESSION_NOT_FOUND_1 = 117, SESSION_NOT_FOUND_2 = 118, @@ -345,10 +345,6 @@ enum CdmKeyStatus { }; typedef std::map CdmKeyStatusMap; -#define CORE_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - enum CdmLicenseType { kLicenseTypeOffline, kLicenseTypeStreaming, diff --git a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp index 066baf28..8455ad4b 100644 --- a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp @@ -13,6 +13,7 @@ #include "cdm_engine.h" #include "config_test_env.h" +#include "device_files.h" #include "initialization_data.h" #include "file_store.h" #include "license_request.h" diff --git a/libwvdrmengine/cdm/core/test/config_test_env.h b/libwvdrmengine/cdm/core/test/config_test_env.h index 8d1dcd16..7c00cc1c 100644 --- a/libwvdrmengine/cdm/core/test/config_test_env.h +++ b/libwvdrmengine/cdm/core/test/config_test_env.h @@ -6,6 +6,7 @@ #define CDM_TEST_CONFIG_TEST_ENV_H_ #include +#include "disallow_copy_and_assign.h" #include "wv_cdm_types.h" // Declare class ConfigTestEnv - holds the configuration settings needed diff --git a/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp b/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp index f5bde7e1..d8a188fd 100644 --- a/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp @@ -17,8 +17,8 @@ #include "license_request.h" #include "log.h" #include "oec_session_util.h" -#include "../../oemcrypto/mock/src/oemcrypto_key_mock.h" #include "oemcrypto_session_tests_helper.h" +#include "oemcrypto_types.h" #include "properties.h" #include "string_conversions.h" #include "url_request.h" @@ -113,13 +113,13 @@ class WvGenericOperationsTest : public testing::Test, ASSERT_NO_FATAL_FAILURE( oec_util_session_.FillSimpleMessage(duration, control, nonce, pst)); oec_util_session_.license().keys[kGenericEncrypt].control.control_bits |= - htonl(wvoec_mock::kControlAllowEncrypt); + htonl(wvoec::kControlAllowEncrypt); oec_util_session_.license().keys[kGenericDecrypt].control.control_bits |= - htonl(wvoec_mock::kControlAllowDecrypt); + htonl(wvoec::kControlAllowDecrypt); oec_util_session_.license().keys[kGenericSign].control.control_bits |= - htonl(wvoec_mock::kControlAllowSign); + htonl(wvoec::kControlAllowSign); oec_util_session_.license().keys[kGenericVerify].control.control_bits |= - htonl(wvoec_mock::kControlAllowVerify); + htonl(wvoec::kControlAllowVerify); oec_util_session_.license().keys[kGenericSign].key_data_length = wvcdm::MAC_KEY_SIZE; @@ -387,10 +387,10 @@ class WvGenericOperationsDataTest : public WvGenericOperationsTest { ASSERT_NO_FATAL_FAILURE( oec_util_session_.FillSimpleMessage(duration, control, nonce, pst)); oec_util_session_.license().keys[kGenericEncrypt].control.control_bits |= - htonl(wvoec_mock::kControlAllowEncrypt | - wvoec_mock::kControlAllowDecrypt); + htonl(wvoec::kControlAllowEncrypt | + wvoec::kControlAllowDecrypt); oec_util_session_.license().keys[kGenericSign].control.control_bits |= - htonl(wvoec_mock::kControlAllowSign | wvoec_mock::kControlAllowVerify); + htonl(wvoec::kControlAllowSign | wvoec::kControlAllowVerify); oec_util_session_.license().keys[kGenericSign].key_data_length = wvcdm::MAC_KEY_SIZE; diff --git a/libwvdrmengine/cdm/core/test/http_socket.h b/libwvdrmengine/cdm/core/test/http_socket.h index 7c7b9d69..f3ce53c9 100644 --- a/libwvdrmengine/cdm/core/test/http_socket.h +++ b/libwvdrmengine/cdm/core/test/http_socket.h @@ -12,7 +12,7 @@ #include #include -#include "wv_cdm_types.h" // CORE_DISALLOW_COPY_AND_ASSIGN +#include "disallow_copy_and_assign.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/core/test/license_request.h b/libwvdrmengine/cdm/core/test/license_request.h index bb1bbc02..93254c1e 100644 --- a/libwvdrmengine/cdm/core/test/license_request.h +++ b/libwvdrmengine/cdm/core/test/license_request.h @@ -6,7 +6,7 @@ #define CDM_TEST_LICENSE_REQUEST_H_ #include -#include "wv_cdm_types.h" +#include "disallow_copy_and_assign.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/core/test/url_request.h b/libwvdrmengine/cdm/core/test/url_request.h index a14c4f1a..4289598e 100644 --- a/libwvdrmengine/cdm/core/test/url_request.h +++ b/libwvdrmengine/cdm/core/test/url_request.h @@ -6,8 +6,8 @@ #define CDM_TEST_URL_REQUEST_H_ #include +#include "disallow_copy_and_assign.h" #include "http_socket.h" -#include "wv_cdm_types.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/include/timer.h b/libwvdrmengine/cdm/include/timer.h index 9646d29b..a6a4138f 100644 --- a/libwvdrmengine/cdm/include/timer.h +++ b/libwvdrmengine/cdm/include/timer.h @@ -7,7 +7,9 @@ #ifndef CDM_BASE_TIMER_H_ #define CDM_BASE_TIMER_H_ -#include "wv_cdm_types.h" +#include + +#include "disallow_copy_and_assign.h" namespace wvcdm { diff --git a/libwvdrmengine/cdm/include/wv_content_decryption_module.h b/libwvdrmengine/cdm/include/wv_content_decryption_module.h index 0435e973..b03f05e7 100644 --- a/libwvdrmengine/cdm/include/wv_content_decryption_module.h +++ b/libwvdrmengine/cdm/include/wv_content_decryption_module.h @@ -11,6 +11,7 @@ #include #include "cdm_identifier.h" +#include "disallow_copy_and_assign.h" #include "file_store.h" #include "lock.h" #include "metrics.pb.h" diff --git a/libwvdrmengine/cdm/test/unit-test.mk b/libwvdrmengine/cdm/test/unit-test.mk index a3330769..6ece55c7 100644 --- a/libwvdrmengine/cdm/test/unit-test.mk +++ b/libwvdrmengine/cdm/test/unit-test.mk @@ -23,6 +23,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/test \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/oemcrypto/include \ LOCAL_C_INCLUDES += external/protobuf/src diff --git a/libwvdrmengine/cdm/core/include/clock.h b/libwvdrmengine/cdm/util/include/clock.h similarity index 59% rename from libwvdrmengine/cdm/core/include/clock.h rename to libwvdrmengine/cdm/util/include/clock.h index 44cab11f..46565a7e 100644 --- a/libwvdrmengine/cdm/core/include/clock.h +++ b/libwvdrmengine/cdm/util/include/clock.h @@ -1,11 +1,9 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. +// Copyright 2013 Google Inc. All Rights Reserved. // // Clock - Platform independent interface for a time library // -#ifndef WVCDM_CORE_CLOCK_H_ -#define WVCDM_CORE_CLOCK_H_ +#ifndef WVCDM_UTIL_CLOCK_H_ +#define WVCDM_UTIL_CLOCK_H_ #include @@ -23,4 +21,4 @@ class Clock { } // namespace wvcdm -#endif // WVCDM_CORE_CLOCK_H_ +#endif // WVCDM_UTIL_CLOCK_H_ diff --git a/libwvdrmengine/cdm/util/include/disallow_copy_and_assign.h b/libwvdrmengine/cdm/util/include/disallow_copy_and_assign.h new file mode 100644 index 00000000..37b79c26 --- /dev/null +++ b/libwvdrmengine/cdm/util/include/disallow_copy_and_assign.h @@ -0,0 +1,15 @@ +// Copyright 2018 Google Inc. All Rights Reserved. + +#ifndef WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_ +#define WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_ + +namespace wvcdm { + +#define CORE_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + + +} // namespace wvcdm + +#endif // WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_ diff --git a/libwvdrmengine/cdm/core/include/file_store.h b/libwvdrmengine/cdm/util/include/file_store.h similarity index 84% rename from libwvdrmengine/cdm/core/include/file_store.h rename to libwvdrmengine/cdm/util/include/file_store.h index 86564eaa..ef0bd60c 100644 --- a/libwvdrmengine/cdm/core/include/file_store.h +++ b/libwvdrmengine/cdm/util/include/file_store.h @@ -1,17 +1,15 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. +// Copyright 2013 Google Inc. All Rights Reserved. // // File - Platform independent interface for a File class // -#ifndef WVCDM_CORE_FILE_STORE_H_ -#define WVCDM_CORE_FILE_STORE_H_ +#ifndef WVCDM_UTIL_FILE_STORE_H_ +#define WVCDM_UTIL_FILE_STORE_H_ #include #include #include -#include "wv_cdm_types.h" +#include "disallow_copy_and_assign.h" namespace wvcdm { @@ -79,4 +77,4 @@ class FileSystem { } // namespace wvcdm -#endif // WVCDM_CORE_FILE_STORE_H_ +#endif // WVCDM_UTIL_FILE_STORE_H_ diff --git a/libwvdrmengine/cdm/include/file_utils.h b/libwvdrmengine/cdm/util/include/file_utils.h similarity index 100% rename from libwvdrmengine/cdm/include/file_utils.h rename to libwvdrmengine/cdm/util/include/file_utils.h diff --git a/libwvdrmengine/cdm/core/include/lock.h b/libwvdrmengine/cdm/util/include/lock.h similarity index 76% rename from libwvdrmengine/cdm/core/include/lock.h rename to libwvdrmengine/cdm/util/include/lock.h index 08cf9a25..55b5e03a 100644 --- a/libwvdrmengine/cdm/core/include/lock.h +++ b/libwvdrmengine/cdm/util/include/lock.h @@ -1,13 +1,11 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. +// Copyright 2013 Google Inc. All Rights Reserved. // // Lock - Platform independent interface for a Mutex class // -#ifndef WVCDM_CORE_LOCK_H_ -#define WVCDM_CORE_LOCK_H_ +#ifndef WVCDM_UTIL_LOCK_H_ +#define WVCDM_UTIL_LOCK_H_ -#include "wv_cdm_types.h" +#include "disallow_copy_and_assign.h" namespace wvcdm { @@ -50,4 +48,4 @@ class AutoLock { } // namespace wvcdm -#endif // WVCDM_CORE_LOCK_H_ +#endif // WVCDM_UTIL_LOCK_H_ diff --git a/libwvdrmengine/cdm/core/include/log.h b/libwvdrmengine/cdm/util/include/log.h similarity index 82% rename from libwvdrmengine/cdm/core/include/log.h rename to libwvdrmengine/cdm/util/include/log.h index ad96d2a2..be9b5e03 100644 --- a/libwvdrmengine/cdm/core/include/log.h +++ b/libwvdrmengine/cdm/util/include/log.h @@ -1,11 +1,9 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. +// Copyright 2013 Google Inc. All Rights Reserved. // // Log - Platform independent interface for a Logging class // -#ifndef WVCDM_CORE_LOG_H_ -#define WVCDM_CORE_LOG_H_ +#ifndef WVCDM_UTIL_LOG_H_ +#define WVCDM_UTIL_LOG_H_ namespace wvcdm { @@ -31,6 +29,7 @@ void Log(const char* file, const char* function, int line, LogPriority level, const char* fmt, ...); // Log APIs +#ifndef LOGE #define LOGE(...) Log(__FILE__, __func__, __LINE__, \ wvcdm::LOG_ERROR, __VA_ARGS__) #define LOGW(...) Log(__FILE__, __func__, __LINE__, \ @@ -41,6 +40,7 @@ void Log(const char* file, const char* function, int line, LogPriority level, wvcdm::LOG_DEBUG, __VA_ARGS__) #define LOGV(...) Log(__FILE__, __func__, __LINE__, \ wvcdm::LOG_VERBOSE, __VA_ARGS__) +#endif } // namespace wvcdm -#endif // WVCDM_CORE_LOG_H_ +#endif // WVCDM_UTIL_LOG_H_ diff --git a/libwvdrmengine/cdm/core/include/string_conversions.h b/libwvdrmengine/cdm/util/include/string_conversions.h similarity index 75% rename from libwvdrmengine/cdm/core/include/string_conversions.h rename to libwvdrmengine/cdm/util/include/string_conversions.h index d1044f76..efc08678 100644 --- a/libwvdrmengine/cdm/core/include/string_conversions.h +++ b/libwvdrmengine/cdm/util/include/string_conversions.h @@ -1,9 +1,7 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. +// Copyright 2013 Google Inc. All Rights Reserved. -#ifndef WVCDM_CORE_STRING_CONVERSIONS_H_ -#define WVCDM_CORE_STRING_CONVERSIONS_H_ +#ifndef WVCDM_UTIL_STRING_CONVERSIONS_H_ +#define WVCDM_UTIL_STRING_CONVERSIONS_H_ #include #include @@ -29,4 +27,4 @@ inline int64_t ntohll64(int64_t x) { return htonll64(x); } } // namespace wvcdm -#endif // WVCDM_CORE_STRING_CONVERSIONS_H_ +#endif // WVCDM_UTIL_STRING_CONVERSIONS_H_ diff --git a/libwvdrmengine/cdm/src/clock.cpp b/libwvdrmengine/cdm/util/src/clock.cpp similarity index 100% rename from libwvdrmengine/cdm/src/clock.cpp rename to libwvdrmengine/cdm/util/src/clock.cpp diff --git a/libwvdrmengine/cdm/src/file_store.cpp b/libwvdrmengine/cdm/util/src/file_store.cpp similarity index 100% rename from libwvdrmengine/cdm/src/file_store.cpp rename to libwvdrmengine/cdm/util/src/file_store.cpp diff --git a/libwvdrmengine/cdm/src/file_utils.cpp b/libwvdrmengine/cdm/util/src/file_utils.cpp similarity index 100% rename from libwvdrmengine/cdm/src/file_utils.cpp rename to libwvdrmengine/cdm/util/src/file_utils.cpp diff --git a/libwvdrmengine/cdm/src/lock.cpp b/libwvdrmengine/cdm/util/src/lock.cpp similarity index 100% rename from libwvdrmengine/cdm/src/lock.cpp rename to libwvdrmengine/cdm/util/src/lock.cpp diff --git a/libwvdrmengine/cdm/src/log.cpp b/libwvdrmengine/cdm/util/src/log.cpp similarity index 100% rename from libwvdrmengine/cdm/src/log.cpp rename to libwvdrmengine/cdm/util/src/log.cpp diff --git a/libwvdrmengine/cdm/core/src/string_conversions.cpp b/libwvdrmengine/cdm/util/src/string_conversions.cpp similarity index 98% rename from libwvdrmengine/cdm/core/src/string_conversions.cpp rename to libwvdrmengine/cdm/util/src/string_conversions.cpp index 1f5661e3..7e7ecb76 100644 --- a/libwvdrmengine/cdm/core/src/string_conversions.cpp +++ b/libwvdrmengine/cdm/util/src/string_conversions.cpp @@ -1,6 +1,4 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. +// Copyright 2013 Google Inc. All Rights Reserved. #include "string_conversions.h" diff --git a/libwvdrmengine/level3/arm/Android.mk b/libwvdrmengine/level3/arm/Android.mk index 0e4038a4..6b53a898 100644 --- a/libwvdrmengine/level3/arm/Android.mk +++ b/libwvdrmengine/level3/arm/Android.mk @@ -7,6 +7,7 @@ LOCAL_CFLAGS := \ LOCAL_C_INCLUDES := \ system/core/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/level3/include \ vendor/widevine/libwvdrmengine/oemcrypto/include LOCAL_MODULE := libwvlevel3 diff --git a/libwvdrmengine/level3/arm64/Android.mk b/libwvdrmengine/level3/arm64/Android.mk index 66daa31c..ceac6f19 100644 --- a/libwvdrmengine/level3/arm64/Android.mk +++ b/libwvdrmengine/level3/arm64/Android.mk @@ -7,6 +7,7 @@ LOCAL_CFLAGS := \ LOCAL_C_INCLUDES := \ system/core/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/level3/include \ vendor/widevine/libwvdrmengine/oemcrypto/include LOCAL_MODULE := libwvlevel3 diff --git a/libwvdrmengine/level3/mips/Android.mk b/libwvdrmengine/level3/mips/Android.mk index 8e5f6849..340da34a 100644 --- a/libwvdrmengine/level3/mips/Android.mk +++ b/libwvdrmengine/level3/mips/Android.mk @@ -7,6 +7,7 @@ LOCAL_CFLAGS := \ LOCAL_C_INCLUDES := \ system/core/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/level3/include \ vendor/widevine/libwvdrmengine/oemcrypto/include LOCAL_MODULE := libwvlevel3 diff --git a/libwvdrmengine/level3/mips64/Android.mk b/libwvdrmengine/level3/mips64/Android.mk index 354528fa..8e9f2d81 100644 --- a/libwvdrmengine/level3/mips64/Android.mk +++ b/libwvdrmengine/level3/mips64/Android.mk @@ -7,6 +7,7 @@ LOCAL_CFLAGS := \ LOCAL_C_INCLUDES := \ system/core/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/level3/include \ vendor/widevine/libwvdrmengine/oemcrypto/include LOCAL_MODULE := libwvlevel3 diff --git a/libwvdrmengine/level3/x86/Android.mk b/libwvdrmengine/level3/x86/Android.mk index 92b8bfd4..8a7a91e2 100644 --- a/libwvdrmengine/level3/x86/Android.mk +++ b/libwvdrmengine/level3/x86/Android.mk @@ -7,6 +7,7 @@ LOCAL_CFLAGS := \ LOCAL_C_INCLUDES := \ system/core/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/level3/include \ vendor/widevine/libwvdrmengine/oemcrypto/include LOCAL_MODULE := libwvlevel3 diff --git a/libwvdrmengine/level3/x86_64/Android.mk b/libwvdrmengine/level3/x86_64/Android.mk index ca3aa664..cad2502a 100644 --- a/libwvdrmengine/level3/x86_64/Android.mk +++ b/libwvdrmengine/level3/x86_64/Android.mk @@ -7,6 +7,7 @@ LOCAL_CFLAGS := \ LOCAL_C_INCLUDES := \ system/core/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/level3/include \ vendor/widevine/libwvdrmengine/oemcrypto/include LOCAL_MODULE := libwvlevel3 diff --git a/libwvdrmengine/mediacrypto/Android.mk b/libwvdrmengine/mediacrypto/Android.mk index 5855cbf1..213ae902 100644 --- a/libwvdrmengine/mediacrypto/Android.mk +++ b/libwvdrmengine/mediacrypto/Android.mk @@ -14,6 +14,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediacrypto/include \ vendor/widevine/libwvdrmengine/oemcrypto/include \ @@ -49,6 +50,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include_hidl \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediacrypto/include_hidl \ diff --git a/libwvdrmengine/mediacrypto/test/Android.mk b/libwvdrmengine/mediacrypto/test/Android.mk index 01ea90ea..b7e6e91e 100644 --- a/libwvdrmengine/mediacrypto/test/Android.mk +++ b/libwvdrmengine/mediacrypto/test/Android.mk @@ -14,6 +14,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/mediacrypto/include \ vendor/widevine/libwvdrmengine/oemcrypto/include \ @@ -70,6 +71,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include_hidl \ vendor/widevine/libwvdrmengine/mediacrypto/include_hidl \ vendor/widevine/libwvdrmengine/mediacrypto/include \ diff --git a/libwvdrmengine/mediadrm/Android.mk b/libwvdrmengine/mediadrm/Android.mk index 89f040c5..b0fa75a2 100644 --- a/libwvdrmengine/mediadrm/Android.mk +++ b/libwvdrmengine/mediadrm/Android.mk @@ -15,6 +15,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediadrm/include \ vendor/widevine/libwvdrmengine/oemcrypto/include \ @@ -51,6 +52,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include_hidl \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediadrm/include_hidl \ diff --git a/libwvdrmengine/mediadrm/test/Android.mk b/libwvdrmengine/mediadrm/test/Android.mk index 10c413ba..4c648ec6 100644 --- a/libwvdrmengine/mediadrm/test/Android.mk +++ b/libwvdrmengine/mediadrm/test/Android.mk @@ -14,6 +14,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediadrm/include \ vendor/widevine/libwvdrmengine/oemcrypto/include \ @@ -70,6 +71,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include_hidl \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediadrm/include_hidl \ @@ -133,6 +135,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/metrics/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ vendor/widevine/libwvdrmengine/include_hidl \ vendor/widevine/libwvdrmengine/include \ vendor/widevine/libwvdrmengine/mediadrm/include_hidl \ diff --git a/libwvdrmengine/oemcrypto/include/oemcrypto_types.h b/libwvdrmengine/oemcrypto/include/oemcrypto_types.h new file mode 100644 index 00000000..ba00f7d6 --- /dev/null +++ b/libwvdrmengine/oemcrypto/include/oemcrypto_types.h @@ -0,0 +1,67 @@ +// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary +// source code may only be used and distributed under the Widevine Master +// License Agreement. + +#ifndef WV_OEMCRYPTO_TYPES_H_ +#define WV_OEMCRYPTO_TYPES_H_ + +#include + +namespace wvoec { + +// This is the format of a Widevine keybox. +typedef struct WidevineKeybox { // 128 bytes total. + // C character string identifying the device. Null terminated. + uint8_t device_id_[32]; + // 128 bit AES key assigned to device. Generated by Widevine. + uint8_t device_key_[16]; + // Key Data. Encrypted data. + uint8_t data_[72]; + // Constant code used to recognize a valid keybox "kbox" = 0x6b626f78. + uint8_t magic_[4]; + // The CRC checksum of the first 124 bytes of the keybox. + uint8_t crc_[4]; +} WidevineKeybox; + +// Key Control Block Bit Masks: +const uint32_t kControlObserveDataPath = (1<<31); +const uint32_t kControlObserveHDCP = (1<<30); +const uint32_t kControlObserveCGMS = (1<<29); +const uint32_t kControlRequireAntiRollbackHardware = (1<<28); +const uint32_t kSharedLicense = (1<<23); +const uint32_t kControlSRMVersionRequired = (1<<22); +const uint32_t kControlDisableAnalogOutput = (1<<21); +const uint32_t kControlSecurityPatchLevelShift = 15; +const uint32_t kControlSecurityPatchLevelMask = + (0x3F< -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "log.h" -#include "oem_cert.h" -#include "oemcrypto_engine_mock.h" -#include "oemcrypto_logging.h" -#include "properties.h" -#include "string_conversions.h" - -namespace wvoec_mock { -namespace { -typedef OEMCryptoResult (*L1_Initialize_t)(void); -typedef OEMCryptoResult (*L1_Terminate_t)(void); -typedef OEMCryptoResult (*L1_CopyBuffer_t)(const uint8_t* data_addr, - size_t data_length, - OEMCrypto_DestBufferDesc* out_buffer, - uint8_t subsample_flags); -const std::string kDefaultOptionsFile = "/data/mediadrm/oemcrypto/options.txt"; -} // namespace - -class AndroidModifiableCryptoEngine : public CryptoEngine { - public: - AndroidModifiableCryptoEngine(std::auto_ptr file_system) - : CryptoEngine(file_system), - options_file_(kDefaultOptionsFile), - srm_loaded_(false), - srm_version_(0), - level1_valid_(false), - level1_library_(NULL) { - std::string path; - if (wvcdm::Properties::GetDeviceFilesBasePath(wvcdm::kSecurityLevelL3, - &path)) { - options_file_ = path + "options.txt"; - } - } - - void MaybeReadOptionsFile() { - static time_t last_check = 0; - static time_t last_changed = 0; - time_t now = time(NULL); - if (now > last_check + 5) { // Check every five seconds. - last_check = now; - struct stat file_stat; - if (stat(options_file_.c_str(), &file_stat)) { - LOGE("Could not stat %s: %s", options_file_.c_str(), strerror(errno)); - return; - } - if (file_stat.st_mtime > last_changed) { - last_changed = file_stat.st_mtime; - ReadOptionsFile(); - } - } - } - - void ReadOptionsFile() { - FILE *file = fopen(options_file_.c_str(), "r"); - if (!file) { - LOGE("Could not read %s %s", options_file_.c_str(), strerror(errno)); - return; - } - while (!feof(file)) { - char name[80 + 1]; - int64_t value; - if (fscanf(file, "%80s %lld", name, &value)) { - LOGD("Option %s = %lld", name, value); - options_[std::string(name)] = value; - } - } - fclose(file); - InitializeLogging(); - } - - int64_t GetOption(const std::string &key, int64_t default_value) { - MaybeReadOptionsFile(); - if (options_.find(key) == options_.end() ) { - LOGW("Option %s not set. Using default %lld", key.c_str(), default_value); - return default_value; - } - return options_[key]; - } - - void InitializeLogging() { - int log_level = GetOption("log_level", wvcdm::LOG_DEBUG); - int categories = 0; - if (GetOption("kLoggingTraceOEMCryptoCalls", 0) > 0) - categories |= kLoggingTraceOEMCryptoCalls; - if (GetOption("kLoggingDumpContentKeys", 0) > 0) - categories |= kLoggingDumpContentKeys; - if (GetOption("kLoggingDumpKeyControlBlocks", 0) > 0) - categories |= kLoggingDumpKeyControlBlocks; - if (GetOption("kLoggingDumpDerivedKeys", 0) > 0) - categories |= kLoggingDumpDerivedKeys; - if (GetOption("kLoggingTraceNonce", 0) > 0) - categories |= kLoggingTraceNonce; - if (GetOption("kLoggingTraceDecryption", 0) > 0) - categories |= kLoggingTraceDecryption; - if (GetOption("kLoggingTraceUsageTable", 0) > 0) - categories |= kLoggingTraceUsageTable; - if (GetOption("kLoggingTraceDecryptCalls", 0) > 0) - categories |= kLoggingTraceDecryptCalls; - if (GetOption("kLoggingDumpTraceAll", 0) > 0) - categories |= kLoggingDumpTraceAll; - SetLoggingSettings(log_level, categories); - } - -#define QUOTE_DEFINE(A) #A -#define QUOTE(A) QUOTE_DEFINE(A) -#define LOOKUP(Name, Function) \ - Name = (L1_##Name##t)dlsym(level1_library_, QUOTE(Function)); \ - if (!Name) { \ - LOGW("Could not load L1 %s.", \ - QUOTE(Function)); \ - Terminate(); \ - return false; \ - } - - virtual bool Initialize() { - LOGD("OEMCrypto Mock With Options " " " __DATE__ " " __TIME__); - MaybeReadOptionsFile(); - if (!GetOption("use_fallback", 1)) { - LOGD("Level 1 fallback ignored."); - return true; - } - level1_library_ = dlopen("level1_backup_liboemcrypto.so", RTLD_NOW); - if (level1_library_ == NULL) { - LOGE("Could not load backup: %s", dlerror()); - return false; - } - LOOKUP(Initialize_, OEMCrypto_Initialize); - LOOKUP(Terminate_, OEMCrypto_Terminate); - LOOKUP(CopyBuffer_, OEMCrypto_CopyBuffer); - level1_valid_ = true; - OEMCryptoResult sts = Initialize_(); - LOGD("L1 fall back initialized. status = %d.", sts); - if (sts != OEMCrypto_SUCCESS) { - LOGW("Terminating L1 because init failed."); - Terminate(); - LOGW("Continuing Mock without L1 fallback."); - } - return true; - } - - virtual void Terminate() { - if (level1_valid_) Terminate_(); - if (level1_library_ != NULL) { - LOGD("Closing L1 fall back.\n"); - dlclose(level1_library_); - level1_valid_ = false; - level1_library_ = NULL; - CopyBuffer_ = NULL; - Initialize_ = NULL; - Terminate_ = NULL; - } else { - LOGD("Terminate mock.\n"); - } - } - - const char *HDCPCapabilityAsString(OEMCrypto_HDCP_Capability value) { - switch (value) { - case HDCP_NONE: - return "No HDCP supported, no secure data path"; - case HDCP_V1: - return "HDCP version 1.0"; - case HDCP_V2: - return "HDCP version 2.0"; - case HDCP_V2_1: - return "HDCP version 2.1"; - case HDCP_V2_2: - return "HDCP version 2.2"; - case HDCP_NO_DIGITAL_OUTPUT: - return "No HDCP device attached/using local display with secure path"; - default: - return ""; - } - } - - - OEMCrypto_ProvisioningMethod config_provisioning_method() { - if (GetOption("use_keybox", 1)) { - return OEMCrypto_Keybox; - } else { - return OEMCrypto_OEMCertificate; - } - } - - OEMCryptoResult get_oem_certificate(SessionContext* session, - uint8_t* public_cert, - size_t* public_cert_length) { - if (GetOption("use_keybox", 1)) { - LOGD("OEM Cert asked for when use_keybox = 1."); - return OEMCrypto_ERROR_NOT_IMPLEMENTED; - } - if (kOEMPublicCertSize == 0) { - LOGD("OEM Cert Size is 0."); - return OEMCrypto_ERROR_NOT_IMPLEMENTED; - } - if (public_cert_length == NULL) { - LOGD("OEM Cert length is 0."); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; - } - if (*public_cert_length < kOEMPublicCertSize) { - *public_cert_length = kOEMPublicCertSize; - return OEMCrypto_ERROR_SHORT_BUFFER; - } - *public_cert_length = kOEMPublicCertSize; - if (public_cert == NULL) { - return OEMCrypto_ERROR_SHORT_BUFFER; - } - memcpy(public_cert, kOEMPublicCert, kOEMPublicCertSize); - if (!session->LoadRSAKey(kOEMPrivateKey, kOEMPrivateKeySize)) { - LOGE("Private RSA Key did not load correctly."); - return OEMCrypto_ERROR_INVALID_RSA_KEY; - } - return OEMCrypto_SUCCESS; - } - - // Returns "L3" for a software only library. L1 is for hardware protected - // data paths. - const char *config_security_level() { - switch (GetOption("security_level", 0)) { - default: - LOGW("Option security_level not set. Default is L3."); - case 3: - return "L3"; - case 2: - return "L2"; - case 1: - return "L1"; - } - } - - // Returns the HDCP version currently in use. - OEMCrypto_HDCP_Capability config_current_hdcp_capability() { - static OEMCrypto_HDCP_Capability current_hdcp = HDCP_NONE; - OEMCrypto_HDCP_Capability new_current_hdcp = - static_cast(GetOption("current_hdcp", 0)); - if (current_hdcp != new_current_hdcp) { - LOGI("OEMCrypto current HDCP changed from %d (%s) to %d (%s)", current_hdcp, - HDCPCapabilityAsString(current_hdcp), new_current_hdcp, - HDCPCapabilityAsString(new_current_hdcp)); - current_hdcp = new_current_hdcp; - } - return current_hdcp; - } - - // Returns the max HDCP version supported. - OEMCrypto_HDCP_Capability config_maximum_hdcp_capability() { - static OEMCrypto_HDCP_Capability max_hdcp = HDCP_NONE; - MaybeReadOptionsFile(); - OEMCrypto_HDCP_Capability new_max_hdcp = - static_cast(GetOption("max_hdcp", 0)); - if (max_hdcp != new_max_hdcp) { - LOGI("OEMCrypto max HDCP changed from %d (%s) to %d (%s)", max_hdcp, - HDCPCapabilityAsString(max_hdcp), new_max_hdcp, - HDCPCapabilityAsString(new_max_hdcp)); - max_hdcp = new_max_hdcp; - } - return max_hdcp; - } - - // This should start at 0, and be incremented only when a security patch has - // been applied to the device that fixes a security bug. - uint8_t config_security_patch_level() { - return GetOption("security_patch_level", 0); - } - - size_t max_buffer_size() { - int max = GetOption("max_buffer_size", 0); - // If max is 1, just use default max buffer. - if (max == 1) return CryptoEngine::max_buffer_size(); - return max; // If 0, no restriction. If something else, use that restriction. - } - - bool srm_update_supported() { - int supported = GetOption("srm_update_supported", 0); - LOGI("OEMCrypto mock %s supporting SRM update.", - supported ? "is" : "is not"); - return supported != 0; - } - - OEMCryptoResult current_srm_version(uint16_t *version) { - if (srm_loaded_) { - LOGV("SRM loaded. version used is %d.", srm_version_); - *version = srm_version_; - return OEMCrypto_SUCCESS; - } - int value = GetOption("srm_initial_version", -1); - if (value > 0) { - LOGV("SRM version from get option: %d.", value); - srm_version_ = value; - *version = value; - return OEMCrypto_SUCCESS; - } else { - LOGI("SRM initial version is %d -- reporting not implemented.", value); - return OEMCrypto_ERROR_NOT_IMPLEMENTED; - } - } - - // Convert uint24 or uint40 into a uint64. - int64_t unpack_odd_bytes(const uint8_t *buffer, size_t length) { - uint8_t small_buffer[8]; - memset(small_buffer, 0, 8); - if (length > 8) { - LOGE("OEMCrypto Mock: programmer error. unpack %d bytes.", length); - length = 8; - } - size_t offset = 8 - length; - memcpy(small_buffer + offset, buffer, length); - return wvcdm::htonll64(*reinterpret_cast(small_buffer)); - } - - OEMCryptoResult load_srm(const uint8_t *buffer, size_t buffer_length) { - if (!srm_update_supported()) { - LOGE("OEMCrypto mock update not supported, but load_srm called."); - return OEMCrypto_ERROR_NOT_IMPLEMENTED; - } - int result = GetOption("srm_load_fail", 0); - if (result > 0) { - LOGE("OEMCrypto mock load_srm returning error %d.", result); - return static_cast(result); - } - int new_version = GetOption("srm_load_version", -1); - if (new_version >= 0) { - if (new_version < srm_version_) { - LOGE("New SRM version is lower than existing SRM version: %d < %d", - new_version, srm_version_); - return OEMCrypto_ERROR_INVALID_CONTEXT; - } - srm_version_ = new_version; - LOGI("OEMCrypto mock told to change SRM version to %d.", srm_version_); - srm_loaded_ = true; - return OEMCrypto_SUCCESS; - } - if (buffer_length < 395) { - LOGE("OEMCrypto mock bad buffer size: %ld < 395.", buffer_length); - return OEMCrypto_ERROR_SHORT_BUFFER; - } - uint8_t srm_id = buffer[0] >> 4; - uint8_t hdcp2_indicator = buffer[0] & 0x0F; - uint8_t reserved = buffer[1]; - uint16_t version = htons(*reinterpret_cast(&buffer[2])); - if (reserved) { - LOGE("OEMCrypto mock. SRM's second byte nonzero: %02X.", reserved); - return OEMCrypto_ERROR_INVALID_CONTEXT; - } - uint8_t generation = buffer[4]; - if (generation > 1) { - LOGW("OEMCrypto mock. SRM Generation number is %d, but only first gen is parsed.", - generation); - LOGW("If the revoked device is in a a later generation, it will not be recognized."); - } - int64_t length = unpack_odd_bytes(buffer + 5, 3); // 24 bits. - if (length + 5 != buffer_length) { - LOGW("OEMCrypto mock. SRM length is %lld = 0x%llx, but I expected %zd = 0x%zx.", - length, length, buffer_length - 5, buffer_length - 5); - } - int64_t count = 0; - const uint8_t *ids; - if (srm_id == 8 && hdcp2_indicator == 0) { - // https://www.digital-cp.com/sites/default/files/specifications/HDCP%20Specification%20Rev1_4_Secure.pdf - count = buffer[8]; - LOGI("OEMCrypto mock loading HDCP1 SRM. version = %d. count=%lld.", - version, count); - ids = buffer + 9; - if (buffer_length < 9 + count*5) { - LOGE("OEMCrypto mock bad buffer size for count = %lld: %d < %lld.", - count, buffer_length, 12 + count*5); - return OEMCrypto_ERROR_SHORT_BUFFER; - } - } else if (srm_id == 9 && hdcp2_indicator == 1) { - // https://www.digital-cp.com/sites/default/files/specifications/HDCP%20on%20HDMI%20Specification%20Rev2_2_Final1.pdf - count = unpack_odd_bytes(buffer + 8, 2) >> 6; // 10 bits = 2 bytes - 6. - LOGI("OEMCrypto mock loading HDCP2 SRM. version = %d. count=%lld.", - version, count); - ids = buffer + 12; - if (buffer_length < 12 + count*5) { - LOGE("OEMCrypto mock bad buffer size for count: %d < %ld.", - buffer_length, 12 + count*5); - return OEMCrypto_ERROR_SHORT_BUFFER; - } - } else { - LOGE("OEMCrypto mock bad buffer start: %02X%02X%02X%02X...", buffer[0], - buffer[1], buffer[2], buffer[3]); - return OEMCrypto_ERROR_INVALID_CONTEXT; - } - for(size_t i = 0; i < count; i++) { - int64_t id = unpack_odd_bytes(ids + 5*i, 5); - srm_revocation_list_.push_back(id); - LOGI("OEMCrypto mock SRM revokes device %lld = 0x%llx", id, id); - } - srm_loaded_ = true; - srm_version_ = version; - return OEMCrypto_SUCCESS; - } - - OEMCryptoResult remove_srm() { - if (!srm_update_supported()) { - LOGE("OEMCrypto mock update not supported, bug load_srm called."); - return OEMCrypto_ERROR_NOT_IMPLEMENTED; - } - srm_version_ = 0; - srm_loaded_ = false; - return OEMCrypto_SUCCESS; - } - - bool srm_blacklisted_device_attached() { - if (GetOption("srm_load_version", -1) < 0) { - return scan_revoked_list(); - } - static int blacklisted = 0; - int new_value = GetOption("srm_blacklisted_device_attached", 0); - if (new_value != blacklisted) { - LOGI("SRM blacklisted device changed from %d to %d", blacklisted, - new_value); - blacklisted = new_value; - } - return blacklisted > 0; - } - - bool scan_revoked_list() { - static int64_t old_attached_id = 0; - int64_t attached_id = GetOption("srm_attached_device_id", 0); - bool print_all_ids = false; - if (attached_id != old_attached_id) { - LOGD("OEMCrypto mock -- ID of attached device is %lld = 0x%lld", - attached_id, attached_id); - old_attached_id = attached_id; - print_all_ids = true; - } - for (size_t i = 0; i < srm_revocation_list_.size(); i++) { - if (print_all_ids) { - LOGD("OEMCrypto mock: %d) revoked id %lld = 0x%lld.", i, - srm_revocation_list_[i], srm_revocation_list_[i]); - } - if (srm_revocation_list_[i] == attached_id) { - LOGD("OEMCrypto mock: attached device %lld = 0x%lld is revoked.", - attached_id, attached_id); - return true; - } - } - LOGD("OEMCrypto mock: attached device %lld is not revoked.", attached_id); - return false; - } - - virtual int nonce_flood_count() { GetOption("nonce_flood_count", 20); } - - virtual void adjust_destination(OEMCrypto_DestBufferDesc *out_description, - size_t data_length, uint8_t subsample_flags) { - if (out_description->type != OEMCrypto_BufferType_Secure) return; - if (!level1_valid_) { - static bool warned_once = false; - if (!warned_once) { - warned_once = true; - LOGW("OEMCrypto Mock: given secure buffer with no level1 fallback."); - } - return; - } - if (subsample_flags & OEMCrypto_FirstSubsample) { - final_destination_.type = OEMCrypto_BufferType_Secure; - final_destination_.buffer.secure.handle = - out_description->buffer.secure.handle; - final_destination_.buffer.secure.max_length = - out_description->buffer.secure.max_length; - final_destination_.buffer.secure.offset = - out_description->buffer.secure.offset; - temp_buffer_.resize(final_destination_.buffer.secure.max_length); - temp_buffer_length_ = 0; - } - if (temp_buffer_length_ != out_description->buffer.secure.offset) { - LOGW("OEMCrypto: offset into secure buffer is not correct %zd != %zd.", - temp_buffer_length_, out_description->buffer.secure.offset); - } - size_t new_length = temp_buffer_length_ + data_length; - if (new_length > temp_buffer_.size()) { - LOGW("Temp buffer was not big enough. %zd > %zd.", new_length, - temp_buffer_.size()); - temp_buffer_.resize(new_length); - } - destination_ = &temp_buffer_[temp_buffer_length_]; - temp_buffer_length_ = new_length; - } - - // Push destination buffer to L1 output. - virtual OEMCryptoResult PushDestination( - OEMCrypto_DestBufferDesc *out_description, uint8_t subsample_flags) { - if (level1_valid_ && - (out_description->type == OEMCrypto_BufferType_Secure)) { - if (subsample_flags & OEMCrypto_LastSubsample) { - return CopyBuffer_(&temp_buffer_[0], temp_buffer_length_, - &final_destination_, - OEMCrypto_FirstSubsample | OEMCrypto_LastSubsample); - } - } - return OEMCrypto_SUCCESS; - } - - private: - // If the SRM version has been loaded or not. If not, we use the system - // property to find the current SRM version. - bool srm_loaded_; - // Current srm version. Before an SRM has been loaded, this will be set from - // the system property. - int srm_version_; - // List of forbidden/revoked devices. - std::vector srm_revocation_list_; - - std::map options_; - - std::string options_file_; - bool level1_valid_; - void* level1_library_; - L1_CopyBuffer_t CopyBuffer_; - L1_Initialize_t Initialize_; - L1_Terminate_t Terminate_; - OEMCrypto_DestBufferDesc final_destination_; - std::vector temp_buffer_; - size_t temp_buffer_length_; // Length of temp buffer currently in use. -}; - -CryptoEngine* CryptoEngine::MakeCryptoEngine( - std::auto_ptr file_system) { - return new AndroidModifiableCryptoEngine(file_system); -} - -} // namespace wvoec_mock diff --git a/libwvdrmengine/oemcrypto/mock/src/wv_keybox.h b/libwvdrmengine/oemcrypto/mock/src/wv_keybox.h deleted file mode 100644 index af3bffc7..00000000 --- a/libwvdrmengine/oemcrypto/mock/src/wv_keybox.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. - -#ifndef WV_KEYBOX_H_ -#define WV_KEYBOX_H_ - -#include - -namespace wvoec_mock { - -// This is the format of a Widevine keybox. -typedef struct { // 128 bytes total. - // C character string identifying the device. Null terminated. - uint8_t device_id_[32]; - // 128 bit AES key assigned to device. Generated by Widevine. - uint8_t device_key_[16]; - // Key Data. Encrypted data. - uint8_t data_[72]; - // Constant code used to recognize a valid keybox "kbox" = 0x6b626f78. - uint8_t magic_[4]; - // The CRC checksum of the first 124 bytes of the keybox. - uint8_t crc_[4]; -} WidevineKeybox; - -} // namespace wvoec_mock - -#endif // WV_KEYBOX_H_ diff --git a/libwvdrmengine/oemcrypto/mock/test/oemcrypto_logging_test.cpp b/libwvdrmengine/oemcrypto/mock/test/oemcrypto_logging_test.cpp deleted file mode 100644 index f21b4a8d..00000000 --- a/libwvdrmengine/oemcrypto/mock/test/oemcrypto_logging_test.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. - -#include "OEMCryptoCENC.h" - -#include -#include -#include "log.h" -#include "oemcrypto_logging.h" -#include "oemcrypto_mock.cpp" - -class OEMCryptoLoggingTest : public ::testing::Test { - protected: - OEMCryptoLoggingTest() {} - - void SetUp() { - ::testing::Test::SetUp(); - ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize()); - } - - void TearDown() { - OEMCrypto_Terminate(); - ::testing::Test::TearDown(); - } -}; - -TEST_F(OEMCryptoLoggingTest, TestDumpHexFunctions) { - uint8_t vector[] = {0xFA, 0x11, 0x28, 0x33}; - std::string buffer; - wvoec_mock::dump_hex_helper(buffer, "name", vector, 4u); - ASSERT_EQ("name = \n wvcdm::a2b_hex(\"FA112833\");\n", buffer); - - uint8_t vector2[] = { - 0xFA, 0x11, 0x28, 0x33, 0xFA, 0x11, 0x28, 0x33, 0xFA, 0x11, - 0x28, 0x33, 0xFA, 0x11, 0x28, 0x33, 0xFA, 0x11, 0x28, 0x33, - 0xFA, 0x11, 0x28, 0x33, 0x01, 0x14, 0x28, 0xAB, 0xFA, 0xCD, - 0xEF, 0x67, 0x01, 0x14, 0x28, 0xAB, 0xFA, 0xCD, 0xEF, 0x67, - }; - - buffer.clear(); // dump_hex_helper appends to buffer - wvoec_mock::dump_hex_helper(buffer, "name", vector2, 40u); - ASSERT_EQ( - "name = \n " - "wvcdm::a2b_hex(" - "\"FA112833FA112833FA112833FA112833FA112833FA112833011428ABFACDEF67\"\n " - " \"011428ABFACDEF67\");\n", - buffer); - - buffer.clear(); // dump_hex_helper appends to buffer - wvoec_mock::dump_array_part_helper(buffer, "array", 5u, "name", vector2, 40u); - ASSERT_EQ( - "std::string s5_name = \n " - "wvcdm::a2b_hex(" - "\"FA112833FA112833FA112833FA112833FA112833FA112833011428ABFACDEF67\"\n " - " \"011428ABFACDEF67\");\narray[5].name = message_ptr + " - "message.find(s5_name.data());\n", - buffer); - - buffer.clear(); // dump_hex_helper appends to buffer - wvoec_mock::dump_array_part_helper(buffer, "array", 5u, "name", NULL, 40u); - ASSERT_EQ("array[5].name = NULL;\n", buffer); -} - -TEST_F(OEMCryptoLoggingTest, TestChangeLoggingLevel) { - wvoec_mock::SetLoggingLevel(wvcdm::LOG_WARN); - ASSERT_EQ(wvcdm::LOG_WARN, wvcdm::g_cutoff); - - wvoec_mock::SetLoggingLevel(wvcdm::LOG_INFO); - ASSERT_EQ(wvcdm::LOG_INFO, wvcdm::g_cutoff); - - wvoec_mock::SetLoggingSettings(wvcdm::LOG_WARN, - wvoec_mock::kLoggingDumpTraceAll); - ASSERT_EQ(wvcdm::LOG_WARN, wvcdm::g_cutoff); - ASSERT_TRUE(wvoec_mock::LogCategoryEnabled(wvoec_mock::kLoggingDumpTraceAll)); - wvoec_mock::TurnOffLoggingForAllCategories(); - - wvoec_mock::SetLoggingLevel(wvcdm::LOG_VERBOSE); - ASSERT_EQ(wvcdm::LOG_VERBOSE, wvcdm::g_cutoff); - - wvoec_mock::SetLoggingLevel(wvcdm::LOG_WARN); -} - -TEST_F(OEMCryptoLoggingTest, TestChangeLoggingCategories) { - using namespace wvoec_mock; - TurnOffLoggingForAllCategories(); - ASSERT_FALSE(LogCategoryEnabled(kLoggingTraceDecryption | - kLoggingTraceOEMCryptoCalls)); - - AddLoggingForCategories(kLoggingDumpKeyControlBlocks | - kLoggingDumpDerivedKeys); - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpKeyControlBlocks)); - ASSERT_FALSE(LogCategoryEnabled(kLoggingTraceUsageTable)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpTraceAll)); - - RemoveLoggingForCategories(kLoggingDumpKeyControlBlocks | - kLoggingTraceUsageTable); - ASSERT_FALSE(LogCategoryEnabled(kLoggingDumpKeyControlBlocks)); - - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpDerivedKeys)); - ASSERT_FALSE(LogCategoryEnabled(kLoggingTraceUsageTable)); - - TurnOffLoggingForAllCategories(); - ASSERT_FALSE(LogCategoryEnabled(kLoggingTraceUsageTable)); - - AddLoggingForCategories(kLoggingDumpTraceAll); - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpKeyControlBlocks)); - - ASSERT_TRUE(LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpContentKeys)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpKeyControlBlocks)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpDerivedKeys)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingTraceNonce)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingTraceDecryption)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingTraceUsageTable)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingTraceDecryptCalls)); - ASSERT_TRUE(LogCategoryEnabled(kLoggingDumpTraceAll)); - - RemoveLoggingForCategories(kLoggingDumpKeyControlBlocks); - ASSERT_FALSE(LogCategoryEnabled(kLoggingDumpKeyControlBlocks)); -} diff --git a/libwvdrmengine/oemcrypto/mock/Android.mk b/libwvdrmengine/oemcrypto/ref/Android.mk similarity index 73% rename from libwvdrmengine/oemcrypto/mock/Android.mk rename to libwvdrmengine/oemcrypto/ref/Android.mk index 79208ea6..869e164d 100644 --- a/libwvdrmengine/oemcrypto/mock/Android.mk +++ b/libwvdrmengine/oemcrypto/ref/Android.mk @@ -4,20 +4,20 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ src/keys.cpp \ - src/oemcrypto_auth_mock.cpp \ + src/oemcrypto_auth_ref.cpp \ src/oemcrypto_engine_device_properties.cpp \ - src/oemcrypto_engine_mock.cpp \ - src/oemcrypto_key_mock.cpp \ - src/oemcrypto_keybox_mock.cpp \ + src/oemcrypto_engine_ref.cpp \ + src/oemcrypto_key_ref.cpp \ + src/oemcrypto_keybox_ref.cpp \ src/oemcrypto_keybox_testkey.cpp \ src/oemcrypto_logging.cpp \ - src/oemcrypto_mock.cpp \ + src/oemcrypto_ref.cpp \ src/oemcrypto_nonce_table.cpp \ - src/oemcrypto_old_usage_table_mock.cpp \ + src/oemcrypto_old_usage_table_ref.cpp \ src/oemcrypto_rsa_key_shared.cpp \ src/oemcrypto_session.cpp \ src/oemcrypto_session_key_table.cpp \ - src/oemcrypto_usage_table_mock.cpp \ + src/oemcrypto_usage_table_ref.cpp \ src/wvcrc.cpp \ LOCAL_MODULE_TAGS := tests @@ -25,7 +25,7 @@ LOCAL_MODULE_TAGS := tests LOCAL_C_INCLUDES += \ $(LOCAL_PATH)/../include \ $(LOCAL_PATH)/src \ - vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ LOCAL_SHARED_LIBRARIES := \ libcutils \ diff --git a/libwvdrmengine/oemcrypto/ref/README.md b/libwvdrmengine/oemcrypto/ref/README.md new file mode 100644 index 00000000..efb2e3ca --- /dev/null +++ b/libwvdrmengine/oemcrypto/ref/README.md @@ -0,0 +1,5 @@ +# Reference OEMCrypto + +This directory contains a testing-only implementation of OEMCrypto. **This +implementation is *NOT* suitable for production use and should *NOT* be released +on devices.** diff --git a/libwvdrmengine/oemcrypto/mock/src/keys.cpp b/libwvdrmengine/oemcrypto/ref/src/keys.cpp similarity index 100% rename from libwvdrmengine/oemcrypto/mock/src/keys.cpp rename to libwvdrmengine/oemcrypto/ref/src/keys.cpp diff --git a/libwvdrmengine/oemcrypto/mock/src/keys.h b/libwvdrmengine/oemcrypto/ref/src/keys.h similarity index 100% rename from libwvdrmengine/oemcrypto/mock/src/keys.h rename to libwvdrmengine/oemcrypto/ref/src/keys.h diff --git a/libwvdrmengine/oemcrypto/mock/src/oem_cert.cpp b/libwvdrmengine/oemcrypto/ref/src/oem_cert.cpp similarity index 99% rename from libwvdrmengine/oemcrypto/mock/src/oem_cert.cpp rename to libwvdrmengine/oemcrypto/ref/src/oem_cert.cpp index 3df15d68..7a0278cc 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oem_cert.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oem_cert.cpp @@ -2,7 +2,7 @@ #include "oem_cert.h" -namespace wvoec_mock { +namespace wvoec_ref { extern const uint32_t kOEMSystemId_Prod = 7346; @@ -389,4 +389,4 @@ const uint8_t* kOEMPublicCert = kOEMPublicCert_Prod; const size_t kOEMPrivateKeySize = kOEMPrivateKeySize_Prod; const size_t kOEMPublicCertSize = kOEMPublicCertSize_Prod; -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oem_cert.h b/libwvdrmengine/oemcrypto/ref/src/oem_cert.h similarity index 89% rename from libwvdrmengine/oemcrypto/mock/src/oem_cert.h rename to libwvdrmengine/oemcrypto/ref/src/oem_cert.h index 70b522ff..3d0476b9 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oem_cert.h +++ b/libwvdrmengine/oemcrypto/ref/src/oem_cert.h @@ -5,7 +5,7 @@ #include #include -namespace wvoec_mock { +namespace wvoec_ref { // Refer to the following in main modules extern const uint32_t kOEMSystemId; @@ -16,6 +16,6 @@ extern const uint8_t* kOEMPublicCert; extern const size_t kOEMPrivateKeySize; extern const size_t kOEMPublicCertSize; -} // namespace wvoec_mock +} // namespace wvoec_ref #endif // OEM_CERT_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_auth_mock.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.cpp similarity index 97% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_auth_mock.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.cpp index d909c975..5cb4a024 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_auth_mock.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.cpp @@ -2,23 +2,23 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#include "oemcrypto_auth_mock.h" +#include "oemcrypto_auth_ref.h" #include #include "keys.h" #include "log.h" -#include "oemcrypto_key_mock.h" +#include "oemcrypto_key_ref.h" #include "oemcrypto_logging.h" #include "oemcrypto_rsa_key_shared.h" -#include "wv_cdm_constants.h" namespace { // A 2048 bit RSA key in PKCS#8 PrivateKeyInfo format -// This is the RSA Test Key. +// This is the RSA Test Key. This key is not derived +// from any Widevine authentication root. static const uint8_t kTestRSAPKCS8PrivateKeyInfo2_2048[] = { 0x30, 0x82, 0x04, 0xbc, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, @@ -176,7 +176,7 @@ static const uint8_t kTestRSAPKCS8PrivateKeyInfo2_2048[] = { } // namespace -namespace wvoec_mock { +namespace wvoec_ref { AuthenticationRoot::AuthenticationRoot(OEMCrypto_ProvisioningMethod method) : provisioning_method_(method), @@ -202,4 +202,4 @@ bool AuthenticationRoot::Validate() { return NO_ERROR == ValidateKeybox(); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_auth_mock.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.h similarity index 83% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_auth_mock.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.h index 230be008..b5c78798 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_auth_mock.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.h @@ -2,10 +2,10 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef OEMCRYPTO_AUTH_MOCK_H_ -#define OEMCRYPTO_AUTH_MOCK_H_ +#ifndef OEMCRYPTO_AUTH_REF_H_ +#define OEMCRYPTO_AUTH_REF_H_ #include #include @@ -13,12 +13,14 @@ #include #include "OEMCryptoCENC.h" // Needed for enums only. -#include "oemcrypto_key_mock.h" -#include "oemcrypto_keybox_mock.h" +#include "disallow_copy_and_assign.h" +#include "oemcrypto_key_ref.h" +#include "oemcrypto_keybox_ref.h" #include "oemcrypto_rsa_key_shared.h" -#include "wv_cdm_types.h" +#include "oemcrypto_scoped_ptr.h" +#include "oemcrypto_types.h" -namespace wvoec_mock { +namespace wvoec_ref { class AuthenticationRoot { public: @@ -73,6 +75,6 @@ class AuthenticationRoot { CORE_DISALLOW_COPY_AND_ASSIGN(AuthenticationRoot); }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // OEMCRYPTO_AUTH_MOCK_H_ +#endif // OEMCRYPTO_AUTH_REF_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties.cpp similarity index 60% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties.cpp index ce206dea..aadde989 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties.cpp @@ -2,16 +2,16 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" -namespace wvoec_mock { +namespace wvoec_ref { CryptoEngine* CryptoEngine::MakeCryptoEngine( - std::auto_ptr file_system) { + scoped_ptr file_system) { return new CryptoEngine(file_system); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_L1.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_L1.cpp similarity index 78% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_L1.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_L1.cpp index d8da4672..ac8a87a2 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_L1.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_L1.cpp @@ -2,17 +2,17 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // // This file contains oemcrypto engine properties that would be for a // level 1 device. -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" -namespace wvoec_mock { +namespace wvoec_ref { class L1CryptoEngine : public CryptoEngine { public: - explicit L1CryptoEngine(std::auto_ptr file_system) + explicit L1CryptoEngine(scoped_ptr file_system) : CryptoEngine(file_system) {} bool config_local_display_only() { return true; } @@ -31,8 +31,8 @@ class L1CryptoEngine : public CryptoEngine { }; CryptoEngine* CryptoEngine::MakeCryptoEngine( - std::auto_ptr file_system) { + scoped_ptr file_system) { return new L1CryptoEngine(file_system); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_cert.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_cert.cpp similarity index 77% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_cert.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_cert.cpp index 932af52a..3774eced 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_cert.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_cert.cpp @@ -2,20 +2,20 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // // This file contains oemcrypto engine properties that would be for a device // that does not have persistant storage or a keybox. // // Note: We also define it to be L2 for illustration only. Production devices // are rarely level 2. -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" -namespace wvoec_mock { +namespace wvoec_ref { class CertOnlyCryptoEngine : public CryptoEngine { public: - explicit CertOnlyCryptoEngine(std::auto_ptr file_system) + explicit CertOnlyCryptoEngine(scoped_ptr file_system) : CryptoEngine(file_system) {} bool config_local_display_only() { return true; } @@ -30,8 +30,8 @@ class CertOnlyCryptoEngine : public CryptoEngine { }; CryptoEngine* CryptoEngine::MakeCryptoEngine( - std::auto_ptr file_system) { + scoped_ptr file_system) { return new CertOnlyCryptoEngine(file_system); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_prov30.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_prov30.cpp similarity index 90% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_prov30.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_prov30.cpp index 96105c67..12766764 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_device_properties_prov30.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_prov30.cpp @@ -2,24 +2,24 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // // This file contains oemcrypto engine properties that would be for a // level 2 device that does not have persistant storage or a keybox. // Note: this is for illustration only. Production devices are rarely level 2. -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" #include #include "log.h" #include "oem_cert.h" -namespace wvoec_mock { +namespace wvoec_ref { class Prov30CryptoEngine : public CryptoEngine { public: - explicit Prov30CryptoEngine(std::auto_ptr file_system) + explicit Prov30CryptoEngine(scoped_ptr file_system) : CryptoEngine(file_system) {} bool config_local_display_only() { return true; } @@ -77,8 +77,8 @@ class Prov30CryptoEngine : public CryptoEngine { }; CryptoEngine* CryptoEngine::MakeCryptoEngine( - std::auto_ptr file_system) { + scoped_ptr file_system) { return new Prov30CryptoEngine(file_system); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp similarity index 92% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp index ef739673..0d11aa12 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp @@ -2,9 +2,9 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" #include #include @@ -17,19 +17,17 @@ #include "keys.h" #include "log.h" -#include "oemcrypto_key_mock.h" +#include "oemcrypto_key_ref.h" #include "oemcrypto_rsa_key_shared.h" -#include "string_conversions.h" -#include "wv_cdm_constants.h" -namespace wvoec_mock { +namespace wvoec_ref { // Note: The class CryptoEngine is configured at compile time by compiling in // different device property files. The methods in this file are generic to // all configurations. See the files oemcrypto_engine_device_properties*.cpp // for methods that are configured for specific configurations. -CryptoEngine::CryptoEngine(std::auto_ptr file_system) +CryptoEngine::CryptoEngine(scoped_ptr file_system) : root_of_trust_(config_provisioning_method()), file_system_(file_system), usage_table_(this) { @@ -123,4 +121,4 @@ OEMCryptoResult CryptoEngine::SetDestination( return OEMCrypto_SUCCESS; } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.h similarity index 90% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.h index 9d8b1f44..c99abb13 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_engine_mock.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.h @@ -2,10 +2,10 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef MOCK_OEMCRYPTO_ENGINE_MOCK_H_ -#define MOCK_OEMCRYPTO_ENGINE_MOCK_H_ +#ifndef REF_OEMCRYPTO_ENGINE_REF_H_ +#define REF_OEMCRYPTO_ENGINE_REF_H_ #include #include @@ -18,14 +18,15 @@ #include "OEMCryptoCENC.h" // Needed for enums only. #include "file_store.h" #include "lock.h" -#include "oemcrypto_auth_mock.h" -#include "oemcrypto_key_mock.h" +#include "oemcrypto_auth_ref.h" +#include "oemcrypto_key_ref.h" #include "oemcrypto_rsa_key_shared.h" +#include "oemcrypto_scoped_ptr.h" #include "oemcrypto_session.h" -#include "oemcrypto_usage_table_mock.h" -#include "wv_cdm_types.h" +#include "oemcrypto_usage_table_ref.h" +#include "oemcrypto_types.h" -namespace wvoec_mock { +namespace wvoec_ref { typedef std::map ActiveSessions; @@ -37,7 +38,7 @@ class CryptoEngine { // NOTE: The caller must instantiate a FileSystem object - ownership // will be transferred to the new CryptoEngine object. static CryptoEngine* MakeCryptoEngine( - std::auto_ptr file_system); + scoped_ptr file_system); virtual ~CryptoEngine(); @@ -82,7 +83,7 @@ class CryptoEngine { size_t GetNumberOfOpenSessions() { return sessions_.size(); } size_t GetMaxNumberOfSessions() { - // An arbitrary limit for mock implementation. + // An arbitrary limit for ref implementation. static const size_t kMaxSupportedOEMCryptoSessions = 64; return kMaxSupportedOEMCryptoSessions; } @@ -170,19 +171,19 @@ class CryptoEngine { } protected: - explicit CryptoEngine(std::auto_ptr file_system); + explicit CryptoEngine(scoped_ptr file_system); uint8_t* destination_; private: ActiveSessions sessions_; AuthenticationRoot root_of_trust_; wvcdm::Lock session_table_lock_; - std::auto_ptr file_system_; + scoped_ptr file_system_; UsageTable usage_table_; CORE_DISALLOW_COPY_AND_ASSIGN(CryptoEngine); }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // MOCK_OEMCRYPTO_ENGINE_MOCK_H_ +#endif // REF_OEMCRYPTO_ENGINE_REF_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_key_mock.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.cpp similarity index 64% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_key_mock.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.cpp index fa0b108b..412a3bd0 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_key_mock.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.cpp @@ -2,18 +2,18 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#include "oemcrypto_key_mock.h" +#include "oemcrypto_key_ref.h" +#include "oemcrypto_types.h" #include #include #include "log.h" #include "oemcrypto_logging.h" -#include "wv_cdm_constants.h" -namespace wvoec_mock { +namespace wvoec_ref { bool KeyControlBlock::Validate() { if (memcmp(verification_, "kctl", 4) && // original verification @@ -45,15 +45,15 @@ uint32_t KeyControlBlock::ExtractField(const std::vector& str, KeyControlBlock::KeyControlBlock( const std::vector& key_control_string) { - if (key_control_string.size() < wvcdm::KEY_CONTROL_SIZE) { + if (key_control_string.size() < wvoec::KEY_CONTROL_SIZE) { LOGE("KCB: BAD Size: %d (not %d)", key_control_string.size(), - wvcdm::KEY_CONTROL_SIZE); + wvoec::KEY_CONTROL_SIZE); return; } memcpy(verification_, &key_control_string[0], 4); - duration_ = ExtractField(key_control_string, 1); - nonce_ = ExtractField(key_control_string, 2); + duration_ = ExtractField(key_control_string, 1); + nonce_ = ExtractField(key_control_string, 2); control_bits_ = ExtractField(key_control_string, 3); if (LogCategoryEnabled(kLoggingDumpKeyControlBlocks)) { LOGD("KCB:"); @@ -63,19 +63,20 @@ KeyControlBlock::KeyControlBlock( LOGD(" magic: %08X", verification()); LOGD(" bits: %08X", control_bits()); LOGD(" bit kSharedLicense %s.", - (control_bits() & kSharedLicense) ? "set" : "unset"); + (control_bits() & wvoec::kSharedLicense) ? "set" : "unset"); LOGD(" bit kControlSRMVersionRequired %s.", - (control_bits() & kControlSRMVersionRequired) ? "set" : "unset"); + (control_bits() & wvoec::kControlSRMVersionRequired) ? "set" : "unset"); LOGD(" bit kControlDisableAnalogOutput %s.", - (control_bits() & kControlDisableAnalogOutput) ? "set" : "unset"); + (control_bits() & wvoec::kControlDisableAnalogOutput) ? "set" + : "unset"); LOGD(" bits kControlSecurityPatchLevel 0x%02x.", - (control_bits() & kControlSecurityPatchLevelMask) - >> kControlSecurityPatchLevelShift); - switch (control_bits() & kControlReplayMask) { - case kControlNonceRequired: + (control_bits() & wvoec::kControlSecurityPatchLevelMask) >> + wvoec::kControlSecurityPatchLevelShift); + switch (control_bits() & wvoec::kControlReplayMask) { + case wvoec::kControlNonceRequired: LOGD(" bits kControlReplay kControlNonceRequired."); break; - case kControlNonceOrEntry: + case wvoec::kControlNonceOrEntry: LOGD(" bits kControlReplay kControlNonceOrEntry."); break; default: @@ -83,28 +84,28 @@ KeyControlBlock::KeyControlBlock( break; } LOGD(" bits kControlHDCPVersion 0x%02x.", - (control_bits() & kControlHDCPVersionMask) - >> kControlHDCPVersionShift); + (control_bits() & wvoec::kControlHDCPVersionMask) >> + wvoec::kControlHDCPVersionShift); LOGD(" bit kControlAllowEncrypt %s.", - (control_bits() & kControlAllowEncrypt) ? "set" : "unset"); + (control_bits() & wvoec::kControlAllowEncrypt) ? "set" : "unset"); LOGD(" bit kControlAllowDecrypt %s.", - (control_bits() & kControlAllowDecrypt) ? "set" : "unset"); + (control_bits() & wvoec::kControlAllowDecrypt) ? "set" : "unset"); LOGD(" bit kControlAllowSign %s.", - (control_bits() & kControlAllowSign) ? "set" : "unset"); + (control_bits() & wvoec::kControlAllowSign) ? "set" : "unset"); LOGD(" bit kControlAllowVerify %s.", - (control_bits() & kControlAllowVerify) ? "set" : "unset"); + (control_bits() & wvoec::kControlAllowVerify) ? "set" : "unset"); LOGD(" bit kControlObserveDataPath %s.", - (control_bits() & kControlObserveDataPath) ? "set" : "unset"); + (control_bits() & wvoec::kControlObserveDataPath) ? "set" : "unset"); LOGD(" bit kControlObserveHDCP %s.", - (control_bits() & kControlObserveHDCP) ? "set" : "unset"); + (control_bits() & wvoec::kControlObserveHDCP) ? "set" : "unset"); LOGD(" bit kControlObserveCGMS %s.", - (control_bits() & kControlObserveCGMS) ? "set" : "unset"); + (control_bits() & wvoec::kControlObserveCGMS) ? "set" : "unset"); LOGD(" bit kControlDataPathSecure %s.", - (control_bits() & kControlDataPathSecure) ? "set" : "unset"); + (control_bits() & wvoec::kControlDataPathSecure) ? "set" : "unset"); LOGD(" bit kControlNonceEnabled %s.", - (control_bits() & kControlNonceEnabled) ? "set" : "unset"); + (control_bits() & wvoec::kControlNonceEnabled) ? "set" : "unset"); LOGD(" bit kControlHDCPRequired %s.", - (control_bits() & kControlHDCPRequired) ? "set" : "unset"); + (control_bits() & wvoec::kControlHDCPRequired) ? "set" : "unset"); uint32_t cgms_bits = control_bits() & 0x3; const char* cgms_values[4] = {"free", "BAD", "once", "never"}; LOGD(" CGMS = %s", cgms_values[cgms_bits]); @@ -118,7 +119,7 @@ void Key::UpdateDuration(const KeyControlBlock& control) { void KeyControlBlock::RequireLocalDisplay() { // Set all bits to require HDCP Local Display Only. - control_bits_ |= kControlHDCPVersionMask; + control_bits_ |= wvoec::kControlHDCPVersionMask; } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_key_mock.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.h similarity index 62% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_key_mock.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.h index dab47e87..894d240c 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_key_mock.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_key_ref.h @@ -2,43 +2,16 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef OEMCRYPTO_KEY_MOCK_H_ -#define OEMCRYPTO_KEY_MOCK_H_ +#ifndef OEMCRYPTO_KEY_REF_H_ +#define OEMCRYPTO_KEY_REF_H_ #include #include #include -namespace wvoec_mock { - -const uint32_t kControlObserveDataPath = (1<<31); -const uint32_t kControlObserveHDCP = (1<<30); -const uint32_t kControlObserveCGMS = (1<<29); -const uint32_t kControlRequireAntiRollbackHardware = (1<<28); -const uint32_t kSharedLicense = (1<<23); -const uint32_t kControlSRMVersionRequired = (1<<22); -const uint32_t kControlDisableAnalogOutput = (1<<21); -const uint32_t kControlSecurityPatchLevelShift = 15; -const uint32_t kControlSecurityPatchLevelMask = - (0x3F< content_key_id_; }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // OEMCRYPTO_KEY_MOCK_H_ +#endif // OEMCRYPTO_KEY_REF_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_mock.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_ref.cpp similarity index 90% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_mock.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_ref.cpp index 70e909ca..bf960558 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_mock.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_ref.cpp @@ -2,23 +2,24 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#include "oemcrypto_keybox_mock.h" +#include "oemcrypto_keybox_ref.h" #include // needed for ntoh() #include #include #include + #include "log.h" -#include "wv_keybox.h" +#include "oemcrypto_types.h" #include "wvcrc32.h" -namespace wvoec_mock { +namespace wvoec_ref { namespace { -const WidevineKeybox kTestKeybox = { +const wvoec::WidevineKeybox kTestKeybox = { // Sample keybox used for test vectors { // deviceID @@ -69,7 +70,7 @@ KeyboxError WvKeybox::Validate() { uint32_t crc_stored; uint8_t* crc_stored_bytes = (uint8_t*) &crc_stored; memcpy(crc_stored_bytes, crc_, sizeof(crc_)); - WidevineKeybox keybox; + wvoec::WidevineKeybox keybox; memset(&keybox, 0, sizeof(keybox)); memcpy(keybox.device_id_, &device_id_[0], device_id_.size()); memcpy(keybox.device_key_, &device_key_[0], sizeof(keybox.device_key_)); @@ -91,8 +92,8 @@ bool WvKeybox::InstallKeybox(const uint8_t* buffer, size_t keyBoxLength) { return false; } - const WidevineKeybox* keybox - = reinterpret_cast(buffer); + const wvoec::WidevineKeybox* keybox + = reinterpret_cast(buffer); size_t device_id_length = strnlen(reinterpret_cast(keybox->device_id_), 32); device_id_.assign(keybox->device_id_, @@ -111,4 +112,4 @@ WvTestKeybox::WvTestKeybox() { sizeof(kTestKeybox)); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_mock.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_ref.h similarity index 82% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_mock.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_ref.h index 3609a01a..8dd2fe6d 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_mock.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_ref.h @@ -2,14 +2,14 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef OEMCRYPTO_KEYBOX_MOCK_H_ -#define OEMCRYPTO_KEYBOX_MOCK_H_ +#ifndef OEMCRYPTO_KEYBOX_REF_H_ +#define OEMCRYPTO_KEYBOX_REF_H_ -#include "oemcrypto_key_mock.h" +#include "oemcrypto_key_ref.h" -namespace wvoec_mock { +namespace wvoec_ref { const int DEVICE_KEY_LENGTH = 16; typedef uint8_t WvKeyboxKey[DEVICE_KEY_LENGTH]; @@ -48,6 +48,6 @@ class WvTestKeybox : public WvKeybox { WvTestKeybox(); }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // OEMCRYPTO_KEYBOX_MOCK_H_ +#endif // OEMCRYPTO_KEYBOX_REF_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_testkey.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_testkey.cpp similarity index 91% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_testkey.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_testkey.cpp index 3b6b91b2..6035181e 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_keybox_testkey.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_keybox_testkey.cpp @@ -4,16 +4,16 @@ // // Test keybox. -#include "oemcrypto_keybox_mock.h" -#include "wv_keybox.h" +#include "oemcrypto_keybox_ref.h" +#include "oemcrypto_types.h" -namespace wvoec_mock { +namespace wvoec_ref { namespace { // Note: this is a valid keybox, but it is not accepted by production servers. // However, it is different from the one used for most of the unit tests. -const WidevineKeybox kKeybox = { +const wvoec::WidevineKeybox kKeybox = { // Sample keybox used for test vectors { // deviceID @@ -53,4 +53,4 @@ bool WvKeybox::Prepare() { return true; } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_logging.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_logging.cpp similarity index 96% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_logging.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_logging.cpp index 3379fe04..935b2c47 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_logging.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_logging.cpp @@ -6,7 +6,7 @@ #include -namespace wvoec_mock { +namespace wvoec_ref { int logging_category_setting = 0x00; @@ -49,7 +49,7 @@ void dump_hex_helper(std::string& buffer, std::string name, '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; for (size_t i = 0; i < length; i++) { if (i == 0) { - buffer += "\n wvcdm::a2b_hex(\""; + buffer += "\n a2b_hex(\""; } else if (i % 32 == 0) { buffer += "\"\n \""; } @@ -103,4 +103,4 @@ void dump_array_part(std::string array, size_t index, std::string name, LOGV(buffer.c_str()); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/include/oemcrypto_logging.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_logging.h similarity index 96% rename from libwvdrmengine/oemcrypto/include/oemcrypto_logging.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_logging.h index 0fa9f0c3..625f5508 100644 --- a/libwvdrmengine/oemcrypto/include/oemcrypto_logging.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_logging.h @@ -11,7 +11,7 @@ #include "OEMCryptoCENC.h" #include "log.h" -namespace wvoec_mock { +namespace wvoec_ref { // The constants below represent integers with a single "on" bit that // represents categories of logging This allows users to specify with @@ -62,6 +62,6 @@ void dump_array_part_helper(std::string& buffer, std::string array, void dump_array_part(std::string array, size_t index, std::string name, const uint8_t* vector, size_t length); -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif +#endif // WVOEC_OEMCRYPTO_LOGGING_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_nonce_table.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_nonce_table.cpp similarity index 94% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_nonce_table.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_nonce_table.cpp index 6e072acb..5412a960 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_nonce_table.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_nonce_table.cpp @@ -2,11 +2,11 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // #include "oemcrypto_nonce_table.h" -namespace wvoec_mock { +namespace wvoec_ref { void NonceTable::AddNonce(uint32_t nonce) { int new_slot = -1; @@ -66,4 +66,4 @@ void NonceTable::Flush() { } } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_nonce_table.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_nonce_table.h similarity index 76% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_nonce_table.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_nonce_table.h index 7b8072e7..6b24ac81 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_nonce_table.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_nonce_table.h @@ -2,14 +2,14 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef MOCK_OEMCRYPTO_NONCE_TABLE_H_ -#define MOCK_OEMCRYPTO_NONCE_TABLE_H_ +#ifndef REF_OEMCRYPTO_NONCE_TABLE_H_ +#define REF_OEMCRYPTO_NONCE_TABLE_H_ #include -namespace wvoec_mock { +namespace wvoec_ref { class NonceTable { public: @@ -35,6 +35,6 @@ class NonceTable { uint32_t nonces_[kTableSize]; }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // MOCK_OEMCRYPTO_NONCE_TABLE_H_ +#endif // REF_OEMCRYPTO_NONCE_TABLE_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_old_usage_table_mock.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_old_usage_table_ref.cpp similarity index 82% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_old_usage_table_mock.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_old_usage_table_ref.cpp index b82c1231..426e2c02 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_old_usage_table_mock.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_old_usage_table_ref.cpp @@ -2,12 +2,12 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // // This is from the v12 version of oemcrypto usage tables. It is used for // devices that upgrade from v12 to v13 in the field, and need to convert from // the old type of usage table to the new. -#include "oemcrypto_old_usage_table_mock.h" +#include "oemcrypto_old_usage_table_ref.h" #include #include @@ -22,14 +22,15 @@ #include "file_store.h" #include "log.h" -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" #include "oemcrypto_logging.h" -#include "properties.h" +// TODO(fredgc): Setting the device files base bath is currently broken as +// wvcdm::Properties is no longer used by the reference code. +//#include "properties.h" #include "pst_report.h" #include "string_conversions.h" -#include "wv_cdm_constants.h" -namespace wvoec_mock { +namespace wvoec_ref { OldUsageTableEntry::OldUsageTableEntry(const std::vector &pst_hash) : pst_hash_(pst_hash), @@ -47,9 +48,9 @@ OldUsageTableEntry::OldUsageTableEntry(const OldStoredUsageEntry *buffer) { time_of_last_decrypt_ = buffer->time_of_last_decrypt; status_ = buffer->status; mac_key_server_.assign(buffer->mac_key_server, - buffer->mac_key_server + wvcdm::MAC_KEY_SIZE); + buffer->mac_key_server + wvoec::MAC_KEY_SIZE); mac_key_client_.assign(buffer->mac_key_client, - buffer->mac_key_client + wvcdm::MAC_KEY_SIZE); + buffer->mac_key_client + wvoec::MAC_KEY_SIZE); } OldUsageTable::OldUsageTable(CryptoEngine *ce) { @@ -58,16 +59,17 @@ OldUsageTable::OldUsageTable(CryptoEngine *ce) { table_.clear(); // Load saved table. - wvcdm::FileSystem* file_system = ce->file_system(); + wvcdm::FileSystem *file_system = ce->file_system(); wvcdm::File *file; std::string path; // Note: this path is OK for a real implementation, but using security level 1 // would be better. - if (!wvcdm::Properties::GetDeviceFilesBasePath(wvcdm::kSecurityLevelL3, - &path)) { + // TODO(fredgc, jfore): Address how this property is presented to the ref. + // For now, the path is empty. + /*if (!Properties::GetDeviceFilesBasePath(kSecurityLevelL3, &path)) { LOGE("OldUsageTable: Unable to get base path"); return; - } + }*/ std::string filename = path + "UsageTable.dat"; if (!file_system->Exists(filename)) { if (LogCategoryEnabled(kLoggingTraceUsageTable)) { @@ -119,14 +121,14 @@ OldUsageTable::OldUsageTable(CryptoEngine *ce) { } // Next, decrypt the table. - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, encrypted_table->iv, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, encrypted_table->iv, wvoec::KEY_IV_SIZE); AES_KEY aes_key; AES_set_decrypt_key(&key[0], 128, &aes_key); - AES_cbc_encrypt(&encrypted_buffer[SHA256_DIGEST_LENGTH + wvcdm::KEY_IV_SIZE], - &buffer[SHA256_DIGEST_LENGTH + wvcdm::KEY_IV_SIZE], - file_size - SHA256_DIGEST_LENGTH - wvcdm::KEY_IV_SIZE, - &aes_key, iv_buffer, AES_DECRYPT); + AES_cbc_encrypt(&encrypted_buffer[SHA256_DIGEST_LENGTH + wvoec::KEY_IV_SIZE], + &buffer[SHA256_DIGEST_LENGTH + wvoec::KEY_IV_SIZE], + file_size - SHA256_DIGEST_LENGTH - wvoec::KEY_IV_SIZE, &aes_key, + iv_buffer, AES_DECRYPT); // Next, read the generation number from a different location. // On a real implementation, you should NOT put the generation number in @@ -176,7 +178,8 @@ OldUsageTableEntry *OldUsageTable::FindEntry(const std::vector &pst) { return FindEntryLocked(pst); } -OldUsageTableEntry *OldUsageTable::FindEntryLocked(const std::vector &pst) { +OldUsageTableEntry *OldUsageTable::FindEntryLocked( + const std::vector &pst) { std::vector pst_hash; if (!ComputeHash(pst, pst_hash)) { LOGE("OldUsageTable: Could not compute hash of pst."); @@ -189,7 +192,8 @@ OldUsageTableEntry *OldUsageTable::FindEntryLocked(const std::vector &p return it->second; } -OldUsageTableEntry *OldUsageTable::CreateEntry(const std::vector &pst) { +OldUsageTableEntry *OldUsageTable::CreateEntry( + const std::vector &pst) { std::vector pst_hash; if (!ComputeHash(pst, pst_hash)) { LOGE("OldUsageTable: Could not compute hash of pst."); @@ -210,15 +214,16 @@ void OldUsageTable::Clear() { } void OldUsageTable::DeleteFile(CryptoEngine *ce) { - wvcdm::FileSystem* file_system = ce->file_system(); + wvcdm::FileSystem *file_system = ce->file_system(); std::string path; // Note: this path is OK for a real implementation, but using security level 1 // would be better. - if (!wvcdm::Properties::GetDeviceFilesBasePath(wvcdm::kSecurityLevelL3, - &path)) { + // TODO(jfore): Address how this property is presented to the ref. For now, + // the path is empty. + /*if (!Properties::GetDeviceFilesBasePath(kSecurityLevelL3, &path)) { LOGE("OldUsageTable: Unable to get base path"); return; - } + }*/ std::string filename = path + "UsageTable.dat"; if (file_system->Exists(filename)) { if (!file_system->Remove(filename)) { @@ -228,7 +233,7 @@ void OldUsageTable::DeleteFile(CryptoEngine *ce) { } bool OldUsageTable::ComputeHash(const std::vector &pst, - std::vector &pst_hash) { + std::vector &pst_hash) { // The PST is not fixed size, and we have no promises that it is reasonbly // sized, so we compute a hash of it, and store that instead. pst_hash.resize(SHA256_DIGEST_LENGTH); @@ -239,4 +244,4 @@ bool OldUsageTable::ComputeHash(const std::vector &pst, return true; } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_old_usage_table_mock.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_old_usage_table_ref.h similarity index 79% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_old_usage_table_mock.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_old_usage_table_ref.h index beede045..7aa1c105 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_old_usage_table_mock.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_old_usage_table_ref.h @@ -1,26 +1,26 @@ - // Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary - // source code may only be used and distributed under the Widevine Master - // License Agreement. +// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary +// source code may only be used and distributed under the Widevine Master +// License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // // This is from the v12 version of oemcrypto usage tables. It is used for // devices that upgrade from v12 to v13 in the field, and need to convert from // the old type of usage table to the new. -#ifndef OEMCRYPTO_OLD_USAGE_TABLE_MOCK_H_ -#define OEMCRYPTO_OLD_USAGE_TABLE_MOCK_H_ +#ifndef OEMCRYPTO_OLD_USAGE_TABLE_REF_H_ +#define OEMCRYPTO_OLD_USAGE_TABLE_REF_H_ #include #include #include #include -#include "lock.h" #include "OEMCryptoCENC.h" +#include "lock.h" +#include "oemcrypto_types.h" #include "openssl/sha.h" -#include "wv_cdm_constants.h" -namespace wvoec_mock { +namespace wvoec_ref { class CryptoEngine; class UsagetTableEntry; @@ -32,8 +32,8 @@ struct OldStoredUsageEntry { int64_t time_of_first_decrypt; int64_t time_of_last_decrypt; enum OEMCrypto_Usage_Entry_Status status; - uint8_t mac_key_server[wvcdm::MAC_KEY_SIZE]; - uint8_t mac_key_client[wvcdm::MAC_KEY_SIZE]; + uint8_t mac_key_server[wvoec::MAC_KEY_SIZE]; + uint8_t mac_key_client[wvoec::MAC_KEY_SIZE]; }; typedef union { @@ -43,7 +43,7 @@ typedef union { struct OldStoredUsageTable { uint8_t signature[SHA256_DIGEST_LENGTH]; - uint8_t iv[wvcdm::KEY_IV_SIZE]; + uint8_t iv[wvoec::KEY_IV_SIZE]; int64_t generation; uint64_t count; AlignedOldStoredUsageEntry entries[]; @@ -90,6 +90,6 @@ class OldUsageTable { CryptoEngine *ce_; }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // OEMCRYPTO_OLD_USAGE_TABLE_MOCK_H_ +#endif // OEMCRYPTO_OLD_USAGE_TABLE_REF_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_ref.cpp similarity index 94% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_ref.cpp index 53d604ab..95964c29 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_mock.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_ref.cpp @@ -22,12 +22,11 @@ #include #include "file_store.h" #include "log.h" -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" #include "oemcrypto_logging.h" #include "oemcrypto_session.h" -#include "oemcrypto_usage_table_mock.h" +#include "oemcrypto_usage_table_ref.h" #include "string_conversions.h" -#include "wv_cdm_constants.h" namespace { const uint8_t kBakedInCertificateMagicBytes[] = {0xDE, 0xAD, 0xBE, 0xEF}; @@ -39,7 +38,7 @@ uint32_t unaligned_dereference_uint32(const void* unaligned_ptr) { uint32_t value; const uint8_t* src = reinterpret_cast(unaligned_ptr); uint8_t* dest = reinterpret_cast(&value); - for (unsigned long i=0; i < sizeof(value); i++) { + for (unsigned long i = 0; i < sizeof(value); i++) { dest[i] = src[i]; } return value; @@ -47,14 +46,14 @@ uint32_t unaligned_dereference_uint32(const void* unaligned_ptr) { } // namespace -namespace wvoec_mock { +namespace wvoec_ref { static CryptoEngine* crypto_engine = NULL; typedef struct { - uint8_t signature[wvcdm::MAC_KEY_SIZE]; - uint8_t context[wvcdm::MAC_KEY_SIZE]; - uint8_t iv[wvcdm::KEY_IV_SIZE]; + uint8_t signature[wvoec::MAC_KEY_SIZE]; + uint8_t context[wvoec::MAC_KEY_SIZE]; + uint8_t iv[wvoec::KEY_IV_SIZE]; uint8_t enc_rsa_key[]; } WrappedRSAKey; @@ -69,7 +68,7 @@ extern "C" OEMCryptoResult OEMCrypto_Initialize(void) { } // NOTE: This requires a compatible Filesystem implementation. // NOTE: Ownership of the FileSystem object is transferred to CryptoEngine - std::auto_ptr fs(new wvcdm::FileSystem()); + scoped_ptr fs(new wvcdm::FileSystem()); crypto_engine = CryptoEngine::MakeCryptoEngine(fs); if (!crypto_engine || !crypto_engine->Initialize()) { @@ -103,8 +102,9 @@ extern "C" OEMCryptoResult OEMCrypto_Terminate(void) { extern "C" OEMCryptoResult OEMCrypto_OpenSession(OEMCrypto_SESSION* session) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { - LOGI("-- OEMCryptoResult OEMCrypto_OpenSession" - "(OEMCrypto_SESSION *session)\n"); + LOGI( + "-- OEMCryptoResult OEMCrypto_OpenSession" + "(OEMCrypto_SESSION *session)\n"); } if (!crypto_engine) { LOGE("OEMCrypto_OpenSession: OEMCrypto not initialized."); @@ -118,15 +118,16 @@ extern "C" OEMCryptoResult OEMCrypto_OpenSession(OEMCrypto_SESSION* session) { SessionId sid = crypto_engine->CreateSession(); *session = (OEMCrypto_SESSION)sid; if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { - LOGD("[OEMCrypto_OpenSession(): SID=%08X]", sid); + LOGD("[OEMCrypto_OpenSession(): SID=%08x]", sid); } return OEMCrypto_SUCCESS; } extern "C" OEMCryptoResult OEMCrypto_CloseSession(OEMCrypto_SESSION session) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { - LOGI("-- OEMCryptoResult OEMCrypto_CloseSession" - "(OEMCrypto_SESSION session)\n"); + LOGI( + "-- OEMCryptoResult OEMCrypto_CloseSession" + "(OEMCrypto_SESSION session)\n"); } if (!crypto_engine) { LOGE("OEMCrypto_CloseSession: OEMCrypto not initialized."); @@ -209,8 +210,9 @@ static uint64_t TimeStamp(void) { extern "C" OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session, uint32_t* nonce) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { - LOGI("-- OEMCryptoResult OEMCrypto_GenerateNonce" - "(OEMCrypto_SESSION session,\n"); + LOGI( + "-- OEMCryptoResult OEMCrypto_GenerateNonce" + "(OEMCrypto_SESSION session,\n"); } if (!crypto_engine) { LOGE("OEMCrypto_GenerateNonce: OEMCrypto not initialized."); @@ -251,7 +253,7 @@ extern "C" OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session, session_ctx->AddNonce(nonce_value); *nonce = nonce_value; if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { - LOGI("nonce = %08X\n", nonce_value); + LOGI("nonce = %08x\n", nonce_value); } return OEMCrypto_SUCCESS; } @@ -322,23 +324,23 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( if (wvcdm::g_cutoff >= wvcdm::LOG_VERBOSE) { dump_hex("message", message, message_length); dump_hex("signature", signature, signature_length); - dump_hex("enc_mac_key_iv", enc_mac_key_iv, wvcdm::KEY_IV_SIZE); - dump_hex("enc_mac_keys", enc_mac_keys, 2 * wvcdm::MAC_KEY_SIZE); + dump_hex("enc_mac_key_iv", enc_mac_key_iv, wvoec::KEY_IV_SIZE); + dump_hex("enc_mac_keys", enc_mac_keys, 2 * wvoec::MAC_KEY_SIZE); dump_hex("pst", pst, pst_length); - dump_hex("srm_requirement", srm_requirement, wvcdm::KEY_CONTROL_SIZE); + dump_hex("srm_requirement", srm_requirement, wvoec::KEY_CONTROL_SIZE); for (size_t i = 0; i < num_keys; i++) { LOGV("key_array[%zu].key_id_length=%zu;\n", i, key_array[i].key_id_length); dump_array_part("key_array", i, "key_id", key_array[i].key_id, key_array[i].key_id_length); dump_array_part("key_array", i, "key_data_iv", key_array[i].key_data_iv, - wvcdm::KEY_IV_SIZE); + wvoec::KEY_IV_SIZE); dump_array_part("key_array", i, "key_data", key_array[i].key_data, key_array[i].key_data_length); dump_array_part("key_array", i, "key_control_iv", - key_array[i].key_control_iv, wvcdm::KEY_IV_SIZE); + key_array[i].key_control_iv, wvoec::KEY_IV_SIZE); dump_array_part("key_array", i, "key_control", key_array[i].key_control, - wvcdm::KEY_IV_SIZE); + wvoec::KEY_IV_SIZE); } } } @@ -368,15 +370,15 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( } // Range check - if (!RangeCheck(message, message_length, enc_mac_keys, - 2 * wvcdm::MAC_KEY_SIZE, true) || - !RangeCheck(message, message_length, enc_mac_key_iv, wvcdm::KEY_IV_SIZE, + if (!RangeCheck(message, message_length, enc_mac_keys, 2 * wvoec::MAC_KEY_SIZE, true) || + !RangeCheck(message, message_length, enc_mac_key_iv, wvoec::KEY_IV_SIZE, true) || !RangeCheck(message, message_length, pst, pst_length, true) || !RangeCheck(message, message_length, srm_requirement, - wvcdm::SRM_REQUIREMENT_SIZE, true)) { - LOGE("[OEMCrypto_LoadKeys(): OEMCrypto_ERROR_INVALID_CONTEXT - range " - "check.]"); + wvoec::SRM_REQUIREMENT_SIZE, true)) { + LOGE( + "[OEMCrypto_LoadKeys(): OEMCrypto_ERROR_INVALID_CONTEXT - range " + "check.]"); return OEMCrypto_ERROR_INVALID_CONTEXT; } @@ -386,13 +388,15 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( !RangeCheck(message, message_length, key_array[i].key_data, key_array[i].key_data_length, false) || !RangeCheck(message, message_length, key_array[i].key_data_iv, - wvcdm::KEY_IV_SIZE, false) || + wvoec::KEY_IV_SIZE, false) || !RangeCheck(message, message_length, key_array[i].key_control, - wvcdm::KEY_CONTROL_SIZE, false) || + wvoec::KEY_CONTROL_SIZE, false) || !RangeCheck(message, message_length, key_array[i].key_control_iv, - wvcdm::KEY_IV_SIZE, false)) { - LOGE("[OEMCrypto_LoadKeys(): OEMCrypto_ERROR_INVALID_CONTEXT -range " - "check %d]", i); + wvoec::KEY_IV_SIZE, false)) { + LOGE( + "[OEMCrypto_LoadKeys(): OEMCrypto_ERROR_INVALID_CONTEXT -range " + "check %d]", + i); return OEMCrypto_ERROR_INVALID_CONTEXT; } } @@ -403,8 +407,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( } extern "C" OEMCryptoResult OEMCrypto_LoadEntitledContentKeys( - OEMCrypto_SESSION session, - size_t num_keys, + OEMCrypto_SESSION session, size_t num_keys, const OEMCrypto_EntitledContentKeyObject* key_array) { if (num_keys == 0) { LOGE("[OEMCrypto_LoadEntitledContentKeys(): key_array is empty."); @@ -461,9 +464,9 @@ extern "C" OEMCryptoResult OEMCrypto_RefreshKeys( if (!RangeCheck(message, message_length, key_array[i].key_id, key_array[i].key_id_length, true) || !RangeCheck(message, message_length, key_array[i].key_control, - wvcdm::KEY_CONTROL_SIZE, false) || + wvoec::KEY_CONTROL_SIZE, false) || !RangeCheck(message, message_length, key_array[i].key_control_iv, - wvcdm::KEY_IV_SIZE, true)) { + wvoec::KEY_IV_SIZE, true)) { LOGE("[OEMCrypto_RefreshKeys(): Range Check %d]", i); return OEMCrypto_ERROR_INVALID_CONTEXT; } @@ -486,12 +489,12 @@ extern "C" OEMCryptoResult OEMCrypto_RefreshKeys( key_id.assign(key_array[i].key_id, key_array[i].key_id + key_array[i].key_id_length); key_control.assign(key_array[i].key_control, - key_array[i].key_control + wvcdm::KEY_CONTROL_SIZE); + key_array[i].key_control + wvoec::KEY_CONTROL_SIZE); if (key_array[i].key_control_iv == NULL) { key_control_iv.clear(); } else { key_control_iv.assign(key_array[i].key_control_iv, - key_array[i].key_control_iv + wvcdm::KEY_IV_SIZE); + key_array[i].key_control_iv + wvoec::KEY_IV_SIZE); } } else { // key_id could be null if special control key type @@ -499,7 +502,7 @@ extern "C" OEMCryptoResult OEMCrypto_RefreshKeys( key_id.clear(); key_control_iv.clear(); key_control.assign(key_array[i].key_control, - key_array[i].key_control + wvcdm::KEY_CONTROL_SIZE); + key_array[i].key_control + wvoec::KEY_CONTROL_SIZE); } status = session_ctx->RefreshKey(key_id, key_control, key_control_iv); @@ -531,14 +534,15 @@ extern "C" OEMCryptoResult OEMCrypto_QueryKeyControl( } uint32_t* block = reinterpret_cast(key_control_block); if ((key_control_block_length == NULL) || - (*key_control_block_length < wvcdm::KEY_CONTROL_SIZE)) { + (*key_control_block_length < wvoec::KEY_CONTROL_SIZE)) { LOGE("[OEMCrypto_QueryKeyControl(): OEMCrypto_ERROR_SHORT_BUFFER]"); return OEMCrypto_ERROR_SHORT_BUFFER; } - *key_control_block_length = wvcdm::KEY_CONTROL_SIZE; + *key_control_block_length = wvoec::KEY_CONTROL_SIZE; if (key_id == NULL) { - LOGE("[OEMCrypto_QueryKeyControl(): key_id null. " - "OEMCrypto_ERROR_UNKNOWN_FAILURE]"); + LOGE( + "[OEMCrypto_QueryKeyControl(): key_id null. " + "OEMCrypto_ERROR_UNKNOWN_FAILURE]"); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -656,7 +660,7 @@ extern "C" OEMCryptoResult OEMCrypto_CopyBuffer( crypto_engine->SetDestination(out_buffer, data_length, subsample_flags); if (status != OEMCrypto_SUCCESS) return status; if (crypto_engine->destination() != NULL) { - memcpy(crypto_engine->destination(), data_addr, data_length); + memmove(crypto_engine->destination(), data_addr, data_length); } return crypto_engine->PushDestination(out_buffer, subsample_flags); } @@ -701,8 +705,8 @@ extern "C" OEMCryptoResult OEMCrypto_InstallKeybox(const uint8_t* keybox, return OEMCrypto_ERROR_WRITE_KEYBOX; } -extern "C" OEMCryptoResult OEMCrypto_LoadTestKeybox( - const uint8_t* buffer, size_t length) { +extern "C" OEMCryptoResult OEMCrypto_LoadTestKeybox(const uint8_t* buffer, + size_t length) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_LoadTestKeybox()\n"); } @@ -880,7 +884,7 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey30( dump_hex("encrypted_message_key", encrypted_message_key, encrypted_message_key_length); dump_hex("enc_rsa_key", enc_rsa_key, enc_rsa_key_length); - dump_hex("enc_rsa_key_iv", enc_rsa_key_iv, wvcdm::KEY_IV_SIZE); + dump_hex("enc_rsa_key_iv", enc_rsa_key_iv, wvoec::KEY_IV_SIZE); } } if (!crypto_engine) { @@ -929,8 +933,9 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey30( if (!session_ctx->InstallRSAEncryptedKey(encrypted_message_key, encrypted_message_key_length)) { - LOGE("OEMCrypto_RewrapDeviceRSAKey30: " - "Error loading encrypted_message_key."); + LOGE( + "OEMCrypto_RewrapDeviceRSAKey30: " + "Error loading encrypted_message_key."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -942,9 +947,10 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey30( } size_t padding = pkcs8_rsa_key[enc_rsa_key_length - 1]; if (padding > 16) { - LOGE("[OEMCrypto_RewrapDeviceRSAKey30(): " - "Encrypted RSA has bad padding: %d]", - padding); + LOGE( + "[OEMCrypto_RewrapDeviceRSAKey30(): " + "Encrypted RSA has bad padding: %d]", + padding); return OEMCrypto_ERROR_INVALID_RSA_KEY; } size_t rsa_key_length = enc_rsa_key_length - padding; @@ -984,7 +990,8 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey30( unsigned int sig_length = sizeof(wrapped->signature); if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) { LOGI(("message verified with HMAC and mac_key_server, key = " + - wvcdm::b2a_hex(session_ctx->mac_key_server())).c_str()); + wvcdm::b2a_hex(session_ctx->mac_key_server())) + .c_str()); } if (!HMAC(EVP_sha256(), &session_ctx->mac_key_server()[0], session_ctx->mac_key_server().size(), wrapped->context, @@ -1007,7 +1014,7 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey( const uint8_t* signature, size_t signature_length, const uint32_t* unaligned_nonce, const uint8_t* enc_rsa_key, size_t enc_rsa_key_length, const uint8_t* enc_rsa_key_iv, - uint8_t* wrapped_rsa_key, size_t* wrapped_rsa_key_length) { + uint8_t* wrapped_rsa_key, size_t* wrapped_rsa_key_length) { uint32_t nonce = unaligned_dereference_uint32(unaligned_nonce); if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls | kLoggingTraceNonce)) { LOGI("-- OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey(%d)\n", session); @@ -1023,7 +1030,7 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey( } if (wvcdm::g_cutoff >= wvcdm::LOG_VERBOSE) { dump_hex("enc_rsa_key", enc_rsa_key, enc_rsa_key_length); - dump_hex("enc_rsa_key_iv", enc_rsa_key_iv, wvcdm::KEY_IV_SIZE); + dump_hex("enc_rsa_key_iv", enc_rsa_key_iv, wvoec::KEY_IV_SIZE); } } if (!crypto_engine) { @@ -1072,8 +1079,7 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey( sizeof(uint32_t), true) || !RangeCheck(message, message_length, enc_rsa_key, enc_rsa_key_length, true) || - !RangeCheck(message, message_length, enc_rsa_key_iv, wvcdm::KEY_IV_SIZE, - true)) { + !RangeCheck(message, message_length, enc_rsa_key_iv, wvoec::KEY_IV_SIZE, true)) { LOGE("[OEMCrypto_RewrapDeviceRSAKey(): - range check.]"); return OEMCrypto_ERROR_INVALID_CONTEXT; } @@ -1133,7 +1139,8 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey( unsigned int sig_length = sizeof(wrapped->signature); if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) { LOGI(("message verified with HMAC and mac_key_server, key = " + - wvcdm::b2a_hex(session_ctx->mac_key_server())).c_str()); + wvcdm::b2a_hex(session_ctx->mac_key_server())) + .c_str()); } if (!HMAC(EVP_sha256(), &session_ctx->mac_key_server()[0], session_ctx->mac_key_server().size(), wrapped->context, @@ -1393,7 +1400,7 @@ extern "C" OEMCryptoResult OEMCrypto_GetHDCPCapability( } extern "C" uint32_t OEMCrypto_GetAnalogOutputFlags() { -// TODO(b/69867568, fredgc): parameterize this. + // TODO(b/69867568, fredgc): parameterize this. return 0; } @@ -1463,7 +1470,7 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Encrypt( algorithm); if (wvcdm::g_cutoff >= wvcdm::LOG_VERBOSE) { dump_hex("in_buffer", in_buffer, buffer_length); - dump_hex("iv", iv, wvcdm::KEY_IV_SIZE); + dump_hex("iv", iv, wvoec::KEY_IV_SIZE); } } if (!crypto_engine) { @@ -1502,7 +1509,7 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Decrypt( algorithm); if (wvcdm::g_cutoff >= wvcdm::LOG_VERBOSE) { dump_hex("in_buffer", in_buffer, buffer_length); - dump_hex("iv", iv, wvcdm::KEY_IV_SIZE); + dump_hex("iv", iv, wvoec::KEY_IV_SIZE); } } if (!crypto_engine) { @@ -1681,9 +1688,10 @@ extern "C" OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session, return sts; } -extern "C" OEMCryptoResult OEMCrypto_DeleteUsageEntry( - OEMCrypto_SESSION, const uint8_t*, size_t, const uint8_t*, size_t, - const uint8_t*, size_t) { +extern "C" OEMCryptoResult OEMCrypto_DeleteUsageEntry(OEMCrypto_SESSION, + const uint8_t*, size_t, + const uint8_t*, size_t, + const uint8_t*, size_t) { // TODO(fredgc): delete this. return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -1768,8 +1776,7 @@ extern "C" OEMCryptoResult OEMCrypto_RemoveSRM() { } extern "C" OEMCryptoResult OEMCrypto_CreateUsageTableHeader( - uint8_t* header_buffer, - size_t* header_buffer_length) { + uint8_t* header_buffer, size_t* header_buffer_length) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_CreateUsageTableHeader()\n"); } @@ -1781,8 +1788,8 @@ extern "C" OEMCryptoResult OEMCrypto_CreateUsageTableHeader( LOGE("OEMCrypto_CreateUsageTableHeader: Configured without Usage Tables."); return OEMCrypto_ERROR_NOT_IMPLEMENTED; } - return crypto_engine->usage_table() - .CreateUsageTableHeader(header_buffer, header_buffer_length); + return crypto_engine->usage_table().CreateUsageTableHeader( + header_buffer, header_buffer_length); } extern "C" OEMCryptoResult OEMCrypto_LoadUsageTableHeader( @@ -1943,15 +1950,11 @@ extern "C" OEMCryptoResult OEMCrypto_CopyOldUsageEntry( return session_ctx->CopyOldUsageEntry(pstv); } -extern "C" -OEMCryptoResult OEMCrypto_CreateOldUsageEntry(uint64_t time_since_license_received, - uint64_t time_since_first_decrypt, - uint64_t time_since_last_decrypt, - OEMCrypto_Usage_Entry_Status status, - uint8_t *server_mac_key, - uint8_t *client_mac_key, - const uint8_t* pst, - size_t pst_length) { +extern "C" OEMCryptoResult OEMCrypto_CreateOldUsageEntry( + uint64_t time_since_license_received, uint64_t time_since_first_decrypt, + uint64_t time_since_last_decrypt, OEMCrypto_Usage_Entry_Status status, + uint8_t* server_mac_key, uint8_t* client_mac_key, const uint8_t* pst, + size_t pst_length) { if (LogCategoryEnabled(kLoggingTraceOEMCryptoCalls)) { LOGI("-- OEMCryptoResult OEMCrypto_CreateOldUsageEntry()\n"); } @@ -1968,4 +1971,4 @@ OEMCryptoResult OEMCrypto_CreateOldUsageEntry(uint64_t time_since_license_receiv pst_length); } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_rsa_key_shared.cpp similarity index 96% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_rsa_key_shared.cpp index 2aa668a7..1166564c 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_rsa_key_shared.cpp @@ -2,7 +2,7 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // #include "oemcrypto_rsa_key_shared.h" @@ -16,7 +16,7 @@ #include "oemcrypto_logging.h" -namespace wvoec_mock { +namespace wvoec_ref { void dump_boringssl_error() { int count = 0; @@ -98,4 +98,4 @@ bool RSA_shared_ptr::LoadPkcs8RsaKey(const uint8_t* buffer, size_t length) { } } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_rsa_key_shared.h similarity index 92% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_rsa_key_shared.h index f39aa8d4..5910b376 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_rsa_key_shared.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_rsa_key_shared.h @@ -2,7 +2,7 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // #ifndef OEMCRYPTO_RSA_KEY_SHARED_H_ #define OEMCRYPTO_RSA_KEY_SHARED_H_ @@ -11,7 +11,7 @@ #include -namespace wvoec_mock { +namespace wvoec_ref { // Shared pointer with specialized destructor. This pointer is only shared // from a CryptoEngine to a Session -- so we don't have to use full reference @@ -37,6 +37,6 @@ class RSA_shared_ptr { // Log errors from BoringSSL. void dump_boringssl_error(); -} // namespace wvoec_mock +} // namespace wvoec_ref #endif // OEMCRYPTO_RSA_KEY_SHARED_H_ diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_scoped_ptr.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_scoped_ptr.h new file mode 100644 index 00000000..d631858a --- /dev/null +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_scoped_ptr.h @@ -0,0 +1,44 @@ +#ifndef OEMCRYPTO_SCOPED_PTR_H_ +#define OEMCRYPTO_SCOPED_PTR_H_ + +#include +#include + +#include + +namespace wvoec_ref { + +// TODO(fredgc, jfore): scoped_ptr may not be the best name for this smart +// pointer type. It basically works like auto_ptr which is deprecated. +#if __cplusplus < 201103L + +template +class scoped_ptr { + public: + explicit scoped_ptr(T* p = NULL) : ptr_(p) {} + T* get() const { return ptr_.get(); } + + private: + std::auto_ptr ptr_; +}; + +#else + +template +class scoped_ptr { + public: + explicit scoped_ptr(T* p = nullptr) : ptr_(p) {} + scoped_ptr(scoped_ptr& r) { ptr_ = std::move(r.ptr_); } + T& operator*() const { return *ptr_; } + T* operator->() const { return ptr_.get(); } + T* get() const { return ptr_.get(); } + void reset(T* p = NULL) { ptr_.reset(); } + + private: + std::unique_ptr ptr_; +}; +#endif + +} // namespace wvoec_ref + +#endif // OEMCRYPTO_SCOPED_PTR_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.cpp similarity index 93% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.cpp index 4894cd99..559fbfe8 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.cpp @@ -2,7 +2,7 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // #include "oemcrypto_session.h" @@ -26,12 +26,13 @@ #include "keys.h" #include "log.h" -#include "oemcrypto_engine_mock.h" -#include "oemcrypto_key_mock.h" +#include "oemcrypto_engine_ref.h" +#include "oemcrypto_key_ref.h" #include "oemcrypto_logging.h" #include "oemcrypto_rsa_key_shared.h" +#include "oemcrypto_types.h" +#include "disallow_copy_and_assign.h" #include "string_conversions.h" -#include "wv_cdm_constants.h" static const int kPssSaltLength = 20; @@ -47,7 +48,7 @@ void ctr128_inc64(uint8_t* counter) { } } // namespace -namespace wvoec_mock { +namespace wvoec_ref { /***************************************/ @@ -285,7 +286,7 @@ bool SessionContext::RSADeriveKeys( return false; } session_key_.resize(decrypted_size); - if (decrypted_size != static_cast(wvcdm::KEY_SIZE)) { + if (decrypted_size != static_cast(wvoec::KEY_SIZE)) { LOGE("[RSADeriveKeys(): error. Session key is wrong size: %d.]", decrypted_size); dump_boringssl_error(); @@ -306,7 +307,7 @@ bool SessionContext::GenerateSignature(const uint8_t* message, return false; } - if (mac_key_client_.size() != wvcdm::MAC_KEY_SIZE) { + if (mac_key_client_.size() != wvoec::MAC_KEY_SIZE) { return false; } @@ -320,7 +321,7 @@ bool SessionContext::GenerateSignature(const uint8_t* message, if (usage_entry_status_ == kUsageEntryLoaded) { usage_entry_mac_key_client.assign( usage_entry_->mac_key_client(), - usage_entry_->mac_key_client() + wvcdm::MAC_KEY_SIZE * sizeof(uint8_t)); + usage_entry_->mac_key_client() + wvoec::MAC_KEY_SIZE * sizeof(uint8_t)); using_usage_entry_mac_key_client = mac_key_client_ == usage_entry_mac_key_client; } @@ -335,7 +336,7 @@ bool SessionContext::GenerateSignature(const uint8_t* message, } unsigned int md_len = *signature_length; - if (HMAC(EVP_sha256(), &mac_key_client_[0], wvcdm::MAC_KEY_SIZE, message, + if (HMAC(EVP_sha256(), &mac_key_client_[0], wvoec::MAC_KEY_SIZE, message, message_length, signature, &md_len)) { *signature_length = md_len; return true; @@ -452,7 +453,7 @@ bool SessionContext::ValidateMessage(const uint8_t* given_message, OEMCryptoResult SessionContext::CheckStatusOnline(uint32_t nonce, uint32_t control) { - if (!(control & kControlNonceEnabled)) { + if (!(control & wvoec::kControlNonceEnabled)) { LOGE("LoadKeys: Server provided Nonce_Required but Nonce_Enabled = 0."); // Server error. Continue, and assume nonce required. } @@ -473,7 +474,7 @@ OEMCryptoResult SessionContext::CheckStatusOnline(uint32_t nonce, OEMCryptoResult SessionContext::CheckStatusOffline(uint32_t nonce, uint32_t control) { - if (control & kControlNonceEnabled) { + if (control & wvoec::kControlNonceEnabled) { LOGE("KCB: Server provided NonceOrEntry but Nonce_Enabled = 1."); // Server error. Continue, and assume nonce required. } @@ -495,17 +496,17 @@ OEMCryptoResult SessionContext::CheckStatusOffline(uint32_t nonce, OEMCryptoResult SessionContext::CheckNonceOrEntry( const KeyControlBlock& key_control_block) { - switch (key_control_block.control_bits() & kControlReplayMask) { - case kControlNonceRequired: // Online license. Nonce always required. + switch (key_control_block.control_bits() & wvoec::kControlReplayMask) { + case wvoec::kControlNonceRequired: // Online license. Nonce always required. return CheckStatusOnline(key_control_block.nonce(), key_control_block.control_bits()); break; - case kControlNonceOrEntry: // Offline license. Nonce required on first use. + case wvoec::kControlNonceOrEntry: // Offline license. Nonce required on first use. return CheckStatusOffline(key_control_block.nonce(), key_control_block.control_bits()); break; default: - if ((key_control_block.control_bits() & kControlNonceEnabled) && + if ((key_control_block.control_bits() & wvoec::kControlNonceEnabled) && (!CheckNonce(key_control_block.nonce()))) { LOGE("LoadKeys: BAD Nonce"); return OEMCrypto_ERROR_INVALID_NONCE; @@ -599,15 +600,15 @@ OEMCryptoResult SessionContext::LoadKeys( enc_key_data.assign(key_array[i].key_data, key_array[i].key_data + key_array[i].key_data_length); key_data_iv.assign(key_array[i].key_data_iv, - key_array[i].key_data_iv + wvcdm::KEY_IV_SIZE); + key_array[i].key_data_iv + wvoec::KEY_IV_SIZE); if (key_array[i].key_control == NULL) { status = OEMCrypto_ERROR_UNKNOWN_FAILURE; break; } key_control.assign(key_array[i].key_control, - key_array[i].key_control + wvcdm::KEY_CONTROL_SIZE); + key_array[i].key_control + wvoec::KEY_CONTROL_SIZE); key_control_iv.assign(key_array[i].key_control_iv, - key_array[i].key_control_iv + wvcdm::KEY_IV_SIZE); + key_array[i].key_control_iv + wvoec::KEY_IV_SIZE); OEMCryptoResult result = InstallKey(key_id, enc_key_data, key_data_iv, key_control, @@ -624,9 +625,9 @@ OEMCryptoResult SessionContext::LoadKeys( if (enc_mac_keys != NULL) { // V2.1 license protocol: update mac keys after processing license response const std::vector enc_mac_keys_str = std::vector( - enc_mac_keys, enc_mac_keys + 2 * wvcdm::MAC_KEY_SIZE); + enc_mac_keys, enc_mac_keys + 2 * wvoec::MAC_KEY_SIZE); const std::vector enc_mac_key_iv_str = std::vector( - enc_mac_key_iv, enc_mac_key_iv + wvcdm::KEY_IV_SIZE); + enc_mac_key_iv, enc_mac_key_iv + wvoec::KEY_IV_SIZE); if (!UpdateMacKeys(enc_mac_keys_str, enc_mac_key_iv_str)) { LOGE("Failed to update mac keys.\n"); @@ -763,14 +764,14 @@ OEMCryptoResult SessionContext::InstallKey( return OEMCrypto_ERROR_INVALID_CONTEXT; } if ((key_control_block.control_bits() & - kControlRequireAntiRollbackHardware) && + wvoec::kControlRequireAntiRollbackHardware) && !ce_->config_is_anti_rollback_hw_present()) { LOGE("Anti-rollback hardware is required but hardware not present."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } uint8_t minimum_patch_level = - (key_control_block.control_bits() & kControlSecurityPatchLevelMask) >> - kControlSecurityPatchLevelShift; + (key_control_block.control_bits() & wvoec::kControlSecurityPatchLevelMask) >> + wvoec::kControlSecurityPatchLevelShift; if (minimum_patch_level > OEMCrypto_Security_Patch_Level()) { LOGE("[InstallKey(): security patch level: %d. Minimum:%d]", OEMCrypto_Security_Patch_Level(), minimum_patch_level); @@ -781,13 +782,13 @@ OEMCryptoResult SessionContext::InstallKey( LOGE("LoadKeys: Failed Nonce/PST check."); return result; } - if (key_control_block.control_bits() & kSharedLicense) { + if (key_control_block.control_bits() & wvoec::kSharedLicense) { if (!second_license) { LOGE("LoadKeys: Shared License, but no keys previously loaded."); return OEMCrypto_ERROR_MISSING_MASTER; } } - if (key_control_block.control_bits() & kControlSRMVersionRequired) { + if (key_control_block.control_bits() & wvoec::kControlSRMVersionRequired) { if (srm_requirements_status_ == NoSRMVersion) { LOGE("[LoadKeys: control bit says SRM version required]"); return OEMCrypto_ERROR_INVALID_CONTEXT; @@ -818,7 +819,7 @@ bool SessionContext::InstallRSAEncryptedKey( return false; } encryption_key_.resize(decrypted_size); - if (decrypted_size != static_cast(wvcdm::KEY_SIZE)) { + if (decrypted_size != static_cast(wvoec::KEY_SIZE)) { LOGE("[RSADeriveKeys(): error. Session key is wrong size: %d.]", decrypted_size); dump_boringssl_error(); @@ -841,7 +842,7 @@ OEMCryptoResult SessionContext::RefreshKey( LOGE("Parse key control error."); return OEMCrypto_ERROR_INVALID_CONTEXT; } - if ((key_control_block.control_bits() & kControlNonceEnabled) && + if ((key_control_block.control_bits() & wvoec::kControlNonceEnabled) && (!CheckNonce(key_control_block.nonce()))) { LOGE("KCB: BAD Nonce"); return OEMCrypto_ERROR_INVALID_NONCE; @@ -896,7 +897,7 @@ OEMCryptoResult SessionContext::RefreshKey( } return OEMCrypto_ERROR_INVALID_CONTEXT; } - if ((key_control_block.control_bits() & kControlNonceEnabled) && + if ((key_control_block.control_bits() & wvoec::kControlNonceEnabled) && (!CheckNonce(key_control_block.nonce()))) { LOGE("KCB: BAD Nonce"); return OEMCrypto_ERROR_INVALID_NONCE; @@ -910,8 +911,8 @@ bool SessionContext::DecryptRSAKey(const uint8_t* enc_rsa_key, const uint8_t* enc_rsa_key_iv, uint8_t* pkcs8_rsa_key) { // Decrypt rsa key with keybox. - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, enc_rsa_key_iv, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, enc_rsa_key_iv, wvoec::KEY_IV_SIZE); AES_KEY aes_key; AES_set_decrypt_key(&encryption_key_[0], 128, &aes_key); AES_cbc_encrypt(enc_rsa_key, pkcs8_rsa_key, enc_rsa_key_length, &aes_key, @@ -924,8 +925,8 @@ bool SessionContext::EncryptRSAKey(const uint8_t* pkcs8_rsa_key, const uint8_t* enc_rsa_key_iv, uint8_t* enc_rsa_key) { // Encrypt rsa key with keybox. - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, enc_rsa_key_iv, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, enc_rsa_key_iv, wvoec::KEY_IV_SIZE); AES_KEY aes_key; AES_set_encrypt_key(&encryption_key_[0], 128, &aes_key); AES_cbc_encrypt(pkcs8_rsa_key, enc_rsa_key, enc_rsa_key_length, &aes_key, @@ -960,14 +961,14 @@ OEMCryptoResult SessionContext::CheckKeyUse(const std::string& log_string, LOGE("[%s(): control bit says not allowed.", log_string.c_str()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - if (control.control_bits() & kControlDataPathSecure) { + if (control.control_bits() & wvoec::kControlDataPathSecure) { if (!ce_->config_closed_platform() && buffer_type == OEMCrypto_BufferType_Clear) { LOGE("[%s(): Secure key with insecure buffer]", log_string.c_str()); return OEMCrypto_ERROR_DECRYPT_FAILED; } } - if (control.control_bits() & kControlReplayMask) { + if (control.control_bits() & wvoec::kControlReplayMask) { if (!CheckUsageEntry()) { LOGE("[%s(): usage entry not valid]", log_string.c_str()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; @@ -982,10 +983,10 @@ OEMCryptoResult SessionContext::CheckKeyUse(const std::string& log_string, if (!ce_->config_local_display_only()) { // Only look at HDCP and Analog restrictions if the display can be // non-local. - if (control.control_bits() & kControlHDCPRequired) { + if (control.control_bits() & wvoec::kControlHDCPRequired) { uint8_t required_hdcp = - (control.control_bits() & kControlHDCPVersionMask) >> - kControlHDCPVersionShift; + (control.control_bits() & wvoec::kControlHDCPVersionMask) >> + wvoec::kControlHDCPVersionShift; if (ce_->srm_blacklisted_device_attached()) { required_hdcp = HDCP_NO_DIGITAL_OUTPUT; } @@ -999,7 +1000,7 @@ OEMCryptoResult SessionContext::CheckKeyUse(const std::string& log_string, } if (!ce_->config_local_display_only() || buffer_type == OEMCrypto_BufferType_Clear) { - if (control.control_bits() & kControlDisableAnalogOutput) { + if (control.control_bits() & wvoec::kControlDisableAnalogOutput) { LOGE("[%s(): control bit says disable analog.", log_string.c_str()); return OEMCrypto_ERROR_ANALOG_OUTPUT; } @@ -1023,7 +1024,7 @@ OEMCryptoResult SessionContext::Generic_Encrypt(const uint8_t* in_buffer, LOGE("[Generic_Encrypt(): CONTENT_KEY has wrong size: %d", key.size()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - OEMCryptoResult result = CheckKeyUse("Generic_Encrypt", kControlAllowEncrypt, + OEMCryptoResult result = CheckKeyUse("Generic_Encrypt", wvoec::kControlAllowEncrypt, OEMCrypto_BufferType_Clear); if (result != OEMCrypto_SUCCESS) return result; if (algorithm != OEMCrypto_AES_CBC_128_NO_PADDING) { @@ -1040,8 +1041,8 @@ OEMCryptoResult SessionContext::Generic_Encrypt(const uint8_t* in_buffer, LOGE("[Generic_Encrypt(): FAILURE]"); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, iv, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, iv, wvoec::KEY_IV_SIZE); AES_cbc_encrypt(in_buffer, out_buffer, buffer_length, &aes_key, iv_buffer, AES_ENCRYPT); return OEMCrypto_SUCCESS; @@ -1063,7 +1064,7 @@ OEMCryptoResult SessionContext::Generic_Decrypt(const uint8_t* in_buffer, LOGE("[Generic_Decrypt(): CONTENT_KEY has wrong size."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - OEMCryptoResult result = CheckKeyUse("Generic_Decrypt", kControlAllowDecrypt, + OEMCryptoResult result = CheckKeyUse("Generic_Decrypt", wvoec::kControlAllowDecrypt, OEMCrypto_BufferType_Clear); if (result != OEMCrypto_SUCCESS) return result; @@ -1081,8 +1082,8 @@ OEMCryptoResult SessionContext::Generic_Decrypt(const uint8_t* in_buffer, LOGE("[Generic_Decrypt(): FAILURE]"); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, iv, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, iv, wvoec::KEY_IV_SIZE); AES_cbc_encrypt(in_buffer, out_buffer, buffer_length, &aes_key, iv_buffer, AES_DECRYPT); return OEMCrypto_SUCCESS; @@ -1108,7 +1109,7 @@ OEMCryptoResult SessionContext::Generic_Sign(const uint8_t* in_buffer, LOGE("[Generic_Sign(): CONTENT_KEY has wrong size; %d", key.size()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - OEMCryptoResult result = CheckKeyUse("Generic_Sign", kControlAllowSign, + OEMCryptoResult result = CheckKeyUse("Generic_Sign", wvoec::kControlAllowSign, OEMCrypto_BufferType_Clear); if (result != OEMCrypto_SUCCESS) return result; if (algorithm != OEMCrypto_HMAC_SHA256) { @@ -1144,7 +1145,7 @@ OEMCryptoResult SessionContext::Generic_Verify(const uint8_t* in_buffer, LOGE("[Generic_Verify(): CONTENT_KEY has wrong size: %d", key.size()); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - OEMCryptoResult result = CheckKeyUse("Generic_Verify", kControlAllowVerify, + OEMCryptoResult result = CheckKeyUse("Generic_Verify", wvoec::kControlAllowVerify, OEMCrypto_BufferType_Clear); if (result != OEMCrypto_SUCCESS) return result; if (algorithm != OEMCrypto_HMAC_SHA256) { @@ -1175,8 +1176,8 @@ bool SessionContext::UpdateMacKeys(const std::vector& enc_mac_keys, return false; } mac_key_server_ = std::vector( - mac_keys.begin(), mac_keys.begin() + wvcdm::MAC_KEY_SIZE); - mac_key_client_ = std::vector(mac_keys.begin() + wvcdm::MAC_KEY_SIZE, + mac_keys.begin(), mac_keys.begin() + wvoec::MAC_KEY_SIZE); + mac_key_client_ = std::vector(mac_keys.begin() + wvoec::MAC_KEY_SIZE, mac_keys.end()); if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) { LOGI(("mac_key_client_ has been updated to = " + @@ -1276,10 +1277,10 @@ OEMCryptoResult SessionContext::LoadUsageEntry( // Copy the mac keys to the current session. mac_key_server_ = std::vector( usage_entry_->mac_key_server(), - usage_entry_->mac_key_server() + wvcdm::MAC_KEY_SIZE); + usage_entry_->mac_key_server() + wvoec::MAC_KEY_SIZE); mac_key_client_ = std::vector( usage_entry_->mac_key_client(), - usage_entry_->mac_key_client() + wvcdm::MAC_KEY_SIZE); + usage_entry_->mac_key_client() + wvoec::MAC_KEY_SIZE); if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) { LOGI(("mac_key_client_ has been updated to = " + wvcdm::b2a_hex(mac_key_client_)).c_str()); @@ -1354,8 +1355,8 @@ OEMCryptoResult SessionContext::DecryptCENC( // If the data is clear, we do not need a current key selected. if (!is_encrypted) { if (buffer_type != OEMCrypto_BufferType_Direct) { - memcpy(reinterpret_cast(clear_data), cipher_data, - cipher_data_length); + memmove(reinterpret_cast(clear_data), cipher_data, + cipher_data_length); return OEMCrypto_SUCCESS; } // For reference implementation, we quietly drop the clear direct video. @@ -1420,7 +1421,7 @@ OEMCryptoResult SessionContext::DecryptCBC( pattern_offset = (pattern_offset + 1) % pattern_length; } if (skip_block || (size < AES_BLOCK_SIZE)) { - memcpy(&clear_data[l], &cipher_data[l], size); + memmove(&clear_data[l], &cipher_data[l], size); } else { uint8_t aes_output[AES_BLOCK_SIZE]; // Save the iv for the next block, in case cipher_data is in the same @@ -1458,7 +1459,7 @@ OEMCryptoResult SessionContext::PatternDecryptCTR( pattern_offset = (pattern_offset + 1) % pattern_length; } if (skip_block) { - memcpy(&clear_data[l], &cipher_data[l], size); + memmove(&clear_data[l], &cipher_data[l], size); } else { uint8_t aes_output[AES_BLOCK_SIZE]; AES_encrypt(iv, aes_output, &aes_key); @@ -1518,22 +1519,12 @@ OEMCryptoResult SessionContext::DecryptCTR(const uint8_t* key_u8, int out_len = 0; while (remaining) { -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) - EVP_CIPHER_CTX ctx_struct; - EVP_CIPHER_CTX* evp_cipher_ctx = &ctx_struct; - EVP_CIPHER_CTX_init(evp_cipher_ctx); -#else EVP_CIPHER_CTX* evp_cipher_ctx = EVP_CIPHER_CTX_new(); -#endif EVP_CIPHER_CTX_set_padding(evp_cipher_ctx, 0); if (!EVP_DecryptInit_ex(evp_cipher_ctx, EVP_aes_128_ctr(), NULL, key_u8, aes_iv_u8)) { LOGE("[DecryptCTR(): EVP_INIT ERROR]"); -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) - EVP_CIPHER_CTX_cleanup(evp_cipher_ctx); -#else EVP_CIPHER_CTX_free(evp_cipher_ctx); -#endif return OEMCrypto_ERROR_DECRYPT_FAILED; } @@ -1553,11 +1544,7 @@ OEMCryptoResult SessionContext::DecryptCTR(const uint8_t* key_u8, if (!EVP_DecryptUpdate(evp_cipher_ctx, &clear_data[l], &out_len, &cipher_data[l], decrypt_length)) { LOGE("[DecryptCTR(): EVP_UPDATE_ERROR]"); -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) - EVP_CIPHER_CTX_cleanup(evp_cipher_ctx); -#else EVP_CIPHER_CTX_free(evp_cipher_ctx); -#endif return OEMCrypto_ERROR_DECRYPT_FAILED; } l += decrypt_length; @@ -1568,18 +1555,10 @@ OEMCryptoResult SessionContext::DecryptCTR(const uint8_t* key_u8, &clear_data[cipher_data_length - remaining], &final)) { LOGE("[DecryptCTR(): EVP_FINAL_ERROR]"); -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) - EVP_CIPHER_CTX_cleanup(evp_cipher_ctx); -#else EVP_CIPHER_CTX_free(evp_cipher_ctx); -#endif return OEMCrypto_ERROR_DECRYPT_FAILED; } -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) - EVP_CIPHER_CTX_cleanup(evp_cipher_ctx); -#else EVP_CIPHER_CTX_free(evp_cipher_ctx); -#endif // If remaining is not zero, reset the iv before the second pass. if (remaining) { @@ -1590,4 +1569,4 @@ OEMCryptoResult SessionContext::DecryptCTR(const uint8_t* key_u8, return OEMCrypto_SUCCESS; } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.h similarity index 96% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.h index ff81932d..11be5197 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session.h @@ -2,10 +2,10 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef MOCK_OEMCRYPTO_SESSION_H_ -#define MOCK_OEMCRYPTO_SESSION_H_ +#ifndef REF_OEMCRYPTO_SESSION_H_ +#define REF_OEMCRYPTO_SESSION_H_ #include #include @@ -15,17 +15,15 @@ #include #include "OEMCryptoCENC.h" // Needed for enums only. -#include "file_store.h" -#include "lock.h" -#include "oemcrypto_auth_mock.h" -#include "oemcrypto_key_mock.h" +#include "oemcrypto_auth_ref.h" +#include "oemcrypto_key_ref.h" #include "oemcrypto_nonce_table.h" #include "oemcrypto_rsa_key_shared.h" #include "oemcrypto_session_key_table.h" -#include "oemcrypto_usage_table_mock.h" -#include "wv_cdm_types.h" +#include "oemcrypto_usage_table_ref.h" +#include "oemcrypto_types.h" -namespace wvoec_mock { +namespace wvoec_ref { class CryptoEngine; typedef uint32_t SessionId; @@ -245,6 +243,6 @@ class SessionContext { CORE_DISALLOW_COPY_AND_ASSIGN(SessionContext); }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // MOCK_OEMCRYPTO_SESSION_H_ +#endif // REF_OEMCRYPTO_SESSION_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session_key_table.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session_key_table.cpp similarity index 97% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_session_key_table.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_session_key_table.cpp index c7a1ae6d..e8e737a6 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session_key_table.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session_key_table.cpp @@ -2,14 +2,14 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // #include "oemcrypto_session_key_table.h" #include "keys.h" #include "log.h" -namespace wvoec_mock { +namespace wvoec_ref { SessionKeyTable::~SessionKeyTable() { for (KeyMap::iterator i = keys_.begin(); i != keys_.end(); ++i) { @@ -116,4 +116,4 @@ bool EntitlementKeyTable::GetEntitlementKey( return true; } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session_key_table.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session_key_table.h similarity index 84% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_session_key_table.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_session_key_table.h index 3f6a4f44..694e19d8 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_session_key_table.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_session_key_table.h @@ -2,19 +2,20 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef MOCK_OEMCRYPTO_SESSION_KEY_TABLE_H_ -#define MOCK_OEMCRYPTO_SESSION_KEY_TABLE_H_ +#ifndef REF_OEMCRYPTO_SESSION_KEY_TABLE_H_ +#define REF_OEMCRYPTO_SESSION_KEY_TABLE_H_ #include #include #include -#include "oemcrypto_key_mock.h" -#include "wv_cdm_types.h" +#include "disallow_copy_and_assign.h" +#include "oemcrypto_key_ref.h" +#include "oemcrypto_types.h" -namespace wvoec_mock { +namespace wvoec_ref { class SessionContext; class CryptoEngine; @@ -65,6 +66,6 @@ class EntitlementKeyTable { CORE_DISALLOW_COPY_AND_ASSIGN(EntitlementKeyTable); }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // MOCK_OEMCRYPTO_SESSION_KEY_TABLE_H_ +#endif // REF_OEMCRYPTO_SESSION_KEY_TABLE_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_usage_table_mock.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.cpp similarity index 89% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_usage_table_mock.cpp rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.cpp index 8ad51bc0..564632e2 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_usage_table_mock.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.cpp @@ -2,9 +2,9 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#include "oemcrypto_usage_table_mock.h" +#include "oemcrypto_usage_table_ref.h" #include #include @@ -19,15 +19,16 @@ #include "file_store.h" #include "log.h" -#include "oemcrypto_engine_mock.h" +#include "oemcrypto_engine_ref.h" #include "oemcrypto_logging.h" -#include "oemcrypto_old_usage_table_mock.h" -#include "properties.h" +#include "oemcrypto_old_usage_table_ref.h" +// TODO(fredgc): Setting the device files base bath is currently broken as +// wvcdm::Properties is no longer used by the reference code. +//#include "properties.h" #include "pst_report.h" #include "string_conversions.h" -#include "wv_cdm_constants.h" -namespace wvoec_mock { +namespace wvoec_ref { namespace { const size_t kMagicLength = 8; const char* kEntryVerification = "USEENTRY"; @@ -84,19 +85,19 @@ bool UsageTableEntry::VerifyPST(const uint8_t* pst, size_t pst_length) { bool UsageTableEntry::VerifyMacKeys(const std::vector& server, const std::vector& client) { - return (server.size() == wvcdm::MAC_KEY_SIZE) && - (client.size() == wvcdm::MAC_KEY_SIZE) && - (0 == memcmp(&server[0], data_.mac_key_server, wvcdm::MAC_KEY_SIZE)) && - (0 == memcmp(&client[0], data_.mac_key_client, wvcdm::MAC_KEY_SIZE)); + return (server.size() == wvoec::MAC_KEY_SIZE) && + (client.size() == wvoec::MAC_KEY_SIZE) && + (0 == memcmp(&server[0], data_.mac_key_server, wvoec::MAC_KEY_SIZE)) && + (0 == memcmp(&client[0], data_.mac_key_client, wvoec::MAC_KEY_SIZE)); } bool UsageTableEntry::SetMacKeys(const std::vector& server, const std::vector& client) { - if ((server.size() != wvcdm::MAC_KEY_SIZE) || - (client.size() != wvcdm::MAC_KEY_SIZE)) + if ((server.size() != wvoec::MAC_KEY_SIZE) || + (client.size() != wvoec::MAC_KEY_SIZE)) return false; - memcpy(data_.mac_key_server, &server[0], wvcdm::MAC_KEY_SIZE); - memcpy(data_.mac_key_client, &client[0], wvcdm::MAC_KEY_SIZE); + memcpy(data_.mac_key_server, &server[0], wvoec::MAC_KEY_SIZE); + memcpy(data_.mac_key_client, &client[0], wvoec::MAC_KEY_SIZE); return true; } @@ -130,13 +131,12 @@ OEMCryptoResult UsageTableEntry::ReportUsage(const std::vector& pst, if (recent_decrypt_) return OEMCrypto_ERROR_ENTRY_NEEDS_UPDATE; if (pst.size() == 0 || pst.size() > kMaxPSTLength || pst.size() != data_.pst_length) { - LOGE("ReportUsage: bad pst length = %d, should be %d.", - pst.size(), data_.pst_length); + LOGE("ReportUsage: bad pst length = %d, should be %d.", pst.size(), + data_.pst_length); return OEMCrypto_ERROR_WRONG_PST; } if (memcmp(&pst[0], data_.pst, data_.pst_length)) { - LOGE("ReportUsage: wrong pst %s, should be %s.", - wvcdm::b2a_hex(pst).c_str(), + LOGE("ReportUsage: wrong pst %s, should be %s.", wvcdm::b2a_hex(pst).c_str(), wvcdm::HexEncode(data_.pst, data_.pst_length).c_str()); return OEMCrypto_ERROR_WRONG_PST; } @@ -163,12 +163,13 @@ OEMCryptoResult UsageTableEntry::ReportUsage(const std::vector& pst, if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) { std::vector mac_key_client( data_.mac_key_client, - data_.mac_key_client + wvcdm::MAC_KEY_SIZE * sizeof(uint8_t)); + data_.mac_key_client + wvoec::MAC_KEY_SIZE * sizeof(uint8_t)); LOGI(("message signed with HMAC and data_.mac_key_client, " "mac_key_client = " + - wvcdm::b2a_hex(mac_key_client)).c_str()); + wvcdm::b2a_hex(mac_key_client)) + .c_str()); } - if (!HMAC(EVP_sha1(), data_.mac_key_client, wvcdm::MAC_KEY_SIZE, + if (!HMAC(EVP_sha1(), data_.mac_key_client, wvoec::MAC_KEY_SIZE, buffer + SHA_DIGEST_LENGTH, length_needed - SHA_DIGEST_LENGTH, pst_report.signature(), &md_len)) { LOGE("ReportUsage: could not compute signature."); @@ -209,9 +210,9 @@ OEMCryptoResult UsageTableEntry::SaveData(CryptoEngine* ce, const std::vector& key = ce->DeviceRootKey(override_to_real); // Encrypt the entry. - RAND_bytes(encrypted->iv, wvcdm::KEY_IV_SIZE); - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; // working iv buffer. - memcpy(iv_buffer, encrypted->iv, wvcdm::KEY_IV_SIZE); + RAND_bytes(encrypted->iv, wvoec::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; // working iv buffer. + memcpy(iv_buffer, encrypted->iv, wvoec::KEY_IV_SIZE); AES_KEY aes_key; AES_set_encrypt_key(&key[0], 128, &aes_key); AES_cbc_encrypt( @@ -265,8 +266,8 @@ OEMCryptoResult UsageTableEntry::LoadData(CryptoEngine* ce, uint32_t index, } // Next, decrypt the entry. - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, encrypted->iv, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, encrypted->iv, wvoec::KEY_IV_SIZE); AES_KEY aes_key; AES_set_decrypt_key(&key[0], 128, &aes_key); AES_cbc_encrypt(&buffer[kEncryptionOffset], &clear_buffer[kEncryptionOffset], @@ -279,7 +280,8 @@ OEMCryptoResult UsageTableEntry::LoadData(CryptoEngine* ce, uint32_t index, wvcdm::HexEncode(clear->verification, kMagicLength).c_str(), clear->verification, wvcdm::HexEncode(reinterpret_cast(kEntryVerification), - kMagicLength).c_str(), + kMagicLength) + .c_str(), reinterpret_cast(kEntryVerification)); return OEMCrypto_ERROR_BAD_MAGIC; } @@ -306,23 +308,23 @@ OEMCryptoResult UsageTableEntry::CopyOldUsageEntry( data_.time_of_first_decrypt = old_entry->time_of_first_decrypt_; data_.time_of_last_decrypt = old_entry->time_of_last_decrypt_; data_.status = old_entry->status_; - if (old_entry->mac_key_server_.size() != wvcdm::MAC_KEY_SIZE) { + if (old_entry->mac_key_server_.size() != wvoec::MAC_KEY_SIZE) { LOGE("CopyOldEntry: Old entry has bad server mac key."); } else { memcpy(data_.mac_key_server, &(old_entry->mac_key_server_[0]), - wvcdm::MAC_KEY_SIZE); + wvoec::MAC_KEY_SIZE); } - if (old_entry->mac_key_client_.size() != wvcdm::MAC_KEY_SIZE) { + if (old_entry->mac_key_client_.size() != wvoec::MAC_KEY_SIZE) { LOGE("CopyOldEntry: Old entry has bad client mac key."); } else { memcpy(data_.mac_key_client, &(old_entry->mac_key_client_[0]), - wvcdm::MAC_KEY_SIZE); + wvoec::MAC_KEY_SIZE); if (LogCategoryEnabled(kLoggingDumpDerivedKeys)) { std::vector mac_key_client( data_.mac_key_client, - data_.mac_key_client + wvcdm::MAC_KEY_SIZE * sizeof(uint8_t)); - LOGI(("data_.mac_key_client has changed to = " + - wvcdm::b2a_hex(mac_key_client)).c_str()); + data_.mac_key_client + wvoec::MAC_KEY_SIZE * sizeof(uint8_t)); + LOGI(("data_.mac_key_client has changed to = " + + wvcdm::b2a_hex(mac_key_client)).c_str()); } } if (pst.size() > kMaxPSTLength) { @@ -336,12 +338,11 @@ OEMCryptoResult UsageTableEntry::CopyOldUsageEntry( return OEMCrypto_SUCCESS; } - size_t UsageTableEntry::SignedEntrySize() { size_t base = sizeof(SignedEntryBlock); // round up to make even number of blocks: - size_t blocks = (base - 1) / wvcdm::KEY_IV_SIZE + 1; - return blocks * wvcdm::KEY_IV_SIZE; + size_t blocks = (base - 1) / wvoec::KEY_IV_SIZE + 1; + return blocks * wvoec::KEY_IV_SIZE; } UsageTable::~UsageTable() { @@ -354,8 +355,8 @@ UsageTable::~UsageTable() { size_t UsageTable::SignedHeaderSize(size_t count) { size_t base = sizeof(SignedHeaderBlock) + count * sizeof(int64_t); // round up to make even number of blocks: - size_t blocks = (base - 1) / wvcdm::KEY_IV_SIZE + 1; - return blocks * wvcdm::KEY_IV_SIZE; + size_t blocks = (base - 1) / wvoec::KEY_IV_SIZE + 1; + return blocks * wvoec::KEY_IV_SIZE; } OEMCryptoResult UsageTable::UpdateUsageEntry(SessionContext* session, @@ -503,9 +504,9 @@ OEMCryptoResult UsageTable::SaveUsageTableHeader(uint8_t* signed_buffer, const std::vector& key = ce_->DeviceRootKey(override_to_real); // Encrypt the entry. - RAND_bytes(encrypted->iv, wvcdm::KEY_IV_SIZE); - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; // working iv buffer. - memcpy(iv_buffer, encrypted->iv, wvcdm::KEY_IV_SIZE); + RAND_bytes(encrypted->iv, wvoec::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; // working iv buffer. + memcpy(iv_buffer, encrypted->iv, wvoec::KEY_IV_SIZE); AES_KEY aes_key; AES_set_encrypt_key(&key[0], 128, &aes_key); AES_cbc_encrypt( @@ -558,8 +559,8 @@ OEMCryptoResult UsageTable::LoadUsageTableHeader( } // Next, decrypt the entry. - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, encrypted->iv, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, encrypted->iv, wvoec::KEY_IV_SIZE); AES_KEY aes_key; AES_set_decrypt_key(&key[0], 128, &aes_key); AES_cbc_encrypt(&buffer[kEncryptionOffset], &clear_buffer[kEncryptionOffset], @@ -572,7 +573,8 @@ OEMCryptoResult UsageTable::LoadUsageTableHeader( wvcdm::HexEncode(clear->verification, kMagicLength).c_str(), clear->verification, wvcdm::HexEncode(reinterpret_cast(kHeaderVerification), - kMagicLength).c_str(), + kMagicLength) + .c_str(), reinterpret_cast(kHeaderVerification)); return OEMCrypto_ERROR_BAD_MAGIC; } @@ -641,11 +643,13 @@ bool UsageTable::SaveGenerationNumber() { std::string path; // Note: this path is OK for a real implementation, but using security level 1 // would be better. - if (!wvcdm::Properties::GetDeviceFilesBasePath(wvcdm::kSecurityLevelL3, + // TODO(jfore, rfrias): Address how this property is presented to the ref. + // For now, the path is empty. + /*if (!Properties::GetDeviceFilesBasePath(kSecurityLevelL3, &path)) { LOGE("UsageTable: Unable to get base path"); return false; - } + }*/ // On a real implementation, you should NOT put the generation number in // a file in user space. It should be stored in secure memory. std::string filename = path + "GenerationNumber.dat"; @@ -666,16 +670,17 @@ bool UsageTable::LoadGenerationNumber(bool or_make_new_one) { std::string path; // Note: this path is OK for a real implementation, but using security level 1 // would be better. - if (!wvcdm::Properties::GetDeviceFilesBasePath(wvcdm::kSecurityLevelL3, + // TODO(jfore, rfrias): Address how this property is presented to the ref. + // For now, the path is empty. + /*if (!Properties::GetDeviceFilesBasePath(kSecurityLevelL3, &path)) { LOGE("UsageTable: Unable to get base path"); return false; - } + }*/ // On a real implementation, you should NOT put the generation number in // a file in user space. It should be stored in secure memory. std::string filename = path + "GenerationNumber.dat"; - wvcdm::File* file = file_system->Open(filename, - wvcdm::FileSystem::kReadOnly); + wvcdm::File* file = file_system->Open(filename, wvcdm::FileSystem::kReadOnly); if (!file) { if (or_make_new_one) { RAND_bytes(reinterpret_cast(&master_generation_number_), @@ -702,7 +707,7 @@ OEMCryptoResult UsageTable::CreateUsageTableHeader( *header_buffer_length = signed_header_size; if (!LoadGenerationNumber(true)) return OEMCrypto_ERROR_UNKNOWN_FAILURE; // Make sure there are no entries that are currently tied to an open session. - for (size_t i=0; i < sessions_.size(); ++i) { + for (size_t i = 0; i < sessions_.size(); ++i) { if (sessions_[i] != NULL) { LOGE("CreateUsageTableHeader: index %d used by session.", i); return OEMCrypto_ERROR_INVALID_SESSION; @@ -736,8 +741,8 @@ OEMCryptoResult UsageTable::CreateOldUsageEntry( uint8_t* server_mac_key, uint8_t* client_mac_key, const uint8_t* pst, size_t pst_length) { if (!old_table_) old_table_ = new OldUsageTable(ce_); - std::vector pstv(pst, pst+pst_length); - OldUsageTableEntry *old_entry = old_table_->CreateEntry(pstv); + std::vector pstv(pst, pst + pst_length); + OldUsageTableEntry* old_entry = old_table_->CreateEntry(pstv); int64_t now = time(NULL); old_entry->time_of_license_received_ = now - time_since_license_received; @@ -745,10 +750,10 @@ OEMCryptoResult UsageTable::CreateOldUsageEntry( old_entry->time_of_last_decrypt_ = now - time_since_last_decrypt; old_entry->status_ = status; old_entry->mac_key_server_.assign(server_mac_key, - server_mac_key + wvcdm::MAC_KEY_SIZE); + server_mac_key + wvoec::MAC_KEY_SIZE); old_entry->mac_key_client_.assign(client_mac_key, - client_mac_key + wvcdm::MAC_KEY_SIZE); + client_mac_key + wvoec::MAC_KEY_SIZE); return OEMCrypto_SUCCESS; } -} // namespace wvoec_mock +} // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_usage_table_mock.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.h similarity index 93% rename from libwvdrmengine/oemcrypto/mock/src/oemcrypto_usage_table_mock.h rename to libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.h index 1dcfe6ea..b9cf64b9 100644 --- a/libwvdrmengine/oemcrypto/mock/src/oemcrypto_usage_table_mock.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_usage_table_ref.h @@ -2,10 +2,10 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. // -// Mock implementation of OEMCrypto APIs +// Ref implementation of OEMCrypto APIs // -#ifndef OEMCRYPTO_USAGE_TABLE_MOCK_H_ -#define OEMCRYPTO_USAGE_TABLE_MOCK_H_ +#ifndef OEMCRYPTO_USAGE_TABLE_REF_H_ +#define OEMCRYPTO_USAGE_TABLE_REF_H_ #include #include @@ -13,12 +13,10 @@ #include #include "OEMCryptoCENC.h" -#include "file_store.h" -#include "lock.h" #include "openssl/sha.h" -#include "wv_cdm_constants.h" +#include "oemcrypto_types.h" -namespace wvoec_mock { +namespace wvoec_ref { class SessionContext; class CryptoEngine; @@ -34,8 +32,8 @@ struct StoredUsageEntry { int64_t time_of_first_decrypt; int64_t time_of_last_decrypt; enum OEMCrypto_Usage_Entry_Status status; - uint8_t mac_key_server[wvcdm::MAC_KEY_SIZE]; - uint8_t mac_key_client[wvcdm::MAC_KEY_SIZE]; + uint8_t mac_key_server[wvoec::MAC_KEY_SIZE]; + uint8_t mac_key_client[wvoec::MAC_KEY_SIZE]; uint32_t index; uint8_t pst[kMaxPSTLength+1]; // add 1 for padding. uint8_t pst_length; @@ -134,6 +132,6 @@ class UsageTable { OldUsageTable *old_table_; }; -} // namespace wvoec_mock +} // namespace wvoec_ref -#endif // OEMCRYPTO_USAGE_TABLE_MOCK_H_ +#endif // OEMCRYPTO_USAGE_TABLE_REF_H_ diff --git a/libwvdrmengine/oemcrypto/mock/src/wvcrc.cpp b/libwvdrmengine/oemcrypto/ref/src/wvcrc.cpp similarity index 100% rename from libwvdrmengine/oemcrypto/mock/src/wvcrc.cpp rename to libwvdrmengine/oemcrypto/ref/src/wvcrc.cpp diff --git a/libwvdrmengine/oemcrypto/mock/src/wvcrc32.h b/libwvdrmengine/oemcrypto/ref/src/wvcrc32.h similarity index 100% rename from libwvdrmengine/oemcrypto/mock/src/wvcrc32.h rename to libwvdrmengine/oemcrypto/ref/src/wvcrc32.h diff --git a/libwvdrmengine/oemcrypto/test/Android.mk b/libwvdrmengine/oemcrypto/test/Android.mk index 5b9a1d1b..26350cd2 100644 --- a/libwvdrmengine/oemcrypto/test/Android.mk +++ b/libwvdrmengine/oemcrypto/test/Android.mk @@ -2,6 +2,9 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) +LOCAL_C_INCLUDES := \ + vendor/widevine/libwvdrmengine/cdm/util/include \ + LOCAL_MODULE:=oemcrypto_test LOCAL_MODULE_TAGS := tests diff --git a/libwvdrmengine/oemcrypto/test/common.mk b/libwvdrmengine/oemcrypto/test/common.mk index bf2254f1..647eb67c 100644 --- a/libwvdrmengine/oemcrypto/test/common.mk +++ b/libwvdrmengine/oemcrypto/test/common.mk @@ -17,6 +17,7 @@ LOCAL_C_INCLUDES += \ $(LOCAL_PATH)/../include \ $(LOCAL_PATH)/../mock/src \ vendor/widevine/libwvdrmengine/cdm/core/include \ + vendor/widevine/libwvdrmengine/cdm/util/include \ LOCAL_STATIC_LIBRARIES := \ libcdm \ diff --git a/libwvdrmengine/oemcrypto/test/oec_device_features.h b/libwvdrmengine/oemcrypto/test/oec_device_features.h index becea2af..f8929d7f 100644 --- a/libwvdrmengine/oemcrypto/test/oec_device_features.h +++ b/libwvdrmengine/oemcrypto/test/oec_device_features.h @@ -4,7 +4,7 @@ #include #include "OEMCryptoCENC.h" -#include "wv_keybox.h" +#include "oemcrypto_types.h" namespace wvoec { diff --git a/libwvdrmengine/oemcrypto/test/oec_session_util.cpp b/libwvdrmengine/oemcrypto/test/oec_session_util.cpp index 6c546cf6..64907fb8 100644 --- a/libwvdrmengine/oemcrypto/test/oec_session_util.cpp +++ b/libwvdrmengine/oemcrypto/test/oec_session_util.cpp @@ -26,14 +26,12 @@ #include #include "OEMCryptoCENC.h" +#include "disallow_copy_and_assign.h" #include "log.h" #include "oec_device_features.h" #include "oec_test_data.h" -#include "oemcrypto_key_mock.h" +#include "oemcrypto_types.h" #include "string_conversions.h" -#include "wv_cdm_constants.h" -#include "wv_cdm_types.h" -#include "wv_keybox.h" using namespace std; @@ -102,9 +100,9 @@ Session::Session() : open_(false), forced_session_id_(false), session_id_(0), - mac_key_server_(wvcdm::MAC_KEY_SIZE), - mac_key_client_(wvcdm::MAC_KEY_SIZE), - enc_key_(wvcdm::KEY_SIZE), + mac_key_server_(MAC_KEY_SIZE), + mac_key_client_(MAC_KEY_SIZE), + enc_key_(KEY_SIZE), public_rsa_(0), message_size_(sizeof(MessageData)), // Most tests only use 4 keys. Other tests will explicitly call @@ -187,7 +185,7 @@ void Session::DeriveKey(const uint8_t* key, const vector& context, CMAC_CTX* cmac_ctx = CMAC_CTX_new(); ASSERT_NE(static_cast(NULL), cmac_ctx); - ASSERT_EQ(1, CMAC_Init(cmac_ctx, key, wvcdm::KEY_SIZE, cipher, 0)); + ASSERT_EQ(1, CMAC_Init(cmac_ctx, key, KEY_SIZE, cipher, 0)); std::vector message; message.push_back(counter); @@ -223,7 +221,7 @@ void Session::DeriveKeys(const uint8_t* master_key, } void Session::GenerateDerivedKeysFromKeybox( - const wvoec_mock::WidevineKeybox& keybox) { + const wvoec::WidevineKeybox& keybox) { GenerateNonce(); vector mac_context; vector enc_context; @@ -269,9 +267,9 @@ void Session::LoadTestKeys(const std::string& pst, bool new_mac_keys) { key_array_, pst_ptr, pst.length(), NULL, OEMCrypto_ContentLicense)); // Update new generated keys. - memcpy(&mac_key_server_[0], license_.mac_keys, wvcdm::MAC_KEY_SIZE); - memcpy(&mac_key_client_[0], license_.mac_keys + wvcdm::MAC_KEY_SIZE, - wvcdm::MAC_KEY_SIZE); + memcpy(&mac_key_server_[0], license_.mac_keys, MAC_KEY_SIZE); + memcpy(&mac_key_client_[0], license_.mac_keys + MAC_KEY_SIZE, + MAC_KEY_SIZE); } else { ASSERT_EQ( OEMCrypto_SUCCESS, @@ -299,9 +297,9 @@ void Session::LoadEnitlementTestKeys(const std::string& pst, key_array_, pst_ptr, pst.length(), NULL, OEMCrypto_EntitlementLicense)); // Update new generated keys. - memcpy(&mac_key_server_[0], license_.mac_keys, wvcdm::MAC_KEY_SIZE); - memcpy(&mac_key_client_[0], license_.mac_keys + wvcdm::MAC_KEY_SIZE, - wvcdm::MAC_KEY_SIZE); + memcpy(&mac_key_server_[0], license_.mac_keys, MAC_KEY_SIZE); + memcpy(&mac_key_client_[0], license_.mac_keys + MAC_KEY_SIZE, + MAC_KEY_SIZE); } else { ASSERT_EQ( expected_sts, @@ -479,7 +477,7 @@ void Session::FillSimpleMessage(uint32_t duration, uint32_t control, memset(license_.keys[i].key_id, i, license_.keys[i].key_id_length); EXPECT_EQ(1, GetRandBytes(license_.keys[i].key_data, sizeof(license_.keys[i].key_data))); - license_.keys[i].key_data_length = wvcdm::KEY_SIZE; + license_.keys[i].key_data_length = KEY_SIZE; EXPECT_EQ(1, GetRandBytes(license_.keys[i].key_iv, sizeof(license_.keys[i].key_iv))); EXPECT_EQ(1, GetRandBytes(license_.keys[i].control_iv, @@ -493,14 +491,14 @@ void Session::FillSimpleMessage(uint32_t duration, uint32_t control, } else if (global_features.api_version == 12) { // For version 12, we require OEMCrypto to handle kc12 for all licenses. memcpy(license_.keys[i].control.verification, "kc12", 4); - } else if (control & wvoec_mock::kControlSecurityPatchLevelMask) { + } else if (control & wvoec::kControlSecurityPatchLevelMask) { // For versions before 12, we require the special key control block only // when there are newer features present. memcpy(license_.keys[i].control.verification, "kc11", 4); - } else if (control & wvoec_mock::kControlRequireAntiRollbackHardware) { + } else if (control & wvoec::kControlRequireAntiRollbackHardware) { memcpy(license_.keys[i].control.verification, "kc10", 4); - } else if (control & (wvoec_mock::kControlHDCPVersionMask | - wvoec_mock::kControlReplayMask)) { + } else if (control & (wvoec::kControlHDCPVersionMask | + wvoec::kControlReplayMask)) { memcpy(license_.keys[i].control.verification, "kc09", 4); } else { memcpy(license_.keys[i].control.verification, "kctl", 4); @@ -526,7 +524,7 @@ void Session::FillSimpleEntitlementMessage( memset(license_.keys[i].key_id, i, license_.keys[i].key_id_length); EXPECT_EQ(1, GetRandBytes(license_.keys[i].key_data, sizeof(license_.keys[i].key_data))); - license_.keys[i].key_data_length = wvcdm::KEY_SIZE * 2; // AES-256 keys + license_.keys[i].key_data_length = KEY_SIZE * 2; // AES-256 keys EXPECT_EQ(1, GetRandBytes(license_.keys[i].key_iv, sizeof(license_.keys[i].key_iv))); EXPECT_EQ(1, GetRandBytes(license_.keys[i].control_iv, @@ -540,14 +538,14 @@ void Session::FillSimpleEntitlementMessage( } else if (global_features.api_version == 12) { // For version 12, we require OEMCrypto to handle kc12 for all licenses. memcpy(license_.keys[i].control.verification, "kc12", 4); - } else if (control & wvoec_mock::kControlSecurityPatchLevelMask) { + } else if (control & wvoec::kControlSecurityPatchLevelMask) { // For versions before 12, we require the special key control block only // when there are newer features present. memcpy(license_.keys[i].control.verification, "kc11", 4); - } else if (control & wvoec_mock::kControlRequireAntiRollbackHardware) { + } else if (control & wvoec::kControlRequireAntiRollbackHardware) { memcpy(license_.keys[i].control.verification, "kc10", 4); - } else if (control & (wvoec_mock::kControlHDCPVersionMask | - wvoec_mock::kControlReplayMask)) { + } else if (control & (wvoec::kControlHDCPVersionMask | + wvoec::kControlReplayMask)) { memcpy(license_.keys[i].control.verification, "kc09", 4); } else { memcpy(license_.keys[i].control.verification, "kctl", 4); @@ -591,21 +589,21 @@ void Session::EncryptAndSign() { encrypted_license() = license_; uint8_t iv_buffer[16]; - memcpy(iv_buffer, &license_.mac_key_iv[0], wvcdm::KEY_IV_SIZE); + memcpy(iv_buffer, &license_.mac_key_iv[0], KEY_IV_SIZE); AES_KEY aes_key; AES_set_encrypt_key(&enc_key_[0], 128, &aes_key); AES_cbc_encrypt(&license_.mac_keys[0], &encrypted_license().mac_keys[0], - 2 * wvcdm::MAC_KEY_SIZE, &aes_key, iv_buffer, AES_ENCRYPT); + 2 * MAC_KEY_SIZE, &aes_key, iv_buffer, AES_ENCRYPT); for (unsigned int i = 0; i < num_keys_; i++) { - memcpy(iv_buffer, &license_.keys[i].control_iv[0], wvcdm::KEY_IV_SIZE); + memcpy(iv_buffer, &license_.keys[i].control_iv[0], KEY_IV_SIZE); AES_set_encrypt_key(&license_.keys[i].key_data[0], 128, &aes_key); AES_cbc_encrypt( reinterpret_cast(&license_.keys[i].control), reinterpret_cast(&encrypted_license().keys[i].control), - wvcdm::KEY_SIZE, &aes_key, iv_buffer, AES_ENCRYPT); + KEY_SIZE, &aes_key, iv_buffer, AES_ENCRYPT); - memcpy(iv_buffer, &license_.keys[i].key_iv[0], wvcdm::KEY_IV_SIZE); + memcpy(iv_buffer, &license_.keys[i].key_iv[0], KEY_IV_SIZE); AES_set_encrypt_key(&enc_key_[0], 128, &aes_key); AES_cbc_encrypt( &license_.keys[i].key_data[0], &encrypted_license().keys[i].key_data[0], @@ -620,14 +618,14 @@ void Session::EncryptAndSign() { void Session::EncryptProvisioningMessage( RSAPrivateKeyMessage* data, RSAPrivateKeyMessage* encrypted, const vector& encryption_key) { - ASSERT_EQ(encryption_key.size(), wvcdm::KEY_SIZE); + ASSERT_EQ(encryption_key.size(), KEY_SIZE); *encrypted = *data; - size_t padding = wvcdm::KEY_SIZE - (data->rsa_key_length % wvcdm::KEY_SIZE); + size_t padding = KEY_SIZE - (data->rsa_key_length % KEY_SIZE); memset(data->rsa_key + data->rsa_key_length, static_cast(padding), padding); encrypted->rsa_key_length = data->rsa_key_length + padding; uint8_t iv_buffer[16]; - memcpy(iv_buffer, &data->rsa_key_iv[0], wvcdm::KEY_IV_SIZE); + memcpy(iv_buffer, &data->rsa_key_iv[0], KEY_IV_SIZE); AES_KEY aes_key; AES_set_encrypt_key(&encryption_key[0], 128, &aes_key); AES_cbc_encrypt(&data->rsa_key[0], &encrypted->rsa_key[0], @@ -740,8 +738,8 @@ void Session::TestDecryptCTR(bool select_key_first, for (size_t i = 0; i < unencryptedData.size(); i++) unencryptedData[i] = i % 256; EXPECT_EQ(1, GetRandBytes(&unencryptedData[0], unencryptedData.size())); - vector encryptionIv(wvcdm::KEY_IV_SIZE); - EXPECT_EQ(1, GetRandBytes(&encryptionIv[0], wvcdm::KEY_IV_SIZE)); + vector encryptionIv(KEY_IV_SIZE); + EXPECT_EQ(1, GetRandBytes(&encryptionIv[0], KEY_IV_SIZE)); vector encryptedData(unencryptedData.size()); EncryptCTR(unencryptedData, license_.keys[key_index].key_data, &encryptionIv[0], &encryptedData); @@ -893,7 +891,7 @@ void Session::MakeRSACertificate(struct RSAPrivateKeyMessage* encrypted, memcpy(message.rsa_key, rsa_key.data(), rsa_key.size()); message.rsa_key_length = rsa_key.size(); } - EXPECT_EQ(1, GetRandBytes(message.rsa_key_iv, wvcdm::KEY_IV_SIZE)); + EXPECT_EQ(1, GetRandBytes(message.rsa_key_iv, KEY_IV_SIZE)); message.nonce = nonce_; EncryptProvisioningMessage(&message, encrypted, *encryption_key); diff --git a/libwvdrmengine/oemcrypto/test/oec_session_util.h b/libwvdrmengine/oemcrypto/test/oec_session_util.h index 60c84ecf..05645cdd 100644 --- a/libwvdrmengine/oemcrypto/test/oec_session_util.h +++ b/libwvdrmengine/oemcrypto/test/oec_session_util.h @@ -12,8 +12,8 @@ #include #include "oec_device_features.h" +#include "oemcrypto_types.h" #include "pst_report.h" -#include "wv_cdm_constants.h" using namespace std; @@ -66,10 +66,10 @@ const size_t kMaxDecryptSize = 100 * 1024; // In specification. typedef struct { uint8_t key_id[kTestKeyIdMaxLength]; size_t key_id_length; - uint8_t key_data[wvcdm::MAC_KEY_SIZE]; + uint8_t key_data[MAC_KEY_SIZE]; size_t key_data_length; - uint8_t key_iv[wvcdm::KEY_IV_SIZE]; - uint8_t control_iv[wvcdm::KEY_IV_SIZE]; + uint8_t key_iv[KEY_IV_SIZE]; + uint8_t control_iv[KEY_IV_SIZE]; KeyControlBlock control; // Note: cipher_mode may not be part of a real signed message. For these // tests, it is convenient to keep it in this structure anyway. @@ -79,8 +79,8 @@ typedef struct { // This structure will be signed to simulate a message from the server. struct MessageData { MessageKeyData keys[kMaxNumKeys]; - uint8_t mac_key_iv[wvcdm::KEY_IV_SIZE]; - uint8_t mac_keys[2 * wvcdm::MAC_KEY_SIZE]; + uint8_t mac_key_iv[KEY_IV_SIZE]; + uint8_t mac_keys[2 * MAC_KEY_SIZE]; uint8_t pst[kMaxPSTLength]; }; @@ -88,7 +88,7 @@ struct MessageData { // server. struct RSAPrivateKeyMessage { uint8_t rsa_key[kMaxTestRSAKeyLength]; - uint8_t rsa_key_iv[wvcdm::KEY_IV_SIZE]; + uint8_t rsa_key_iv[KEY_IV_SIZE]; size_t rsa_key_length; uint32_t nonce; }; @@ -107,10 +107,10 @@ struct Test_PST_Report { }; struct EntitledContentKeyData { - uint8_t entitlement_key_id[wvcdm::KEY_SIZE]; - uint8_t content_key_id[wvcdm::KEY_SIZE]; - uint8_t content_key_data_iv[wvcdm::KEY_SIZE]; - uint8_t content_key_data[wvcdm::KEY_SIZE]; + uint8_t entitlement_key_id[KEY_SIZE]; + uint8_t content_key_id[KEY_SIZE]; + uint8_t content_key_data_iv[KEY_SIZE]; + uint8_t content_key_data[KEY_SIZE]; }; // Increment counter for AES-CTR. The CENC spec specifies we increment only @@ -152,7 +152,7 @@ class Session { vector* enc_context); // Generate known mac and enc keys using OEMCrypto_GenerateDerivedKeys and // also fill out enc_key_, mac_key_server_, and mac_key_client_. - void GenerateDerivedKeysFromKeybox(const wvoec_mock::WidevineKeybox& keybox); + void GenerateDerivedKeysFromKeybox(const wvoec::WidevineKeybox& keybox); // Generate known mac and enc keys using OEMCrypto_DeriveKeysFromSessionKey // and also fill out enc_key_, mac_key_server_, and mac_key_client_. void GenerateDerivedKeysFromSessionKey(); diff --git a/libwvdrmengine/oemcrypto/test/oec_test_data.h b/libwvdrmengine/oemcrypto/test/oec_test_data.h index 23e5d774..dc2d09fc 100644 --- a/libwvdrmengine/oemcrypto/test/oec_test_data.h +++ b/libwvdrmengine/oemcrypto/test/oec_test_data.h @@ -10,7 +10,8 @@ #include #include "OEMCryptoCENC.h" -#include "wv_keybox.h" +#include "oemcrypto_types.h" + namespace wvoec { @@ -20,7 +21,7 @@ namespace wvoec { // The first keybox, kTestKeybox, with deviceID "TestKey01" is used for most of // the tests. It should be loaded by OEMCrypto when OEMCrypto_LoadTestKeybox // is called. -static const wvoec_mock::WidevineKeybox kTestKeybox = { +static const wvoec::WidevineKeybox kTestKeybox = { // Sample keybox used for test vectors { // deviceID = WidevineTestOnlyKeybox000 @@ -55,7 +56,7 @@ static const wvoec_mock::WidevineKeybox kTestKeybox = { // These are old test keyboxes. The first keybox can be used to update an // older OEMCrypto because it is the same keybox that was previously used in // unit tests. -static const wvoec_mock::WidevineKeybox kValidKeybox01 = { +static const wvoec::WidevineKeybox kValidKeybox01 = { // Sample keybox used for test vectors { // deviceID @@ -87,7 +88,7 @@ static const wvoec_mock::WidevineKeybox kValidKeybox01 = { } }; -static const wvoec_mock::WidevineKeybox kValidKeybox02 = { +static const wvoec::WidevineKeybox kValidKeybox02 = { // Sample keybox used for test vectors { // deviceID @@ -119,7 +120,7 @@ static const wvoec_mock::WidevineKeybox kValidKeybox02 = { } }; -static const wvoec_mock::WidevineKeybox kValidKeybox03 = { +static const wvoec::WidevineKeybox kValidKeybox03 = { // Sample keybox used for test vectors { // deviceID diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.cpp index 1a1b09be..d0163627 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.cpp @@ -82,10 +82,10 @@ void SessionUtil::CreateWrappedRSAKey(uint32_t allowed_schemes, } } -void SessionUtil::InstallKeybox(const wvoec_mock::WidevineKeybox& keybox, +void SessionUtil::InstallKeybox(const wvoec::WidevineKeybox& keybox, bool good) { - uint8_t wrapped[sizeof(wvoec_mock::WidevineKeybox)]; - size_t length = sizeof(wvoec_mock::WidevineKeybox); + uint8_t wrapped[sizeof(wvoec::WidevineKeybox)]; + size_t length = sizeof(wvoec::WidevineKeybox); keybox_ = keybox; ASSERT_EQ( OEMCrypto_SUCCESS, diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.h b/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.h index f0124c63..2f4010d2 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.h +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_session_tests_helper.h @@ -26,7 +26,7 @@ public: // If force is true, we assert that the key loads successfully. void CreateWrappedRSAKey(uint32_t allowed_schemes, bool force); - void InstallKeybox(const wvoec_mock::WidevineKeybox& keybox, bool good); + void InstallKeybox(const wvoec::WidevineKeybox& keybox, bool good); void EnsureTestKeys(); @@ -34,7 +34,7 @@ public: std::vector encoded_rsa_key_; std::vector wrapped_rsa_key_; - wvoec_mock::WidevineKeybox keybox_; + wvoec::WidevineKeybox keybox_; }; } // namespace wvoec diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index dab958dc..fc00f9a4 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -34,11 +34,12 @@ #include "oec_session_util.h" #include "oec_test_data.h" #include "oemcrypto_session_tests_helper.h" -#include "oemcrypto_key_mock.h" -#include "properties.h" +#include "oemcrypto_types.h" #include "string_conversions.h" -#include "wv_cdm_constants.h" -#include "wv_keybox.h" + +#ifdef CDM_TESTS +#include "properties.h" +#endif using ::testing::Bool; using ::testing::Combine; @@ -64,11 +65,7 @@ void PrintTo(const tuplecurrent_test_info(); @@ -682,7 +681,7 @@ TEST_F(OEMCryptoSessionTestKeyboxTest, GoodForceKeybox) { ASSERT_EQ(DeviceFeatures::FORCE_TEST_KEYBOX, global_features.derive_key_method) << "ForceKeybox tests will modify the installed keybox."; - wvoec_mock::WidevineKeybox keybox = kValidKeybox02; + wvoec::WidevineKeybox keybox = kValidKeybox02; OEMCryptoResult sts; InstallKeybox(keybox, true); sts = OEMCrypto_IsKeyboxValid(); @@ -698,7 +697,7 @@ TEST_F(OEMCryptoSessionTestKeyboxTest, BadCRCForceKeybox) { ASSERT_EQ(DeviceFeatures::FORCE_TEST_KEYBOX, global_features.derive_key_method) << "ForceKeybox tests will modify the installed keybox."; - wvoec_mock::WidevineKeybox keybox = kValidKeybox02; + wvoec::WidevineKeybox keybox = kValidKeybox02; keybox.crc_[1] ^= 42; OEMCryptoResult sts; InstallKeybox(keybox, false); @@ -710,7 +709,7 @@ TEST_F(OEMCryptoSessionTestKeyboxTest, BadMagicForceKeybox) { ASSERT_EQ(DeviceFeatures::FORCE_TEST_KEYBOX, global_features.derive_key_method) << "ForceKeybox tests will modify the installed keybox."; - wvoec_mock::WidevineKeybox keybox = kValidKeybox02; + wvoec::WidevineKeybox keybox = kValidKeybox02; keybox.magic_[1] ^= 42; OEMCryptoResult sts; InstallKeybox(keybox, false); @@ -722,7 +721,7 @@ TEST_F(OEMCryptoSessionTestKeyboxTest, BadDataForceKeybox) { ASSERT_EQ(DeviceFeatures::FORCE_TEST_KEYBOX, global_features.derive_key_method) << "ForceKeybox tests will modify the installed keybox."; - wvoec_mock::WidevineKeybox keybox = kValidKeybox02; + wvoec::WidevineKeybox keybox = kValidKeybox02; keybox.data_[1] ^= 42; OEMCryptoResult sts; InstallKeybox(keybox, false); @@ -775,7 +774,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyWithNonce) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(0, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + s.FillSimpleMessage(0, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); } @@ -792,7 +791,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeySeveralNonce) { s.GenerateNonce(); // three. s.GenerateNonce(); // four. ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(0, wvoec_mock::kControlNonceEnabled, first_nonce)); + s.FillSimpleMessage(0, wvoec::kControlNonceEnabled, first_nonce)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); } @@ -965,7 +964,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyWithBadRange4) { vector bad_buffer( s.encrypted_license().keys[1].key_data, - s.encrypted_license().keys[1].key_data + wvcdm::KEY_SIZE); + s.encrypted_license().keys[1].key_data + wvoec::KEY_SIZE); s.key_array()[1].key_data = &bad_buffer[0]; OEMCryptoResult sts = OEMCrypto_LoadKeys( @@ -1039,7 +1038,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyWithBadNonce) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(0, - wvoec_mock::kControlNonceEnabled, + wvoec::kControlNonceEnabled, 42)); // bad nonce. ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); OEMCryptoResult sts = OEMCrypto_LoadKeys( @@ -1057,7 +1056,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyWithRepeatNonce) { ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); uint32_t nonce = s.get_nonce(); ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(0, wvoec_mock::kControlNonceEnabled, nonce)); + s.FillSimpleMessage(0, wvoec::kControlNonceEnabled, nonce)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); ASSERT_NO_FATAL_FAILURE(s.close()); @@ -1065,7 +1064,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyWithRepeatNonce) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(0, - wvoec_mock::kControlNonceEnabled, + wvoec::kControlNonceEnabled, nonce)); // same old nonce. ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); OEMCryptoResult sts = OEMCrypto_LoadKeys( @@ -1091,8 +1090,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyNonceReopenSession) { // and might not clear out the nonce table correctly. ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); - ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(0, - wvoec_mock::kControlNonceEnabled, + ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(0, wvoec::kControlNonceEnabled, nonce)); // same old nonce ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); OEMCryptoResult sts = OEMCrypto_LoadKeys( @@ -1117,8 +1115,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyNonceWrongSession) { Session s2; ASSERT_NO_FATAL_FAILURE(s2.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s2)); - ASSERT_NO_FATAL_FAILURE(s2.FillSimpleMessage(0, - wvoec_mock::kControlNonceEnabled, + ASSERT_NO_FATAL_FAILURE(s2.FillSimpleMessage(0, wvoec::kControlNonceEnabled, nonce)); // nonce from session s1 ASSERT_NO_FATAL_FAILURE(s2.EncryptAndSign()); OEMCryptoResult sts = OEMCrypto_LoadKeys( @@ -1245,7 +1242,7 @@ TEST_F(OEMCryptoSessionTests, LoadKeyNoKeyWithNonce) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(0, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + s.FillSimpleMessage(0, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); int kNoKeys = 0; ASSERT_NE( @@ -1261,7 +1258,7 @@ TEST_F(OEMCryptoSessionTests, QueryKeyControl) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(0, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + s.FillSimpleMessage(0, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); // Note: successful cases are tested in VerifyTestKeys. @@ -1288,7 +1285,7 @@ TEST_F(OEMCryptoSessionTests, AntiRollbackHardwareRequired) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlRequireAntiRollbackHardware, 0)); + 0, wvoec::kControlRequireAntiRollbackHardware, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); OEMCryptoResult sts = OEMCrypto_LoadKeys( s.session_id(), s.message_ptr(), s.message_size(), &s.signature()[0], @@ -1310,7 +1307,7 @@ TEST_F(OEMCryptoSessionTests, CheckMinimumPatchLevel) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, patch_level << wvoec_mock::kControlSecurityPatchLevelShift, 0)); + 0, patch_level << wvoec::kControlSecurityPatchLevelShift, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_EQ( OEMCrypto_SUCCESS, @@ -1326,7 +1323,7 @@ TEST_F(OEMCryptoSessionTests, CheckMinimumPatchLevel) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, (patch_level + 1) << wvoec_mock::kControlSecurityPatchLevelShift, + 0, (patch_level + 1) << wvoec::kControlSecurityPatchLevelShift, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_EQ( @@ -1343,7 +1340,7 @@ TEST_F(OEMCryptoSessionTests, CheckMinimumPatchLevel) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, (patch_level - 1) << wvoec_mock::kControlSecurityPatchLevelShift, + 0, (patch_level - 1) << wvoec::kControlSecurityPatchLevelShift, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_EQ( @@ -1385,8 +1382,8 @@ class SessionTestDecryptWithHDCP : public OEMCryptoSessionTests, ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( 0, - (version << wvoec_mock::kControlHDCPVersionShift) | - wvoec_mock::kControlObserveHDCP | wvoec_mock::kControlHDCPRequired, + (version << wvoec::kControlHDCPVersionShift) | + wvoec::kControlObserveHDCP | wvoec::kControlHDCPRequired, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); @@ -1430,14 +1427,14 @@ TEST_P(SessionTestRefreshKeyTest, RefreshWithNonce) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - kDuration, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + kDuration, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys("", new_mac_keys_)); s.GenerateNonce(); // License renewal message is signed by client and verified by the server. ASSERT_NO_FATAL_FAILURE(s.VerifyClientSignature()); ASSERT_NO_FATAL_FAILURE(s.RefreshTestKeys(num_keys_, - wvoec_mock::kControlNonceEnabled, + wvoec::kControlNonceEnabled, s.get_nonce(), OEMCrypto_SUCCESS)); } @@ -1460,14 +1457,14 @@ TEST_P(SessionTestRefreshKeyTest, RefreshOldNonceAPI11) { ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); uint32_t nonce = s.get_nonce(); ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(kDuration, wvoec_mock::kControlNonceEnabled, nonce)); + s.FillSimpleMessage(kDuration, wvoec::kControlNonceEnabled, nonce)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys("", new_mac_keys_)); // License renewal message is signed by client and verified by the server. ASSERT_NO_FATAL_FAILURE(s.VerifyClientSignature()); // Tryinng to reuse the same nonce. ASSERT_NO_FATAL_FAILURE( - s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce, + s.RefreshTestKeys(num_keys_, wvoec::kControlNonceEnabled, nonce, OEMCrypto_ERROR_INVALID_NONCE)); } @@ -1476,7 +1473,7 @@ TEST_P(SessionTestRefreshKeyTest, RefreshBadNonceAPI11) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - kDuration, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + kDuration, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys("", new_mac_keys_)); s.GenerateNonce(); @@ -1484,7 +1481,7 @@ TEST_P(SessionTestRefreshKeyTest, RefreshBadNonceAPI11) { ASSERT_NO_FATAL_FAILURE(s.VerifyClientSignature()); uint32_t nonce = s.get_nonce() ^ 42; ASSERT_NO_FATAL_FAILURE( - s.RefreshTestKeys(num_keys_, wvoec_mock::kControlNonceEnabled, nonce, + s.RefreshTestKeys(num_keys_, wvoec::kControlNonceEnabled, nonce, OEMCrypto_ERROR_INVALID_NONCE)); } @@ -1494,7 +1491,7 @@ TEST_P(SessionTestRefreshKeyTest, RefreshLargeBuffer) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - kDuration, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + kDuration, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys("", new_mac_keys_)); s.GenerateNonce(); @@ -1502,7 +1499,7 @@ TEST_P(SessionTestRefreshKeyTest, RefreshLargeBuffer) { // This uses a large buffer for the renewal message. ASSERT_NO_FATAL_FAILURE(s.VerifyClientSignature(kMaxMessageSize)); ASSERT_NO_FATAL_FAILURE(s.RefreshTestKeys(num_keys_, - wvoec_mock::kControlNonceEnabled, + wvoec::kControlNonceEnabled, s.get_nonce(), OEMCrypto_SUCCESS)); } @@ -1514,7 +1511,7 @@ TEST_P(SessionTestRefreshKeyTest, RefreshWithNoSelectKey) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - kDuration, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + kDuration, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys("", new_mac_keys_)); // Call select key before the refresh. No calls below to TestDecryptCTR with @@ -1528,7 +1525,7 @@ TEST_P(SessionTestRefreshKeyTest, RefreshWithNoSelectKey) { // message is not actually encrypted. It is, however, signed. // FillRefreshMessage fills the message with a duration of kLongDuration. ASSERT_NO_FATAL_FAILURE(s.FillRefreshMessage( - num_keys_, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + num_keys_, wvoec::kControlNonceEnabled, s.get_nonce())); s.ServerSignBuffer(reinterpret_cast(&s.encrypted_license()), s.message_size(), &s.signature()); OEMCrypto_KeyRefreshObject key_array[num_keys_]; @@ -2136,7 +2133,7 @@ TEST_F(OEMCryptoSessionTests, DecryptSecureToClear) { ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( kDuration, - wvoec_mock::kControlObserveDataPath | wvoec_mock::kControlDataPathSecure, + wvoec::kControlObserveDataPath | wvoec::kControlDataPathSecure, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); @@ -2149,7 +2146,7 @@ TEST_F(OEMCryptoSessionTests, DecryptNoAnalogToClearAPI13) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - kDuration, wvoec_mock::kControlDisableAnalogOutput, 0)); + kDuration, wvoec::kControlDisableAnalogOutput, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); ASSERT_NO_FATAL_FAILURE( @@ -2161,7 +2158,7 @@ TEST_F(OEMCryptoSessionTests, KeyDuration) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - kDuration, wvoec_mock::kControlNonceEnabled, s.get_nonce())); + kDuration, wvoec::kControlNonceEnabled, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR(true, OEMCrypto_SUCCESS)); @@ -3823,22 +3820,22 @@ class GenericCryptoTest : public OEMCryptoSessionTests { ASSERT_NO_FATAL_FAILURE( session_.FillSimpleMessage(duration, control, nonce, pst)); session_.license().keys[0].control.control_bits |= - htonl(wvoec_mock::kControlAllowEncrypt); + htonl(wvoec::kControlAllowEncrypt); session_.license().keys[1].control.control_bits |= - htonl(wvoec_mock::kControlAllowDecrypt); + htonl(wvoec::kControlAllowDecrypt); session_.license().keys[2].control.control_bits |= - htonl(wvoec_mock::kControlAllowSign); + htonl(wvoec::kControlAllowSign); session_.license().keys[3].control.control_bits |= - htonl(wvoec_mock::kControlAllowVerify); + htonl(wvoec::kControlAllowVerify); - session_.license().keys[2].key_data_length = wvcdm::MAC_KEY_SIZE; - session_.license().keys[3].key_data_length = wvcdm::MAC_KEY_SIZE; + session_.license().keys[2].key_data_length = wvoec::MAC_KEY_SIZE; + session_.license().keys[3].key_data_length = wvoec::MAC_KEY_SIZE; clear_buffer_.assign(buffer_size_, 0); for (size_t i = 0; i < clear_buffer_.size(); i++) { clear_buffer_[i] = 1 + i % 250; } - for (size_t i = 0; i < wvcdm::KEY_IV_SIZE; i++) { + for (size_t i = 0; i < wvoec::KEY_IV_SIZE; i++) { iv_[i] = i; } } @@ -3854,8 +3851,8 @@ class GenericCryptoTest : public OEMCryptoSessionTests { ASSERT_EQ(0, AES_set_encrypt_key(session_.license().keys[key_index].key_data, AES_BLOCK_SIZE * 8, &aes_key)); - uint8_t iv_buffer[wvcdm::KEY_IV_SIZE]; - memcpy(iv_buffer, iv_, wvcdm::KEY_IV_SIZE); + uint8_t iv_buffer[wvoec::KEY_IV_SIZE]; + memcpy(iv_buffer, iv_, wvoec::KEY_IV_SIZE); out_buffer->resize(in_buffer.size()); ASSERT_GT(in_buffer.size(), 0u); ASSERT_EQ(0u, in_buffer.size() % AES_BLOCK_SIZE); @@ -3869,7 +3866,7 @@ class GenericCryptoTest : public OEMCryptoSessionTests { unsigned int md_len = SHA256_DIGEST_LENGTH; signature->resize(SHA256_DIGEST_LENGTH); HMAC(EVP_sha256(), session_.license().keys[key_index].key_data, - wvcdm::MAC_KEY_SIZE, &in_buffer[0], in_buffer.size(), + wvoec::MAC_KEY_SIZE, &in_buffer[0], in_buffer.size(), signature->data(), &md_len); } @@ -3953,7 +3950,7 @@ class GenericCryptoTest : public OEMCryptoSessionTests { size_t buffer_size_; vector clear_buffer_; vector encrypted_buffer_; - uint8_t iv_[wvcdm::KEY_IV_SIZE]; + uint8_t iv_[wvoec::KEY_IV_SIZE]; Session session_; }; @@ -4048,7 +4045,7 @@ TEST_F(GenericCryptoTest, GenericKeyDecryptSameBufferAPI12) { TEST_F(GenericCryptoTest, GenericSecureToClear) { session_.license().keys[1].control.control_bits |= htonl( - wvoec_mock::kControlObserveDataPath | wvoec_mock::kControlDataPathSecure); + wvoec::kControlObserveDataPath | wvoec::kControlDataPathSecure); EncryptAndLoadKeys(); unsigned int key_index = 1; vector encrypted; @@ -4370,7 +4367,7 @@ class GenericCryptoKeyIdLengthTest : public GenericCryptoTest { const uint32_t kNoNonce = 0; session_.set_num_keys(5); ASSERT_NO_FATAL_FAILURE(session_.FillSimpleMessage( - kDuration, wvoec_mock::kControlAllowDecrypt, kNoNonce)); + kDuration, wvoec::kControlAllowDecrypt, kNoNonce)); SetUniformKeyIdLength(16); // Start with all key ids being 16 bytes. // But, we are testing that the key ids do not have to have the same length. session_.SetKeyId(0, "123456789012"); // 12 bytes (common key id length). @@ -4461,7 +4458,7 @@ class UsageTableTest : public GenericCryptoTest { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceOrEntry, s.get_nonce(), pst)); + 0, wvoec::kControlNonceOrEntry, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys(pst, new_mac_keys_)); @@ -4508,7 +4505,7 @@ TEST_P(UsageTableTestWithMAC, OnlineLicense) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -4538,7 +4535,7 @@ TEST_P(UsageTableTestWithMAC, OnlineLicenseUnused) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -4562,7 +4559,7 @@ TEST_P(UsageTableTestWithMAC, ForbidReportWithNoUpdate) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -4592,7 +4589,7 @@ TEST_P(UsageTableTestWithMAC, OnlineLicenseWithRefresh) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -4605,7 +4602,7 @@ TEST_P(UsageTableTestWithMAC, OnlineLicenseWithRefresh) { size_t kAllKeys = 1; ASSERT_NO_FATAL_FAILURE(s.RefreshTestKeys( kAllKeys, - wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), OEMCrypto_SUCCESS)); ASSERT_NO_FATAL_FAILURE(s.UpdateUsageEntry(&encrypted_usage_header_)); ASSERT_NO_FATAL_FAILURE( @@ -4621,7 +4618,7 @@ TEST_F(UsageTableTest, RepeatOnlineLicense) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -4652,7 +4649,7 @@ TEST_F(UsageTableTest, OnlineEmptyPST) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -4672,7 +4669,7 @@ TEST_F(UsageTableTest, OnlineMissingEntry) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); // ENTRY NOT CREATED: ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -4689,7 +4686,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoEncrypt) { std::string pst = "A PST"; uint32_t nonce = session_.get_nonce(); MakeFourKeys( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, nonce, pst); ASSERT_NO_FATAL_FAILURE(session_.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(session_.CreateNewUsageEntry()); @@ -4726,7 +4723,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoDecrypt) { std::string pst = "my_pst"; uint32_t nonce = session_.get_nonce(); MakeFourKeys( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, nonce, pst); ASSERT_NO_FATAL_FAILURE(session_.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(session_.CreateNewUsageEntry()); @@ -4763,7 +4760,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoSign) { std::string pst = "my_pst"; uint32_t nonce = session_.get_nonce(); MakeFourKeys( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, nonce, pst); ASSERT_NO_FATAL_FAILURE(session_.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(session_.CreateNewUsageEntry()); @@ -4811,7 +4808,7 @@ TEST_P(UsageTableTestWithMAC, GenericCryptoVerify) { std::string pst = "my_pst"; uint32_t nonce = session_.get_nonce(); MakeFourKeys( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, nonce, pst); ASSERT_NO_FATAL_FAILURE(session_.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(session_.CreateNewUsageEntry()); @@ -4854,7 +4851,7 @@ TEST_P(UsageTableTestWithMAC, OfflineLicenseRefresh) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceOrEntry, s.get_nonce(), pst)); + 0, wvoec::kControlNonceOrEntry, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys(pst, new_mac_keys_)); @@ -4865,7 +4862,7 @@ TEST_P(UsageTableTestWithMAC, OfflineLicenseRefresh) { ASSERT_NO_FATAL_FAILURE(s.VerifyClientSignature()); size_t kAllKeys = 1; ASSERT_NO_FATAL_FAILURE(s.RefreshTestKeys( - kAllKeys, wvoec_mock::kControlNonceOrEntry, 0, OEMCrypto_SUCCESS)); + kAllKeys, wvoec::kControlNonceOrEntry, 0, OEMCrypto_SUCCESS)); ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR()); ASSERT_NO_FATAL_FAILURE(s.UpdateUsageEntry(&encrypted_usage_header_)); ASSERT_NO_FATAL_FAILURE( @@ -4918,7 +4915,7 @@ TEST_P(UsageTableTestWithMAC, ReloadOfflineLicenseWithRefresh) { decrypt_time)); // last decrypt size_t kAllKeys = 1; ASSERT_NO_FATAL_FAILURE(s.RefreshTestKeys( - kAllKeys, wvoec_mock::kControlNonceOrEntry, 0, OEMCrypto_SUCCESS)); + kAllKeys, wvoec::kControlNonceOrEntry, 0, OEMCrypto_SUCCESS)); ASSERT_NO_FATAL_FAILURE(s.TestDecryptCTR()); ASSERT_NO_FATAL_FAILURE(s.UpdateUsageEntry(&encrypted_usage_header_)); ASSERT_NO_FATAL_FAILURE(s.GenerateVerifyReport(pst, kActive, @@ -4963,7 +4960,7 @@ TEST_P(UsageTableTestWithMAC, BadReloadOfflineLicense) { ASSERT_NO_FATAL_FAILURE(s2.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s2)); ASSERT_NO_FATAL_FAILURE(s2.FillSimpleMessage( - 0, wvoec_mock::kControlNonceOrEntry, s2.get_nonce(), pst)); + 0, wvoec::kControlNonceOrEntry, s2.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s2.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s2.LoadUsageEntry(s)); uint8_t* pst_ptr = s2.encrypted_license().pst; @@ -4997,7 +4994,7 @@ TEST_P(UsageTableTestWithMAC, OfflineBadNonce) { ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(0, wvoec_mock::kControlNonceOrEntry, 42, pst)); + s.FillSimpleMessage(0, wvoec::kControlNonceOrEntry, 42, pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); uint8_t* pst_ptr = s.encrypted_license().pst; OEMCryptoResult sts = OEMCrypto_LoadKeys( @@ -5016,7 +5013,7 @@ TEST_P(UsageTableTestWithMAC, OfflineEmptyPST) { ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); ASSERT_NO_FATAL_FAILURE( - s.FillSimpleMessage(0, wvoec_mock::kControlNonceOrEntry, s.get_nonce())); + s.FillSimpleMessage(0, wvoec::kControlNonceOrEntry, s.get_nonce())); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); OEMCryptoResult sts = OEMCrypto_LoadKeys( s.session_id(), s.message_ptr(), s.message_size(), &s.signature()[0], @@ -5141,7 +5138,7 @@ TEST_P(UsageTableTestWithMAC, BadRange) { ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(session_.CreateNewUsageEntry()); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceOrEntry, s.get_nonce(), pst)); + 0, wvoec::kControlNonceOrEntry, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); uint8_t* pst_ptr = s.license().pst; // Bad: not in encrypted_license. ASSERT_NE( @@ -5160,7 +5157,7 @@ TEST_F(UsageTableTest, UpdateFailsWithNullPtr) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -5190,7 +5187,7 @@ class UsageTableDefragTest : public UsageTableTest { char c2 = 'A' + (index % 26); pst = pst + c1 + c2; ASSERT_NO_FATAL_FAILURE(s->FillSimpleMessage( - 0, wvoec_mock::kControlNonceOrEntry, s->get_nonce(), pst)); + 0, wvoec::kControlNonceOrEntry, s->get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s->EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s->CreateNewUsageEntry()); ASSERT_EQ(s->usage_entry_number(), index); @@ -5380,7 +5377,7 @@ TEST_F(UsageTableDefragTest, TwoHundredEntries) { ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&sessions[i])); std::string pst = MakePST(i); ASSERT_NO_FATAL_FAILURE(sessions[i].FillSimpleMessage( - 0, wvoec_mock::kControlNonceOrEntry, sessions[i].get_nonce(), pst)); + 0, wvoec::kControlNonceOrEntry, sessions[i].get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(sessions[i].EncryptAndSign()); // We attempt to create a new usage table entry for this session. OEMCryptoResult status; @@ -5587,7 +5584,7 @@ TEST_F(UsageTableTest, GenerateReportWrongPST) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceOrEntry, s.get_nonce(), pst)); + 0, wvoec::kControlNonceOrEntry, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys(pst, new_mac_keys_)); @@ -5684,7 +5681,7 @@ TEST_F(UsageTableTest, VerifyUsageTimes) { ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestSessionKeys(&s)); ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage( - 0, wvoec_mock::kControlNonceEnabled | wvoec_mock::kControlNonceRequired, + 0, wvoec::kControlNonceEnabled | wvoec::kControlNonceRequired, s.get_nonce(), pst)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.CreateNewUsageEntry()); @@ -5874,7 +5871,7 @@ TEST_F(UsageTableTest, LoadSharedLicense) { s.license().keys[i].key_id_length); s.license().keys[i].control.nonce = 0; s.license().keys[i].control.control_bits = - htonl(wvoec_mock::kSharedLicense); + htonl(wvoec::kSharedLicense); } ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys(pst, false)); @@ -5903,7 +5900,7 @@ TEST_F(UsageTableTest, LoadSharedLicenseWithNoMaster) { s.license().keys[i].key_id_length); s.license().keys[i].control.nonce = 0; s.license().keys[i].control.control_bits = - htonl(wvoec_mock::kSharedLicense); + htonl(wvoec::kSharedLicense); } ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); uint8_t* pst_ptr = s.encrypted_license().pst; diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test_android.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test_android.cpp index ba5355c0..e5a5fd52 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test_android.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test_android.cpp @@ -142,7 +142,6 @@ TEST_F(OEMCryptoAndroidOCTest, MinVersionNumber13) { ASSERT_GE(version, 13u); } -#if 0 // TODO(b/64001862) // These tests are required for Pi MR1 Android devices. class OEMCryptoAndroidPiMR1Test : public OEMCryptoAndroidOCTest {}; @@ -150,6 +149,5 @@ TEST_F(OEMCryptoAndroidPiMR1Test, MinVersionNumber14) { uint32_t version = OEMCrypto_APIVersion(); ASSERT_GE(version, 14u); } -#endif } // namespace wvoec diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test_main.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test_main.cpp index 631fbfc7..1dabae30 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test_main.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test_main.cpp @@ -4,7 +4,9 @@ #include "OEMCryptoCENC.h" #include "log.h" #include "oec_device_features.h" +#ifdef CDM_TESTS #include "properties.h" +#endif static void acknowledge_cast() { std::cout @@ -15,7 +17,9 @@ static void acknowledge_cast() { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); +#ifdef CDM_TESTS wvcdm::Properties::Init(); +#endif wvcdm::g_cutoff = wvcdm::LOG_INFO; bool is_cast_receiver = false; bool force_load_test_keybox = false; diff --git a/libwvdrmengine/vts/vendor_module/Android.mk b/libwvdrmengine/vts/vendor_module/Android.mk index 2812e80a..7f61ba72 100644 --- a/libwvdrmengine/vts/vendor_module/Android.mk +++ b/libwvdrmengine/vts/vendor_module/Android.mk @@ -9,6 +9,7 @@ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/cdm/include \ vendor/widevine/libwvdrmengine/cdm/core/include \ vendor/widevine/libwvdrmengine/cdm/core/test \ + vendor/widevine/libwvdrmengine/cdm/util/include \ system/libhidl/base/include \ system/core/base/include \ system/libvintf/include \ diff --git a/libwvdrmengine/vts/vendor_module/vts_module.h b/libwvdrmengine/vts/vendor_module/vts_module.h index 870798dd..8d18d800 100644 --- a/libwvdrmengine/vts/vendor_module/vts_module.h +++ b/libwvdrmengine/vts/vendor_module/vts_module.h @@ -45,4 +45,3 @@ namespace widevine_vts { }; // namespace widevine_vts #endif //WIDEVINE_VENDOR_VTS_MODULE -