From b8d32f0d6e634886ac11e5c4b0464fc45ccae61e Mon Sep 17 00:00:00 2001 From: Matt Feddersen Date: Thu, 28 Mar 2024 17:53:56 -0700 Subject: [PATCH] OPK v19.1 --- CHANGELOG.md | 57 ++ linux/src/log.cpp | 4 +- oemcrypto/include/OEMCryptoCENC.h | 37 +- oemcrypto/include/level3.h | 92 ++- oemcrypto/odk/Android.bp | 13 + oemcrypto/odk/include/core_message_features.h | 6 +- oemcrypto/odk/include/odk_structs.h | 4 +- oemcrypto/odk/src/core_message_features.cpp | 4 +- oemcrypto/odk/src/core_message_serialize.cpp | 2 + oemcrypto/odk/src/odk.c | 4 + oemcrypto/odk/src/odk_timer.c | 5 +- oemcrypto/odk/test/odk_core_message_test.cpp | 3 + oemcrypto/odk/test/odk_golden_v16.cpp | 2 + oemcrypto/odk/test/odk_golden_v17.cpp | 2 + oemcrypto/odk/test/odk_golden_v18.cpp | 2 + oemcrypto/odk/test/odk_test.cpp | 14 +- oemcrypto/odk/test/odk_test_helper.cpp | 16 +- oemcrypto/odk/test/odk_test_helper.h | 4 +- oemcrypto/oemcrypto_unittests.gyp | 2 + oemcrypto/opk/Android.bp | 43 ++ oemcrypto/opk/build/Makefile.rules | 359 ++++++++++++ oemcrypto/opk/oemcrypto_ta/oemcrypto.c | 128 +++-- .../opk/oemcrypto_ta/oemcrypto_api_macros.h | 2 +- .../opk/oemcrypto_ta/oemcrypto_key_types.h | 6 + .../opk/oemcrypto_ta/oemcrypto_session.c | 86 ++- .../opk/oemcrypto_ta/oemcrypto_session.h | 15 +- .../opk/oemcrypto_ta/oemcrypto_usage_table.c | 3 + .../oemcrypto_ta/wtpi/wtpi_config_interface.h | 29 +- .../wtpi/wtpi_crypto_asymmetric_interface.h | 41 +- .../wtpi/wtpi_device_key_interface.h | 16 +- .../oemcrypto_ta/wtpi/wtpi_hdcp_interface.h | 70 +++ .../wtpi/wtpi_provisioning_4_interface.h | 31 +- .../wtpi_reference/config/default.h | 2 +- .../oemcrypto_ta/wtpi_reference/cose_util.c | 3 +- .../oemcrypto_ta/wtpi_reference/crypto_util.c | 5 +- .../oemcrypto_ta/wtpi_reference/ecc_util.c | 3 - .../wtpi_reference/wtpi_clock_and_gn_layer1.c | 69 +-- .../oemcrypto_ta/wtpi_reference/wtpi_config.c | 20 +- ...crypto_and_key_management_layer1_openssl.c | 14 +- .../wtpi_reference/wtpi_crypto_asymmetric.c | 42 ++ .../wtpi_crypto_wrap_asymmetric.c | 32 +- .../wtpi_reference/wtpi_device_key.c | 139 ++++- .../oemcrypto_ta/wtpi_reference/wtpi_hdcp.c | 28 + .../wtpi_reference/wtpi_provisioning_4.c | 135 ++--- .../wtpi_test/clock_interface_test.cpp | 2 +- .../wtpi_test/common/GEN_common_serializer.c | 96 +++- .../wtpi_test/common/common_special_cases.c | 81 +-- .../wtpi_test/common/common_special_cases.h | 2 + .../oemcrypto_ta/wtpi_test/crypto_test.cpp | 156 ++++-- .../provisioning_4_interface_test.cpp | 61 +- .../ree/GEN_oemcrypto_tee_test_api.c | 199 +++---- .../wtpi_test/ree/GEN_ree_serializer.c | 528 +++++++++++------- .../wtpi_test/ree/GEN_ree_serializer.h | 37 +- .../wtpi_test/tee/GEN_dispatcher.c | 205 ++++--- .../wtpi_test/tee/GEN_tee_serializer.c | 341 +++++------ .../wtpi_test/tee/GEN_tee_serializer.h | 38 +- .../wtpi_test/tee/tee_special_cases.c | 6 + .../wtpi_test/tee/tee_special_cases.h | 1 + .../ports/linux/common/tos_secure_buffers.c | 2 + .../opk/ports/linux/common/tos_transport.cpp | 1 + oemcrypto/opk/ports/linux/rules.mk | 12 +- .../ports/linux/ta/common/tee_simulator.cpp | 4 +- .../linux/ta/common/wtpi_impl/sources.mk | 1 + .../ta/common/wtpi_impl/wtpi_test_impl.gyp | 1 + oemcrypto/opk/ports/optee/Makefile | 5 +- oemcrypto/opk/ports/optee/host/rules.mk | 12 +- .../ta/common/wtpi_impl/genkeypair_ecc.c | 23 +- .../ta/common/wtpi_impl/genkeypair_rsa.c | 23 +- .../optee/ta/common/wtpi_impl/sources.mk | 1 + .../ta/common/wtpi_impl/util/crypto_util.h | 14 +- .../wtpi_impl/util/crypto_util_mbedtls.c | 261 +++++---- .../wtpi_crypto_and_key_management_layer1.c | 115 ++-- .../common/wtpi_impl/wtpi_crypto_asymmetric.c | 99 ++-- .../ta/common/wtpi_impl/wtpi_provisioning_4.c | 6 + .../wtpi_impl/wtpi_root_of_trust_layer1.c | 39 +- .../optee/ta/oemcrypto_ta/oemcrypto_ta.c | 5 +- .../optee/ta/wtpi_test_ta/wtpi_test_ta.c | 4 +- .../interface_impls/wtpi_provisioning_4.c | 18 +- .../opk/ports/trusty/ta/reference/rules.mk | 1 + .../common/GEN_common_serializer.c | 109 +++- .../common/common_special_cases.c | 4 +- .../common/opk_serialization_base.c | 104 +++- .../os_interfaces/tos_transport_interface.h | 2 +- .../opk/serialization/ree/GEN_oemcrypto_api.c | 35 ++ .../serialization/ree/GEN_ree_serializer.c | 210 +++++-- .../serialization/ree/GEN_ree_serializer.h | 6 + .../opk/serialization/tee/GEN_dispatcher.c | 28 +- .../serialization/tee/GEN_tee_serializer.c | 36 +- .../serialization/tee/GEN_tee_serializer.h | 6 + oemcrypto/test/GEN_api_lock_file.c | 6 + oemcrypto/test/common.mk | 5 + .../test/fuzz_tests/oemcrypto_fuzz_helper.cc | 1 - oemcrypto/test/oec_device_features.cpp | 3 + oemcrypto/test/oec_session_util.cpp | 39 +- oemcrypto/test/oec_session_util.h | 14 +- oemcrypto/test/oemcrypto_basic_test.cpp | 10 +- oemcrypto/test/oemcrypto_cast_test.h | 3 + oemcrypto/test/oemcrypto_decrypt_test.cpp | 6 +- oemcrypto/test/oemcrypto_decrypt_test.h | 2 +- .../test/oemcrypto_generic_crypto_test.cpp | 10 +- oemcrypto/test/oemcrypto_license_test.h | 2 +- .../test/oemcrypto_provisioning_test.cpp | 37 +- oemcrypto/test/oemcrypto_test_android.cpp | 4 +- oemcrypto/test/oemcrypto_usage_table_test.cpp | 7 +- .../util/src/signed_csr_payload_validator.cpp | 4 +- util/include/wv_attributes.h | 8 + util/test/test_sleep.cpp | 9 +- 107 files changed, 3215 insertions(+), 1489 deletions(-) create mode 100644 oemcrypto/opk/Android.bp create mode 100644 oemcrypto/opk/build/Makefile.rules create mode 100644 oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_hdcp_interface.h create mode 100644 oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_hdcp.c diff --git a/CHANGELOG.md b/CHANGELOG.md index 449db2c..579e4af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,62 @@ [TOC] +## [Version 19.1][v19.1] + +This is a minor release that includes a few security fixes and bug fixes. + +General + +- Change OEMCrypto_FreeSecureBuffer() |output_descriptor| parameter to be +[in,out] type. +- Use strlen() instead of sizeof() to get the length of BUILD_INFO. +- Add OEMCrypto_GetEmbeddedDrmCertificate() definition to OPK, with +OEMCrypto_ERROR_NOT_IMPLEMENTED. +- Remove default.h include file from wtpi_config, which was causing a mismatch +between reported config values and actual config values. +- Remove extra is_debug field and trailing comma from BuildInformation. +- Reduce trusted clock skew on restarts in wtpi_reference implementation. +- Remove -Wno-unused-parameter cflag. +- Increase transport buffer size from 32K to 34K to accommodate larger buffer +requirements from OEMCrypto_LoadProvisioning +- Fix BCC payload item count in wtpi_reference +- Add WTPI_DeriveNewAsymmetricKeyHandle() and +WTPI_CreateUDSDerivedAsymmetricKeyHandle() to wtpi_provisioning_4_interface.h. +These implementations are only required if you are using +wtpi_reference/wtpi_provisioning_4.c. +- Use new context values when wrapping OEM and DRM certs that are generated +during Provisioning 4. The previous context value is still used to unwrap older +certs if that legacy format is detected or a newer unwrap fails. +- Add initial support for HDCP auth control from within the Widevine TA. This is +an experimental feature that is gated behind the build time flag +USE_OPK_FEATURE_SETHDCP. With this feature enabled, HDCP is set to max on +OEMCrypto_Initialize() and turned off at OEMCrypto_Terminate(), if such control +is supported by the TEE. + +OPK serialization layer + +- Avoid writing any value to output parameters if the OEMCryptoResult is not +OEMCrypto_SUCCESS. (Applies to [out] type only. Not [in] or [in,out]). This +avoids subtle bugs where the serialization logic may unexpectedly modify (eg +set to 0) an output parameter on failure. +- Initialize pointers in a few corner cases. + +Tests + +- Fix default cipher mode for CAS unit test. +- Skip entitlement session tests that are only supported on CAS devices. +- Don't force decrypt count to increase in unit tests. +- Skip some cast tests if not supported. + +OP-TEE port changes + +- Fix memory leaks on failure cases in AES decrypt, RSA key creation, and ECC +key creation. +- Check incoming message size from REE to avoid OOB. +- Generate ECC keypair and zero pad appropriately. +- Add file existence check in RPMB impl. +- Cleanup keybox and key handles consistently after use. + ## [Version 19.0][v19.0] This is the initial release of OPK v19.0, which implements OEMCrypto v19.0. @@ -542,3 +598,4 @@ Public release for OEMCrypto API and ODK library version 16.4. [v18.3]: https://widevine-partner.googlesource.com/oemcrypto/+/refs/tags/v18.3 [v18.4]: https://widevine-partner.googlesource.com/oemcrypto/+/refs/tags/v18.4 [v19.0]: https://widevine-partner.googlesource.com/oemcrypto/+/refs/tags/v19.0 +[v19.1]: https://widevine-partner.googlesource.com/oemcrypto/+/refs/tags/v19.1 diff --git a/linux/src/log.cpp b/linux/src/log.cpp index 1e688c6..5b0a9e9 100644 --- a/linux/src/log.cpp +++ b/linux/src/log.cpp @@ -33,8 +33,8 @@ void InitLogging() { void Log(const char* file, const char* function, int line, LogPriority level, const char* fmt, ...) { const char* severities[] = {"ERROR", "WARN", "INFO", "DEBUG", "VERBOSE"}; - if (level >= - static_cast(sizeof(severities) / sizeof(*severities))) { + if (level < 0 || level >= static_cast(sizeof(severities) / + sizeof(severities[0]))) { fprintf(kOutputFile, "[FATAL:%s(%d):%s] Invalid log priority level: %d\n", file, line, function, level); return; diff --git a/oemcrypto/include/OEMCryptoCENC.h b/oemcrypto/include/OEMCryptoCENC.h index 31d1640..0131355 100644 --- a/oemcrypto/include/OEMCryptoCENC.h +++ b/oemcrypto/include/OEMCryptoCENC.h @@ -3,7 +3,7 @@ // License Agreement. /** - * @mainpage OEMCrypto API v19.0 + * @mainpage OEMCrypto API v19.1 * * OEMCrypto is the low level library implemented by the OEM to provide key and * content protection, usually in a separate secure memory or process space. The @@ -521,6 +521,8 @@ typedef enum OEMCrypto_ProvisioningMethod { OEMCrypto_OEMCertificate = 3, // Device has Boot Certificate Chain (BCC). OEMCrypto_BootCertificateChain = 4, + // Device has baked in DRM certificate with reprovisioning (level 3 only). + OEMCrypto_DrmReprovisioning = 5 } OEMCrypto_ProvisioningMethod; /** @@ -740,6 +742,8 @@ typedef enum OEMCrypto_SignatureHashAlgorithm { #define OEMCrypto_GetUsageEntryInfo _oecc148 #define OEMCrypto_GetBCCType _oecc149 #define OEMCrypto_LoadRelease _oecc150 +#define OEMCrypto_GetEmbeddedDrmCertificate _oecc151 +#define OEMCrypto_UseSecondaryKey _oecc152 // clang-format on /// @addtogroup initcontrol @@ -5585,7 +5589,7 @@ OEMCryptoResult OEMCrypto_AllocateSecureBuffer( * will cause the unit test using secure buffers to fail. * * @param[in] session: session id for operation. - * @param[out] output_descriptor: the buffer descriptor modified by + * @param[in,out] output_descriptor: the buffer descriptor modified by * OEMCrypto_AllocateSecureBuffer() * @param[in] secure_fd: The integer returned by * OEMCrypto_AllocateSecureBuffer() @@ -6108,6 +6112,35 @@ OEMCryptoResult OEMCrypto_LoadProvisioning_V18( /****************************************************************************/ /****************************************************************************/ +/* The following functions are used by internal L3 CDMs and are not required by + * other CDM implementations. + */ + +/** + * Get the embedded Drm Certificate used by internal L3 CDMs. + * + * @param[out] public_cert where the certificate is stored. + * @param[in,out] public_cert_length the length, in bytes, of the certificate. + * + * @retval OEMCrypto_SUCCESS on success + * @retval OEMCrypto_ERROR_SHORT_BUFFER if public_cert_length is too small. + * @retval OEMCrypto_ERROR_NOT_IMPLEMENTED + */ +OEMCryptoResult OEMCrypto_GetEmbeddedDrmCertificate(uint8_t* public_cert, + size_t* public_cert_length); + +/** + * Marks the given session as using a secondary key. This should return success + * when not implemented. + * + * @param[in] session_id: handle for the session to be used. + * @param[in] dual_key: whether this session uses a secondary key. + * + * @ignore + * @retval OEMCrypto_SUCCESS on success + */ +OEMCryptoResult OEMCrypto_UseSecondaryKey(OEMCrypto_SESSION session_id, + bool dual_key); #ifdef __cplusplus } diff --git a/oemcrypto/include/level3.h b/oemcrypto/include/level3.h index 08789c8..677d29a 100644 --- a/oemcrypto/include/level3.h +++ b/oemcrypto/include/level3.h @@ -17,8 +17,6 @@ #include "OEMCryptoCENC.h" #include "level3_file_system.h" -namespace wvoec3 { - // clang-format off #ifdef DYNAMIC_ADAPTER #define Level3_IsInApp _lcc00 @@ -27,7 +25,6 @@ namespace wvoec3 { #define Level3_InstallKeyboxOrOEMCert _lcc03 #define Level3_GetKeyData _lcc04 #define Level3_IsKeyboxOrOEMCertValid _lcc05 -#define Level3_GetRandom _lcc06 #define Level3_GetDeviceID _lcc07 #define Level3_WrapKeyboxOrOEMCert _lcc08 #define Level3_OpenSession _lcc09 @@ -82,9 +79,9 @@ namespace wvoec3 { #define Level3_PrepAndSignLicenseRequest _lcc96 #define Level3_PrepAndSignRenewalRequest _lcc97 #define Level3_PrepAndSignProvisioningRequest _lcc98 -#define Level3_LoadLicense _lcc99 +#define Level3_LoadLicense_V18 _lcc99 #define Level3_LoadRenewal _lcc101 -#define Level3_LoadProvisioning _lcc102 +#define Level3_LoadProvisioning_V18 _lcc102 #define Level3_LoadOEMPrivateKey _lcc103 #define Level3_GetOEMPublicCertificate _lcc104 #define Level3_DecryptCENC_V17 _lcc105 @@ -121,16 +118,21 @@ namespace wvoec3 { #define Level3_EnterTestMode _lcc140 #define Level3_GetDeviceSignedCsrPayload _lcc141 #define Level3_SetDecryptHash _lcc143 +#define Level3_LoadLicense _lcc144 +#define Level3_LoadProvisioning _lcc145 +#define Level3_LoadProvisioningCast _lcc146 #define Level3_PrepAndSignReleaseRequest _lcc147 #define Level3_GetUsageEntryInfo _lcc148 +#define Level3_GetBCCType _lcc149 #define Level3_LoadRelease _lcc150 +#define Level3_GetEmbeddedDrmCertificate _lcc151 +#define Level3_UseSecondaryKey _lcc152 #else #define Level3_Initialize _oecc01 #define Level3_Terminate _oecc02 #define Level3_InstallKeyboxOrOEMCert _oecc03 #define Level3_GetKeyData _oecc04 #define Level3_IsKeyboxOrOEMCertValid _oecc05 -#define Level3_GetRandom _oecc06 #define Level3_GetDeviceID _oecc07 #define Level3_WrapKeyboxOrOEMCert _oecc08 #define Level3_OpenSession _oecc09 @@ -187,9 +189,9 @@ namespace wvoec3 { #define Level3_PrepAndSignLicenseRequest _oecc96 #define Level3_PrepAndSignRenewalRequest _oecc97 #define Level3_PrepAndSignProvisioningRequest _oecc98 -#define Level3_LoadLicense _oecc99 +#define Level3_LoadLicense_V18 _oecc99 #define Level3_LoadRenewal _oecc101 -#define Level3_LoadProvisioning _oecc102 +#define Level3_LoadProvisioning_V18 _oecc102 #define Level3_LoadOEMPrivateKey _oecc103 #define Level3_GetOEMPublicCertificate _oecc104 #define Level3_DecryptCENC_V17 _oecc105 @@ -205,7 +207,7 @@ namespace wvoec3 { #define Level3_ReassociateEntitledKeySession _oecc119 #define Level3_LoadCasECMKeys _oecc120 #define Level3_LoadEntitledContentKeys _oecc121 // place holder for v17. -#define Level3_ProductionReady _oecc122 +#define Level3_ProductionReady _oecc122 #define Level3_Idle _oecc123 #define Level3_Wake _oecc124 #define Level3_BuildInformation _oecc125 @@ -226,10 +228,16 @@ namespace wvoec3 { #define Level3_EnterTestMode _oecc140 #define Level3_GetDeviceSignedCsrPayload _oecc141 #define Level3_SetDecryptHash _oecc143 +#define Level3_LoadLicense _oecc144 +#define Level3_LoadProvisioning _oecc145 +#define Level3_LoadProvisioningCast _oecc146 #define Level3_PrepAndSignReleaseRequest _oecc147 #define Level3_GetUsageEntryInfo _oecc148 +#define Level3_GetBCCType _oecc149 #define Level3_LoadRelease _oecc150 - +// Internal-only. +#define Level3_GetEmbeddedDrmCertificate _oecc151 +#define Level3_UseSecondaryKey _oecc152 #endif #define Level3_GetInitializationState _oecl3o01 @@ -270,13 +278,12 @@ OEMCryptoResult Level3_GetOEMPublicCertificate(uint8_t* public_cert, size_t* public_cert_length); OEMCryptoResult Level3_GetDeviceID(uint8_t* deviceID, size_t* idLength); OEMCryptoResult Level3_GetKeyData(uint8_t* keyData, size_t* keyDataLength); -OEMCryptoResult Level3_GetRandom(uint8_t* randomData, size_t dataLength); OEMCryptoResult Level3_LoadOEMPrivateKey(OEMCrypto_SESSION session); OEMCryptoResult Level3_LoadDRMPrivateKey(OEMCrypto_SESSION session, OEMCrypto_PrivateKeyType key_type, const uint8_t* wrapped_rsa_key, size_t wrapped_rsa_key_length); -OEMCryptoResult Level3_LoadProvisioning( +OEMCryptoResult Level3_LoadProvisioning_V18( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, size_t core_message_length, const uint8_t* signature, size_t signature_length, uint8_t* wrapped_private_key, @@ -363,12 +370,12 @@ OEMCryptoResult Level3_LoadTestKeybox(const uint8_t* buffer, size_t length); OEMCryptoResult Level3_SelectKey(const OEMCrypto_SESSION session, const uint8_t* key_id, size_t key_id_length, OEMCryptoCipherMode cipher_mode); -OEMCryptoResult Level3_LoadLicense(OEMCrypto_SESSION session, - const uint8_t* message, - size_t message_length, - size_t core_message_length, - const uint8_t* signature, - size_t signature_length); +OEMCryptoResult Level3_LoadLicense_V18(OEMCrypto_SESSION session, + const uint8_t* message, + size_t message_length, + size_t core_message_length, + const uint8_t* signature, + size_t signature_length); OEMCryptoResult Level3_LoadKeys( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, const uint8_t* signature, size_t signature_length, @@ -506,6 +513,29 @@ OEMCryptoResult Level3_Generic_Verify(const uint8_t* key_handle, OEMCryptoResult Level3_GetSignatureHashAlgorithm( OEMCrypto_SESSION session, OEMCrypto_SignatureHashAlgorithm* algorithm); OEMCryptoResult Level3_EnterTestMode(void); +OEMCryptoResult Level3_LoadLicense( + OEMCrypto_SESSION session, const uint8_t* context, size_t context_length, + const uint8_t* derivation_key, size_t derivation_key_length, + const uint8_t* message, size_t message_length, size_t core_message_length, + const uint8_t* signature, size_t signature_length); +OEMCryptoResult Level3_LoadProvisioning( + OEMCrypto_SESSION session, const uint8_t* provision_request, + size_t provision_request_length, const uint8_t* message, + size_t message_length, size_t core_message_length, const uint8_t* signature, + size_t signature_length, uint8_t* wrapped_private_key, + size_t* wrapped_private_key_length); +OEMCryptoResult Level3_LoadProvisioningCast( + OEMCrypto_SESSION session, const uint8_t* derivation_key, + size_t derivation_key_length, const uint8_t* provision_request, + size_t provision_request_length, const uint8_t* message, + size_t message_length, size_t core_message_length, const uint8_t* signature, + size_t signature_length, uint8_t* wrapped_private_key, + size_t* wrapped_private_key_length); +OEMCryptoResult Level3_GetBCCType(OEMCrypto_BCCType* bcc_type); +OEMCryptoResult Level3_GetEmbeddedDrmCertificate(uint8_t* public_cert, + size_t* public_cert_length); +OEMCryptoResult Level3_UseSecondaryKey(OEMCrypto_SESSION session_id, + bool dual_key); // The following are specific to Google's Level 3 implementation and are not // required. @@ -519,6 +549,30 @@ enum Level3InitializationState { LEVEL3_VERIFY_DEVICE_KEYS_FAILURE = 5, }; +enum Level3RunningMode { + LEVEL3_MODE_HAYSTACK_ONLY = 0, + LEVEL3_MODE_RIKERS_DEFAULT = 1, + LEVEL3_MODE_RIKERS_ONLY = 2, +}; + +/* + * Level3_GetRunningMode + * + * Description: + * Returns the current mode the Level3 is running in. This shouldn't change + * while the processes is running. + * + * Parameters: + * N/A + * + * Threading: + * No other function calls will be made while this function is running. + * + * Version: + * This method is new in API version 19. + */ +Level3RunningMode Level3_GetRunningMode(void); + /* * Level3_GetInitializationState * @@ -572,6 +626,8 @@ void Level3_OutputErrorLogs(); } // extern "C" +namespace wvoec3 { + // The following are interfaces needed for Google's Level 3 OEMCrypto // specifically, which partners are expected to implement. diff --git a/oemcrypto/odk/Android.bp b/oemcrypto/odk/Android.bp index 18c7c78..90c4a6d 100644 --- a/oemcrypto/odk/Android.bp +++ b/oemcrypto/odk/Android.bp @@ -25,6 +25,11 @@ cc_library_static { "vendor/widevine/libwvdrmengine/oemcrypto/odk/include", "vendor/widevine/libwvdrmengine/oemcrypto/odk/src", ], + header_libs: [ + "jni_headers", + "libbase_headers", + "liblog_headers", + ], srcs: [ "src/odk.c", @@ -51,6 +56,11 @@ cc_library_static { "vendor/widevine/libwvdrmengine/oemcrypto/odk/include", "vendor/widevine/libwvdrmengine/oemcrypto/odk/src", ], + header_libs: [ + "jni_headers", + "libbase_headers", + "liblog_headers", + ], srcs: [ "src/core_message_deserialize.cpp", @@ -100,6 +110,9 @@ cc_test { ], srcs: [ + "test/odk_golden_v16.cpp", + "test/odk_golden_v17.cpp", + "test/odk_golden_v18.cpp", "test/odk_test.cpp", "test/odk_test_helper.cpp", "test/odk_timer_test.cpp", diff --git a/oemcrypto/odk/include/core_message_features.h b/oemcrypto/odk/include/core_message_features.h index 34da682..b2dda6a 100644 --- a/oemcrypto/odk/include/core_message_features.h +++ b/oemcrypto/odk/include/core_message_features.h @@ -26,9 +26,9 @@ struct CoreMessageFeatures { // This is the published version of the ODK Core Message library. The default // behavior is for the server to restrict messages to at most this version - // number. The default is 18.3. - uint32_t maximum_major_version = 18; - uint32_t maximum_minor_version = 3; + // number. The default is 19.1. + uint32_t maximum_major_version = 19; + uint32_t maximum_minor_version = 1; bool operator==(const CoreMessageFeatures &other) const; bool operator!=(const CoreMessageFeatures &other) const { diff --git a/oemcrypto/odk/include/odk_structs.h b/oemcrypto/odk/include/odk_structs.h index 8926d16..3335f95 100644 --- a/oemcrypto/odk/include/odk_structs.h +++ b/oemcrypto/odk/include/odk_structs.h @@ -16,10 +16,10 @@ extern "C" { /* The version of this library. */ #define ODK_MAJOR_VERSION 19 -#define ODK_MINOR_VERSION 0 +#define ODK_MINOR_VERSION 1 /* ODK Version string. Date changed automatically on each release. */ -#define ODK_RELEASE_DATE "ODK v19.0 2023-12-07" +#define ODK_RELEASE_DATE "ODK v19.1 2024-03-25" /* The lowest version number for an ODK message. */ #define ODK_FIRST_VERSION 16 diff --git a/oemcrypto/odk/src/core_message_features.cpp b/oemcrypto/odk/src/core_message_features.cpp index 8f20763..4143d14 100644 --- a/oemcrypto/odk/src/core_message_features.cpp +++ b/oemcrypto/odk/src/core_message_features.cpp @@ -30,10 +30,10 @@ CoreMessageFeatures CoreMessageFeatures::DefaultFeatures( features.maximum_minor_version = 2; // 17.2 break; case 18: - features.maximum_minor_version = 3; // 18.3 + features.maximum_minor_version = 4; // 18.4 break; case 19: - features.maximum_minor_version = 0; // 19.0 + features.maximum_minor_version = 1; // 19.1 break; default: features.maximum_minor_version = 0; diff --git a/oemcrypto/odk/src/core_message_serialize.cpp b/oemcrypto/odk/src/core_message_serialize.cpp index b2fc97b..888b957 100644 --- a/oemcrypto/odk/src/core_message_serialize.cpp +++ b/oemcrypto/odk/src/core_message_serialize.cpp @@ -143,6 +143,8 @@ bool CreateCoreReleaseResponse(const CoreMessageFeatures& features, int64_t seconds_since_license_requested, int64_t seconds_since_first_decrypt, std::string* oemcrypto_core_message) { + (void)seconds_since_license_requested; + (void)seconds_since_first_decrypt; ODK_ReleaseResponse release_response{}; if (!CreateResponseHeader(features, ODK_Release_Response_Type, &release_response.core_message, core_request)) { diff --git a/oemcrypto/odk/src/odk.c b/oemcrypto/odk/src/odk.c index 5faa2de..3f4090f 100644 --- a/oemcrypto/odk/src/odk.c +++ b/oemcrypto/odk/src/odk.c @@ -239,6 +239,10 @@ OEMCryptoResult ODK_PrepareCoreReleaseRequest( uint32_t clock_security_level, int64_t seconds_since_license_requested, int64_t seconds_since_first_decrypt, ODK_ClockValues* clock_values, uint64_t system_time_seconds) { + (void)status; + (void)clock_security_level; + (void)seconds_since_license_requested; + (void)seconds_since_first_decrypt; if (core_message_size == NULL || nonce_values == NULL || clock_values == NULL) { return ODK_ERROR_CORE_MESSAGE; diff --git a/oemcrypto/odk/src/odk_timer.c b/oemcrypto/odk/src/odk_timer.c index 9e630d5..c76fc5a 100644 --- a/oemcrypto/odk/src/odk_timer.c +++ b/oemcrypto/odk/src/odk_timer.c @@ -274,7 +274,10 @@ OEMCryptoResult ODK_InitializeSessionValues(ODK_TimerLimits* timer_limits, nonce_values->api_minor_version = 2; break; case 18: - nonce_values->api_minor_version = 3; + nonce_values->api_minor_version = 4; + break; + case 19: + nonce_values->api_minor_version = 1; break; default: nonce_values->api_minor_version = 0; diff --git a/oemcrypto/odk/test/odk_core_message_test.cpp b/oemcrypto/odk/test/odk_core_message_test.cpp index 2065883..bea7891 100644 --- a/oemcrypto/odk/test/odk_core_message_test.cpp +++ b/oemcrypto/odk/test/odk_core_message_test.cpp @@ -13,7 +13,10 @@ #include "core_message_serialize_proto.h" #include "core_message_types.h" #include "gtest/gtest.h" +#include "license_protocol.pb.h" #include "odk.h" +#include "odk_structs.h" +#include "third_party/absl/log/log.h" #include "third_party/absl/strings/escaping.h" namespace wvodk_test { diff --git a/oemcrypto/odk/test/odk_golden_v16.cpp b/oemcrypto/odk/test/odk_golden_v16.cpp index d3375a0..3dcf1f7 100644 --- a/oemcrypto/odk/test/odk_golden_v16.cpp +++ b/oemcrypto/odk/test/odk_golden_v16.cpp @@ -6,7 +6,9 @@ #include #include +#include "OEMCryptoCENCCommon.h" #include "core_message_deserialize.h" +#include "core_message_features.h" #include "core_message_serialize.h" #include "core_message_serialize_proto.h" #include "core_message_types.h" diff --git a/oemcrypto/odk/test/odk_golden_v17.cpp b/oemcrypto/odk/test/odk_golden_v17.cpp index b29bd00..e1e832c 100644 --- a/oemcrypto/odk/test/odk_golden_v17.cpp +++ b/oemcrypto/odk/test/odk_golden_v17.cpp @@ -6,7 +6,9 @@ #include #include +#include "OEMCryptoCENCCommon.h" #include "core_message_deserialize.h" +#include "core_message_features.h" #include "core_message_serialize.h" #include "core_message_serialize_proto.h" #include "core_message_types.h" diff --git a/oemcrypto/odk/test/odk_golden_v18.cpp b/oemcrypto/odk/test/odk_golden_v18.cpp index 7674f01..acbd8dc 100644 --- a/oemcrypto/odk/test/odk_golden_v18.cpp +++ b/oemcrypto/odk/test/odk_golden_v18.cpp @@ -6,7 +6,9 @@ #include #include +#include "OEMCryptoCENCCommon.h" #include "core_message_deserialize.h" +#include "core_message_features.h" #include "core_message_serialize.h" #include "core_message_serialize_proto.h" #include "core_message_types.h" diff --git a/oemcrypto/odk/test/odk_test.cpp b/oemcrypto/odk/test/odk_test.cpp index e9f8dd9..5201ff8 100644 --- a/oemcrypto/odk/test/odk_test.cpp +++ b/oemcrypto/odk/test/odk_test.cpp @@ -18,9 +18,11 @@ #include "core_message_serialize_proto.h" #include "core_message_types.h" #include "gtest/gtest.h" +#include "license_protocol.pb.h" #include "odk_overflow.h" #include "odk_structs.h" #include "odk_structs_priv.h" +#include "odk_target.h" #include "odk_test_helper.h" namespace wvodk_test { @@ -258,7 +260,7 @@ TEST(OdkTest, SerializeFieldsStress) { size_t total_size = 0; for (int i = 0; i < n; i++) { fields[i].type = static_cast( - std::rand() % static_cast(ODK_LAST_STRESSABLE_TYPE)); + std::rand() % (static_cast(ODK_LAST_STRESSABLE_TYPE) + 1)); fields[i].value = malloc(ODK_AllocSize(fields[i].type)); fields[i].name = "stress"; total_size += ODK_FieldLength(fields[i].type); @@ -1272,8 +1274,8 @@ std::vector TestCases() { // number. {16, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 16, 5}, {17, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 17, 2}, - {18, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 18, 3}, - {19, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 19, 0}, + {18, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 18, 4}, + {19, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 19, 1}, // Here are some known good versions. Make extra sure they work. {ODK_MAJOR_VERSION, 16, 3, 16, 3}, {ODK_MAJOR_VERSION, 16, 4, 16, 4}, @@ -1284,12 +1286,16 @@ std::vector TestCases() { {ODK_MAJOR_VERSION, 18, 2, 18, 2}, {ODK_MAJOR_VERSION, 18, 3, 18, 3}, {ODK_MAJOR_VERSION, 19, 0, 19, 0}, + {ODK_MAJOR_VERSION, 19, 1, 19, 1}, {0, 16, 3, 16, 3}, {0, 16, 4, 16, 4}, {0, 16, 5, 16, 5}, {0, 17, 1, 17, 1}, {0, 17, 2, 17, 2}, - {0, 18, 3, 18, 3}, // Change to 19 when the default version is updated. + {0, 18, 3, 18, 3}, + {0, 18, 4, 18, 4}, + {0, 19, 0, 19, 0}, + {0, 19, 1, 19, 1}, }; return test_cases; } diff --git a/oemcrypto/odk/test/odk_test_helper.cpp b/oemcrypto/odk/test/odk_test_helper.cpp index 2c95cfe..184515d 100644 --- a/oemcrypto/odk/test/odk_test_helper.cpp +++ b/oemcrypto/odk/test/odk_test_helper.cpp @@ -360,22 +360,20 @@ size_t ODK_FieldLength(ODK_FieldType type) { return sizeof(uint64_t); case ODK_INT64: return sizeof(uint64_t); - case ODK_BOOL: // Booleans are stored in the message as 32 bit ints. - return sizeof(uint32_t); case ODK_SUBSTRING: return sizeof(uint32_t) + sizeof(uint32_t); case ODK_DEVICEID: return ODK_DEVICE_ID_LEN_MAX; - case ODK_MESSAGECOUNTER: - return ODK_MESSAGECOUNTERINFO_SIZE; case ODK_DEVICEINFO: return ODK_DEVICE_INFO_LEN_MAX; + case ODK_MESSAGECOUNTER: + return ODK_MESSAGECOUNTERINFO_SIZE; case ODK_RENEWALDATA: return ODK_KEYBOX_RENEWAL_DATA_SIZE; case ODK_HASH: return ODK_SHA256_HASH_SIZE; - default: - return SIZE_MAX; + case ODK_BOOL: // Booleans are stored in the message as 32 bit ints. + return sizeof(uint32_t); } } @@ -738,15 +736,15 @@ void ODK_ExpectEqualBuf(const void* s1, const void* s2, size_t n, if (temp_fd >= 0) { close(temp_fd); } else { - std::cerr << "Failed to open temp file." << std::endl; + std::cerr << "Failed to open temp file." << '\n'; break; } std::string tmp(_tmp); std::fstream out(tmp, std::ios::out | std::ios::binary); out.write(static_cast(buffers[i]), n); out.close(); - std::cerr << std::endl - << "Message buffer " << i << " dumped to " << tmp << std::endl; + std::cerr << '\n' + << "Message buffer " << i << " dumped to " << tmp << '\n'; size_t bytes_written; uint8_t* buf = const_cast(reinterpret_cast(buffers[i])); diff --git a/oemcrypto/odk/test/odk_test_helper.h b/oemcrypto/odk/test/odk_test_helper.h index 7357a2f..5005b94 100644 --- a/oemcrypto/odk/test/odk_test_helper.h +++ b/oemcrypto/odk/test/odk_test_helper.h @@ -9,6 +9,7 @@ #include #include +#include "OEMCryptoCENCCommon.h" #include "odk_structs.h" #include "odk_structs_priv.h" @@ -28,7 +29,7 @@ enum ODK_FieldType { ODK_HASH, // The "stressable" types are the ones we can put in a stress test that packs // and unpacks random data and can expect to get back the same thing. - ODK_LAST_STRESSABLE_TYPE, + ODK_LAST_STRESSABLE_TYPE = ODK_HASH, // Put boolean after ODK_LAST_STRESSABLE_TYPE, so that we skip boolean type in // SerializeFieldsStress because we unpack any nonzero to 'true'. ODK_BOOL, @@ -83,7 +84,6 @@ struct ODK_ProvisioningResponseParams { ODK_CoreMessage core_message; uint8_t device_id[ODK_DEVICE_ID_LEN_MAX]; uint32_t device_id_length; - uint32_t padding_u32; ODK_MessageCounterInfo counter_info; ODK_ParsedProvisioning parsed_provisioning; std::vector extra_fields; diff --git a/oemcrypto/oemcrypto_unittests.gyp b/oemcrypto/oemcrypto_unittests.gyp index 14ee093..3985423 100644 --- a/oemcrypto/oemcrypto_unittests.gyp +++ b/oemcrypto/oemcrypto_unittests.gyp @@ -17,6 +17,8 @@ 'platform_specific_dir': '> $(depfile) +# Add extra rules as in (2). +# We remove slashes and replace spaces with new lines; +# remove blank lines; +# delete the first line and append a colon to the remaining lines. +sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\ + grep -v '^$$' |\ + sed -e 1d -e 's|$$|:|' \ + >> $(depfile) +rm $(depfile).raw +endef + +# Command definitions: +# - cmd_foo is the actual command to run; +# - quiet_cmd_foo is the brief-output summary of the command. + +quiet_cmd_cc = CC($(TOOLSET)) $@ +cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_cxx = CXX($(TOOLSET)) $@ +cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_touch = TOUCH $@ +cmd_touch = touch $@ + +quiet_cmd_copy = COPY $@ +# send stderr to /dev/null to ignore messages when linking directories. +cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@") + +quiet_cmd_alink = AR($(TOOLSET)) $@ +cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^) + +quiet_cmd_alink_thin = AR($(TOOLSET)) $@ +cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^) + +# Due to circular dependencies between libraries :(, we wrap the +# special "figure out circular dependencies" flags around the entire +# input list during linking. +quiet_cmd_link = LINK($(TOOLSET)) $@ +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) + +# We support two kinds of shared objects (.so): +# 1) shared_library, which is just bundling together many dependent libraries +# into a link line. +# 2) loadable_module, which is generating a module intended for dlopen(). +# +# They differ only slightly: +# In the former case, we want to package all dependent code into the .so. +# In the latter case, we want to package just the API exposed by the +# outermost module. +# This means shared_library uses --whole-archive, while loadable_module doesn't. +# (Note that --whole-archive is incompatible with the --start-group used in +# normal linking.) + +# Other shared-object link notes: +# - Set SONAME to the library filename so our binaries don't reference +# the local, absolute paths used on the link command-line. +quiet_cmd_solink = SOLINK($(TOOLSET)) $@ +cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS) + +quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@ +cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS) + + +# Define an escape_quotes function to escape single quotes. +# This allows us to handle quotes properly as long as we always use +# use single quotes and escape_quotes. +escape_quotes = $(subst ','\'',$(1)) +# This comment is here just to include a ' to unconfuse syntax highlighting. +# Define an escape_vars function to escape '$' variable syntax. +# This allows us to read/write command lines with shell variables (e.g. +# $LD_LIBRARY_PATH), without triggering make substitution. +escape_vars = $(subst $$,$$$$,$(1)) +# Helper that expands to a shell command to echo a string exactly as it is in +# make. This uses printf instead of echo because printf's behaviour with respect +# to escape sequences is more portable than echo's across different shells +# (e.g., dash, bash). +exact_echo = printf '%s\n' '$(call escape_quotes,$(1))' + +# Helper to compare the command we're about to run against the command +# we logged the last time we ran the command. Produces an empty +# string (false) when the commands match. +# Tricky point: Make has no string-equality test function. +# The kernel uses the following, but it seems like it would have false +# positives, where one string reordered its arguments. +# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ +# $(filter-out $(cmd_$@), $(cmd_$(1)))) +# We instead substitute each for the empty string into the other, and +# say they're equal if both substitutions produce the empty string. +# .d files contain ? instead of spaces, take that into account. +command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\ + $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1)))) + +# Helper that is non-empty when a prerequisite changes. +# Normally make does this implicitly, but we force rules to always run +# so we can check their command lines. +# $? -- new prerequisites +# $| -- order-only dependencies +prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?)) + +# Helper that executes all postbuilds until one fails. +define do_postbuilds + @E=0;\ + for p in $(POSTBUILDS); do\ + eval $$p;\ + E=$$?;\ + if [ $$E -ne 0 ]; then\ + break;\ + fi;\ + done;\ + if [ $$E -ne 0 ]; then\ + rm -rf "$@";\ + exit $$E;\ + fi +endef + +# do_cmd: run a command via the above cmd_foo names, if necessary. +# Should always run for a given target to handle command-line changes. +# Second argument, if non-zero, makes it do asm/C/C++ dependency munging. +# Third argument, if non-zero, makes it do POSTBUILDS processing. +# Note: We intentionally do NOT call dirx for depfile, since it contains ? for +# spaces already and dirx strips the ? characters. +define do_cmd +$(if $(or $(command_changed),$(prereq_changed)), + @$(call exact_echo, $($(quiet)cmd_$(1))) + @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))" + $(if $(findstring flock,$(word 1,$(cmd_$1))), + @$(cmd_$(1)) + @echo " $(quiet_cmd_$(1)): Finished", + @$(cmd_$(1)) + ) + @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile) + @$(if $(2),$(fixup_dep)) + $(if $(and $(3), $(POSTBUILDS)), + $(call do_postbuilds) + ) +) +endef + +# Declare the "all" target first so it is the default, +# even though we don't have the deps yet. +.PHONY: all +all: + +# make looks for ways to re-generate included makefiles, but in our case, we +# don't have a direct way. Explicitly telling make that it has nothing to do +# for them makes it go faster. +%.d: ; + +# Use FORCE_DO_CMD to force a target to run. Should be coupled with +# do_cmd. +.PHONY: FORCE_DO_CMD +FORCE_DO_CMD: + +TOOLSET := target +# Suffix rules, putting all outputs into $(obj). +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) + + +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,oemcrypto/odk/src/odk.target.mk)))),) + include oemcrypto/odk/src/odk.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,oemcrypto/opk/build/ta.target.mk)))),) + include oemcrypto/opk/build/ta.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,oemcrypto/opk/oemcrypto_ta/oemcrypto_ta.target.mk)))),) + include oemcrypto/opk/oemcrypto_ta/oemcrypto_ta.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,oemcrypto/opk/oemcrypto_ta/wtpi_reference/oemcrypto_ta_reference_clock.target.mk)))),) + include oemcrypto/opk/oemcrypto_ta/wtpi_reference/oemcrypto_ta_reference_clock.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,oemcrypto/opk/oemcrypto_ta/wtpi_reference/oemcrypto_ta_reference_crypto.target.mk)))),) + include oemcrypto/opk/oemcrypto_ta/wtpi_reference/oemcrypto_ta_reference_crypto.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,oemcrypto/opk/oemcrypto_ta/wtpi_reference/oemcrypto_ta_reference_root_of_trust.target.mk)))),) + include oemcrypto/opk/oemcrypto_ta/wtpi_reference/oemcrypto_ta_reference_root_of_trust.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,oemcrypto/opk/serialization/tee/opk_tee.target.mk)))),) + include oemcrypto/opk/serialization/tee/opk_tee.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,third_party/boringssl/crypto.target.mk)))),) + include third_party/boringssl/crypto.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,third_party/cbor.target.mk)))),) + include third_party/cbor.target.mk +endif + +# "all" is a concatenation of the "all" targets from all the included +# sub-makefiles. This is just here to clarify. +all: + +# Add in dependency-tracking rules. $(all_deps) is the list of every single +# target in our tree. Only consider the ones with .d (dependency) info: +d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d)) +ifneq ($(d_files),) + include $(d_files) +endif diff --git a/oemcrypto/opk/oemcrypto_ta/oemcrypto.c b/oemcrypto/opk/oemcrypto_ta/oemcrypto.c index 320c1f9..f01523a 100644 --- a/oemcrypto/opk/oemcrypto_ta/oemcrypto.c +++ b/oemcrypto/opk/oemcrypto_ta/oemcrypto.c @@ -34,6 +34,8 @@ #include "wtpi_config_interface.h" #include "wtpi_crypto_and_key_management_interface_layer1.h" #include "wtpi_crypto_asymmetric_interface.h" +#include "wtpi_device_key_interface.h" +#include "wtpi_hdcp_interface.h" #include "wtpi_idle_interface.h" #include "wtpi_initialize_terminate_interface.h" #include "wtpi_logging_interface.h" @@ -227,9 +229,9 @@ static OEMCryptoResult RewrapDeviceDRMKey( goto cleanup; } - result = - WTPI_WrapAsymmetricKey(wrapped_drm_key, wrapped_drm_key_length, - drm_key_type, clear_drm_key, enc_drm_key_length); + result = WTPI_WrapAsymmetricKey(DEVICE_KEY_WRAP_DRM_CERT, wrapped_drm_key, + wrapped_drm_key_length, drm_key_type, + clear_drm_key, enc_drm_key_length); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to re-wrap DRM private key with result: %u", result); goto cleanup; @@ -384,6 +386,16 @@ OEMCryptoResult OEMCrypto_Initialize(void) { // keybox. } +#ifdef USE_OPK_FEATURE_SETHDCP + OEMCrypto_HDCP_Capability max_hdcp_level = WTPI_MaxHDCPCapability(); + result = WTPI_SetHDCPLevel(max_hdcp_level); + if (result == OEMCrypto_ERROR_NOT_IMPLEMENTED) { + LOGI("WTPI_SetHDCPLevel() not implemented."); + } else if (result != OEMCrypto_SUCCESS) { + LOGE("WTPI_SetHDCPLevel() failed for target level %d", max_hdcp_level); + } +#endif // USE_OPK_FEATURE_SETHDCP + OPKI_InitializeSessionTable(); OPKI_InitializeEntitledKeySessionTable(); OPKI_InitializeKeyTable(); @@ -438,6 +450,16 @@ OEMCryptoResult OEMCrypto_Terminate(void) { OEMCryptoResult key_terminate_result = OPKI_TerminateKeyTable(); OEMCryptoResult asymmetric_key_terminate_result = OPKI_TerminateAsymmetricKeyTable(); + +#ifdef USE_OPK_FEATURE_SETHDCP + OEMCryptoResult hdcp_result = WTPI_SetHDCPLevel(HDCP_NONE); + if (hdcp_result != OEMCrypto_SUCCESS || + hdcp_result != OEMCrypto_ERROR_NOT_IMPLEMENTED) { + // Log failure for now, allow to continue + LOGE("WTPI_SetHDCPLevel() failed for target level %d", max_hdcp_level); + } +#endif // USE_OPK_FEATURE_SETHDCP + OEMCryptoResult keybox_result = WTPI_TerminateKeybox(); OEMCryptoResult clock_result = WTPI_TerminateClock(); OEMCryptoResult key_management_result = WTPI_K1_TerminateKeyManagement(); @@ -557,8 +579,9 @@ static OEMCryptoResult DeriveKeysFromSessionKey( if (session_context->drm_private_key == NULL) goto cleanup; private_key = session_context->drm_private_key; result = WTPI_UnwrapIntoAsymmetricKeyHandle( - private_key->wrapped_key, private_key->wrapped_key_length, - private_key->key_type, &private_key_handle, &allowed_schemes); + DEVICE_KEY_WRAP_DRM_CERT, private_key->wrapped_key, + private_key->wrapped_key_length, private_key->key_type, + &private_key_handle, &allowed_schemes); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to unwrap DRM private key into key handle with result: %u", result); @@ -2412,6 +2435,8 @@ OEMCryptoResult OEMCrypto_InstallKeyboxOrOEMCert(const uint8_t* keybox, return WTPI_UnwrapValidateAndInstallKeybox(keybox, length); #else + (void)keybox; + (void)length; return OEMCrypto_ERROR_NOT_IMPLEMENTED; #endif } @@ -2457,6 +2482,8 @@ OEMCryptoResult OEMCrypto_FactoryInstallBCCSignature(const uint8_t* signature, WTPI_StoreBCCSignature(sig_buffer, sizeof(uint8_t) + signature_length); return result; #else + (void)signature; + (void)signature_length; return OEMCrypto_ERROR_NOT_IMPLEMENTED; #endif } @@ -2684,9 +2711,10 @@ OEMCryptoResult OEMCrypto_BuildInformation(char* buffer, "\"MAX_ASYMMETRIC_SIGNATURE_SIZE\":\"" XSTR(MAX_ASYMMETRIC_SIGNATURE_SIZE)"\"" "}" -#endif +#else "," "\"is_debug\":false" +#endif "}"; const size_t build_info_length1 = strlen(kBuildInfo1); @@ -2827,8 +2855,8 @@ OEMCryptoResult OEMCrypto_LoadDRMPrivateKey(OEMCrypto_SESSION session, WTPI_AsymmetricKey_Handle private_key_handle; uint32_t allowed_schemes; result = WTPI_UnwrapIntoAsymmetricKeyHandle( - wrapped_drm_key, wrapped_drm_key_length, drm_key_type, - &private_key_handle, &allowed_schemes); + DEVICE_KEY_WRAP_DRM_CERT, wrapped_drm_key, wrapped_drm_key_length, + drm_key_type, &private_key_handle, &allowed_schemes); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to unwrap DRM private key into key handle with result: %u", result); @@ -2903,7 +2931,7 @@ OEMCryptoResult OEMCrypto_GenerateRSASignature( return OEMCrypto_ERROR_SIGNATURE_FAILURE; } - if (session_context->state == SESSION_LOAD_DRM_RSA_KEY) { + if (session_context->state == SESSION_CAST_RSA_KEY_LOADED) { if ((session_context->allowed_schemes & padding_scheme) != padding_scheme) { LOGE("Invalid padding scheme: %u", session_context->allowed_schemes); return OEMCrypto_ERROR_INVALID_KEY; @@ -2912,8 +2940,9 @@ OEMCryptoResult OEMCrypto_GenerateRSASignature( uint32_t allowed_schemes; AsymmetricKey* private_key = session_context->drm_private_key; result = WTPI_UnwrapIntoAsymmetricKeyHandle( - private_key->wrapped_key, private_key->wrapped_key_length, - private_key->key_type, &private_key_handle, &allowed_schemes); + DEVICE_KEY_WRAP_DRM_CERT, private_key->wrapped_key, + private_key->wrapped_key_length, private_key->key_type, + &private_key_handle, &allowed_schemes); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to unwrap DRM private key into key handle with result: %u", result); @@ -2941,8 +2970,8 @@ OEMCryptoResult OEMCrypto_GenerateRSASignature( } static OEMCryptoResult LoadProvisioningCommon( - OEMCryptoSession* session_context, const uint8_t* provision_request, - size_t provision_request_length, const uint8_t* message, + OEMCryptoSession* session_context, const uint8_t* provision_request UNUSED, + size_t provision_request_length UNUSED, const uint8_t* message, size_t message_length, size_t core_message_length, const uint8_t* signature, size_t signature_length, uint8_t* wrapped_private_key, size_t* wrapped_private_key_length) { @@ -3069,12 +3098,27 @@ OEMCryptoResult OEMCrypto_LoadProvisioningCast( LOGE("OEMCrypto is not yet initialized"); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } + if (OPKI_GetSessionType(session) != SESSION_TYPE_OEMCRYPTO) { + LOGE("Unexpected session type."); + return OEMCrypto_ERROR_INVALID_SESSION; + } + OEMCryptoSession* session_context = NULL; + OEMCryptoResult result = OPKI_GetSession(session, &session_context); + if (result != OEMCrypto_SUCCESS) { + LOGE("Failed to get session with result: %u, session = %u", result, + session); + return result; + } + ABORT_IF(session_context == NULL, + "OPKI_GetSession() provided invalid output."); if (WTPI_GetProvisioningMethod() == OEMCrypto_Keybox) { // TODO(b/316053127): clean this up a bit. - return OEMCrypto_LoadProvisioning( + result = OEMCrypto_LoadProvisioning( session, provision_request, provision_request_length, message, message_length, core_message_length, signature, signature_length, wrapped_private_key, wrapped_private_key_length); + if (result != OEMCrypto_SUCCESS) return result; + return OPKI_SetStatePostCall(session_context, API_LOADPROVISIONINGCAST); } if (OPKI_GetSessionType(session) != SESSION_TYPE_OEMCRYPTO) { LOGE("Unexpected session type."); @@ -3085,15 +3129,6 @@ OEMCryptoResult OEMCrypto_LoadProvisioningCast( RETURN_INVALID_CONTEXT_IF_NULL(signature); RETURN_INVALID_CONTEXT_IF_ZERO(signature_length); RETURN_INVALID_CONTEXT_IF_NULL(wrapped_private_key_length); - OEMCryptoSession* session_context = NULL; - OEMCryptoResult result = OPKI_GetSession(session, &session_context); - if (result != OEMCrypto_SUCCESS) { - LOGE("Failed to get session with result: %u, session = %u", result, - session); - return result; - } - ABORT_IF(session_context == NULL, - "OPKI_GetSession() provided invalid output."); // If this call is just to find the size of the wrapped key, then we won't // derive new keys because that call will erase the drm private key when it's @@ -3109,10 +3144,12 @@ OEMCryptoResult OEMCrypto_LoadProvisioningCast( } } - return LoadProvisioningCommon( + result = LoadProvisioningCommon( session_context, provision_request, provision_request_length, message, message_length, core_message_length, signature, signature_length, wrapped_private_key, wrapped_private_key_length); + if (result != OEMCrypto_SUCCESS) return result; + return OPKI_SetStatePostCall(session_context, API_LOADPROVISIONINGCAST); } OEMCryptoResult OEMCrypto_CreateUsageTableHeader(uint8_t* header_buffer, @@ -3576,7 +3613,7 @@ OEMCryptoResult OEMCrypto_ProcessOTAKeybox(OEMCrypto_SESSION session UNUSED, } OEMCryptoResult OEMCrypto_GetBootCertificateChain( - uint8_t* bcc, size_t* bcc_size, uint8_t* additional_signature, + uint8_t* bcc, size_t* bcc_size, uint8_t* additional_signature UNUSED, size_t* additional_signature_size) { if (g_opk_system_state != SYSTEM_INITIALIZED) { LOGE("OEMCrypto is not yet initialized"); @@ -3654,10 +3691,19 @@ OEMCryptoResult OEMCrypto_GenerateCertificateKeyPair( return result; } } + + // Determine which stage of Prov 4 provisioning we are in + // Stage 1: OEM private key is NOT installed, we are requesting it. + // Stage 2: OEM private key is installed, now requesting DRM cert. + const bool is_stage1 = (session_context->prov40_oem_private_key == NULL); + const CertSignatureType requested_cert_type = + is_stage1 ? CERT_SIGNATURE_OEM : CERT_SIGNATURE_DRM; + const uint32_t wrapping_context = is_stage1 ? DEVICE_KEY_WRAP_OEM_CERT : DEVICE_KEY_WRAP_DRM_CERT; + AsymmetricKeyType generated_key_type; result = WTPI_GenerateRandomCertificateKeyPair( - &generated_key_type, wrapped_private_key, wrapped_private_key_size, - public_key, public_key_size); + requested_cert_type, &generated_key_type, wrapped_private_key, + wrapped_private_key_size, public_key, public_key_size); if (public_key_signature == NULL || *public_key_signature_size < required_signature_size || result == OEMCrypto_ERROR_SHORT_BUFFER) { @@ -3675,10 +3721,8 @@ OEMCryptoResult OEMCrypto_GenerateCertificateKeyPair( LOGE("Invalid key_type: %d", generated_key_type); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - /* The provisioning stage is determined by whether the - * prov40_oem_private_key is installed. NOT installed: first stage; - * Installed: second stage. */ - if (session_context->prov40_oem_private_key == NULL) { + + if (is_stage1) { /* This is the first stage for obtaining an OEM leaf cert. Sign with BCC * leaf private key. */ result = @@ -3691,9 +3735,9 @@ OEMCryptoResult OEMCrypto_GenerateCertificateKeyPair( uint32_t allowed_schemes_unused; AsymmetricKey* oem_private_key = session_context->prov40_oem_private_key; result = WTPI_UnwrapIntoAsymmetricKeyHandle( - oem_private_key->wrapped_key, oem_private_key->wrapped_key_length, - oem_private_key->key_type, &signing_key_handle, - &allowed_schemes_unused); + DEVICE_KEY_WRAP_OEM_CERT, oem_private_key->wrapped_key, + oem_private_key->wrapped_key_length, oem_private_key->key_type, + &signing_key_handle, &allowed_schemes_unused); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to unwrap OEM private key into key handle with result: %u", result); @@ -3736,8 +3780,8 @@ OEMCryptoResult OEMCrypto_GenerateCertificateKeyPair( WTPI_AsymmetricKey_Handle csr_signing_key_handle; uint32_t allowed_schemes; result = WTPI_UnwrapIntoAsymmetricKeyHandle( - wrapped_private_key, *wrapped_private_key_size, generated_key_type, - &csr_signing_key_handle, &allowed_schemes); + wrapping_context, wrapped_private_key, *wrapped_private_key_size, + generated_key_type, &csr_signing_key_handle, &allowed_schemes); if (result != OEMCrypto_SUCCESS) { LOGE( "Failed to unwrap the CSR signing key into key handle with result: " @@ -3768,6 +3812,7 @@ OEMCryptoResult OEMCrypto_GenerateCertificateKeyPair( LOGE("Failed to create asymmetric CSR signing key with result: %u", result); return result; } + session_context->prov40_csr_keywrap_context = wrapping_context; return OPKI_SetStatePostCall(session_context, API_GENERATECERTIFICATEKEYPAIR); } @@ -3871,8 +3916,8 @@ OEMCryptoResult OEMCrypto_InstallOemPrivateKey( WTPI_AsymmetricKey_Handle private_key_handle; uint32_t allowed_schemes; result = WTPI_UnwrapIntoAsymmetricKeyHandle( - wrapped_private_key, wrapped_private_key_length, oem_key_type, - &private_key_handle, &allowed_schemes); + DEVICE_KEY_WRAP_OEM_CERT, wrapped_private_key, wrapped_private_key_length, + oem_key_type, &private_key_handle, &allowed_schemes); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to unwrap OEM private key into key handle with result: %u", result); @@ -3987,7 +4032,7 @@ OEMCryptoResult OEMCrypto_ReassociateEntitledKeySession( break; } } // loop entitlement keys - } // loop entitled keys + } // loop entitled keys if (!key_found) { LOGE("Failed to find entitlement keys in session = %u", entitlement_session); @@ -4385,3 +4430,8 @@ OEMCryptoResult OEMCrypto_GetOEMKeyToken(OEMCrypto_SESSION key_session UNUSED, return OEMCrypto_ERROR_NOT_IMPLEMENTED; } #endif + +OEMCryptoResult OEMCrypto_GetEmbeddedDrmCertificate( + uint8_t* public_cert UNUSED, size_t* public_cert_length UNUSED) { + return OEMCrypto_ERROR_NOT_IMPLEMENTED; +} diff --git a/oemcrypto/opk/oemcrypto_ta/oemcrypto_api_macros.h b/oemcrypto/opk/oemcrypto_ta/oemcrypto_api_macros.h index 3864337..cef2e79 100644 --- a/oemcrypto/opk/oemcrypto_ta/oemcrypto_api_macros.h +++ b/oemcrypto/opk/oemcrypto_ta/oemcrypto_api_macros.h @@ -34,7 +34,7 @@ // version bumps to v17.1, the first released OPK implementation would be // v17.1.0 #define API_MAJOR_VERSION 19 -#define API_MINOR_VERSION 0 +#define API_MINOR_VERSION 1 #define OPK_PATCH_VERSION 0 #endif /* OEMCRYPTO_TA_OEMCRYPTO_API_MACROS_H_ */ diff --git a/oemcrypto/opk/oemcrypto_ta/oemcrypto_key_types.h b/oemcrypto/opk/oemcrypto_ta/oemcrypto_key_types.h index 6ded38d..d10ac3e 100644 --- a/oemcrypto/opk/oemcrypto_ta/oemcrypto_key_types.h +++ b/oemcrypto/opk/oemcrypto_ta/oemcrypto_key_types.h @@ -49,6 +49,12 @@ typedef enum AsymmetricKeyType { PROV40_ED25519_PRIVATE_KEY = (int)0x495ffa5c, } AsymmetricKeyType; +typedef enum CertSignatureType { + CERT_SIGNATURE_OEM = (int)0x386eebf3, + CERT_SIGNATURE_DRM = (int)0x6b4684e3, + CERT_SIGNATURE_CSR = (int)0x1f37a40a, +} CertSignatureType; + /* The valid possible sizes of the crypto and private key. The name is the size in bits, while the value is the size in bytes. */ typedef enum KeySize { diff --git a/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.c b/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.c index 4e4997a..a497974 100644 --- a/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.c +++ b/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.c @@ -24,8 +24,10 @@ #include "wtpi_clock_interface_layer1.h" #include "wtpi_crc32_interface.h" #include "wtpi_decrypt_sample_interface.h" +#include "wtpi_hdcp_interface.h" #include "wtpi_logging_interface.h" #include "wtpi_root_of_trust_interface_layer1.h" +#include "wtpi_device_key_interface.h" NO_IGNORE_RESULT static bool IsSupportedDrmKeyType(AsymmetricKeyType key_type) { return key_type == DRM_RSA_PRIVATE_KEY || key_type == DRM_ECC_PRIVATE_KEY; @@ -118,8 +120,9 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case API_GENERATENONCE: switch (session->state) { case (SESSION_OPENED): - case (SESSION_INSTALL_OEM_PRIVATE_KEY): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_PROV4_OEM_KEY_LOADED): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -127,7 +130,8 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case API_PREPANDSIGN_LICENSE_REQUEST: switch (session->state) { case (SESSION_PREPARING_REQUEST): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -135,10 +139,11 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case API_PREPANDSIGN_PROVISION_REQUEST: switch (session->state) { case (SESSION_OPENED): - case (SESSION_INSTALL_OEM_PRIVATE_KEY): - case (SESSION_PREPARING_REQUEST): - case (SESSION_LOAD_DRM_RSA_KEY): case (SESSION_LOAD_OEM_RSA_KEY): + case (SESSION_PROV4_OEM_KEY_LOADED): + case (SESSION_PREPARING_REQUEST): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -157,7 +162,7 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, } case API_LOADPROVISIONING: switch (session->state) { - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): case (SESSION_WAIT_FOR_PROVISIONING): return OEMCrypto_SUCCESS; default: @@ -171,18 +176,27 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, default: goto err; } + case API_LOADPROVISIONINGCAST: + switch (session->state) { + case (SESSION_WAIT_FOR_PROVISIONING): + return OEMCrypto_SUCCESS; + default: + goto err; + } case API_LOADDRMPRIVATEKEY: switch (session->state) { case (SESSION_OPENED): case (SESSION_PREPARING_REQUEST): case (SESSION_USAGE_ENTRY_LOADED): // Prov 4 OEM private key installed at beginning of session - case (SESSION_INSTALL_OEM_PRIVATE_KEY): + case (SESSION_PROV4_OEM_KEY_LOADED): // Provisioning 4 skips LoadProvisioning case (SESSION_WAIT_FOR_PROVISIONING): // This can happen when using testing the CDM with a pre-provisioned // device. - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_PROVISIONED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -205,7 +219,7 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case (SESSION_OPENED): case (SESSION_PREPARING_REQUEST): case (SESSION_USAGE_ENTRY_LOADED): - case (SESSION_INSTALL_OEM_PRIVATE_KEY): + case (SESSION_PROV4_OEM_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -214,7 +228,8 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, switch (session->state) { case (SESSION_OPENED): case (SESSION_LOAD_OEM_RSA_KEY): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -222,7 +237,8 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case API_CREATENEWUSAGEENTRY: switch (session->state) { case (SESSION_OPENED): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): case (SESSION_WAIT_FOR_LICENSE): return OEMCrypto_SUCCESS; default: @@ -231,7 +247,8 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case API_LOADUSAGEENTRY: switch (session->state) { case (SESSION_OPENED): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -239,7 +256,8 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case API_REUSEUSAGEENTRY: switch (session->state) { case (SESSION_OPENED): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -299,7 +317,8 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, switch (session->state) { case (SESSION_OPENED): case (SESSION_LICENSE_LOADED): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): case (SESSION_PLAYING): return OEMCrypto_SUCCESS; default: @@ -310,7 +329,8 @@ OEMCryptoResult OPKI_CheckStatePreCall(OEMCryptoSession* session, case (SESSION_USAGE_ENTRY_LOADED): case (SESSION_OPENED): case (SESSION_WAIT_FOR_LICENSE): - case (SESSION_LOAD_DRM_RSA_KEY): + case (SESSION_DRM_KEY_LOADED): + case (SESSION_CAST_RSA_KEY_LOADED): return OEMCrypto_SUCCESS; default: goto err; @@ -347,7 +367,7 @@ OEMCryptoResult OPKI_SetStatePostCall(OEMCryptoSession* session, switch (api) { case API_OPENSESSION: if (session->drm_private_key) { - session->state = SESSION_LOAD_DRM_RSA_KEY; + session->state = SESSION_DRM_KEY_LOADED; } else { session->state = SESSION_OPENED; } @@ -364,30 +384,38 @@ OEMCryptoResult OPKI_SetStatePostCall(OEMCryptoSession* session, case API_LOADKEYS: case API_LOADLICENSE: case API_LOADRENEWAL: - case API_LOADRELEASE: case API_REFRESHKEYS: session->state = SESSION_LICENSE_LOADED; break; case API_LOADPROVISIONING: session->state = SESSION_PROVISIONED; break; - case API_GENERATERSASIGNATURE: - session->state = SESSION_CAST_RECEIVER; + case API_LOADPROVISIONINGCAST: + session->state = SESSION_CAST_PROVISIONED; break; case API_LOADUSAGEENTRY: session->state = SESSION_USAGE_ENTRY_LOADED; break; case API_DEACTIVATEUSAGEENTRY: + case API_LOADRELEASE: session->state = SESSION_INACTIVE; break; case API_LOADDRMPRIVATEKEY: - session->state = SESSION_LOAD_DRM_RSA_KEY; + if (session->state == SESSION_CAST_RECEIVER || + session->state == SESSION_CAST_PROVISIONED || + session->state == SESSION_CAST_RSA_KEY_LOADED || + (session->allowed_schemes & kSign_PKCS1_Block1) == + kSign_PKCS1_Block1 /* Cast only scheme */) { + session->state = SESSION_CAST_RSA_KEY_LOADED; + } else { + session->state = SESSION_DRM_KEY_LOADED; + } break; case API_LOADOEMPRIVATEKEY: session->state = SESSION_LOAD_OEM_RSA_KEY; break; case API_INSTALLOEMPRIVATEKEY: - session->state = SESSION_INSTALL_OEM_PRIVATE_KEY; + session->state = SESSION_PROV4_OEM_KEY_LOADED; break; case API_DECRYPTCENC: case API_GENERICENCRYPT: @@ -412,6 +440,7 @@ OEMCryptoResult OPKI_SetStatePostCall(OEMCryptoSession* session, case API_GETHASHERRORCODE: case API_CREATEENTITLEDKEYSESSION: case API_GENERATECERTIFICATEKEYPAIR: + case API_GENERATERSASIGNATURE: /* State does not change. */ break; default: @@ -627,14 +656,17 @@ OEMCryptoResult OPKI_GenerateCertSignature(OEMCryptoSession* session, } AsymmetricKey* signing_key; + uint32_t wrapping_context; if (signature_type == CERT_SIGNATURE_DRM) { if (!DRMKeyMaySign(session->drm_private_key)) return OEMCrypto_ERROR_INVALID_KEY; signing_key = session->drm_private_key; + wrapping_context = DEVICE_KEY_WRAP_DRM_CERT; } else if (signature_type == CERT_SIGNATURE_CSR) { if (!DRMKeyMaySign(session->prov40_csr_signing_key)) return OEMCrypto_ERROR_INVALID_KEY; signing_key = session->prov40_csr_signing_key; + wrapping_context = session->prov40_csr_keywrap_context; } else { return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -642,7 +674,7 @@ OEMCryptoResult OPKI_GenerateCertSignature(OEMCryptoSession* session, WTPI_AsymmetricKey_Handle signing_key_handle; uint32_t allowed_schemes; OEMCryptoResult result = WTPI_UnwrapIntoAsymmetricKeyHandle( - signing_key->wrapped_key, signing_key->wrapped_key_length, + wrapping_context, signing_key->wrapped_key, signing_key->wrapped_key_length, signing_key->key_type, &signing_key_handle, &allowed_schemes); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to unwrap signing key into key handle with result: %u", @@ -666,12 +698,16 @@ NO_IGNORE_RESULT OEMCryptoResult OPKI_GetSessionSignatureHashAlgorithm( if (!session) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const AsymmetricKey* key; + uint32_t context; if (session->drm_private_key != NULL) { key = session->drm_private_key; + context = DEVICE_KEY_WRAP_DRM_CERT; } else if (session->prov40_oem_private_key != NULL) { key = session->prov40_oem_private_key; + context = DEVICE_KEY_WRAP_OEM_CERT; } else if (session->prov40_csr_signing_key != NULL) { key = session->prov40_csr_signing_key; + context = session->prov40_csr_keywrap_context; } else { LOGE("No asymmetric keys loaded."); return OEMCrypto_ERROR_UNKNOWN_FAILURE; @@ -680,8 +716,8 @@ NO_IGNORE_RESULT OEMCryptoResult OPKI_GetSessionSignatureHashAlgorithm( WTPI_AsymmetricKey_Handle key_handle; uint32_t ignored; OEMCryptoResult result = WTPI_UnwrapIntoAsymmetricKeyHandle( - key->wrapped_key, key->wrapped_key_length, key->key_type, &key_handle, - &ignored); + context, key->wrapped_key, key->wrapped_key_length, key->key_type, + &key_handle, &ignored); if (result != OEMCrypto_SUCCESS) { LOGE("Failed to unwrap key into key handle with result: %u", result); return result; diff --git a/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.h b/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.h index d32fa71..cebdbb3 100644 --- a/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.h +++ b/oemcrypto/opk/oemcrypto_ta/oemcrypto_session.h @@ -10,6 +10,7 @@ #include "oemcrypto_compiler_attributes.h" #include "oemcrypto_entitled_key_session.h" #include "oemcrypto_key.h" +#include "oemcrypto_key_types.h" #include "wtpi_config_interface.h" #include "wtpi_crypto_and_key_management_interface_layer1.h" #include "wtpi_crypto_asymmetric_interface.h" @@ -20,6 +21,7 @@ typedef enum OEMCryptoSessionState { SESSION_PREPARING_REQUEST = (int)0x5bf5c800, SESSION_WAIT_FOR_PROVISIONING = (int)0xa93cc63e, SESSION_PROVISIONED = (int)0x95a11af7, + SESSION_CAST_PROVISIONED = (int)0x67b023ea, SESSION_WAIT_FOR_LICENSE = (int)0x8cea3faa, SESSION_LICENSE_LOADED = (int)0xb813366b, SESSION_EXPIRED = (int)0x0c118e73, @@ -29,8 +31,9 @@ typedef enum OEMCryptoSessionState { SESSION_CAST_RECEIVER = (int)0x738620df, SESSION_INVALID = (int)0x23a27071, SESSION_LOAD_OEM_RSA_KEY = (int)0x9d7cae94, - SESSION_LOAD_DRM_RSA_KEY = (int)0xbc17f592, - SESSION_INSTALL_OEM_PRIVATE_KEY = (int)0x902c5b0a, + SESSION_DRM_KEY_LOADED = (int)0xbc17f592, + SESSION_PROV4_OEM_KEY_LOADED = (int)0x902c5b0a, + SESSION_CAST_RSA_KEY_LOADED = (int)0x84a0bb23, } OEMCryptoSessionState; /* The API being executed for the current session. */ @@ -58,6 +61,7 @@ typedef enum OEMCryptoSessionAPI { API_PREPANDSIGN_RENEWAL_REQUEST = (int)0x7b55062c, API_PREPANDSIGN_RELEASE_REQUEST = (int)0x2d870ff4, API_LOADPROVISIONING = (int)0xe8c746c9, + API_LOADPROVISIONINGCAST = (int)0xd2e9ac20, API_LOADDRMPRIVATEKEY = (int)0x573c7779, API_CREATENEWUSAGEENTRY = (int)0x1e328c13, API_REUSEUSAGEENTRY = (int)0x1a35e802, @@ -75,12 +79,6 @@ typedef enum OEMCryptoSessionAPI { API_GETKEYHANDLE = (int)0x81aac42f, } OEMCryptoSessionAPI; -typedef enum CertSignatureType { - CERT_SIGNATURE_OEM = (int)0x386eebf3, - CERT_SIGNATURE_DRM = (int)0x6b4684e3, - CERT_SIGNATURE_CSR = (int)0x1f37a40a, -} CertSignatureType; - typedef struct OEMCryptoSession { OEMCrypto_SESSION session_id; OEMCryptoSessionState state; @@ -92,6 +90,7 @@ typedef struct OEMCryptoSession { * it is the generated OEM private key. For stage 2, it is the generated DRM * private key. */ AsymmetricKey* prov40_csr_signing_key; + uint32_t prov40_csr_keywrap_context; SymmetricKey* mac_key_server; SymmetricKey* mac_key_client; SymmetricKey* encryption_key; diff --git a/oemcrypto/opk/oemcrypto_ta/oemcrypto_usage_table.c b/oemcrypto/opk/oemcrypto_ta/oemcrypto_usage_table.c index e703bf4..ccf9e4f 100644 --- a/oemcrypto/opk/oemcrypto_ta/oemcrypto_usage_table.c +++ b/oemcrypto/opk/oemcrypto_ta/oemcrypto_usage_table.c @@ -1248,6 +1248,9 @@ NO_IGNORE_RESULT OEMCryptoResult OPKI_UpdateClockValues( OEMCrypto_SESSION session_id, ODK_ClockValues* clock_values) { RETURN_INVALID_CONTEXT_IF_NULL(clock_values); UsageEntry* entry = FindUsageEntry(session_id); + if (!entry) { + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } /* New clock values in the usage entry. */ OEMCryptoResult result = UpdateClockValues(entry, clock_values); entry->data.generation_number++; diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_config_interface.h b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_config_interface.h index c44566e..13cdb01 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_config_interface.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_config_interface.h @@ -20,8 +20,8 @@ extern "C" { * * It gives the TA access to metadata about the device such as build info, * resource rating tier, etc. * - * * It allows the TA to control and query the output control mechanisms such - * as CGMS-A, HDCP, etc. + * * It allows the TA to control and query some output control mechanisms such + * as CGMS-A. * * @{ */ @@ -100,20 +100,6 @@ OEMCrypto_WatermarkingSupport WTPI_GetWatermarkingSupport(void); OEMCrypto_DTCP2_Capability WTPI_GetDTCP2Capability(void); -/** - * Gets the current supported version of SRM for the device and sets the - * |srm_version|. Returns OEMCrypto_SUCCESS if it was able to be fetched, - * OEMCrypto_ERROR_INVALID_CONTEXT if |srm_version| is NULL, any - * OEMCrypto_ERROR_UNKNOWN_FAILURE otherwise. - * - * @param[out] srm_version: pointer to SRM version. - * - * @retval OEMCrypto_SUCCESS - * @retval OEMCrypto_ERROR_INVALID_CONTEXT - * @retval OEMCrypto_ERROR_UNKNOWN_FAILURE - */ -OEMCryptoResult WTPI_GetCurrentSRMVersion(uint32_t* srm_version); - /** * Returns whether the device has hardware protection preventing rollback of the * usage table. @@ -158,17 +144,6 @@ bool WTPI_DisableAnalogDisplay(void); */ size_t WTPI_MaxOutputSizeForDecrypt(void); -/** - * Returns the current capability of the device. Look at the OEMCrypto - * integration guide for full details on what the current capability entail. - */ -OEMCrypto_HDCP_Capability WTPI_CurrentHDCPCapability(void); - -/** - * Returns the maximum HDCP capability of the device. Look at the OEMCrypto - * integration guide for full details on what the maximum capability entail. - */ -OEMCrypto_HDCP_Capability WTPI_MaxHDCPCapability(void); /** * Returns the max buffer size allowed for OEMCrypto_Generic_*. diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_crypto_asymmetric_interface.h b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_crypto_asymmetric_interface.h index eedbae9..8670711 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_crypto_asymmetric_interface.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_crypto_asymmetric_interface.h @@ -68,6 +68,7 @@ OEMCryptoResult WTPI_CreateAsymmetricKeyHandle( * * Caller retains ownership of all parameters. * + * @param[in] context: the expected context that was used to wrap the key * @param[in] input: wrapped asymmetric key * @param[in] input_length: size of the wrapped asymmetric key * @param[in] key_type: type of asymmetric key @@ -83,8 +84,9 @@ OEMCryptoResult WTPI_CreateAsymmetricKeyHandle( * @retval OEMCrypto_SUCCESS otherwise */ OEMCryptoResult WTPI_UnwrapIntoAsymmetricKeyHandle( - const uint8_t* input, size_t input_length, AsymmetricKeyType key_type, - WTPI_AsymmetricKey_Handle* key_handle, uint32_t* allowed_schemes); + uint32_t context, const uint8_t* input, size_t input_length, + AsymmetricKeyType key_type, WTPI_AsymmetricKey_Handle* key_handle, + uint32_t* allowed_schemes); /** * Frees |key_handle| that was constructed from a previous call to @@ -133,6 +135,7 @@ OEMCryptoResult WTPI_GetWrappedAsymmetricKeySize(size_t enc_private_key_length, * This is given the clear, PKCS8-padded key and the key may be prefixed with * "SIGN" and a 4-byte code for the padding schemes. * + * @param[in] context: context for wrapping scheme * @param[out] output: destination buffer that will contain the wrapped key data * @param[in] output_length: length of destination buffer * @param[in] key_type: type of asymmetric key @@ -146,7 +149,8 @@ OEMCryptoResult WTPI_GetWrappedAsymmetricKeySize(size_t enc_private_key_length, * @retval OEMCrypto_ERROR_SHORT_BUFFER output_length is too small * @retval OEMCrypto_ERROR_UNKNOWN_FAILURE otherwise */ -OEMCryptoResult WTPI_WrapAsymmetricKey(uint8_t* output, size_t output_length, +OEMCryptoResult WTPI_WrapAsymmetricKey(uint32_t context, uint8_t* output, + size_t output_length, AsymmetricKeyType key_type, const uint8_t* clear_key, size_t clear_key_length); @@ -323,6 +327,37 @@ OEMCryptoResult WTPI_GetSignatureHashAlgorithm( WTPI_AsymmetricKey_Handle key, AsymmetricKeyType key_type, OEMCrypto_SignatureHashAlgorithm* hash_algorithm); +/** + * Derive an asymmetric key pair from the input deriving key. The derived + * key pair is placed into |private_key_handle| and |public_key|. + * + * @param[in] deriving_key: The deriving key in clear bytes. + * @param[in] deriving_key_length: size of of |deriving_key| in bytes. + * @param[in] context: input context for deriving key. + * @param[in] context_length: size of of |context| in bytes. + * @param[in] key_type: type of asymmetric key. + * @param[out] private_key_handle: The derived private key. + * @param[out] public_key: The derived public key. + * @param[in,out] public_key_length: size of |public_key| buffer, may be + * modified based on used/required space of output. + * + * Caller retains ownership of all pointers. + * + * @retval OEMCrypto_ERROR_INVALID_CONTEXT if |deriving_key|, |context|, + * |private_key_handle|, or |public_key_length| is NULL, or any of + * |deriving_key_length|, |context_length| is zero + * @retval OEMCrypto_ERROR_SHORT_BUFFER if |public_key_length| is too small, or + * |public_key| is NULL, in which case it sets |public_key_length| to the + * appropriate length + * @retval OEMCrypto_ERROR_UNKNOWN_FAILURE any other failures + * @retval OEMCrypto_SUCCESS + */ +OEMCryptoResult WTPI_DeriveNewAsymmetricKeyHandle( + const uint8_t* deriving_key, size_t deriving_key_length, + const uint8_t* context, size_t context_length, AsymmetricKeyType key_type, + WTPI_AsymmetricKey_Handle* private_key_handle, uint8_t* public_key, + size_t* public_key_length); + /// @} #ifdef __cplusplus diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_device_key_interface.h b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_device_key_interface.h index 103bd39..7de054d 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_device_key_interface.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_device_key_interface.h @@ -35,13 +35,21 @@ extern "C" { */ #define DEVICE_KEY_WRAP_USAGE_TABLE 0x22d8fdcf -/** A device unique key for encrypting/signing the private key in the DRM - * certificate. This key must be unique to this device so that a DRM certificate - * not be copied from one device to another. +/** A device unique key for encrypting/signing the private key in the DRM/OEM + * certificates. This key must be unique to this device so that a DRM/OEM + * certificate not be copied from one device to another. * This should be used as a key derivation context in * WTPI_K1_DeriveDeviceKeyIntoHandle(). + * + * DEVICE_KEY_WRAP_DRM_CERT_V1 is for unwrapping DRM certs that were wrapped on + * OPK implementations v19.0 and older. + * + * DEVICE_KEY_WRAP_DRM_CERT and DEVICE_KEY_WRAP_OEM_CERT are used as wrapping + * keys */ -#define DEVICE_KEY_WRAP_DRM_CERT 0x1db2a411 +#define DEVICE_KEY_WRAP_DRM_CERT_V1 0x1db2a411 +#define DEVICE_KEY_WRAP_DRM_CERT 0x90833ed3 +#define DEVICE_KEY_WRAP_OEM_CERT 0x88b24739 /** A device unique key for encrypting the internal key used by the * implementation of the key management layer. This should be used as a key diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_hdcp_interface.h b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_hdcp_interface.h new file mode 100644 index 0000000..8a3f8d4 --- /dev/null +++ b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_hdcp_interface.h @@ -0,0 +1,70 @@ +/* Copyright 2024 Google LLC. All Rights Reserved. This file and proprietary + source code may only be used and distributed under the Widevine + License Agreement. */ + +#ifndef OEMCRYPTO_TA_WTPI_HDCP_INTERFACE_H_ +#define OEMCRYPTO_TA_WTPI_HDCP_INTERFACE_H_ + +#include + +#include "OEMCryptoCENC.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @defgroup hdcp HDCP Control + * + * These functions provide access and control of HDCP capabilities. + * + * @{ + */ + +#ifdef USE_OPK_FEATURE_SETHDCP +/** + * Attempts to set the device's HDCP auth level to |level|. Return + * OEMCrypto_ERROR_NOT_IMPLEMENTED if HDCP cannot be controlled from the TEE. + * + * @param[in] level: desired HDCP level + * + * @retval OEMCrypto_SUCCESS + * @retval OEMCrypto_ERROR_INVALID_CONTEXT + * @retval OEMCrypto_ERROR_UNKNOWN_FAILURE + * + */ +OEMCryptoResult WTPI_SetHDCPLevel(OEMCrypto_HDCP_Capability level); +#endif // USE_OPK_FEATURE_SETHDCP + +/** + * Returns the current capability of the device. Look at the OEMCrypto + * integration guide for full details on what the current capability entail. + */ +OEMCrypto_HDCP_Capability WTPI_CurrentHDCPCapability(void); + +/** + * Returns the maximum HDCP capability of the device. Look at the OEMCrypto + * integration guide for full details on what the maximum capability entail. + */ +OEMCrypto_HDCP_Capability WTPI_MaxHDCPCapability(void); + +/** + * Gets the current supported version of SRM for the device and sets the + * |srm_version|. Returns OEMCrypto_SUCCESS if it was able to be fetched, + * OEMCrypto_ERROR_INVALID_CONTEXT if |srm_version| is NULL, any + * OEMCrypto_ERROR_UNKNOWN_FAILURE otherwise. + * + * @param[out] srm_version: pointer to SRM version. + * + * @retval OEMCrypto_SUCCESS + * @retval OEMCrypto_ERROR_INVALID_CONTEXT + * @retval OEMCrypto_ERROR_UNKNOWN_FAILURE + */ +OEMCryptoResult WTPI_GetCurrentSRMVersion(uint32_t* srm_version); + +/// @} + +#ifdef __cplusplus +} +#endif + +#endif /* OEMCRYPTO_TA_WTPI_HDCP_INTERFACE_H_ */ diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_provisioning_4_interface.h b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_provisioning_4_interface.h index db47e7c..dbd63f1 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_provisioning_4_interface.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi/wtpi_provisioning_4_interface.h @@ -8,6 +8,7 @@ #include "OEMCryptoCENC.h" #include "wtpi_crypto_asymmetric_interface.h" +#include "oemcrypto_key_types.h" #ifdef __cplusplus extern "C" { @@ -80,16 +81,19 @@ OEMCryptoResult WTPI_GetMaxBootCertificateChainSize(size_t* out_length); * * Caller retains ownership of all pointers. * + * @param[in] cert_type: DRM or OEM cert type, which should each result in a + * different wrapping context for the |wrapped_private_key| output * @param[out] key_type: Type (RSA or EC) of the generated key pair. * @param[out] wrapped_private_key: The generated private key, wrapped with * encryption key for storage. * @param[in,out] wrapped_private_key_length: size of |wrapped_private_key| * buffer, may be modified based on used/required space of output. * @param[out] public_key: The generated public key. - * @param[in,out] public_key_length: size of |public_key_length| buffer, may be + * @param[in,out] public_key_length: size of |public_key| buffer, may be * modified based on used/required space of output. */ OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( + CertSignatureType cert_type, AsymmetricKeyType* key_type, uint8_t* wrapped_private_key, size_t* wrapped_private_key_length, uint8_t* public_key, size_t* public_key_length); @@ -291,6 +295,31 @@ OEMCryptoResult WTPI_StoreBCCSignature(const uint8_t* signature, OEMCryptoResult WTPI_LoadBCCSignature(uint8_t* signature, size_t* signature_length); +/** + * Retrieve the device unique secret and derive a device specific asymmetric key + * pair (DK_priv/DK_pub) as the root of trust of BCC. The output key must be + * identical across reboots. + * + * Caller retains ownership of all parameters. + * + * @param[out] key_type: type of asymmetric key. + * @param[out] private_key_handle: The derived private key. + * @param[out] public_key: The derived public key. + * @param[in,out] public_key_length: size of |public_key| buffer, may be + * modified based on used/required space of output. + * + * @retval OEMCrypto_ERROR_INVALID_CONTEXT if |key_type|, |private_key_handle|, + * or |public_key_length| is NULL + * @retval OEMCrypto_ERROR_SHORT_BUFFER if |public_key_length| is too small, or + * |public_key| is NULL, in which case it sets |public_key_length| to the + * appropriate length + * @retval OEMCrypto_ERROR_UNKNOWN_FAILURE any other failures + * @retval OEMCrypto_SUCCESS + */ +OEMCryptoResult WTPI_CreateUDSDerivedAsymmetricKeyHandle( + AsymmetricKeyType* key_type, WTPI_AsymmetricKey_Handle* private_key_handle, + uint8_t* public_key, size_t* public_key_length); + /// @} #ifdef __cplusplus diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/config/default.h b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/config/default.h index 354ce2a..5811bfa 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/config/default.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/config/default.h @@ -297,7 +297,7 @@ * Size of overhead required by WTPI_EncryptAndSign (if applicable). */ #ifndef ENCRYPT_AND_SIGN_EXTRA -# define ENCRYPT_AND_SIGN_EXTRA 68 +# define ENCRYPT_AND_SIGN_EXTRA 72 #endif /** diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/cose_util.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/cose_util.c index 3afb3cd..09de797 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/cose_util.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/cose_util.c @@ -377,7 +377,8 @@ static OEMCryptoResult GenerateEncodedBccPayload( uint8_t hash[SHA256_DIGEST_LENGTH]; struct CborOut cbor_out; CborOutInit(out, *out_length, &cbor_out); - CborWriteMap(/*num_pairs=*/4, &cbor_out); + // Make sure the number of items added below matches this num_pairs. + CborWriteMap(/*num_pairs=*/8, &cbor_out); // Add mandatory field Issuer, which is ignored by provisioning server and can // be empty. diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/crypto_util.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/crypto_util.c index 353ad86..e8970a9 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/crypto_util.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/crypto_util.c @@ -109,9 +109,8 @@ bool OPKI_DeriveKeyWithCMAC(const uint8_t* key, KeySize key_size, ABORT_IF_ZERO(context_length); ABORT_IF_NULL(context_suffix); ABORT_IF_NULL(out); - ABORT_IF((key_size != KEY_SIZE_128 && key_size != KEY_SIZE_256) || - (out_key_size != KEY_SIZE_128 && out_key_size != KEY_SIZE_256), - "Invalid key size"); + ABORT_IF(out_key_size != KEY_SIZE_128 && out_key_size != KEY_SIZE_256, + "Invalid output key size"); const EVP_CIPHER* cipher; switch (key_size) { diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/ecc_util.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/ecc_util.c index 57052dd..fb1d83f 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/ecc_util.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/ecc_util.c @@ -99,7 +99,6 @@ bool DeserializeECCPrivateKey(const uint8_t* serialized_bytes, size_t size, /* Step 1: Deserializes PKCS8 PrivateKeyInfo containing an ECC key. */ PKCS8_PRIV_KEY_INFO* priv_info = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL); BIO_free(bio); - bio = NULL; if (priv_info == NULL) { LOGE("Failed to parse private key"); dump_ssl_error(); @@ -108,7 +107,6 @@ bool DeserializeECCPrivateKey(const uint8_t* serialized_bytes, size_t size, /* Step 2: Convert to EC_KEY. */ EVP_PKEY* pkey = EVP_PKCS82PKEY(priv_info); PKCS8_PRIV_KEY_INFO_free(priv_info); - priv_info = NULL; if (pkey == NULL) { LOGE("Failed to convert PKCS8 to EVP"); dump_ssl_error(); @@ -116,7 +114,6 @@ bool DeserializeECCPrivateKey(const uint8_t* serialized_bytes, size_t size, } EC_KEY* key = EVP_PKEY_get1_EC_KEY(pkey); EVP_PKEY_free(pkey); - pkey = NULL; if (key == NULL) { LOGE("Failed to get ECC key"); dump_ssl_error(); diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_clock_and_gn_layer1.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_clock_and_gn_layer1.c index f401002..3fd587a 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_clock_and_gn_layer1.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_clock_and_gn_layer1.c @@ -73,10 +73,9 @@ static OEMCryptoResult InitializeData(void) { LOGE("Failed to load persistent data with result: %d", status); return status; } - uint8_t version_number = buffer[0]; if (status == OPK_ERROR_NO_PERSISTENT_DATA || data_length != PERSISTENT_DATA_SIZE || - version_number != PERSISTENT_FORMAT_VERSION_NUMBER) { + buffer[0] != PERSISTENT_FORMAT_VERSION_NUMBER) { // Note: In the future, we may wish to handle older version numbers. // This is the first initialization. Start the generation number at random // value and the clock at 0. @@ -130,6 +129,39 @@ static OEMCryptoResult SaveData(void) { return WTPI_StorePersistentData(buffer, data_length); } +static OEMCryptoResult GetTrustedTimeAndSave(uint64_t* time_in_s, + bool force_save) { + RETURN_INVALID_CONTEXT_IF_NULL(time_in_s); + OEMCryptoResult status = OEMCrypto_SUCCESS; + if (!gInitialized) { + status = InitializeData(); + if (status != OEMCrypto_SUCCESS) return status; + } + uint64_t hw_timer = 0; + status = WTPI_GetSecureTimer(&hw_timer); + if (status != OEMCrypto_SUCCESS) return status; + uint64_t now = hw_timer + gClockDelta; + // If the hardware clock goes backwards, or the clock delta has not been + // initialized by the saved wall clock, then now might be less than the last + // time. In that case, we increase the delta so that our clock continues to + // move forward. + if (now < gLastTime) { + gClockDelta = gLastTime - hw_timer; + now = gLastTime; + LOGD("Clock drift. update now = %" PRIu64 ", and delta %" PRId64 + " = %" PRIu64 " - %" PRIu64, + now, gClockDelta, gLastTime, hw_timer); + } else { + gLastTime = now; + } + *time_in_s = now; + if (force_save || now > gLastSaveTime + PERIODIC_SAVE_TIME) { + status = SaveData(); + if (status != OEMCrypto_SUCCESS) return status; + } + return OEMCrypto_SUCCESS; +} + /****************************************************************************** The following implement the generation number interface. *******************************************************************************/ @@ -172,39 +204,12 @@ OEMCryptoResult WTPI_InitializeClock(void) { OEMCryptoResult WTPI_TerminateClock(void) { if (!gInitialized) return OEMCrypto_SUCCESS; - return SaveData(); + uint64_t temp = 0; + return GetTrustedTimeAndSave(&temp, true); } OEMCrypto_Clock_Security_Level WTPI_GetClockType(void) { return kSecureTimer; } OEMCryptoResult WTPI_GetTrustedTime(uint64_t* time_in_s) { - RETURN_INVALID_CONTEXT_IF_NULL(time_in_s); - OEMCryptoResult status = OEMCrypto_SUCCESS; - if (!gInitialized) { - status = InitializeData(); - if (status != OEMCrypto_SUCCESS) return status; - } - uint64_t hw_timer = 0; - status = WTPI_GetSecureTimer(&hw_timer); - if (status != OEMCrypto_SUCCESS) return status; - uint64_t now = hw_timer + gClockDelta; - // If the hardware clock goes backwards, or the clock delta has not been - // initialized by the saved wall clock, then now might be less than the last - // time. In that case, we increase the delta so that our clock continues to - // move forward. - if (now < gLastTime) { - gClockDelta = gLastTime - hw_timer; - now = gLastTime; - LOGD("Clock drift. update now = %" PRIu64 ", and delta %" PRId64 - " = %" PRIu64 " - %" PRIu64, - now, gClockDelta, gLastTime, hw_timer); - } else { - gLastTime = now; - } - *time_in_s = now; - if (now > gLastSaveTime + PERIODIC_SAVE_TIME) { - status = SaveData(); - if (status != OEMCrypto_SUCCESS) return status; - } - return OEMCrypto_SUCCESS; + return GetTrustedTimeAndSave(time_in_s, false); } diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_config.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_config.c index 3592c02..94277d5 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_config.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_config.c @@ -4,7 +4,6 @@ * License Agreement. */ -#include "config/default.h" #include "opk_config.h" #include "wtpi_config_interface.h" @@ -21,6 +20,9 @@ OEMCryptoResult WTPI_GetBCCType(OEMCrypto_BCCType* bcc_type) { if (bcc_type == NULL) { return OEMCrypto_ERROR_INVALID_CONTEXT; } + if (WTPI_GetProvisioningMethod() != OEMCrypto_BootCertificateChain) { + return OEMCrypto_ERROR_NOT_IMPLEMENTED; + } *bcc_type = OEMCrypto_CBOR; return OEMCrypto_SUCCESS; } @@ -43,14 +45,6 @@ OEMCrypto_DTCP2_Capability WTPI_GetDTCP2Capability(void) { return OEMCrypto_NO_DTCP2; } -OEMCryptoResult WTPI_GetCurrentSRMVersion(uint32_t* srm_version) { - if (srm_version == NULL) { - return OEMCrypto_ERROR_INVALID_CONTEXT; - } - *srm_version = 0; - return OEMCrypto_SUCCESS; -} - bool WTPI_IsAntiRollbackHWPresent(void) { return OPK_CONFIG_HW_ANTIROLLBACK_SUPPORTED; } @@ -73,14 +67,6 @@ size_t WTPI_MaxOutputSizeForDecrypt(void) { return OPK_CONFIG_MAX_OUTPUT_SIZE_FOR_DECRYPT; } -OEMCrypto_HDCP_Capability WTPI_CurrentHDCPCapability(void) { - return HDCP_NO_DIGITAL_OUTPUT; -} - -OEMCrypto_HDCP_Capability WTPI_MaxHDCPCapability(void) { - return OPK_CONFIG_MAX_HDCP_CAPABILITY; -} - size_t WTPI_MaxBufferSizeForGenericCrypto(void) { return OPK_CONFIG_MAX_BUFFER_SIZE_FOR_GENERIC_CRYPTO; } diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_and_key_management_layer1_openssl.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_and_key_management_layer1_openssl.c index fc1b2d7..c3a77eb 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_and_key_management_layer1_openssl.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_and_key_management_layer1_openssl.c @@ -581,9 +581,10 @@ cleanup: return result; } -OEMCryptoResult WTPI_K1_WrapKey(uint32_t context, +OEMCryptoResult WTPI_K1_WrapKey(uint32_t context UNUSED, WTPI_K1_SymmetricKey_Handle key_handle, - SymmetricKeyType key_type, uint8_t* wrapped_key, + SymmetricKeyType key_type UNUSED, + uint8_t* wrapped_key, size_t wrapped_key_length) { if (key_handle == NULL || wrapped_key == NULL || wrapped_key_length == 0) { return OEMCrypto_ERROR_INVALID_CONTEXT; @@ -608,8 +609,9 @@ OEMCryptoResult WTPI_K1_WrapKey(uint32_t context, } OEMCryptoResult WTPI_K1_UnwrapIntoKeyHandle( - uint32_t context, const uint8_t* wrapped_key, size_t wrapped_key_length, - SymmetricKeyType key_type, WTPI_K1_SymmetricKey_Handle* out_key_handle) { + uint32_t context UNUSED, const uint8_t* wrapped_key, + size_t wrapped_key_length, SymmetricKeyType key_type, + WTPI_K1_SymmetricKey_Handle* out_key_handle) { if (wrapped_key == NULL || wrapped_key_length == 0 || out_key_handle == NULL) { return OEMCrypto_ERROR_INVALID_CONTEXT; @@ -674,8 +676,8 @@ OEMCryptoResult WTPI_C1_RandomBytes(uint8_t* out, size_t size) { } OEMCryptoResult WTPI_K1_PrepareExternalKeyHandle( - WTPI_K1_SymmetricKey_Handle key_handle, uint8_t* out_buffer, - size_t* out_buffer_length) { + WTPI_K1_SymmetricKey_Handle key_handle UNUSED, uint8_t* out_buffer UNUSED, + size_t* out_buffer_length UNUSED) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_asymmetric.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_asymmetric.c index 6099ece..6674dd1 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_asymmetric.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_asymmetric.c @@ -335,3 +335,45 @@ OEMCryptoResult WTPI_GetSignatureHashAlgorithm( } return OEMCrypto_ERROR_UNKNOWN_FAILURE; } + +OEMCryptoResult WTPI_DeriveNewAsymmetricKeyHandle( + const uint8_t* deriving_key, size_t deriving_key_length, + const uint8_t* context, size_t context_length, AsymmetricKeyType key_type, + WTPI_AsymmetricKey_Handle* private_key_handle, uint8_t* public_key, + size_t* public_key_length) { + RETURN_INVALID_CONTEXT_IF_NULL(deriving_key); + RETURN_INVALID_CONTEXT_IF_ZERO(deriving_key_length); + RETURN_INVALID_CONTEXT_IF_NULL(context); + RETURN_INVALID_CONTEXT_IF_ZERO(context_length); + RETURN_INVALID_CONTEXT_IF_NULL(private_key_handle); + RETURN_INVALID_CONTEXT_IF_NULL(public_key_length); + // Currently this is only used by Prov40 for deriving BCC leaf key. Return + // OEMCrypto_ERROR_NOT_IMPLEMENTED otherwise. + if (key_type == PROV40_ED25519_PRIVATE_KEY) { + if (public_key == NULL || *public_key_length < ED25519_PUBLIC_KEY_LEN) { + *public_key_length = ED25519_PUBLIC_KEY_LEN; + return OEMCrypto_ERROR_SHORT_BUFFER; + } + + // ED25519_keypair_from_seed expects the seed to be 32 bytes. + uint8_t seed[32]; + if (HKDF(seed, sizeof(seed), EVP_sha256(), deriving_key, + deriving_key_length, + /*salt=*/NULL, /*salt_len=*/0, context, context_length) != 1) { + WTPI_SecureZeroMemory(seed, sizeof(seed)); + return OEMCrypto_ERROR_UNKNOWN_FAILURE; + } + + uint8_t private_key_temp[ED25519_PRIVATE_KEY_LEN]; + ED25519_keypair_from_seed(public_key, private_key_temp, seed); + *public_key_length = ED25519_PUBLIC_KEY_LEN; + const OEMCryptoResult result = WTPI_CreateAsymmetricKeyHandle( + private_key_temp, sizeof(private_key_temp), key_type, + private_key_handle); + WTPI_SecureZeroMemory(seed, sizeof(seed)); + WTPI_SecureZeroMemory(private_key_temp, sizeof(private_key_temp)); + return result; + } else { + return OEMCrypto_ERROR_NOT_IMPLEMENTED; + } +} diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_wrap_asymmetric.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_wrap_asymmetric.c index 44ca231..816200d 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_wrap_asymmetric.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_crypto_wrap_asymmetric.c @@ -12,6 +12,7 @@ #include "oemcrypto_key_types.h" #include "oemcrypto_overflow.h" #include "wtpi_device_key_interface.h" +#include "wtpi_memory_interface.h" static bool IsSupportedAsymmetricKeyType(AsymmetricKeyType key_type) { return key_type == DRM_RSA_PRIVATE_KEY || key_type == DRM_ECC_PRIVATE_KEY; @@ -50,7 +51,7 @@ static OEMCryptoResult LoadECCKeyInfoAsymmetricKeyHandle( } OEMCryptoResult WTPI_UnwrapIntoAsymmetricKeyHandle( - const uint8_t* wrapped_key, size_t wrapped_key_length, + uint32_t context, const uint8_t* wrapped_key, size_t wrapped_key_length, AsymmetricKeyType key_type, WTPI_AsymmetricKey_Handle* key_handle, uint32_t* allowed_schemes) { if (wrapped_key == NULL || wrapped_key_length == 0 || @@ -59,32 +60,39 @@ OEMCryptoResult WTPI_UnwrapIntoAsymmetricKeyHandle( } RETURN_INVALID_CONTEXT_IF_NULL(key_handle); RETURN_INVALID_CONTEXT_IF_NULL(allowed_schemes); + /* Unwrap encrypted key. */ uint8_t unwrapped_key[PKCS8_DRM_KEY_MAX_SIZE]; size_t unwrapped_key_length = sizeof(unwrapped_key); - const OEMCryptoResult result = WTPI_VerifyAndDecrypt( - DEVICE_KEY_WRAP_DRM_CERT, wrapped_key, wrapped_key_length, unwrapped_key, + OEMCryptoResult result = WTPI_VerifyAndDecrypt( + context, wrapped_key, wrapped_key_length, unwrapped_key, &unwrapped_key_length); if (result == OEMCrypto_ERROR_SHORT_BUFFER) { - return OEMCrypto_ERROR_UNKNOWN_FAILURE; - } else if (result != OEMCrypto_SUCCESS) { - return result; + result = OEMCrypto_ERROR_UNKNOWN_FAILURE; } + if (result != OEMCrypto_SUCCESS) { + goto cleanup; + } + /* Load unwrapped key */ if (key_type == DRM_ECC_PRIVATE_KEY) { - return LoadECCKeyInfoAsymmetricKeyHandle( + result = LoadECCKeyInfoAsymmetricKeyHandle( + unwrapped_key, unwrapped_key_length, key_handle, allowed_schemes); + } else { + result = LoadRSAKeyIntoAsymmetricKeyHandle( unwrapped_key, unwrapped_key_length, key_handle, allowed_schemes); } - return LoadRSAKeyIntoAsymmetricKeyHandle(unwrapped_key, unwrapped_key_length, - key_handle, allowed_schemes); + +cleanup: + WTPI_SecureZeroMemory(unwrapped_key, sizeof(unwrapped_key)); + return result; } -OEMCryptoResult WTPI_WrapAsymmetricKey(uint8_t* wrapped_key, +OEMCryptoResult WTPI_WrapAsymmetricKey(uint32_t context, uint8_t* wrapped_key, size_t wrapped_key_length, UNUSED AsymmetricKeyType key_type, const uint8_t* clear_key, size_t clear_key_length) { - return WTPI_EncryptAndSign(DEVICE_KEY_WRAP_DRM_CERT, clear_key, - clear_key_length, wrapped_key, + return WTPI_EncryptAndSign(context, clear_key, clear_key_length, wrapped_key, &wrapped_key_length); } diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_device_key.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_device_key.c index c2d7408..98de618 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_device_key.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_device_key.c @@ -1,11 +1,11 @@ -/* Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary +/* Copyright 2024 Google LLC. All Rights Reserved. This file and proprietary source code may only be used and distributed under the Widevine License Agreement. */ #include "wtpi_device_key_interface.h" #include - +#include "odk_endian.h" #include "oemcrypto_overflow.h" #include "wtpi_crypto_and_key_management_interface_layer1.h" @@ -30,29 +30,49 @@ static const uint8_t kMagicUuid[UUID_LENGTH] = { 0xb5, 0x76, 0x3b, 0xad, 0x84, 0x05, 0x40, 0xfd, 0xa0, 0x88, 0x3b, 0x6c, 0x69, 0x97, 0xfc, 0x74}; -// 1 in network byte order -static const uint8_t kVersionOne[sizeof(uint32_t)] = {0x00, 0x00, 0x00, 0x01}; - // This is the layout of the |data| field of a WrappedData structure when its -// |version| field is 1. +// |version| field is 1. This covers default implementations of OPK from v17 +// through v18.4 +static const uint8_t kVersionOne[sizeof(uint32_t)] = {0x00, 0x00, 0x00, 0x01}; typedef struct WrappedData_V1 { uint8_t iv[KEY_IV_SIZE]; uint8_t enc_data[]; } WrappedData_V1; +// V2 includes the context used to derive the wrapping and signing keys. +static const uint8_t kVersionTwo[sizeof(uint32_t)] = {0x00, 0x00, 0x00, 0x02}; +typedef struct WrappedData_V2 { + uint8_t context[sizeof(uint32_t)]; + uint8_t iv[KEY_IV_SIZE]; + uint8_t enc_data[]; +} WrappedData_V2; + +static OEMCryptoResult ReadWrapProtocolVersion(const WrappedData* data, + uint32_t* version) { + if (data == NULL || version == NULL) { + return OEMCrypto_ERROR_INVALID_CONTEXT; + } + + uint32_t value = UINT32_MAX; + memcpy(&value, data->version, sizeof(value)); + *version = oemcrypto_htobe32(value); + + return OEMCrypto_SUCCESS; +} + OEMCryptoResult WTPI_GetEncryptAndSignSize(UNUSED uint32_t context, size_t in_size, size_t* wrapped_size) { - if (OPK_AddOverflowUX(in_size, sizeof(WrappedData) + sizeof(WrappedData_V1), + if (OPK_AddOverflowUX(in_size, sizeof(WrappedData) + sizeof(WrappedData_V2), wrapped_size)) { return OEMCrypto_ERROR_INVALID_CONTEXT; } return OEMCrypto_SUCCESS; } -OEMCryptoResult WTPI_EncryptAndSign(uint32_t context, const uint8_t* data, - size_t data_size, uint8_t* out, - size_t* out_size) { +static OEMCryptoResult EncryptAndSign_V2(uint32_t context, const uint8_t* data, + size_t data_size, uint8_t* out, + size_t* out_size) { if (!out_size) { return OEMCrypto_ERROR_INVALID_CONTEXT; } @@ -70,9 +90,11 @@ OEMCryptoResult WTPI_EncryptAndSign(uint32_t context, const uint8_t* data, WrappedData* const wrapped_header = (WrappedData*)out; memcpy(wrapped_header->magic, kMagicUuid, sizeof(wrapped_header->magic)); - memcpy(wrapped_header->version, kVersionOne, sizeof(wrapped_header->version)); + memcpy(wrapped_header->version, kVersionTwo, sizeof(wrapped_header->version)); + + WrappedData_V2* const wrapped_data = (WrappedData_V2*)wrapped_header->data; + memcpy(wrapped_data->context, &context, sizeof(context)); - WrappedData_V1* const wrapped_data = (WrappedData_V1*)wrapped_header->data; /* Pick a random IV for generating keys. */ result = WTPI_C1_RandomBytes(wrapped_data->iv, sizeof(wrapped_data->iv)); if (result != OEMCrypto_SUCCESS) return result; @@ -124,10 +146,6 @@ static OEMCryptoResult VerifyAndDecrypt_V1(uint32_t context, WTPI_K1_FreeKeyHandle(signing_key); if (result != OEMCrypto_SUCCESS) return result; - // If someday we support multiple versions, we'll need to decode - // wrapped_header->version and switch our behavior depending on the version - // we find. But for now, since only version 1 is valid, we can just verify - // that wrapped_header->version is 1. if (memcmp(wrapped_header->magic, kMagicUuid, sizeof(wrapped_header->magic)) != 0 || memcmp(wrapped_header->version, kVersionOne, @@ -162,13 +180,94 @@ static OEMCryptoResult VerifyAndDecrypt_V1(uint32_t context, return result; } +// In V2 the context value is contained with the wrapped data +static OEMCryptoResult VerifyAndDecrypt_V2(uint32_t context, + const uint8_t* data, + size_t data_size, uint8_t* out, + size_t* out_size) { + if (data == NULL || out == NULL || + data_size < sizeof(WrappedData) + sizeof(WrappedData_V2) || + out_size == NULL) { + return OEMCrypto_ERROR_INVALID_CONTEXT; + } + + const WrappedData* const wrapped_header = (const WrappedData*)data; + const WrappedData_V2* const wrapped_data = + (const WrappedData_V2*)wrapped_header->data; + + uint32_t wrapped_context = UINT32_MAX; + memcpy(&wrapped_context, wrapped_data->context, sizeof(wrapped_context)); + + if (wrapped_context != context) { + return OEMCrypto_ERROR_INVALID_KEY; + } + + // Verify the signature first, before interpreting. + WTPI_K1_SymmetricKey_Handle signing_key = NULL; + OEMCryptoResult result = WTPI_K1_DeriveDeviceKeyIntoHandle( + context, MAC_KEY_SERVER, &signing_key, KEY_SIZE_256); + if (result != OEMCrypto_SUCCESS) return result; + const size_t offset = sizeof(wrapped_header->signature); + result = + WTPI_C1_HMAC_SHA256_Verify(signing_key, data + offset, data_size - offset, + wrapped_header->signature); + WTPI_K1_FreeKeyHandle(signing_key); + if (result != OEMCrypto_SUCCESS) return result; + + if (memcmp(wrapped_header->magic, kMagicUuid, + sizeof(wrapped_header->magic)) != 0 || + memcmp(wrapped_header->version, kVersionTwo, + sizeof(wrapped_header->version)) != 0) { + return OEMCrypto_ERROR_INVALID_CONTEXT; + } + + const size_t needed_size = + data_size - (sizeof(WrappedData) + sizeof(WrappedData_V2)); + if (*out_size < needed_size) { + *out_size = needed_size; + return OEMCrypto_ERROR_SHORT_BUFFER; + } + + *out_size = needed_size; + + // Decrypt the buffer. + WTPI_K1_SymmetricKey_Handle encryption_key = NULL; + result = WTPI_K1_DeriveDeviceKeyIntoHandle(context, ENCRYPTION_KEY, + &encryption_key, KEY_SIZE_128); + if (result != OEMCrypto_SUCCESS) return result; + KeySize key_size; + result = WTPI_K1_GetKeySize(encryption_key, &key_size); + if (result != OEMCrypto_SUCCESS) return result; + result = WTPI_C1_AESCBCDecrypt(encryption_key, (size_t)key_size, + wrapped_data->enc_data, needed_size, + wrapped_data->iv, out); + WTPI_K1_FreeKeyHandle(encryption_key); + return result; +} + +OEMCryptoResult WTPI_EncryptAndSign(uint32_t context, const uint8_t* data, + size_t data_size, uint8_t* out, + size_t* out_size) { + return EncryptAndSign_V2(context, data, data_size, out, out_size); +} + OEMCryptoResult WTPI_VerifyAndDecrypt(uint32_t context, const uint8_t* data, size_t data_size, uint8_t* out, size_t* out_size) { - // This function is broken out separately in order to ease maintenance for - // those who also need to maintain backwards-compatibility with other, older - // wrapping formats. - return VerifyAndDecrypt_V1(context, data, data_size, out, out_size); + if (data_size < sizeof(WrappedData)) return OEMCrypto_ERROR_INVALID_CONTEXT; + uint32_t version = UINT32_MAX; + OEMCryptoResult res = + ReadWrapProtocolVersion((const WrappedData*)data, &version); + if (res != OEMCrypto_SUCCESS) return res; + + switch (version) { + case 1: + return VerifyAndDecrypt_V1(context, data, data_size, out, out_size); + case 2: + return VerifyAndDecrypt_V2(context, data, data_size, out, out_size); + default: + return OEMCrypto_ERROR_INVALID_CONTEXT; + } } OEMCryptoResult WTPI_VerifyAndDecryptUsageData_Legacy( diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_hdcp.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_hdcp.c new file mode 100644 index 0000000..2c1189a --- /dev/null +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_hdcp.c @@ -0,0 +1,28 @@ +/* Copyright 2024 Google LLC. All Rights Reserved. This file and proprietary + source code may only be used and distributed under the Widevine + License Agreement. */ + +#include "wtpi_hdcp_interface.h" +#include "opk_config.h" + +#ifdef USE_OPK_FEATURE_SETHDCP +OEMCryptoResult WTPI_SetHDCPLevel(OEMCrypto_HDCP_Capability level){ + return OEMCrypto_ERROR_NOT_IMPLEMENTED; +} +#endif // USE_OPK_FEATURE_SETHDCP + +OEMCrypto_HDCP_Capability WTPI_CurrentHDCPCapability(void) { + return HDCP_NO_DIGITAL_OUTPUT; +} + +OEMCrypto_HDCP_Capability WTPI_MaxHDCPCapability(void) { + return OPK_CONFIG_MAX_HDCP_CAPABILITY; +} + +OEMCryptoResult WTPI_GetCurrentSRMVersion(uint32_t* srm_version) { + if (srm_version == NULL) { + return OEMCrypto_ERROR_INVALID_CONTEXT; + } + *srm_version = 0; + return OEMCrypto_SUCCESS; +} diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_provisioning_4.c b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_provisioning_4.c index 22a9792..ad9fa95 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_provisioning_4.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_reference/wtpi_provisioning_4.c @@ -11,8 +11,10 @@ #include "cose_util.h" #include "oemcrypto_check_macros.h" #include "openssl/hkdf.h" +#include "wtpi_crypto_asymmetric_interface.h" #include "wtpi_device_key_access_interface.h" #include "wtpi_device_key_interface.h" +#include "wtpi_memory_interface.h" #define MAX_BCC_PAYLOAD_SIZE 2048 #define MAX_COSE_SIGN1_SIZE 2048 @@ -29,64 +31,36 @@ static const uint8_t kFakeBccEntrySecrets[BCC_ENTRY_COUNT][KEY_SIZE_128] = { 0x48, 0x14, 0x6b, 0x73}}; #endif -/** - * Derives an ED25519 asymmetric key pair that is used in provisioning 4. - * Caller retains ownership of all parameters. - */ -static OEMCryptoResult DeriveAsymmetricKeyIntoHandle( - const uint8_t* deriving_key, KeySize deriving_key_size, - AsymmetricKeyType* key_type, WTPI_AsymmetricKey_Handle* private_key_handle, - uint8_t* public_key, size_t* public_key_length) { - ABORT_IF_NULL(key_type); - ABORT_IF_NULL(private_key_handle); - ABORT_IF_NULL(public_key_length); - if (public_key == NULL || *public_key_length < ED25519_PUBLIC_KEY_LEN) { - *public_key_length = ED25519_PUBLIC_KEY_LEN; - return OEMCrypto_ERROR_SHORT_BUFFER; - } - if (deriving_key == NULL || deriving_key_size == 0) { - return OEMCrypto_ERROR_UNKNOWN_FAILURE; - } +#define DEVICE_KEY_DERIVATION_CONTEXT_SIZE 20 - const int32_t context = DEVICE_KEY_PROV40_SEED; +static void CreateDeviceKeyDerivationContext(uint8_t* out) { + const int32_t context_seed = DEVICE_KEY_PROV40_SEED; const uint32_t type_32 = (uint32_t)DERIVING_KEY; // Build a full context that is unique to this starting context / key type // combination. We start with a context template with blanks at the beginning // and fill the blanks with the starting context and key type. - uint8_t full_context[20] = {'.', '.', '.', '.', '.', '.', '.', '.', 'W', 'i', - 'd', 'e', 'v', 'i', 'n', 'e', ' ', 'O', 'P', 'K'}; - memcpy(full_context, &context, 4); + uint8_t full_context[DEVICE_KEY_DERIVATION_CONTEXT_SIZE] = { + '.', '.', '.', '.', '.', '.', '.', '.', 'W', 'i', + 'd', 'e', 'v', 'i', 'n', 'e', ' ', 'O', 'P', 'K'}; + memcpy(full_context, &context_seed, 4); memcpy(full_context + 4, &type_32, 4); - - // ED25519_keypair_from_seed expects the seed to be 32 bytes. - uint8_t seed[32]; - if (HKDF(seed, sizeof(seed), EVP_sha256(), deriving_key, deriving_key_size, - /*salt=*/NULL, /*salt_len=*/0, full_context, - sizeof(full_context)) != 1) { - return OEMCrypto_ERROR_UNKNOWN_FAILURE; - } - - uint8_t private_key_temp[ED25519_PRIVATE_KEY_LEN]; - ED25519_keypair_from_seed(public_key, private_key_temp, seed); - *public_key_length = ED25519_PUBLIC_KEY_LEN; - *key_type = PROV40_ED25519_PRIVATE_KEY; - return WTPI_CreateAsymmetricKeyHandle(private_key_temp, - sizeof(private_key_temp), *key_type, - private_key_handle); + memcpy(out, full_context, DEVICE_KEY_DERIVATION_CONTEXT_SIZE); } /** - * Retrieves the device specific asymmetric key pair that is used in + * Creates the device specific asymmetric key pair that is used in * provisioning 4. This key must be unique per individual device. The key must * be identical across reboots. * Caller retains ownership of all parameters. */ -static OEMCryptoResult GetDeviceAsymmetricKeyIntoHandle( +OEMCryptoResult WTPI_CreateUDSDerivedAsymmetricKeyHandle( AsymmetricKeyType* key_type, WTPI_AsymmetricKey_Handle* private_key_handle, uint8_t* public_key, size_t* public_key_length) { - ABORT_IF_NULL(key_type); - ABORT_IF_NULL(private_key_handle); - ABORT_IF_NULL(public_key_length); + RETURN_INVALID_CONTEXT_IF_NULL(key_type); + RETURN_INVALID_CONTEXT_IF_NULL(private_key_handle); + RETURN_INVALID_CONTEXT_IF_NULL(public_key_length); + // Derives an ED25519 asymmetric key pair (DK_priv and DK_pub) from the device + // unique secret. if (public_key == NULL || *public_key_length < ED25519_PUBLIC_KEY_LEN) { *public_key_length = ED25519_PUBLIC_KEY_LEN; return OEMCrypto_ERROR_SHORT_BUFFER; @@ -98,9 +72,14 @@ static OEMCryptoResult GetDeviceAsymmetricKeyIntoHandle( return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - return DeriveAsymmetricKeyIntoHandle(device_key, device_key_size, key_type, - private_key_handle, public_key, - public_key_length); + uint8_t context[DEVICE_KEY_DERIVATION_CONTEXT_SIZE]; + CreateDeviceKeyDerivationContext(context); + OEMCryptoResult result = WTPI_DeriveNewAsymmetricKeyHandle( + device_key, (size_t)device_key_size, context, sizeof(context), + PROV40_ED25519_PRIVATE_KEY, private_key_handle, public_key, + public_key_length); + if (result == OEMCrypto_SUCCESS) *key_type = PROV40_ED25519_PRIVATE_KEY; + return result; } #ifdef USE_DICE_BCC @@ -120,16 +99,21 @@ static OEMCryptoResult BuildPhase2BootCertificateChain( WTPI_AsymmetricKey_Handle device_private_key, uint8_t* out, size_t* out_length) { AsymmetricKeyType entry_key_types[BCC_ENTRY_COUNT]; + for (int i = 0; i < BCC_ENTRY_COUNT; ++i) { + entry_key_types[i] = PROV40_ED25519_PRIVATE_KEY; + } WTPI_AsymmetricKey_Handle entry_private_keys[BCC_ENTRY_COUNT]; memset(entry_private_keys, 0, sizeof(entry_private_keys)); uint8_t entry_public_keys[BCC_ENTRY_COUNT][ED25519_PUBLIC_KEY_LEN]; memset(entry_public_keys, 0, sizeof(entry_public_keys)); size_t entry_public_key_lengths[BCC_ENTRY_COUNT]; + uint8_t context[DEVICE_KEY_DERIVATION_CONTEXT_SIZE]; + CreateDeviceKeyDerivationContext(context); OEMCryptoResult result; for (int i = 0; i < BCC_ENTRY_COUNT; ++i) { - result = DeriveAsymmetricKeyIntoHandle( - kFakeBccEntrySecrets[i], KEY_SIZE_128, &entry_key_types[i], - &entry_private_keys[i], entry_public_keys[i], + result = WTPI_DeriveNewAsymmetricKeyHandle( + kFakeBccEntrySecrets[i], (size_t)KEY_SIZE_128, context, sizeof(context), + entry_key_types[i], &entry_private_keys[i], entry_public_keys[i], &entry_public_key_lengths[i]); if (result != OEMCrypto_SUCCESS) goto cleanup; if (entry_key_types[i] != PROV40_ED25519_PRIVATE_KEY || @@ -182,7 +166,7 @@ OEMCryptoResult WTPI_GetBootCertificateChain(uint8_t* out, size_t* out_length) { WTPI_AsymmetricKey_Handle device_private_key_handle; uint8_t device_public_key[ED25519_PUBLIC_KEY_LEN]; size_t device_public_key_length = sizeof(device_public_key); - OEMCryptoResult result = GetDeviceAsymmetricKeyIntoHandle( + OEMCryptoResult result = WTPI_CreateUDSDerivedAsymmetricKeyHandle( &device_key_type, &device_private_key_handle, device_public_key, &device_public_key_length); if (result != OEMCrypto_SUCCESS) return result; @@ -213,9 +197,9 @@ OEMCryptoResult WTPI_GetMaxBootCertificateChainSize(size_t* out_length) { } OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( - AsymmetricKeyType* key_type, uint8_t* wrapped_private_key, - size_t* wrapped_private_key_length, uint8_t* public_key, - size_t* public_key_length) { + CertSignatureType cert_type, AsymmetricKeyType* key_type, + uint8_t* wrapped_private_key, size_t* wrapped_private_key_length, + uint8_t* public_key, size_t* public_key_length) { if (key_type == NULL || wrapped_private_key_length == NULL || public_key_length == NULL) { return OEMCrypto_ERROR_INVALID_CONTEXT; @@ -242,7 +226,8 @@ OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( size_t clear_private_key_length = sizeof(clear_private_key); if (!NewEccKeyPair(clear_private_key, &clear_private_key_length, public_key, public_key_length)) { - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + goto cleanup; } // Add padding. @@ -254,17 +239,32 @@ OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( size_t actual_wrapped_private_key_length = 0; result = WTPI_GetWrappedAsymmetricKeySize(clear_private_key_length, *key_type, &actual_wrapped_private_key_length); - if (result != OEMCrypto_SUCCESS) return result; + if (result != OEMCrypto_SUCCESS) goto cleanup; + if (*wrapped_private_key_length < actual_wrapped_private_key_length) { // This should not happen as we have checked buffer size. *wrapped_private_key_length = actual_wrapped_private_key_length; - return OEMCrypto_ERROR_SHORT_BUFFER; + result = OEMCrypto_ERROR_SHORT_BUFFER; + goto cleanup; + } + + uint32_t context = 0; + if (cert_type == CERT_SIGNATURE_DRM) { + context = DEVICE_KEY_WRAP_DRM_CERT; + } else if (cert_type == CERT_SIGNATURE_OEM) { + context = DEVICE_KEY_WRAP_OEM_CERT; + } else { + goto cleanup; } *wrapped_private_key_length = actual_wrapped_private_key_length; - return WTPI_WrapAsymmetricKey(wrapped_private_key, - *wrapped_private_key_length, *key_type, - clear_private_key, clear_private_key_length); + result = WTPI_WrapAsymmetricKey(context, wrapped_private_key, + *wrapped_private_key_length, *key_type, + clear_private_key, clear_private_key_length); + +cleanup: + WTPI_SecureZeroMemory(clear_private_key, sizeof(clear_private_key)); + return result; } OEMCryptoResult WTPI_BccKeyCoseSign1(const uint8_t* message, @@ -286,21 +286,24 @@ OEMCryptoResult WTPI_BccKeyCoseSign1(const uint8_t* message, return OEMCrypto_ERROR_SHORT_BUFFER; } - AsymmetricKeyType key_type; + AsymmetricKeyType key_type = PROV40_ED25519_PRIVATE_KEY; WTPI_AsymmetricKey_Handle private_key_handle; uint8_t public_key_unused[ED25519_PUBLIC_KEY_LEN]; size_t public_key_length_unused = sizeof(public_key_unused); #ifdef USE_DICE_BCC // For provisioning 4.0 phase 2, use BCC leaf key as the signing key. - result = DeriveAsymmetricKeyIntoHandle( - kFakeBccEntrySecrets[BCC_ENTRY_COUNT - 1], KEY_SIZE_128, &key_type, - &private_key_handle, public_key_unused, &public_key_length_unused); + uint8_t context[DEVICE_KEY_DERIVATION_CONTEXT_SIZE]; + CreateDeviceKeyDerivationContext(context); + result = WTPI_DeriveNewAsymmetricKeyHandle( + kFakeBccEntrySecrets[BCC_ENTRY_COUNT - 1], (size_t)KEY_SIZE_128, context, + sizeof(context), key_type, &private_key_handle, public_key_unused, + &public_key_length_unused); #else // For provisioning 4.0 phase 1, the signing key is the same as the device // root key. - result = GetDeviceAsymmetricKeyIntoHandle(&key_type, &private_key_handle, - public_key_unused, - &public_key_length_unused); + result = WTPI_CreateUDSDerivedAsymmetricKeyHandle( + &key_type, &private_key_handle, public_key_unused, + &public_key_length_unused); #endif if (result != OEMCrypto_SUCCESS) return result; // Only ED key is expected for now. diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/clock_interface_test.cpp b/oemcrypto/opk/oemcrypto_ta/wtpi_test/clock_interface_test.cpp index 5847d78..4580d08 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/clock_interface_test.cpp +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/clock_interface_test.cpp @@ -108,5 +108,5 @@ TEST_F(ClockRebootTest, CheckClockAfterReboot) { ASSERT_EQ(OEMCrypto_SUCCESS, WTPI_GetTrustedTime(¤t_time)); uint64_t saved_time = LoadTrustedTime(); ASSERT_TRUE(current_time >= saved_time); - remove(kSavedTrustedTime); + ASSERT_EQ(0, remove(kSavedTrustedTime)); } diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/GEN_common_serializer.c b/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/GEN_common_serializer.c index 9c657e5..5318fdb 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/GEN_common_serializer.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/GEN_common_serializer.c @@ -261,12 +261,20 @@ void OPK_Pack_OEMCrypto_KeyObject(ODK_Message* msg, void OPK_Unpack_OEMCrypto_Substring(ODK_Message* msg, OEMCrypto_Substring* obj) { + OEMCrypto_Substring tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_size_t(msg, &obj->offset); OPK_Unpack_size_t(msg, &obj->length); } void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_0( ODK_Message* msg, OEMCrypto_DTCP2_CMI_Descriptor_0* obj) { + OEMCrypto_DTCP2_CMI_Descriptor_0 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->id); OPK_Unpack_uint8_t(msg, &obj->extension); OPK_Unpack_uint16_t(msg, &obj->length); @@ -275,6 +283,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_0( void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_1( ODK_Message* msg, OEMCrypto_DTCP2_CMI_Descriptor_1* obj) { + OEMCrypto_DTCP2_CMI_Descriptor_1 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->id); OPK_Unpack_uint8_t(msg, &obj->extension); OPK_Unpack_uint16_t(msg, &obj->length); @@ -283,6 +295,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_1( void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_2( ODK_Message* msg, OEMCrypto_DTCP2_CMI_Descriptor_2* obj) { + OEMCrypto_DTCP2_CMI_Descriptor_2 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->id); OPK_Unpack_uint8_t(msg, &obj->extension); OPK_Unpack_uint16_t(msg, &obj->length); @@ -291,6 +307,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_2( void OPK_Unpack_OEMCrypto_DTCP2_CMI_Packet(ODK_Message* msg, OEMCrypto_DTCP2_CMI_Packet* obj) { + OEMCrypto_DTCP2_CMI_Packet tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->dtcp2_required); OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_0(msg, &obj->cmi_descriptor_0); OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_1(msg, &obj->cmi_descriptor_1); @@ -299,6 +319,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Packet(ODK_Message* msg, void OPK_Unpack_OEMCrypto_KeyObject(ODK_Message* msg, OEMCrypto_KeyObject* obj) { + OEMCrypto_KeyObject tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_id); OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_data_iv); OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_data); @@ -314,9 +338,11 @@ void OPK_PackNullable_uint64_t(ODK_Message* msg, const uint64_t* value) { } void OPK_UnpackNullable_uint64_t(ODK_Message* msg, uint64_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_uint64_t(msg, *value); + } else { + OPK_Unpack_uint64_t(msg, NULL); } } void OPK_UnpackAlloc_uint64_t(ODK_Message* msg, uint64_t** value) { @@ -333,9 +359,11 @@ void OPK_PackNullable_KeySize(ODK_Message* msg, const KeySize* value) { } void OPK_UnpackNullable_KeySize(ODK_Message* msg, KeySize** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_KeySize(msg, *value); + } else { + OPK_Unpack_KeySize(msg, NULL); } } void OPK_UnpackAlloc_KeySize(ODK_Message* msg, KeySize** value) { @@ -352,9 +380,11 @@ void OPK_PackNullable_uint8_t(ODK_Message* msg, const uint8_t* value) { } void OPK_UnpackNullable_uint8_t(ODK_Message* msg, uint8_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_uint8_t(msg, *value); + } else { + OPK_Unpack_uint8_t(msg, NULL); } } void OPK_UnpackAlloc_uint8_t(ODK_Message* msg, uint8_t** value) { @@ -373,9 +403,11 @@ void OPK_PackNullable_OPK_OutputBuffer(ODK_Message* msg, void OPK_UnpackNullable_OPK_OutputBuffer(ODK_Message* msg, OPK_OutputBuffer** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_OPK_OutputBuffer(msg, *value); + } else { + OPK_Unpack_OPK_OutputBuffer(msg, NULL); } } void OPK_PackNullable_WTPI_K1_SymmetricKey_Handle( @@ -388,9 +420,11 @@ void OPK_PackNullable_WTPI_K1_SymmetricKey_Handle( void OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle( ODK_Message* msg, WTPI_K1_SymmetricKey_Handle** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_WTPI_K1_SymmetricKey_Handle(msg, *value); + } else { + OPK_Unpack_WTPI_K1_SymmetricKey_Handle(msg, NULL); } } void OPK_UnpackAlloc_WTPI_K1_SymmetricKey_Handle( @@ -409,9 +443,11 @@ void OPK_PackNullable_size_t(ODK_Message* msg, const size_t* value) { } void OPK_UnpackNullable_size_t(ODK_Message* msg, size_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_size_t(msg, *value); + } else { + OPK_Unpack_size_t(msg, NULL); } } void OPK_UnpackAlloc_size_t(ODK_Message* msg, size_t** value) { @@ -430,9 +466,11 @@ void OPK_PackNullable_WTPI_AsymmetricKey_Handle( void OPK_UnpackNullable_WTPI_AsymmetricKey_Handle( ODK_Message* msg, WTPI_AsymmetricKey_Handle** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_WTPI_AsymmetricKey_Handle(msg, *value); + } else { + OPK_Unpack_WTPI_AsymmetricKey_Handle(msg, NULL); } } void OPK_UnpackAlloc_WTPI_AsymmetricKey_Handle( @@ -451,9 +489,11 @@ void OPK_PackNullable_uint32_t(ODK_Message* msg, const uint32_t* value) { } void OPK_UnpackNullable_uint32_t(ODK_Message* msg, uint32_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_uint32_t(msg, *value); + } else { + OPK_Unpack_uint32_t(msg, NULL); } } void OPK_UnpackAlloc_uint32_t(ODK_Message* msg, uint32_t** value) { @@ -472,9 +512,11 @@ void OPK_PackNullable_OEMCrypto_SignatureHashAlgorithm( void OPK_UnpackNullable_OEMCrypto_SignatureHashAlgorithm( ODK_Message* msg, OEMCrypto_SignatureHashAlgorithm** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_OEMCrypto_SignatureHashAlgorithm(msg, *value); + } else { + OPK_Unpack_OEMCrypto_SignatureHashAlgorithm(msg, NULL); } } void OPK_UnpackAlloc_OEMCrypto_SignatureHashAlgorithm( @@ -495,9 +537,11 @@ void OPK_PackNullable_AsymmetricKeyType(ODK_Message* msg, void OPK_UnpackNullable_AsymmetricKeyType(ODK_Message* msg, AsymmetricKeyType** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_AsymmetricKeyType(msg, *value); + } else { + OPK_Unpack_AsymmetricKeyType(msg, NULL); } } void OPK_UnpackAlloc_AsymmetricKeyType(ODK_Message* msg, @@ -515,9 +559,11 @@ void OPK_PackNullable_bool(ODK_Message* msg, const bool* value) { } void OPK_UnpackNullable_bool(ODK_Message* msg, bool** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_bool(msg, *value); + } else { + OPK_Unpack_bool(msg, NULL); } } void OPK_UnpackAlloc_bool(ODK_Message* msg, bool** value) { @@ -536,9 +582,11 @@ void OPK_PackNullable_OEMCrypto_BCCType(ODK_Message* msg, void OPK_UnpackNullable_OEMCrypto_BCCType(ODK_Message* msg, OEMCrypto_BCCType** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_OEMCrypto_BCCType(msg, *value); + } else { + OPK_Unpack_OEMCrypto_BCCType(msg, NULL); } } void OPK_UnpackAlloc_OEMCrypto_BCCType(ODK_Message* msg, diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.c b/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.c index 4da75fc..5de2899 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.c @@ -31,21 +31,11 @@ void OPK_Pack_WTPI_AsymmetricKey_Handle( void OPK_Unpack_WTPI_K1_SymmetricKey_Handle( ODK_Message* message, WTPI_K1_SymmetricKey_Handle* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_size_t(message, (size_t*)value); } void OPK_Unpack_WTPI_AsymmetricKey_Handle(ODK_Message* message, WTPI_AsymmetricKey_Handle* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_size_t(message, (size_t*)value); } @@ -76,9 +66,9 @@ void OPK_Pack_OPK_OutputBuffer(ODK_Message* message, void OPK_Unpack_OPK_OutputBuffer(ODK_Message* message, OPK_OutputBuffer* value) { + OPK_OutputBuffer tmp_value; if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; + value = &tmp_value; } OPK_Unpack_uint32_t(message, (uint32_t*)&value->type); @@ -117,11 +107,6 @@ void OPK_Pack_SymmetricKeyType(ODK_Message* message, void OPK_Unpack_SymmetricKeyType(ODK_Message* message, SymmetricKeyType* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_int(message, (int*)value); } @@ -137,11 +122,6 @@ void OPK_Pack_AsymmetricKeyType(ODK_Message* message, void OPK_Unpack_AsymmetricKeyType(ODK_Message* message, AsymmetricKeyType* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_int(message, (int*)value); } @@ -157,11 +137,6 @@ void OPK_Pack_RSA_Padding_Scheme(ODK_Message* message, void OPK_Unpack_RSA_Padding_Scheme(ODK_Message* message, RSA_Padding_Scheme* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint8_t(message, (uint8_t*)value); } @@ -175,11 +150,6 @@ void OPK_Pack_KeySize(ODK_Message* message, const KeySize* value) { } void OPK_Unpack_KeySize(ODK_Message* message, KeySize* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_int(message, (int*)value); } @@ -209,11 +179,6 @@ void OPK_Pack_OEMCrypto_Clock_Security_Level( void OPK_Unpack_OEMCrypto_Clock_Security_Level( ODK_Message* message, OEMCrypto_Clock_Security_Level* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint32_t(message, (uint32_t*)value); } @@ -279,61 +244,31 @@ void OPK_Pack_OEMCrypto_Usage_Entry_Status( void OPK_Unpack_OEMCrypto_Security_Level(ODK_Message* message, OEMCrypto_Security_Level* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint32_t(message, (uint32_t*)value); } void OPK_Unpack_OEMCrypto_ProvisioningMethod( ODK_Message* message, OEMCrypto_ProvisioningMethod* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint32_t(message, (uint32_t*)value); } void OPK_Unpack_OEMCrypto_BCCType(ODK_Message* message, OEMCrypto_BCCType* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint32_t(message, (uint32_t*)value); } void OPK_Unpack_OEMCrypto_WatermarkingSupport( ODK_Message* message, OEMCrypto_WatermarkingSupport* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint32_t(message, (uint32_t*)value); } void OPK_Unpack_OEMCrypto_HDCP_Capability(ODK_Message* message, OEMCrypto_HDCP_Capability* value) { - if (value == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint32_t(message, (uint32_t*)value); } void OPK_Unpack_OEMCrypto_Usage_Entry_Status( ODK_Message* message, OEMCrypto_Usage_Entry_Status* status) { - if (status == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; - } - OPK_Unpack_uint32_t(message, (uint32_t*)status); } @@ -349,10 +284,20 @@ void OPK_Pack_OEMCrypto_SignatureHashAlgorithm( void OPK_Unpack_OEMCrypto_SignatureHashAlgorithm( ODK_Message* message, OEMCrypto_SignatureHashAlgorithm* value) { + OPK_Unpack_int(message, (int*)value); +} + +void OPK_Pack_CertSignatureType(ODK_Message* message, + CertSignatureType* value) { if (value == NULL) { ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); return; } - OPK_Unpack_int(message, (int*)value); + OPK_Pack_uint32_t(message, (uint32_t*)value); +} + +void OPK_Unpack_CertSignatureType(ODK_Message* message, + CertSignatureType* value) { + OPK_Unpack_uint32_t(message, (uint32_t*)value); } diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.h b/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.h index 8816d8f..123131e 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/common/common_special_cases.h @@ -82,5 +82,7 @@ void OPK_Unpack_OEMCrypto_SignatureHashAlgorithm( ODK_Message* message, OEMCrypto_SignatureHashAlgorithm* value); void OPK_Unpack_OEMCrypto_Usage_Entry_Status( ODK_Message* message, OEMCrypto_Usage_Entry_Status* status); +void OPK_Pack_CertSignatureType(ODK_Message* message, CertSignatureType* value); +void OPK_Unpack_CertSignatureType(ODK_Message* message, CertSignatureType* value); #endif diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/crypto_test.cpp b/oemcrypto/opk/oemcrypto_ta/wtpi_test/crypto_test.cpp index e7e5867..ca3c2da 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/crypto_test.cpp +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/crypto_test.cpp @@ -326,7 +326,7 @@ TEST_F(CryptoTest, SHA256FailsWithBadInput) { TEST_F(CryptoTest, SHA256Medium) { std::vector input; for (int i = 0; i < 1024; i++) { - input.push_back(i); + input.push_back(static_cast(i)); } std::vector output(32, 0); @@ -891,11 +891,10 @@ TEST_F(CryptoTest, RSADecrypt) { WTPI_RSADecrypt(handle, hello_world_encrypted, HELLO_WORLD_ENC_LEN, output.data(), &output_len)); - std::string message = "Hello world!"; + output.resize(output_len); + std::string message = "Hello world!\n"; std::vector expected(message.begin(), message.end()); - for (size_t i = 0; i < expected.size(); i++) { - ASSERT_EQ(expected[i], output[i]); - } + ASSERT_EQ(expected, output); } TEST_F(CryptoTest, RSADecryptFailsForBadInput) { @@ -1008,7 +1007,7 @@ TEST_F(CryptoTest, DeriveKeyFromKeyHandleFailsForBadInputs) { out_key_size, NULL)); } -TEST_F(CryptoTest, DeriveKeyFromKeyHandleWorks) { +TEST_F(CryptoTest, DeriveKeyFromKeyHandleWorks1) { std::vector key; for (int i = 0; i < 32; i++) { key.push_back(i); @@ -1056,9 +1055,60 @@ TEST_F(CryptoTest, DeriveKeyFromKeyHandleWorks) { WTPI_C1_HMAC_SHA256(expected_derived_key_handle, input.data(), input.size(), output2.data())); + ASSERT_EQ(output1, output2); +} + +TEST_F(CryptoTest, DeriveKeyFromKeyHandleWorks2) { + std::vector key; for (int i = 0; i < 32; i++) { - ASSERT_EQ(output1[i], output2[i]); + key.push_back(i); } + + WTPI_K1_SymmetricKey_Handle key_handle; + + ASSERT_EQ(OEMCrypto_SUCCESS, + WTPI_K1_CreateKeyHandle(key.data(), KEY_SIZE_128, DERIVING_KEY, + &key_handle)); + + const uint8_t context[] = "TEST"; + const uint8_t key_label[] = "AUTHENTICATION"; + const uint8_t context_suffix[] = {0x00, 0x00, 0x02, 0x00}; + + WTPI_K1_SymmetricKey_Handle out_key_handle; + ASSERT_EQ(OEMCrypto_SUCCESS, + WTPI_K1_DeriveKeyFromKeyHandle( + key_handle, 1, key_label, sizeof(key_label), context, + sizeof(context), context_suffix, sizeof(context_suffix), + MAC_KEY_CLIENT, KEY_SIZE_256, &out_key_handle)); + + const uint8_t expected_derived_key[] = {133, 226, 102, 45, 234, 255, 100, 192, + 182, 69, 206, 74, 162, 150, 32, 241, + 42, 2, 27, 35, 204, 78, 230, 217, + 224, 21, 230, 51, 107, 217, 30, 60}; + + WTPI_K1_SymmetricKey_Handle expected_derived_key_handle; + ASSERT_EQ( + OEMCrypto_SUCCESS, + WTPI_K1_CreateKeyHandle(expected_derived_key, KEY_SIZE_256, + MAC_KEY_CLIENT, &expected_derived_key_handle)); + + // perform an operation with out_key_handle and expected_derived_key_handle + // to prove they are using the same underlying key data + std::vector input; + for (int i = 0; i < 32; i++) { + input.push_back(i); + } + std::vector output1(32, 1); + std::vector output2(32, 2); + + ASSERT_EQ(OEMCrypto_SUCCESS, + WTPI_C1_HMAC_SHA256(out_key_handle, input.data(), input.size(), + output1.data())); + ASSERT_EQ(OEMCrypto_SUCCESS, + WTPI_C1_HMAC_SHA256(expected_derived_key_handle, input.data(), + input.size(), output2.data())); + + ASSERT_EQ(output1, output2); } TEST_F(CryptoTest, DeriveKeyFromKeyHandleWorks256BitDerivingKey) { @@ -1208,18 +1258,20 @@ TEST_F(CryptoTest, WrapAsymmetricKeyFailsForBadInputs) { uint8_t clear_key[256] = {0}; size_t clear_key_length = 256; - ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, - WTPI_WrapAsymmetricKey(NULL, output_length, key_type, clear_key, - clear_key_length)); - ASSERT_EQ( - OEMCrypto_ERROR_SHORT_BUFFER, - WTPI_WrapAsymmetricKey(output, 0, key_type, clear_key, clear_key_length)); - ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, - WTPI_WrapAsymmetricKey(output, output_length, key_type, NULL, - clear_key_length)); ASSERT_EQ( OEMCrypto_ERROR_INVALID_CONTEXT, - WTPI_WrapAsymmetricKey(output, output_length, key_type, clear_key, 0)); + WTPI_WrapAsymmetricKey(DEVICE_KEY_WRAP_DRM_CERT, NULL, output_length, + key_type, clear_key, clear_key_length)); + ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER, + WTPI_WrapAsymmetricKey(DEVICE_KEY_WRAP_DRM_CERT, output, 0, + key_type, clear_key, clear_key_length)); + ASSERT_EQ( + OEMCrypto_ERROR_INVALID_CONTEXT, + WTPI_WrapAsymmetricKey(DEVICE_KEY_WRAP_DRM_CERT, output, output_length, + key_type, NULL, clear_key_length)); + ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, + WTPI_WrapAsymmetricKey(DEVICE_KEY_WRAP_DRM_CERT, output, + output_length, key_type, clear_key, 0)); } TEST_F(CryptoTest, UnwrapAsymmetricKeyFailsForBadInputs) { @@ -1230,16 +1282,20 @@ TEST_F(CryptoTest, UnwrapAsymmetricKeyFailsForBadInputs) { uint32_t allowed_schemes = 0; ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, - WTPI_UnwrapIntoAsymmetricKeyHandle(NULL, input_length, key_type, + WTPI_UnwrapIntoAsymmetricKeyHandle(DEVICE_KEY_WRAP_DRM_CERT, NULL, + input_length, key_type, &key_handle, &allowed_schemes)); ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, - WTPI_UnwrapIntoAsymmetricKeyHandle(input, 0, key_type, &key_handle, + WTPI_UnwrapIntoAsymmetricKeyHandle(DEVICE_KEY_WRAP_DRM_CERT, input, + 0, key_type, &key_handle, &allowed_schemes)); ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, - WTPI_UnwrapIntoAsymmetricKeyHandle(input, input_length, key_type, - NULL, &allowed_schemes)); + WTPI_UnwrapIntoAsymmetricKeyHandle(DEVICE_KEY_WRAP_DRM_CERT, input, + input_length, key_type, NULL, + &allowed_schemes)); ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, - WTPI_UnwrapIntoAsymmetricKeyHandle(input, input_length, key_type, + WTPI_UnwrapIntoAsymmetricKeyHandle(DEVICE_KEY_WRAP_DRM_CERT, input, + input_length, key_type, &key_handle, NULL)); } @@ -1257,16 +1313,16 @@ TEST_F(CryptoTest, WrapAndUnwrapAsymmetricKeyWorks) { std::vector wrapped(buffer_size, 0); ASSERT_EQ(OEMCrypto_SUCCESS, - WTPI_WrapAsymmetricKey(wrapped.data(), wrapped.size(), - DRM_RSA_PRIVATE_KEY, test_rsa_key_der, - TEST_RSA_KEY_DER_LEN)); + WTPI_WrapAsymmetricKey(DEVICE_KEY_WRAP_DRM_CERT, wrapped.data(), + wrapped.size(), DRM_RSA_PRIVATE_KEY, + test_rsa_key_der, TEST_RSA_KEY_DER_LEN)); WTPI_AsymmetricKey_Handle out_handle; uint32_t allowed_schemes; ASSERT_EQ(OEMCrypto_SUCCESS, - WTPI_UnwrapIntoAsymmetricKeyHandle(wrapped.data(), wrapped.size(), - DRM_RSA_PRIVATE_KEY, &out_handle, - &allowed_schemes)); + WTPI_UnwrapIntoAsymmetricKeyHandle( + DEVICE_KEY_WRAP_DRM_CERT, wrapped.data(), wrapped.size(), + DRM_RSA_PRIVATE_KEY, &out_handle, &allowed_schemes)); // perform an operation with the two handles to prove they are the same std::vector decrypted1(256, 0); @@ -1275,19 +1331,19 @@ TEST_F(CryptoTest, WrapAndUnwrapAsymmetricKeyWorks) { ASSERT_EQ(OEMCrypto_SUCCESS, WTPI_RSADecrypt(handle, hello_world_encrypted, HELLO_WORLD_ENC_LEN, decrypted1.data(), &output_len)); + decrypted1.resize(output_len); - output_len = 256; + output_len = decrypted2.size(); ASSERT_EQ( OEMCrypto_SUCCESS, WTPI_RSADecrypt(out_handle, hello_world_encrypted, HELLO_WORLD_ENC_LEN, decrypted2.data(), &output_len)); + decrypted2.resize(output_len); - std::string message = "Hello world!"; + std::string message = "Hello world!\n"; std::vector expected(message.begin(), message.end()); - for (size_t i = 0; i < expected.size(); i++) { - ASSERT_EQ(expected[i], decrypted1[i]); - ASSERT_EQ(expected[i], decrypted2[i]); - } + ASSERT_EQ(expected, decrypted1); + ASSERT_EQ(expected, decrypted2); } TEST_F(CryptoTest, GetKeySizeBasic) { @@ -1419,10 +1475,7 @@ TEST_F(CryptoTest, AESDecryptAndCreateKeyHandleBasic) { ASSERT_EQ(OEMCrypto_SUCCESS, WTPI_C1_HMAC_SHA256(expected_key_handle, input.data(), input.size(), output2.data())); - - for (int i = 0; i < 32; i++) { - ASSERT_EQ(output1[i], output2[i]); - } + ASSERT_EQ(output1, output2); } TEST_F(CryptoTest, AESDecryptAndCreateKeyHandleForMacKeysFailsForBadInput) { @@ -1555,10 +1608,8 @@ TEST_F(CryptoTest, AESDecryptAndCreateKeyHandleForMacKeysBasic) { WTPI_C1_HMAC_SHA256(expected_mac_key_server_handle, input.data(), input.size(), output4.data())); - for (int i = 0; i < 32; i++) { - ASSERT_EQ(output1[i], output2[i]); - ASSERT_EQ(output3[i], output4[i]); - } + ASSERT_EQ(output1, output2); + ASSERT_EQ(output3, output4); } TEST_F(CryptoTest, DeriveDeviceKeyIntoHandleFailsForBadInput) { @@ -1654,9 +1705,7 @@ TEST_F(CryptoTest, WTPI_EncryptAndSign_Then_VerifyAndDecrypt_Works) { WTPI_VerifyAndDecrypt(context, intermediate.data(), intermediate_size, output.data(), &output_size)); - for (size_t i = 0; i < input.size(); i++) { - ASSERT_EQ(input[i], output[i]); - } + ASSERT_EQ(input, output); } TEST_F(CryptoTest, ECCSignFailsForBadInput) { @@ -1732,3 +1781,20 @@ TEST_F(CryptoTest, ECCLoadKeyAndSign) { ASSERT_EQ(WTPI_FreeAsymmetricKeyHandle(key_handle), OEMCrypto_SUCCESS); } + +TEST_F(CryptoTest, GetBCCTypeProv4AndOthers) { + OEMCrypto_ProvisioningMethod method = WTPI_GetProvisioningMethod(); + + OEMCrypto_BCCType bcc_type; + OEMCryptoResult res = WTPI_GetBCCType(&bcc_type); + + if (method == OEMCrypto_BootCertificateChain) { + ASSERT_EQ(res, OEMCrypto_SUCCESS); + } else { + ASSERT_EQ(res, OEMCrypto_ERROR_NOT_IMPLEMENTED); + } +} + +TEST_F(CryptoTest, GetBCCTypeNULL) { + ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, WTPI_GetBCCType(NULL)); +} diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/provisioning_4_interface_test.cpp b/oemcrypto/opk/oemcrypto_ta/wtpi_test/provisioning_4_interface_test.cpp index 37b2f0e..007af20 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/provisioning_4_interface_test.cpp +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/provisioning_4_interface_test.cpp @@ -14,6 +14,7 @@ #include "wtpi_crypto_and_key_management_interface_layer1.h" #include "wtpi_crypto_asymmetric_interface.h" #include "wtpi_provisioning_4_interface.h" +#include "wtpi_device_key_interface.h" using wtpi_test::EcKeyPtr; using wtpi_test::ExtractPublicKeyFromBcc; @@ -267,16 +268,18 @@ TEST_F(Prov4Test, GenerateRandomCertificateKeyPairSuccess) { uint8_t wrapped_private_key[kBufferSize]; size_t wrapped_private_key_length = sizeof(wrapped_private_key); - ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( - &type, wrapped_private_key, &wrapped_private_key_length, - public_key.data(), &public_key_length), - OEMCrypto_ERROR_SHORT_BUFFER); + ASSERT_EQ( + WTPI_GenerateRandomCertificateKeyPair( + CERT_SIGNATURE_DRM, &type, wrapped_private_key, + &wrapped_private_key_length, public_key.data(), &public_key_length), + OEMCrypto_ERROR_SHORT_BUFFER); public_key.resize(public_key_length); - ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( - &type, wrapped_private_key, &wrapped_private_key_length, - public_key.data(), &public_key_length), - OEMCrypto_SUCCESS); + ASSERT_EQ( + WTPI_GenerateRandomCertificateKeyPair( + CERT_SIGNATURE_DRM, &type, wrapped_private_key, + &wrapped_private_key_length, public_key.data(), &public_key_length), + OEMCrypto_SUCCESS); EXPECT_TRUE(type == DRM_ECC_PRIVATE_KEY || type == DRM_RSA_PRIVATE_KEY); EXPECT_GT(public_key_length, size_t(0)); @@ -288,7 +291,7 @@ TEST_F(Prov4Test, GenerateRandomCertificateKeyPairSuccess) { // it with public key to ensure keypair is valid WTPI_AsymmetricKey_Handle key_handle; uint32_t allowed_schemes; - ASSERT_EQ(WTPI_UnwrapIntoAsymmetricKeyHandle(wrapped_private_key, + ASSERT_EQ(WTPI_UnwrapIntoAsymmetricKeyHandle(DEVICE_KEY_WRAP_DRM_CERT, wrapped_private_key, wrapped_private_key_length, type, &key_handle, &allowed_schemes), OEMCrypto_SUCCESS); @@ -373,42 +376,42 @@ TEST_F(Prov4Test, GenerateRandomCertificateKeyPairFailsForBadInput) { size_t wrapped_private_key_length = sizeof(wrapped_private_key); ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( - NULL, wrapped_private_key, &wrapped_private_key_length, + CERT_SIGNATURE_DRM, NULL, wrapped_private_key, + &wrapped_private_key_length, public_key, &public_key_length), + OEMCrypto_ERROR_INVALID_CONTEXT); + + ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( + CERT_SIGNATURE_DRM, &type, wrapped_private_key, NULL, public_key, &public_key_length), OEMCrypto_ERROR_INVALID_CONTEXT); - ASSERT_EQ( - WTPI_GenerateRandomCertificateKeyPair(&type, wrapped_private_key, NULL, - public_key, &public_key_length), - OEMCrypto_ERROR_INVALID_CONTEXT); - - ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair(&type, wrapped_private_key, - &wrapped_private_key_length, - public_key, NULL), + ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( + CERT_SIGNATURE_DRM, &type, wrapped_private_key, + &wrapped_private_key_length, public_key, NULL), OEMCrypto_ERROR_INVALID_CONTEXT); size_t bad_size = 0; - ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair(&type, wrapped_private_key, - &bad_size, public_key, - &public_key_length), + ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( + CERT_SIGNATURE_DRM, &type, wrapped_private_key, &bad_size, + public_key, &public_key_length), OEMCrypto_ERROR_SHORT_BUFFER); EXPECT_GT(bad_size, size_t(0)); bad_size = 0; - ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair(&type, wrapped_private_key, - &wrapped_private_key_length, - public_key, &bad_size), + ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( + CERT_SIGNATURE_DRM, &type, wrapped_private_key, + &wrapped_private_key_length, public_key, &bad_size), OEMCrypto_ERROR_SHORT_BUFFER); EXPECT_GT(bad_size, size_t(0)); ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( - &type, NULL, &wrapped_private_key_length, public_key, - &public_key_length), + CERT_SIGNATURE_DRM, &type, NULL, + &wrapped_private_key_length, public_key, &public_key_length), OEMCrypto_ERROR_SHORT_BUFFER); - ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair(&type, wrapped_private_key, - &wrapped_private_key_length, - NULL, &public_key_length), + ASSERT_EQ(WTPI_GenerateRandomCertificateKeyPair( + CERT_SIGNATURE_DRM, &type, wrapped_private_key, + &wrapped_private_key_length, NULL, &public_key_length), OEMCrypto_ERROR_SHORT_BUFFER); } diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_oemcrypto_tee_test_api.c b/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_oemcrypto_tee_test_api.c index e15ba88..ba35a78 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_oemcrypto_tee_test_api.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_oemcrypto_tee_test_api.c @@ -928,8 +928,9 @@ cleanup_and_return: } OEMCryptoResult WTPI_UnwrapIntoAsymmetricKeyHandle( - const uint8_t* input, size_t input_length, AsymmetricKeyType key_type, - WTPI_AsymmetricKey_Handle* key_handle, uint32_t* allowed_schemes) { + uint32_t context, const uint8_t* input, size_t input_length, + AsymmetricKeyType key_type, WTPI_AsymmetricKey_Handle* key_handle, + uint32_t* allowed_schemes) { pthread_mutex_lock(&api_lock); OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; ODK_Message request = ODK_Message_Create(NULL, 0); @@ -937,7 +938,7 @@ OEMCryptoResult WTPI_UnwrapIntoAsymmetricKeyHandle( API_Initialize(); request = OPK_Pack_UnwrapIntoAsymmetricKeyHandle_Request( - input, input_length, key_type, key_handle, allowed_schemes); + context, input, input_length, key_type, key_handle, allowed_schemes); if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; @@ -1035,7 +1036,8 @@ cleanup_and_return: return result; } -OEMCryptoResult WTPI_WrapAsymmetricKey(uint8_t* output, size_t output_length, +OEMCryptoResult WTPI_WrapAsymmetricKey(uint32_t context, uint8_t* output, + size_t output_length, AsymmetricKeyType key_type, const uint8_t* clear_key, size_t clear_key_length) { @@ -1045,8 +1047,8 @@ OEMCryptoResult WTPI_WrapAsymmetricKey(uint8_t* output, size_t output_length, ODK_Message response = ODK_Message_Create(NULL, 0); API_Initialize(); - request = OPK_Pack_WrapAsymmetricKey_Request(output, output_length, key_type, - clear_key, clear_key_length); + request = OPK_Pack_WrapAsymmetricKey_Request( + context, output, output_length, key_type, clear_key, clear_key_length); if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; @@ -1294,6 +1296,46 @@ cleanup_and_return: return result; } +OEMCryptoResult WTPI_DeriveNewAsymmetricKeyHandle( + const uint8_t* deriving_key, size_t deriving_key_length, + const uint8_t* context, size_t context_length, AsymmetricKeyType key_type, + WTPI_AsymmetricKey_Handle* private_key_handle, uint8_t* public_key, + size_t* public_key_length) { + pthread_mutex_lock(&api_lock); + OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + ODK_Message request = ODK_Message_Create(NULL, 0); + ODK_Message response = ODK_Message_Create(NULL, 0); + + API_Initialize(); + request = OPK_Pack_DeriveNewAsymmetricKeyHandle_Request( + deriving_key, deriving_key_length, context, context_length, key_type, + private_key_handle, public_key, public_key_length); + if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { + if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { + api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; + } else { + api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + } + goto cleanup_and_return; + } + response = API_Transact(&request); + if (api_result != OEMCrypto_SUCCESS) goto cleanup_and_return; + OPK_Unpack_DeriveNewAsymmetricKeyHandle_Response( + &response, &result, &private_key_handle, &public_key, &public_key_length); + + if (ODK_Message_GetStatus(&response) != MESSAGE_STATUS_OK) { + api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + } +cleanup_and_return: + TOS_Transport_ReleaseMessage(&request); + TOS_Transport_ReleaseMessage(&response); + + API_Terminate(); + result = API_CheckResult(result); + pthread_mutex_unlock(&api_lock); + return result; +} + OEMCryptoResult WTPI_GetBootCertificateChain(uint8_t* out, size_t* out_length) { pthread_mutex_lock(&api_lock); OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; @@ -1363,9 +1405,9 @@ cleanup_and_return: } OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( - AsymmetricKeyType* key_type, uint8_t* wrapped_private_key, - size_t* wrapped_private_key_length, uint8_t* public_key, - size_t* public_key_length) { + CertSignatureType cert_type, AsymmetricKeyType* key_type, + uint8_t* wrapped_private_key, size_t* wrapped_private_key_length, + uint8_t* public_key, size_t* public_key_length) { pthread_mutex_lock(&api_lock); OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; ODK_Message request = ODK_Message_Create(NULL, 0); @@ -1373,8 +1415,8 @@ OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( API_Initialize(); request = OPK_Pack_GenerateRandomCertificateKeyPair_Request( - key_type, wrapped_private_key, wrapped_private_key_length, public_key, - public_key_length); + cert_type, key_type, wrapped_private_key, wrapped_private_key_length, + public_key, public_key_length); if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; @@ -1749,6 +1791,44 @@ cleanup_and_return: return result; } +OEMCryptoResult WTPI_CreateUDSDerivedAsymmetricKeyHandle( + AsymmetricKeyType* key_type, WTPI_AsymmetricKey_Handle* private_key_handle, + uint8_t* public_key, size_t* public_key_length) { + pthread_mutex_lock(&api_lock); + OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + ODK_Message request = ODK_Message_Create(NULL, 0); + ODK_Message response = ODK_Message_Create(NULL, 0); + + API_Initialize(); + request = OPK_Pack_CreateUDSDerivedAsymmetricKeyHandle_Request( + key_type, private_key_handle, public_key, public_key_length); + if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { + if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { + api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; + } else { + api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + } + goto cleanup_and_return; + } + response = API_Transact(&request); + if (api_result != OEMCrypto_SUCCESS) goto cleanup_and_return; + OPK_Unpack_CreateUDSDerivedAsymmetricKeyHandle_Response( + &response, &result, &key_type, &private_key_handle, &public_key, + &public_key_length); + + if (ODK_Message_GetStatus(&response) != MESSAGE_STATUS_OK) { + api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + } +cleanup_and_return: + TOS_Transport_ReleaseMessage(&request); + TOS_Transport_ReleaseMessage(&response); + + API_Terminate(); + result = API_CheckResult(result); + pthread_mutex_unlock(&api_lock); + return result; +} + OEMCryptoResult WTPI_Crc32Init(uint32_t* initial_hash) { pthread_mutex_lock(&api_lock); OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; @@ -2209,39 +2289,6 @@ cleanup_and_return: return result; } -OEMCryptoResult WTPI_GetCurrentSRMVersion(uint32_t* srm_version) { - pthread_mutex_lock(&api_lock); - OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; - ODK_Message request = ODK_Message_Create(NULL, 0); - ODK_Message response = ODK_Message_Create(NULL, 0); - - API_Initialize(); - request = OPK_Pack_GetCurrentSRMVersion_Request(srm_version); - if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { - if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { - api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; - } else { - api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; - } - goto cleanup_and_return; - } - response = API_Transact(&request); - if (api_result != OEMCrypto_SUCCESS) goto cleanup_and_return; - OPK_Unpack_GetCurrentSRMVersion_Response(&response, &result, &srm_version); - - if (ODK_Message_GetStatus(&response) != MESSAGE_STATUS_OK) { - api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; - } -cleanup_and_return: - TOS_Transport_ReleaseMessage(&request); - TOS_Transport_ReleaseMessage(&response); - - API_Terminate(); - result = API_CheckResult(result); - pthread_mutex_unlock(&api_lock); - return result; -} - bool WTPI_IsAntiRollbackHWPresent(void) { pthread_mutex_lock(&api_lock); bool result = false; @@ -2498,70 +2545,6 @@ cleanup_and_return: return result; } -OEMCrypto_HDCP_Capability WTPI_CurrentHDCPCapability(void) { - pthread_mutex_lock(&api_lock); - OEMCrypto_HDCP_Capability result = HDCP_NONE; - ODK_Message request = ODK_Message_Create(NULL, 0); - ODK_Message response = ODK_Message_Create(NULL, 0); - - API_Initialize(); - request = OPK_Pack_CurrentHDCPCapability_Request(); - if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { - if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { - api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; - } else { - api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; - } - goto cleanup_and_return; - } - response = API_Transact(&request); - if (api_result != OEMCrypto_SUCCESS) goto cleanup_and_return; - OPK_Unpack_CurrentHDCPCapability_Response(&response, &result); - - if (ODK_Message_GetStatus(&response) != MESSAGE_STATUS_OK) { - api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; - } -cleanup_and_return: - TOS_Transport_ReleaseMessage(&request); - TOS_Transport_ReleaseMessage(&response); - - API_Terminate(); - pthread_mutex_unlock(&api_lock); - return result; -} - -OEMCrypto_HDCP_Capability WTPI_MaxHDCPCapability(void) { - pthread_mutex_lock(&api_lock); - OEMCrypto_HDCP_Capability result = HDCP_NONE; - ODK_Message request = ODK_Message_Create(NULL, 0); - ODK_Message response = ODK_Message_Create(NULL, 0); - - API_Initialize(); - request = OPK_Pack_MaxHDCPCapability_Request(); - if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { - if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { - api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; - } else { - api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; - } - goto cleanup_and_return; - } - response = API_Transact(&request); - if (api_result != OEMCrypto_SUCCESS) goto cleanup_and_return; - OPK_Unpack_MaxHDCPCapability_Response(&response, &result); - - if (ODK_Message_GetStatus(&response) != MESSAGE_STATUS_OK) { - api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; - } -cleanup_and_return: - TOS_Transport_ReleaseMessage(&request); - TOS_Transport_ReleaseMessage(&response); - - API_Terminate(); - pthread_mutex_unlock(&api_lock); - return result; -} - size_t WTPI_MaxBufferSizeForGenericCrypto(void) { pthread_mutex_lock(&api_lock); size_t result = 0; diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.c b/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.c index 810d9bf..52929dc 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.c @@ -79,7 +79,11 @@ void OPK_Unpack_LoadGenerationNumber_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint64_t(msg, value); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint64_t(msg, value); + } else { + OPK_UnpackNullable_uint64_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -141,7 +145,11 @@ void OPK_Unpack_K1_GetKeySize_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_KeySize(msg, size); + if (SuccessResult(*result)) { + OPK_UnpackNullable_KeySize(msg, size); + } else { + OPK_UnpackNullable_KeySize(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -419,7 +427,11 @@ void OPK_Unpack_K1_CreateKeyHandle_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + } else { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -455,7 +467,11 @@ void OPK_Unpack_K1_DeriveDeviceKeyIntoHandle_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + } else { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -495,7 +511,11 @@ void OPK_Unpack_K1_AESDecryptAndCreateKeyHandle_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + } else { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -537,8 +557,16 @@ void OPK_Unpack_K1_AESDecryptAndCreateKeyHandleForMacKeys_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_mac_key_server); - OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_mac_key_client); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_mac_key_server); + } else { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, NULL); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_mac_key_client); + } else { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -587,7 +615,11 @@ void OPK_Unpack_K1_DeriveKeyFromKeyHandle_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + } else { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -672,7 +704,11 @@ void OPK_Unpack_K1_UnwrapIntoKeyHandle_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, out_key_handle); + } else { + OPK_UnpackNullable_WTPI_K1_SymmetricKey_Handle(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -780,7 +816,11 @@ void OPK_Unpack_CreateAsymmetricKeyHandle_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, key_handle); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, key_handle); + } else { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -789,8 +829,8 @@ void OPK_Unpack_CreateAsymmetricKeyHandle_Response( } ODK_Message OPK_Pack_UnwrapIntoAsymmetricKeyHandle_Request( - const uint8_t* input, size_t input_length, AsymmetricKeyType key_type, - const WTPI_AsymmetricKey_Handle* key_handle, + uint32_t context, const uint8_t* input, size_t input_length, + AsymmetricKeyType key_type, const WTPI_AsymmetricKey_Handle* key_handle, const uint32_t* allowed_schemes) { uint32_t api_value = 10025; /* from _tee10025 */ ODK_Message msg = TOS_Transport_GetRequest(); @@ -798,6 +838,7 @@ ODK_Message OPK_Pack_UnwrapIntoAsymmetricKeyHandle_Request( uint64_t timestamp = time(0); OPK_Pack_uint64_t(&msg, ×tamp); OPK_Pack_size_t(&msg, &input_length); + OPK_Pack_uint32_t(&msg, &context); OPK_PackMemory(&msg, (const uint8_t*)input, OPK_ToLengthType(input_length)); OPK_Pack_AsymmetricKeyType(&msg, &key_type); OPK_PackIsNull(&msg, key_handle); @@ -818,8 +859,16 @@ void OPK_Unpack_UnwrapIntoAsymmetricKeyHandle_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, key_handle); - OPK_UnpackNullable_uint32_t(msg, allowed_schemes); + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, key_handle); + } else { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, NULL); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, allowed_schemes); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -884,7 +933,11 @@ void OPK_Unpack_GetWrappedAsymmetricKeySize_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_size_t(msg, buffer_size); + if (SuccessResult(*result)) { + OPK_UnpackNullable_size_t(msg, buffer_size); + } else { + OPK_UnpackNullable_size_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -892,7 +945,8 @@ void OPK_Unpack_GetWrappedAsymmetricKeySize_Response(ODK_Message* msg, } } -ODK_Message OPK_Pack_WrapAsymmetricKey_Request(const uint8_t* output, +ODK_Message OPK_Pack_WrapAsymmetricKey_Request(uint32_t context, + const uint8_t* output, size_t output_length, AsymmetricKeyType key_type, const uint8_t* clear_key, @@ -904,6 +958,7 @@ ODK_Message OPK_Pack_WrapAsymmetricKey_Request(const uint8_t* output, OPK_Pack_uint64_t(&msg, ×tamp); OPK_Pack_size_t(&msg, &output_length); OPK_Pack_size_t(&msg, &clear_key_length); + OPK_Pack_uint32_t(&msg, &context); OPK_PackAlloc(&msg, output); OPK_Pack_AsymmetricKeyType(&msg, &key_type); OPK_PackMemory(&msg, (const uint8_t*)clear_key, @@ -1152,7 +1207,11 @@ void OPK_Unpack_GetSignatureSize_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_size_t(msg, signature_length); + if (SuccessResult(*result)) { + OPK_UnpackNullable_size_t(msg, signature_length); + } else { + OPK_UnpackNullable_size_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1187,7 +1246,68 @@ void OPK_Unpack_GetSignatureHashAlgorithm_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_OEMCrypto_SignatureHashAlgorithm(msg, hash_algorithm); + if (SuccessResult(*result)) { + OPK_UnpackNullable_OEMCrypto_SignatureHashAlgorithm(msg, hash_algorithm); + } else { + OPK_UnpackNullable_OEMCrypto_SignatureHashAlgorithm(msg, NULL); + } + OPK_UnpackEOM(msg); + + if (SuccessResult(*result)) { + OPK_SharedBuffer_FinalizeUnpacking(); + } +} + +ODK_Message OPK_Pack_DeriveNewAsymmetricKeyHandle_Request( + const uint8_t* deriving_key, size_t deriving_key_length, + const uint8_t* context, size_t context_length, AsymmetricKeyType key_type, + const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length) { + uint32_t api_value = 10035; /* from _tee10035 */ + ODK_Message msg = TOS_Transport_GetRequest(); + OPK_Pack_uint32_t(&msg, &api_value); + uint64_t timestamp = time(0); + OPK_Pack_uint64_t(&msg, ×tamp); + OPK_Pack_size_t(&msg, &deriving_key_length); + OPK_Pack_size_t(&msg, &context_length); + OPK_PackNullable_size_t(&msg, public_key_length); + OPK_PackMemory(&msg, (const uint8_t*)deriving_key, + OPK_ToLengthType(deriving_key_length)); + OPK_PackMemory(&msg, (const uint8_t*)context, + OPK_ToLengthType(context_length)); + OPK_Pack_AsymmetricKeyType(&msg, &key_type); + OPK_PackIsNull(&msg, private_key_handle); + OPK_PackAlloc(&msg, public_key); + OPK_PackEOM(&msg); + OPK_SharedBuffer_FinalizePacking(); + return msg; +} + +void OPK_Unpack_DeriveNewAsymmetricKeyHandle_Response( + ODK_Message* msg, OEMCryptoResult* result, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length) { + uint32_t api_value = UINT32_MAX; + OPK_Unpack_uint32_t(msg, &api_value); + if (api_value != 10035) + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); + OPK_UnpackNullable_size_t(msg, public_key_length); + OPK_Unpack_uint32_t(msg, result); + if (!Is_Valid_OEMCryptoResult(*result)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, private_key_handle); + } else { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, NULL); + } + if (SuccessResult(*result)) { + uint8_t* p; + OPK_UnpackInPlace(msg, &p, OPK_FromSizeTPtrPtr(public_key_length)); + if (p && *public_key) { + memcpy(*public_key, p, OPK_SafeDerefSizeTPtrPtr(public_key_length)); + } + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1197,7 +1317,7 @@ void OPK_Unpack_GetSignatureHashAlgorithm_Response( ODK_Message OPK_Pack_GetBootCertificateChain_Request(const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10035; /* from _tee10035 */ + uint32_t api_value = 10036; /* from _tee10036 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1215,7 +1335,7 @@ void OPK_Unpack_GetBootCertificateChain_Response(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10035) + if (api_value != 10036) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, out_length); OPK_Unpack_uint32_t(msg, result); @@ -1238,7 +1358,7 @@ void OPK_Unpack_GetBootCertificateChain_Response(ODK_Message* msg, ODK_Message OPK_Pack_GetMaxBootCertificateChainSize_Request( const size_t* out_length) { - uint32_t api_value = 10036; /* from _tee10036 */ + uint32_t api_value = 10037; /* from _tee10037 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1254,13 +1374,17 @@ void OPK_Unpack_GetMaxBootCertificateChainSize_Response(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10036) + if (api_value != 10037) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_size_t(msg, out_length); + if (SuccessResult(*result)) { + OPK_UnpackNullable_size_t(msg, out_length); + } else { + OPK_UnpackNullable_size_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1269,16 +1393,18 @@ void OPK_Unpack_GetMaxBootCertificateChainSize_Response(ODK_Message* msg, } ODK_Message OPK_Pack_GenerateRandomCertificateKeyPair_Request( - const AsymmetricKeyType* key_type, const uint8_t* wrapped_private_key, + CertSignatureType cert_type, const AsymmetricKeyType* key_type, + const uint8_t* wrapped_private_key, const size_t* wrapped_private_key_length, const uint8_t* public_key, const size_t* public_key_length) { - uint32_t api_value = 10037; /* from _tee10037 */ + uint32_t api_value = 10038; /* from _tee10038 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); OPK_Pack_uint64_t(&msg, ×tamp); OPK_PackNullable_size_t(&msg, wrapped_private_key_length); OPK_PackNullable_size_t(&msg, public_key_length); + OPK_Pack_CertSignatureType(&msg, &cert_type); OPK_PackIsNull(&msg, key_type); OPK_PackAlloc(&msg, wrapped_private_key); OPK_PackAlloc(&msg, public_key); @@ -1293,7 +1419,7 @@ void OPK_Unpack_GenerateRandomCertificateKeyPair_Response( uint8_t** public_key, size_t** public_key_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10037) + if (api_value != 10038) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, wrapped_private_key_length); OPK_UnpackNullable_size_t(msg, public_key_length); @@ -1301,7 +1427,11 @@ void OPK_Unpack_GenerateRandomCertificateKeyPair_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_AsymmetricKeyType(msg, key_type); + if (SuccessResult(*result)) { + OPK_UnpackNullable_AsymmetricKeyType(msg, key_type); + } else { + OPK_UnpackNullable_AsymmetricKeyType(msg, NULL); + } if (SuccessResult(*result)) { uint8_t* p; OPK_UnpackInPlace(msg, &p, OPK_FromSizeTPtrPtr(wrapped_private_key_length)); @@ -1329,7 +1459,7 @@ ODK_Message OPK_Pack_GetSignedCsrPayload_Request( const uint8_t* encoded_device_info, size_t encoded_device_info_length, const uint8_t* signed_csr_payload, const size_t* signed_csr_payload_length) { - uint32_t api_value = 10038; /* from _tee10038 */ + uint32_t api_value = 10039; /* from _tee10039 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1352,7 +1482,7 @@ void OPK_Unpack_GetSignedCsrPayload_Response( size_t** signed_csr_payload_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10038) + if (api_value != 10039) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, signed_csr_payload_length); OPK_Unpack_uint32_t(msg, result); @@ -1375,7 +1505,7 @@ void OPK_Unpack_GetSignedCsrPayload_Response( } ODK_Message OPK_Pack_MaxDeviceInfoSize_Request(void) { - uint32_t api_value = 10039; /* from _tee10039 */ + uint32_t api_value = 10040; /* from _tee10040 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1388,7 +1518,7 @@ ODK_Message OPK_Pack_MaxDeviceInfoSize_Request(void) { void OPK_Unpack_MaxDeviceInfoSize_Response(ODK_Message* msg, size_t* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10039) + if (api_value != 10040) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_size_t(msg, result); OPK_UnpackEOM(msg); @@ -1397,7 +1527,7 @@ void OPK_Unpack_MaxDeviceInfoSize_Response(ODK_Message* msg, size_t* result) { ODK_Message OPK_Pack_GetDeviceInformation_Request(const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10040; /* from _tee10040 */ + uint32_t api_value = 10041; /* from _tee10041 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1415,7 +1545,7 @@ void OPK_Unpack_GetDeviceInformation_Response(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10040) + if (api_value != 10041) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, out_length); OPK_Unpack_uint32_t(msg, result); @@ -1440,7 +1570,7 @@ ODK_Message OPK_Pack_BccKeyCoseSign1_Request(const uint8_t* message, size_t message_length, const uint8_t* signature, const size_t* signature_length) { - uint32_t api_value = 10041; /* from _tee10041 */ + uint32_t api_value = 10042; /* from _tee10042 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1461,7 +1591,7 @@ void OPK_Unpack_BccKeyCoseSign1_Response(ODK_Message* msg, size_t** signature_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10041) + if (api_value != 10042) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, signature_length); OPK_Unpack_uint32_t(msg, result); @@ -1484,7 +1614,7 @@ void OPK_Unpack_BccKeyCoseSign1_Response(ODK_Message* msg, ODK_Message OPK_Pack_GetMaxBccKeyCoseSign1Size_Request( const size_t* out_length) { - uint32_t api_value = 10042; /* from _tee10042 */ + uint32_t api_value = 10043; /* from _tee10043 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1500,13 +1630,17 @@ void OPK_Unpack_GetMaxBccKeyCoseSign1Size_Response(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10042) + if (api_value != 10043) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_size_t(msg, out_length); + if (SuccessResult(*result)) { + OPK_UnpackNullable_size_t(msg, out_length); + } else { + OPK_UnpackNullable_size_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1515,7 +1649,7 @@ void OPK_Unpack_GetMaxBccKeyCoseSign1Size_Response(ODK_Message* msg, } ODK_Message OPK_Pack_GetDeviceFusedStatus_Request(const bool* is_fused) { - uint32_t api_value = 10043; /* from _tee10043 */ + uint32_t api_value = 10044; /* from _tee10044 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1531,13 +1665,17 @@ void OPK_Unpack_GetDeviceFusedStatus_Response(ODK_Message* msg, bool** is_fused) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10043) + if (api_value != 10044) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_bool(msg, is_fused); + if (SuccessResult(*result)) { + OPK_UnpackNullable_bool(msg, is_fused); + } else { + OPK_UnpackNullable_bool(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1546,7 +1684,7 @@ void OPK_Unpack_GetDeviceFusedStatus_Response(ODK_Message* msg, } ODK_Message OPK_Pack_GetBCCSignatureType_Request(void) { - uint32_t api_value = 10044; /* from _tee10044 */ + uint32_t api_value = 10045; /* from _tee10045 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1560,7 +1698,7 @@ void OPK_Unpack_GetBCCSignatureType_Response(ODK_Message* msg, OPK_BCCSignatureType* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10044) + if (api_value != 10045) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OPK_BCCSignatureType(*result)) { @@ -1572,7 +1710,7 @@ void OPK_Unpack_GetBCCSignatureType_Response(ODK_Message* msg, ODK_Message OPK_Pack_GenerateBCCSignature_Request(const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10045; /* from _tee10045 */ + uint32_t api_value = 10046; /* from _tee10046 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1590,7 +1728,7 @@ void OPK_Unpack_GenerateBCCSignature_Response(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10045) + if (api_value != 10046) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, out_length); OPK_Unpack_uint32_t(msg, result); @@ -1613,7 +1751,7 @@ void OPK_Unpack_GenerateBCCSignature_Response(ODK_Message* msg, ODK_Message OPK_Pack_StoreBCCSignature_Request(const uint8_t* signature, size_t signature_length) { - uint32_t api_value = 10046; /* from _tee10046 */ + uint32_t api_value = 10047; /* from _tee10047 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1630,7 +1768,7 @@ void OPK_Unpack_StoreBCCSignature_Response(ODK_Message* msg, OEMCryptoResult* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10046) + if (api_value != 10047) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { @@ -1645,7 +1783,7 @@ void OPK_Unpack_StoreBCCSignature_Response(ODK_Message* msg, ODK_Message OPK_Pack_LoadBCCSignature_Request(const uint8_t* signature, const size_t* signature_length) { - uint32_t api_value = 10047; /* from _tee10047 */ + uint32_t api_value = 10048; /* from _tee10048 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1663,7 +1801,7 @@ void OPK_Unpack_LoadBCCSignature_Response(ODK_Message* msg, size_t** signature_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10047) + if (api_value != 10048) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, signature_length); OPK_Unpack_uint32_t(msg, result); @@ -1684,8 +1822,63 @@ void OPK_Unpack_LoadBCCSignature_Response(ODK_Message* msg, } } +ODK_Message OPK_Pack_CreateUDSDerivedAsymmetricKeyHandle_Request( + const AsymmetricKeyType* key_type, + const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length) { + uint32_t api_value = 10049; /* from _tee10049 */ + ODK_Message msg = TOS_Transport_GetRequest(); + OPK_Pack_uint32_t(&msg, &api_value); + uint64_t timestamp = time(0); + OPK_Pack_uint64_t(&msg, ×tamp); + OPK_PackNullable_size_t(&msg, public_key_length); + OPK_PackIsNull(&msg, key_type); + OPK_PackIsNull(&msg, private_key_handle); + OPK_PackAlloc(&msg, public_key); + OPK_PackEOM(&msg); + OPK_SharedBuffer_FinalizePacking(); + return msg; +} + +void OPK_Unpack_CreateUDSDerivedAsymmetricKeyHandle_Response( + ODK_Message* msg, OEMCryptoResult* result, AsymmetricKeyType** key_type, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length) { + uint32_t api_value = UINT32_MAX; + OPK_Unpack_uint32_t(msg, &api_value); + if (api_value != 10049) + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); + OPK_UnpackNullable_size_t(msg, public_key_length); + OPK_Unpack_uint32_t(msg, result); + if (!Is_Valid_OEMCryptoResult(*result)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_AsymmetricKeyType(msg, key_type); + } else { + OPK_UnpackNullable_AsymmetricKeyType(msg, NULL); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, private_key_handle); + } else { + OPK_UnpackNullable_WTPI_AsymmetricKey_Handle(msg, NULL); + } + if (SuccessResult(*result)) { + uint8_t* p; + OPK_UnpackInPlace(msg, &p, OPK_FromSizeTPtrPtr(public_key_length)); + if (p && *public_key) { + memcpy(*public_key, p, OPK_SafeDerefSizeTPtrPtr(public_key_length)); + } + } + OPK_UnpackEOM(msg); + + if (SuccessResult(*result)) { + OPK_SharedBuffer_FinalizeUnpacking(); + } +} + ODK_Message OPK_Pack_Crc32Init_Request(const uint32_t* initial_hash) { - uint32_t api_value = 10048; /* from _tee10048 */ + uint32_t api_value = 10050; /* from _tee10050 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1700,13 +1893,17 @@ void OPK_Unpack_Crc32Init_Response(ODK_Message* msg, OEMCryptoResult* result, uint32_t** initial_hash) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10048) + if (api_value != 10050) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, initial_hash); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, initial_hash); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1717,7 +1914,7 @@ void OPK_Unpack_Crc32Init_Response(ODK_Message* msg, OEMCryptoResult* result, ODK_Message OPK_Pack_Crc32Cont_Request(const uint8_t* in, size_t in_length, uint32_t prev_crc, const uint32_t* new_crc) { - uint32_t api_value = 10049; /* from _tee10049 */ + uint32_t api_value = 10051; /* from _tee10051 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1735,13 +1932,17 @@ void OPK_Unpack_Crc32Cont_Response(ODK_Message* msg, OEMCryptoResult* result, uint32_t** new_crc) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10049) + if (api_value != 10051) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, new_crc); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, new_crc); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1754,7 +1955,7 @@ ODK_Message OPK_Pack_Crc32Cont_OutputBuffer_Request(const OPK_OutputBuffer* in, size_t in_length, uint32_t prev_crc, const uint32_t* new_crc) { - uint32_t api_value = 10050; /* from _tee10050 */ + uint32_t api_value = 10052; /* from _tee10052 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1786,13 +1987,17 @@ void OPK_Unpack_Crc32Cont_OutputBuffer_Response(ODK_Message* msg, uint32_t** new_crc) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10050) + if (api_value != 10052) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, new_crc); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, new_crc); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1801,7 +2006,7 @@ void OPK_Unpack_Crc32Cont_OutputBuffer_Response(ODK_Message* msg, } ODK_Message OPK_Pack_GetTrustedTime_Request(const uint64_t* time_in_s) { - uint32_t api_value = 10051; /* from _tee10051 */ + uint32_t api_value = 10053; /* from _tee10053 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1817,13 +2022,17 @@ void OPK_Unpack_GetTrustedTime_Response(ODK_Message* msg, uint64_t** time_in_s) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10051) + if (api_value != 10053) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint64_t(msg, time_in_s); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint64_t(msg, time_in_s); + } else { + OPK_UnpackNullable_uint64_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1832,7 +2041,7 @@ void OPK_Unpack_GetTrustedTime_Response(ODK_Message* msg, } ODK_Message OPK_Pack_InitializeClock_Request(void) { - uint32_t api_value = 10052; /* from _tee10052 */ + uint32_t api_value = 10054; /* from _tee10054 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1846,7 +2055,7 @@ void OPK_Unpack_InitializeClock_Response(ODK_Message* msg, OEMCryptoResult* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10052) + if (api_value != 10054) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { @@ -1860,7 +2069,7 @@ void OPK_Unpack_InitializeClock_Response(ODK_Message* msg, } ODK_Message OPK_Pack_TerminateClock_Request(void) { - uint32_t api_value = 10053; /* from _tee10053 */ + uint32_t api_value = 10055; /* from _tee10055 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1874,7 +2083,7 @@ void OPK_Unpack_TerminateClock_Response(ODK_Message* msg, OEMCryptoResult* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10053) + if (api_value != 10055) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { @@ -1888,7 +2097,7 @@ void OPK_Unpack_TerminateClock_Response(ODK_Message* msg, } ODK_Message OPK_Pack_GetClockType_Request(void) { - uint32_t api_value = 10054; /* from _tee10054 */ + uint32_t api_value = 10056; /* from _tee10056 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1902,7 +2111,7 @@ void OPK_Unpack_GetClockType_Response(ODK_Message* msg, OEMCrypto_Clock_Security_Level* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10054) + if (api_value != 10056) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_OEMCrypto_Clock_Security_Level(msg, result); OPK_UnpackEOM(msg); @@ -1910,7 +2119,7 @@ void OPK_Unpack_GetClockType_Response(ODK_Message* msg, } ODK_Message OPK_Pack_GetSecurityLevel_Request(void) { - uint32_t api_value = 10055; /* from _tee10055 */ + uint32_t api_value = 10057; /* from _tee10057 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1924,7 +2133,7 @@ void OPK_Unpack_GetSecurityLevel_Response(ODK_Message* msg, OEMCrypto_Security_Level* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10055) + if (api_value != 10057) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_OEMCrypto_Security_Level(msg, result); OPK_UnpackEOM(msg); @@ -1932,7 +2141,7 @@ void OPK_Unpack_GetSecurityLevel_Response(ODK_Message* msg, } ODK_Message OPK_Pack_GetProvisioningMethod_Request(void) { - uint32_t api_value = 10056; /* from _tee10056 */ + uint32_t api_value = 10058; /* from _tee10058 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1946,7 +2155,7 @@ void OPK_Unpack_GetProvisioningMethod_Response( ODK_Message* msg, OEMCrypto_ProvisioningMethod* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10056) + if (api_value != 10058) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_OEMCrypto_ProvisioningMethod(msg, result); OPK_UnpackEOM(msg); @@ -1954,7 +2163,7 @@ void OPK_Unpack_GetProvisioningMethod_Response( } ODK_Message OPK_Pack_GetBCCType_Request(const OEMCrypto_BCCType* bcc_type) { - uint32_t api_value = 10057; /* from _tee10057 */ + uint32_t api_value = 10059; /* from _tee10059 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1969,13 +2178,17 @@ void OPK_Unpack_GetBCCType_Response(ODK_Message* msg, OEMCryptoResult* result, OEMCrypto_BCCType** bcc_type) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10057) + if (api_value != 10059) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_OEMCrypto_BCCType(msg, bcc_type); + if (SuccessResult(*result)) { + OPK_UnpackNullable_OEMCrypto_BCCType(msg, bcc_type); + } else { + OPK_UnpackNullable_OEMCrypto_BCCType(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1984,7 +2197,7 @@ void OPK_Unpack_GetBCCType_Response(ODK_Message* msg, OEMCryptoResult* result, } ODK_Message OPK_Pack_GetResourceRatingTier_Request(void) { - uint32_t api_value = 10058; /* from _tee10058 */ + uint32_t api_value = 10060; /* from _tee10060 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -1998,7 +2211,7 @@ void OPK_Unpack_GetResourceRatingTier_Response(ODK_Message* msg, uint32_t* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10058) + if (api_value != 10060) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); OPK_UnpackEOM(msg); @@ -2006,7 +2219,7 @@ void OPK_Unpack_GetResourceRatingTier_Response(ODK_Message* msg, } ODK_Message OPK_Pack_IsTAAntiRollbackEnabled_Request(void) { - uint32_t api_value = 10059; /* from _tee10059 */ + uint32_t api_value = 10061; /* from _tee10061 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2020,7 +2233,7 @@ void OPK_Unpack_IsTAAntiRollbackEnabled_Response(ODK_Message* msg, OPK_FeatureStatus* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10059) + if (api_value != 10061) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OPK_FeatureStatus(*result)) { @@ -2031,7 +2244,7 @@ void OPK_Unpack_IsTAAntiRollbackEnabled_Response(ODK_Message* msg, } ODK_Message OPK_Pack_IsProductionReady_Request(void) { - uint32_t api_value = 10060; /* from _tee10060 */ + uint32_t api_value = 10062; /* from _tee10062 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2044,7 +2257,7 @@ ODK_Message OPK_Pack_IsProductionReady_Request(void) { void OPK_Unpack_IsProductionReady_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10060) + if (api_value != 10062) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2052,7 +2265,7 @@ void OPK_Unpack_IsProductionReady_Response(ODK_Message* msg, bool* result) { } ODK_Message OPK_Pack_GetWatermarkingSupport_Request(void) { - uint32_t api_value = 10061; /* from _tee10061 */ + uint32_t api_value = 10063; /* from _tee10063 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2066,46 +2279,15 @@ void OPK_Unpack_GetWatermarkingSupport_Response( ODK_Message* msg, OEMCrypto_WatermarkingSupport* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10061) + if (api_value != 10063) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_OEMCrypto_WatermarkingSupport(msg, result); OPK_UnpackEOM(msg); OPK_SharedBuffer_FinalizeUnpacking(); } -ODK_Message OPK_Pack_GetCurrentSRMVersion_Request(const uint32_t* srm_version) { - uint32_t api_value = 10062; /* from _tee10062 */ - ODK_Message msg = TOS_Transport_GetRequest(); - OPK_Pack_uint32_t(&msg, &api_value); - uint64_t timestamp = time(0); - OPK_Pack_uint64_t(&msg, ×tamp); - OPK_PackIsNull(&msg, srm_version); - OPK_PackEOM(&msg); - OPK_SharedBuffer_FinalizePacking(); - return msg; -} - -void OPK_Unpack_GetCurrentSRMVersion_Response(ODK_Message* msg, - OEMCryptoResult* result, - uint32_t** srm_version) { - uint32_t api_value = UINT32_MAX; - OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10062) - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); - OPK_Unpack_uint32_t(msg, result); - if (!Is_Valid_OEMCryptoResult(*result)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); - } - OPK_UnpackNullable_uint32_t(msg, srm_version); - OPK_UnpackEOM(msg); - - if (SuccessResult(*result)) { - OPK_SharedBuffer_FinalizeUnpacking(); - } -} - ODK_Message OPK_Pack_IsAntiRollbackHWPresent_Request(void) { - uint32_t api_value = 10063; /* from _tee10063 */ + uint32_t api_value = 10064; /* from _tee10064 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2119,7 +2301,7 @@ void OPK_Unpack_IsAntiRollbackHWPresent_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10063) + if (api_value != 10064) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2127,7 +2309,7 @@ void OPK_Unpack_IsAntiRollbackHWPresent_Response(ODK_Message* msg, } ODK_Message OPK_Pack_IsCGMS_AActive_Request(void) { - uint32_t api_value = 10064; /* from _tee10064 */ + uint32_t api_value = 10065; /* from _tee10065 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2140,7 +2322,7 @@ ODK_Message OPK_Pack_IsCGMS_AActive_Request(void) { void OPK_Unpack_IsCGMS_AActive_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10064) + if (api_value != 10065) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2148,7 +2330,7 @@ void OPK_Unpack_IsCGMS_AActive_Response(ODK_Message* msg, bool* result) { } ODK_Message OPK_Pack_SupportsCGMS_A_Request(void) { - uint32_t api_value = 10065; /* from _tee10065 */ + uint32_t api_value = 10066; /* from _tee10066 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2161,7 +2343,7 @@ ODK_Message OPK_Pack_SupportsCGMS_A_Request(void) { void OPK_Unpack_SupportsCGMS_A_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10065) + if (api_value != 10066) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2169,7 +2351,7 @@ void OPK_Unpack_SupportsCGMS_A_Response(ODK_Message* msg, bool* result) { } ODK_Message OPK_Pack_HasAnalogDisplay_Request(void) { - uint32_t api_value = 10066; /* from _tee10066 */ + uint32_t api_value = 10067; /* from _tee10067 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2182,7 +2364,7 @@ ODK_Message OPK_Pack_HasAnalogDisplay_Request(void) { void OPK_Unpack_HasAnalogDisplay_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10066) + if (api_value != 10067) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2190,7 +2372,7 @@ void OPK_Unpack_HasAnalogDisplay_Response(ODK_Message* msg, bool* result) { } ODK_Message OPK_Pack_IsAnalogDisplayActive_Request(void) { - uint32_t api_value = 10067; /* from _tee10067 */ + uint32_t api_value = 10068; /* from _tee10068 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2203,7 +2385,7 @@ ODK_Message OPK_Pack_IsAnalogDisplayActive_Request(void) { void OPK_Unpack_IsAnalogDisplayActive_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10067) + if (api_value != 10068) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2211,7 +2393,7 @@ void OPK_Unpack_IsAnalogDisplayActive_Response(ODK_Message* msg, bool* result) { } ODK_Message OPK_Pack_CanDisableAnalogDisplay_Request(void) { - uint32_t api_value = 10068; /* from _tee10068 */ + uint32_t api_value = 10069; /* from _tee10069 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2225,7 +2407,7 @@ void OPK_Unpack_CanDisableAnalogDisplay_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10068) + if (api_value != 10069) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2233,7 +2415,7 @@ void OPK_Unpack_CanDisableAnalogDisplay_Response(ODK_Message* msg, } ODK_Message OPK_Pack_DisableAnalogDisplay_Request(void) { - uint32_t api_value = 10069; /* from _tee10069 */ + uint32_t api_value = 10070; /* from _tee10070 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2246,7 +2428,7 @@ ODK_Message OPK_Pack_DisableAnalogDisplay_Request(void) { void OPK_Unpack_DisableAnalogDisplay_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10069) + if (api_value != 10070) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2254,7 +2436,7 @@ void OPK_Unpack_DisableAnalogDisplay_Response(ODK_Message* msg, bool* result) { } ODK_Message OPK_Pack_MaxOutputSizeForDecrypt_Request(void) { - uint32_t api_value = 10070; /* from _tee10070 */ + uint32_t api_value = 10071; /* from _tee10071 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2268,59 +2450,15 @@ void OPK_Unpack_MaxOutputSizeForDecrypt_Response(ODK_Message* msg, size_t* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10070) + if (api_value != 10071) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_size_t(msg, result); OPK_UnpackEOM(msg); OPK_SharedBuffer_FinalizeUnpacking(); } -ODK_Message OPK_Pack_CurrentHDCPCapability_Request(void) { - uint32_t api_value = 10071; /* from _tee10071 */ - ODK_Message msg = TOS_Transport_GetRequest(); - OPK_Pack_uint32_t(&msg, &api_value); - uint64_t timestamp = time(0); - OPK_Pack_uint64_t(&msg, ×tamp); - OPK_PackEOM(&msg); - OPK_SharedBuffer_FinalizePacking(); - return msg; -} - -void OPK_Unpack_CurrentHDCPCapability_Response( - ODK_Message* msg, OEMCrypto_HDCP_Capability* result) { - uint32_t api_value = UINT32_MAX; - OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10071) - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); - OPK_Unpack_OEMCrypto_HDCP_Capability(msg, result); - OPK_UnpackEOM(msg); - OPK_SharedBuffer_FinalizeUnpacking(); -} - -ODK_Message OPK_Pack_MaxHDCPCapability_Request(void) { - uint32_t api_value = 10072; /* from _tee10072 */ - ODK_Message msg = TOS_Transport_GetRequest(); - OPK_Pack_uint32_t(&msg, &api_value); - uint64_t timestamp = time(0); - OPK_Pack_uint64_t(&msg, ×tamp); - OPK_PackEOM(&msg); - OPK_SharedBuffer_FinalizePacking(); - return msg; -} - -void OPK_Unpack_MaxHDCPCapability_Response(ODK_Message* msg, - OEMCrypto_HDCP_Capability* result) { - uint32_t api_value = UINT32_MAX; - OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10072) - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); - OPK_Unpack_OEMCrypto_HDCP_Capability(msg, result); - OPK_UnpackEOM(msg); - OPK_SharedBuffer_FinalizeUnpacking(); -} - ODK_Message OPK_Pack_MaxBufferSizeForGenericCrypto_Request(void) { - uint32_t api_value = 10073; /* from _tee10073 */ + uint32_t api_value = 10072; /* from _tee10072 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2334,7 +2472,7 @@ void OPK_Unpack_MaxBufferSizeForGenericCrypto_Response(ODK_Message* msg, size_t* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10073) + if (api_value != 10072) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_size_t(msg, result); OPK_UnpackEOM(msg); @@ -2342,7 +2480,7 @@ void OPK_Unpack_MaxBufferSizeForGenericCrypto_Response(ODK_Message* msg, } ODK_Message OPK_Pack_MaxSampleSize_Request(void) { - uint32_t api_value = 10074; /* from _tee10074 */ + uint32_t api_value = 10073; /* from _tee10073 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2355,7 +2493,7 @@ ODK_Message OPK_Pack_MaxSampleSize_Request(void) { void OPK_Unpack_MaxSampleSize_Response(ODK_Message* msg, size_t* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10074) + if (api_value != 10073) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_size_t(msg, result); OPK_UnpackEOM(msg); @@ -2363,7 +2501,7 @@ void OPK_Unpack_MaxSampleSize_Response(ODK_Message* msg, size_t* result) { } ODK_Message OPK_Pack_SupportedCertificates_Request(void) { - uint32_t api_value = 10075; /* from _tee10075 */ + uint32_t api_value = 10074; /* from _tee10074 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2377,7 +2515,7 @@ void OPK_Unpack_SupportedCertificates_Response(ODK_Message* msg, uint32_t* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10075) + if (api_value != 10074) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); OPK_UnpackEOM(msg); @@ -2385,7 +2523,7 @@ void OPK_Unpack_SupportedCertificates_Response(ODK_Message* msg, } ODK_Message OPK_Pack_ContentDecryptBypassesTA_Request(void) { - uint32_t api_value = 10076; /* from _tee10076 */ + uint32_t api_value = 10075; /* from _tee10075 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2399,7 +2537,7 @@ void OPK_Unpack_ContentDecryptBypassesTA_Response(ODK_Message* msg, bool* result) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10076) + if (api_value != 10075) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_bool(msg, result); OPK_UnpackEOM(msg); @@ -2408,7 +2546,7 @@ void OPK_Unpack_ContentDecryptBypassesTA_Response(ODK_Message* msg, ODK_Message OPK_Pack_GetEncryptAndSignSize_Request( uint32_t context, size_t in_length, const size_t* wrapped_length) { - uint32_t api_value = 10077; /* from _tee10077 */ + uint32_t api_value = 10076; /* from _tee10076 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2426,13 +2564,17 @@ void OPK_Unpack_GetEncryptAndSignSize_Response(ODK_Message* msg, size_t** wrapped_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10077) + if (api_value != 10076) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_size_t(msg, wrapped_length); + if (SuccessResult(*result)) { + OPK_UnpackNullable_size_t(msg, wrapped_length); + } else { + OPK_UnpackNullable_size_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -2445,7 +2587,7 @@ ODK_Message OPK_Pack_EncryptAndSign_Request(uint32_t context, size_t data_length, const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10078; /* from _tee10078 */ + uint32_t api_value = 10077; /* from _tee10077 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2465,7 +2607,7 @@ void OPK_Unpack_EncryptAndSign_Response(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10078) + if (api_value != 10077) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, out_length); OPK_Unpack_uint32_t(msg, result); @@ -2491,7 +2633,7 @@ ODK_Message OPK_Pack_VerifyAndDecrypt_Request(uint32_t context, size_t wrapped_length, const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10079; /* from _tee10079 */ + uint32_t api_value = 10078; /* from _tee10078 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2512,7 +2654,7 @@ void OPK_Unpack_VerifyAndDecrypt_Response(ODK_Message* msg, uint8_t** out, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10079) + if (api_value != 10078) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_UnpackNullable_size_t(msg, out_length); OPK_Unpack_uint32_t(msg, result); @@ -2536,7 +2678,7 @@ void OPK_Unpack_VerifyAndDecrypt_Response(ODK_Message* msg, ODK_Message OPK_Pack_VerifyAndDecryptUsageData_Legacy_Request( const uint8_t* wrapped, size_t wrapped_length, const uint8_t* signature, const uint8_t* iv, const uint8_t* out) { - uint32_t api_value = 10080; /* from _tee10080 */ + uint32_t api_value = 10079; /* from _tee10079 */ ODK_Message msg = TOS_Transport_GetRequest(); OPK_Pack_uint32_t(&msg, &api_value); uint64_t timestamp = time(0); @@ -2556,13 +2698,17 @@ void OPK_Unpack_VerifyAndDecryptUsageData_Legacy_Response( ODK_Message* msg, OEMCryptoResult* result, uint8_t** out) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10080) + if (api_value != 10079) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); OPK_Unpack_uint32_t(msg, result); if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint8_t(msg, out); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint8_t(msg, out); + } else { + OPK_UnpackNullable_uint8_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.h b/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.h index bf03d1a..b0606f4 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/ree/GEN_ree_serializer.h @@ -139,8 +139,8 @@ void OPK_Unpack_CreateAsymmetricKeyHandle_Response( ODK_Message* msg, OEMCryptoResult* result, WTPI_AsymmetricKey_Handle** key_handle); ODK_Message OPK_Pack_UnwrapIntoAsymmetricKeyHandle_Request( - const uint8_t* input, size_t input_length, AsymmetricKeyType key_type, - const WTPI_AsymmetricKey_Handle* key_handle, + uint32_t context, const uint8_t* input, size_t input_length, + AsymmetricKeyType key_type, const WTPI_AsymmetricKey_Handle* key_handle, const uint32_t* allowed_schemes); void OPK_Unpack_UnwrapIntoAsymmetricKeyHandle_Response( ODK_Message* msg, OEMCryptoResult* result, @@ -155,7 +155,8 @@ ODK_Message OPK_Pack_GetWrappedAsymmetricKeySize_Request( void OPK_Unpack_GetWrappedAsymmetricKeySize_Response(ODK_Message* msg, OEMCryptoResult* result, size_t** buffer_size); -ODK_Message OPK_Pack_WrapAsymmetricKey_Request(const uint8_t* output, +ODK_Message OPK_Pack_WrapAsymmetricKey_Request(uint32_t context, + const uint8_t* output, size_t output_length, AsymmetricKeyType key_type, const uint8_t* clear_key, @@ -206,6 +207,15 @@ ODK_Message OPK_Pack_GetSignatureHashAlgorithm_Request( void OPK_Unpack_GetSignatureHashAlgorithm_Response( ODK_Message* msg, OEMCryptoResult* result, OEMCrypto_SignatureHashAlgorithm** hash_algorithm); +ODK_Message OPK_Pack_DeriveNewAsymmetricKeyHandle_Request( + const uint8_t* deriving_key, size_t deriving_key_length, + const uint8_t* context, size_t context_length, AsymmetricKeyType key_type, + const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length); +void OPK_Unpack_DeriveNewAsymmetricKeyHandle_Response( + ODK_Message* msg, OEMCryptoResult* result, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length); ODK_Message OPK_Pack_GetBootCertificateChain_Request(const uint8_t* out, const size_t* out_length); void OPK_Unpack_GetBootCertificateChain_Response(ODK_Message* msg, @@ -218,7 +228,8 @@ void OPK_Unpack_GetMaxBootCertificateChainSize_Response(ODK_Message* msg, OEMCryptoResult* result, size_t** out_length); ODK_Message OPK_Pack_GenerateRandomCertificateKeyPair_Request( - const AsymmetricKeyType* key_type, const uint8_t* wrapped_private_key, + CertSignatureType cert_type, const AsymmetricKeyType* key_type, + const uint8_t* wrapped_private_key, const size_t* wrapped_private_key_length, const uint8_t* public_key, const size_t* public_key_length); void OPK_Unpack_GenerateRandomCertificateKeyPair_Response( @@ -276,6 +287,14 @@ void OPK_Unpack_LoadBCCSignature_Response(ODK_Message* msg, OEMCryptoResult* result, uint8_t** signature, size_t** signature_length); +ODK_Message OPK_Pack_CreateUDSDerivedAsymmetricKeyHandle_Request( + const AsymmetricKeyType* key_type, + const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length); +void OPK_Unpack_CreateUDSDerivedAsymmetricKeyHandle_Response( + ODK_Message* msg, OEMCryptoResult* result, AsymmetricKeyType** key_type, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length); ODK_Message OPK_Pack_Crc32Init_Request(const uint32_t* initial_hash); void OPK_Unpack_Crc32Init_Response(ODK_Message* msg, OEMCryptoResult* result, uint32_t** initial_hash); @@ -325,10 +344,6 @@ void OPK_Unpack_IsProductionReady_Response(ODK_Message* msg, bool* result); ODK_Message OPK_Pack_GetWatermarkingSupport_Request(void); void OPK_Unpack_GetWatermarkingSupport_Response( ODK_Message* msg, OEMCrypto_WatermarkingSupport* result); -ODK_Message OPK_Pack_GetCurrentSRMVersion_Request(const uint32_t* srm_version); -void OPK_Unpack_GetCurrentSRMVersion_Response(ODK_Message* msg, - OEMCryptoResult* result, - uint32_t** srm_version); ODK_Message OPK_Pack_IsAntiRollbackHWPresent_Request(void); void OPK_Unpack_IsAntiRollbackHWPresent_Response(ODK_Message* msg, bool* result); @@ -348,12 +363,6 @@ void OPK_Unpack_DisableAnalogDisplay_Response(ODK_Message* msg, bool* result); ODK_Message OPK_Pack_MaxOutputSizeForDecrypt_Request(void); void OPK_Unpack_MaxOutputSizeForDecrypt_Response(ODK_Message* msg, size_t* result); -ODK_Message OPK_Pack_CurrentHDCPCapability_Request(void); -void OPK_Unpack_CurrentHDCPCapability_Response( - ODK_Message* msg, OEMCrypto_HDCP_Capability* result); -ODK_Message OPK_Pack_MaxHDCPCapability_Request(void); -void OPK_Unpack_MaxHDCPCapability_Response(ODK_Message* msg, - OEMCrypto_HDCP_Capability* result); ODK_Message OPK_Pack_MaxBufferSizeForGenericCrypto_Request(void); void OPK_Unpack_MaxBufferSizeForGenericCrypto_Response(ODK_Message* msg, size_t* result); diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_dispatcher.c b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_dispatcher.c index 10688b0..f51f566 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_dispatcher.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_dispatcher.c @@ -615,6 +615,8 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, { size_t input_length; OPK_Init_size_t((size_t*)&input_length); + uint32_t context; + OPK_Init_uint32_t((uint32_t*)&context); uint8_t* input; OPK_InitPointer((uint8_t**)&input); AsymmetricKeyType key_type; @@ -624,14 +626,14 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, uint32_t* allowed_schemes; OPK_InitPointer((uint8_t**)&allowed_schemes); OPK_Unpack_UnwrapIntoAsymmetricKeyHandle_Request( - request, &input, &input_length, &key_type, &key_handle, + request, &context, &input, &input_length, &key_type, &key_handle, &allowed_schemes); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; OEMCryptoResult result; OPK_Init_uint32_t((uint32_t*)&result); LOGD("UnwrapIntoAsymmetricKeyHandle"); - result = WTPI_UnwrapIntoAsymmetricKeyHandle(input, input_length, key_type, - key_handle, allowed_schemes); + result = WTPI_UnwrapIntoAsymmetricKeyHandle( + context, input, input_length, key_type, key_handle, allowed_schemes); *response = OPK_Pack_UnwrapIntoAsymmetricKeyHandle_Response( result, key_handle, allowed_schemes); break; @@ -676,20 +678,22 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Init_size_t((size_t*)&output_length); size_t clear_key_length; OPK_Init_size_t((size_t*)&clear_key_length); + uint32_t context; + OPK_Init_uint32_t((uint32_t*)&context); uint8_t* output; OPK_InitPointer((uint8_t**)&output); AsymmetricKeyType key_type; OPK_Init_AsymmetricKeyType((AsymmetricKeyType*)&key_type); uint8_t* clear_key; OPK_InitPointer((uint8_t**)&clear_key); - OPK_Unpack_WrapAsymmetricKey_Request(request, &output, &output_length, - &key_type, &clear_key, - &clear_key_length); + OPK_Unpack_WrapAsymmetricKey_Request(request, &context, &output, + &output_length, &key_type, + &clear_key, &clear_key_length); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; OEMCryptoResult result; OPK_Init_uint32_t((uint32_t*)&result); LOGD("WrapAsymmetricKey"); - result = WTPI_WrapAsymmetricKey(output, output_length, key_type, + result = WTPI_WrapAsymmetricKey(context, output, output_length, key_type, clear_key, clear_key_length); *response = OPK_Pack_WrapAsymmetricKey_Response(result, output, output_length); @@ -827,7 +831,40 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Pack_GetSignatureHashAlgorithm_Response(result, hash_algorithm); break; } - case 10035: /* WTPI_GetBootCertificateChain */ + case 10035: /* WTPI_DeriveNewAsymmetricKeyHandle */ + { + size_t deriving_key_length; + OPK_Init_size_t((size_t*)&deriving_key_length); + size_t context_length; + OPK_Init_size_t((size_t*)&context_length); + size_t* public_key_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); + OPK_Init_size_t(public_key_length); + uint8_t* deriving_key; + OPK_InitPointer((uint8_t**)&deriving_key); + uint8_t* context; + OPK_InitPointer((uint8_t**)&context); + AsymmetricKeyType key_type; + OPK_Init_AsymmetricKeyType((AsymmetricKeyType*)&key_type); + WTPI_AsymmetricKey_Handle* private_key_handle; + OPK_InitPointer((uint8_t**)&private_key_handle); + uint8_t* public_key; + OPK_InitPointer((uint8_t**)&public_key); + OPK_Unpack_DeriveNewAsymmetricKeyHandle_Request( + request, &deriving_key, &deriving_key_length, &context, + &context_length, &key_type, &private_key_handle, &public_key, + &public_key_length); + if (!ODK_Message_IsValid(request)) goto handle_invalid_request; + OEMCryptoResult result; + OPK_Init_uint32_t((uint32_t*)&result); + LOGD("DeriveNewAsymmetricKeyHandle"); + result = WTPI_DeriveNewAsymmetricKeyHandle( + deriving_key, deriving_key_length, context, context_length, key_type, + private_key_handle, public_key, public_key_length); + *response = OPK_Pack_DeriveNewAsymmetricKeyHandle_Response( + result, private_key_handle, public_key, public_key_length); + break; + } + case 10036: /* WTPI_GetBootCertificateChain */ { size_t* out_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); OPK_Init_size_t(out_length); @@ -843,7 +880,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Pack_GetBootCertificateChain_Response(result, out, out_length); break; } - case 10036: /* WTPI_GetMaxBootCertificateChainSize */ + case 10037: /* WTPI_GetMaxBootCertificateChainSize */ { size_t* out_length; OPK_InitPointer((uint8_t**)&out_length); @@ -857,13 +894,15 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Pack_GetMaxBootCertificateChainSize_Response(result, out_length); break; } - case 10037: /* WTPI_GenerateRandomCertificateKeyPair */ + case 10038: /* WTPI_GenerateRandomCertificateKeyPair */ { size_t* wrapped_private_key_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); OPK_Init_size_t(wrapped_private_key_length); size_t* public_key_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); OPK_Init_size_t(public_key_length); + CertSignatureType cert_type; + OPK_Init_CertSignatureType((CertSignatureType*)&cert_type); AsymmetricKeyType* key_type; OPK_InitPointer((uint8_t**)&key_type); uint8_t* wrapped_private_key; @@ -871,21 +910,21 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, uint8_t* public_key; OPK_InitPointer((uint8_t**)&public_key); OPK_Unpack_GenerateRandomCertificateKeyPair_Request( - request, &key_type, &wrapped_private_key, &wrapped_private_key_length, - &public_key, &public_key_length); + request, &cert_type, &key_type, &wrapped_private_key, + &wrapped_private_key_length, &public_key, &public_key_length); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; OEMCryptoResult result; OPK_Init_uint32_t((uint32_t*)&result); LOGD("GenerateRandomCertificateKeyPair"); result = WTPI_GenerateRandomCertificateKeyPair( - key_type, wrapped_private_key, wrapped_private_key_length, public_key, - public_key_length); + cert_type, key_type, wrapped_private_key, wrapped_private_key_length, + public_key, public_key_length); *response = OPK_Pack_GenerateRandomCertificateKeyPair_Response( result, key_type, wrapped_private_key, wrapped_private_key_length, public_key, public_key_length); break; } - case 10038: /* WTPI_GetSignedCsrPayload */ + case 10039: /* WTPI_GetSignedCsrPayload */ { size_t challenge_length; OPK_Init_size_t((size_t*)&challenge_length); @@ -915,7 +954,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, result, signed_csr_payload, signed_csr_payload_length); break; } - case 10039: /* WTPI_MaxDeviceInfoSize */ + case 10040: /* WTPI_MaxDeviceInfoSize */ { OPK_Unpack_MaxDeviceInfoSize_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -926,7 +965,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_MaxDeviceInfoSize_Response(result); break; } - case 10040: /* WTPI_GetDeviceInformation */ + case 10041: /* WTPI_GetDeviceInformation */ { size_t* out_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); OPK_Init_size_t(out_length); @@ -942,7 +981,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Pack_GetDeviceInformation_Response(result, out, out_length); break; } - case 10041: /* WTPI_BccKeyCoseSign1 */ + case 10042: /* WTPI_BccKeyCoseSign1 */ { size_t message_length; OPK_Init_size_t((size_t*)&message_length); @@ -964,7 +1003,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, signature_length); break; } - case 10042: /* WTPI_GetMaxBccKeyCoseSign1Size */ + case 10043: /* WTPI_GetMaxBccKeyCoseSign1Size */ { size_t* out_length; OPK_InitPointer((uint8_t**)&out_length); @@ -978,7 +1017,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Pack_GetMaxBccKeyCoseSign1Size_Response(result, out_length); break; } - case 10043: /* WTPI_GetDeviceFusedStatus */ + case 10044: /* WTPI_GetDeviceFusedStatus */ { bool* is_fused; OPK_InitPointer((uint8_t**)&is_fused); @@ -991,7 +1030,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetDeviceFusedStatus_Response(result, is_fused); break; } - case 10044: /* WTPI_GetBCCSignatureType */ + case 10045: /* WTPI_GetBCCSignatureType */ { OPK_Unpack_GetBCCSignatureType_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1002,7 +1041,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetBCCSignatureType_Response(result); break; } - case 10045: /* WTPI_GenerateBCCSignature */ + case 10046: /* WTPI_GenerateBCCSignature */ { size_t* out_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); OPK_Init_size_t(out_length); @@ -1018,7 +1057,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Pack_GenerateBCCSignature_Response(result, out, out_length); break; } - case 10046: /* WTPI_StoreBCCSignature */ + case 10047: /* WTPI_StoreBCCSignature */ { size_t signature_length; OPK_Init_size_t((size_t*)&signature_length); @@ -1034,7 +1073,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_StoreBCCSignature_Response(result); break; } - case 10047: /* WTPI_LoadBCCSignature */ + case 10048: /* WTPI_LoadBCCSignature */ { size_t* signature_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); OPK_Init_size_t(signature_length); @@ -1051,7 +1090,30 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, signature_length); break; } - case 10048: /* WTPI_Crc32Init */ + case 10049: /* WTPI_CreateUDSDerivedAsymmetricKeyHandle */ + { + size_t* public_key_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); + OPK_Init_size_t(public_key_length); + AsymmetricKeyType* key_type; + OPK_InitPointer((uint8_t**)&key_type); + WTPI_AsymmetricKey_Handle* private_key_handle; + OPK_InitPointer((uint8_t**)&private_key_handle); + uint8_t* public_key; + OPK_InitPointer((uint8_t**)&public_key); + OPK_Unpack_CreateUDSDerivedAsymmetricKeyHandle_Request( + request, &key_type, &private_key_handle, &public_key, + &public_key_length); + if (!ODK_Message_IsValid(request)) goto handle_invalid_request; + OEMCryptoResult result; + OPK_Init_uint32_t((uint32_t*)&result); + LOGD("CreateUDSDerivedAsymmetricKeyHandle"); + result = WTPI_CreateUDSDerivedAsymmetricKeyHandle( + key_type, private_key_handle, public_key, public_key_length); + *response = OPK_Pack_CreateUDSDerivedAsymmetricKeyHandle_Response( + result, key_type, private_key_handle, public_key, public_key_length); + break; + } + case 10050: /* WTPI_Crc32Init */ { uint32_t* initial_hash; OPK_InitPointer((uint8_t**)&initial_hash); @@ -1064,7 +1126,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_Crc32Init_Response(result, initial_hash); break; } - case 10049: /* WTPI_Crc32Cont */ + case 10051: /* WTPI_Crc32Cont */ { size_t in_length; OPK_Init_size_t((size_t*)&in_length); @@ -1084,7 +1146,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_Crc32Cont_Response(result, new_crc); break; } - case 10050: /* WTPI_Crc32Cont_OutputBuffer */ + case 10052: /* WTPI_Crc32Cont_OutputBuffer */ { size_t in_length; OPK_Init_size_t((size_t*)&in_length); @@ -1107,7 +1169,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_Crc32Cont_OutputBuffer_Response(result, new_crc); break; } - case 10051: /* WTPI_GetTrustedTime */ + case 10053: /* WTPI_GetTrustedTime */ { uint64_t* time_in_s; OPK_InitPointer((uint8_t**)&time_in_s); @@ -1120,7 +1182,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetTrustedTime_Response(result, time_in_s); break; } - case 10052: /* WTPI_InitializeClock */ + case 10054: /* WTPI_InitializeClock */ { OPK_Unpack_InitializeClock_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1131,7 +1193,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_InitializeClock_Response(result); break; } - case 10053: /* WTPI_TerminateClock */ + case 10055: /* WTPI_TerminateClock */ { OPK_Unpack_TerminateClock_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1142,7 +1204,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_TerminateClock_Response(result); break; } - case 10054: /* WTPI_GetClockType */ + case 10056: /* WTPI_GetClockType */ { OPK_Unpack_GetClockType_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1154,7 +1216,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetClockType_Response(result); break; } - case 10055: /* WTPI_GetSecurityLevel */ + case 10057: /* WTPI_GetSecurityLevel */ { OPK_Unpack_GetSecurityLevel_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1165,7 +1227,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetSecurityLevel_Response(result); break; } - case 10056: /* WTPI_GetProvisioningMethod */ + case 10058: /* WTPI_GetProvisioningMethod */ { OPK_Unpack_GetProvisioningMethod_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1177,7 +1239,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetProvisioningMethod_Response(result); break; } - case 10057: /* WTPI_GetBCCType */ + case 10059: /* WTPI_GetBCCType */ { OEMCrypto_BCCType* bcc_type; OPK_InitPointer((uint8_t**)&bcc_type); @@ -1190,7 +1252,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetBCCType_Response(result, bcc_type); break; } - case 10058: /* WTPI_GetResourceRatingTier */ + case 10060: /* WTPI_GetResourceRatingTier */ { OPK_Unpack_GetResourceRatingTier_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1201,7 +1263,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetResourceRatingTier_Response(result); break; } - case 10059: /* WTPI_IsTAAntiRollbackEnabled */ + case 10061: /* WTPI_IsTAAntiRollbackEnabled */ { OPK_Unpack_IsTAAntiRollbackEnabled_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1212,7 +1274,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_IsTAAntiRollbackEnabled_Response(result); break; } - case 10060: /* WTPI_IsProductionReady */ + case 10062: /* WTPI_IsProductionReady */ { OPK_Unpack_IsProductionReady_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1223,7 +1285,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_IsProductionReady_Response(result); break; } - case 10061: /* WTPI_GetWatermarkingSupport */ + case 10063: /* WTPI_GetWatermarkingSupport */ { OPK_Unpack_GetWatermarkingSupport_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1235,20 +1297,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_GetWatermarkingSupport_Response(result); break; } - case 10062: /* WTPI_GetCurrentSRMVersion */ - { - uint32_t* srm_version; - OPK_InitPointer((uint8_t**)&srm_version); - OPK_Unpack_GetCurrentSRMVersion_Request(request, &srm_version); - if (!ODK_Message_IsValid(request)) goto handle_invalid_request; - OEMCryptoResult result; - OPK_Init_uint32_t((uint32_t*)&result); - LOGD("GetCurrentSRMVersion"); - result = WTPI_GetCurrentSRMVersion(srm_version); - *response = OPK_Pack_GetCurrentSRMVersion_Response(result, srm_version); - break; - } - case 10063: /* WTPI_IsAntiRollbackHWPresent */ + case 10064: /* WTPI_IsAntiRollbackHWPresent */ { OPK_Unpack_IsAntiRollbackHWPresent_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1259,7 +1308,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_IsAntiRollbackHWPresent_Response(result); break; } - case 10064: /* WTPI_IsCGMS_AActive */ + case 10065: /* WTPI_IsCGMS_AActive */ { OPK_Unpack_IsCGMS_AActive_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1270,7 +1319,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_IsCGMS_AActive_Response(result); break; } - case 10065: /* WTPI_SupportsCGMS_A */ + case 10066: /* WTPI_SupportsCGMS_A */ { OPK_Unpack_SupportsCGMS_A_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1281,7 +1330,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_SupportsCGMS_A_Response(result); break; } - case 10066: /* WTPI_HasAnalogDisplay */ + case 10067: /* WTPI_HasAnalogDisplay */ { OPK_Unpack_HasAnalogDisplay_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1292,7 +1341,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_HasAnalogDisplay_Response(result); break; } - case 10067: /* WTPI_IsAnalogDisplayActive */ + case 10068: /* WTPI_IsAnalogDisplayActive */ { OPK_Unpack_IsAnalogDisplayActive_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1303,7 +1352,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_IsAnalogDisplayActive_Response(result); break; } - case 10068: /* WTPI_CanDisableAnalogDisplay */ + case 10069: /* WTPI_CanDisableAnalogDisplay */ { OPK_Unpack_CanDisableAnalogDisplay_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1314,7 +1363,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_CanDisableAnalogDisplay_Response(result); break; } - case 10069: /* WTPI_DisableAnalogDisplay */ + case 10070: /* WTPI_DisableAnalogDisplay */ { OPK_Unpack_DisableAnalogDisplay_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1325,7 +1374,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_DisableAnalogDisplay_Response(result); break; } - case 10070: /* WTPI_MaxOutputSizeForDecrypt */ + case 10071: /* WTPI_MaxOutputSizeForDecrypt */ { OPK_Unpack_MaxOutputSizeForDecrypt_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1336,29 +1385,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_MaxOutputSizeForDecrypt_Response(result); break; } - case 10071: /* WTPI_CurrentHDCPCapability */ - { - OPK_Unpack_CurrentHDCPCapability_Request(request); - if (!ODK_Message_IsValid(request)) goto handle_invalid_request; - OEMCrypto_HDCP_Capability result; - OPK_Init_OEMCrypto_HDCP_Capability((OEMCrypto_HDCP_Capability*)&result); - LOGD("CurrentHDCPCapability"); - result = WTPI_CurrentHDCPCapability(); - *response = OPK_Pack_CurrentHDCPCapability_Response(result); - break; - } - case 10072: /* WTPI_MaxHDCPCapability */ - { - OPK_Unpack_MaxHDCPCapability_Request(request); - if (!ODK_Message_IsValid(request)) goto handle_invalid_request; - OEMCrypto_HDCP_Capability result; - OPK_Init_OEMCrypto_HDCP_Capability((OEMCrypto_HDCP_Capability*)&result); - LOGD("MaxHDCPCapability"); - result = WTPI_MaxHDCPCapability(); - *response = OPK_Pack_MaxHDCPCapability_Response(result); - break; - } - case 10073: /* WTPI_MaxBufferSizeForGenericCrypto */ + case 10072: /* WTPI_MaxBufferSizeForGenericCrypto */ { OPK_Unpack_MaxBufferSizeForGenericCrypto_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1369,7 +1396,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_MaxBufferSizeForGenericCrypto_Response(result); break; } - case 10074: /* WTPI_MaxSampleSize */ + case 10073: /* WTPI_MaxSampleSize */ { OPK_Unpack_MaxSampleSize_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1380,7 +1407,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_MaxSampleSize_Response(result); break; } - case 10075: /* WTPI_SupportedCertificates */ + case 10074: /* WTPI_SupportedCertificates */ { OPK_Unpack_SupportedCertificates_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1391,7 +1418,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_SupportedCertificates_Response(result); break; } - case 10076: /* WTPI_ContentDecryptBypassesTA */ + case 10075: /* WTPI_ContentDecryptBypassesTA */ { OPK_Unpack_ContentDecryptBypassesTA_Request(request); if (!ODK_Message_IsValid(request)) goto handle_invalid_request; @@ -1402,7 +1429,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_ContentDecryptBypassesTA_Response(result); break; } - case 10077: /* WTPI_GetEncryptAndSignSize */ + case 10076: /* WTPI_GetEncryptAndSignSize */ { uint32_t context; OPK_Init_uint32_t((uint32_t*)&context); @@ -1421,7 +1448,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, OPK_Pack_GetEncryptAndSignSize_Response(result, wrapped_length); break; } - case 10078: /* WTPI_EncryptAndSign */ + case 10077: /* WTPI_EncryptAndSign */ { size_t data_length; OPK_Init_size_t((size_t*)&data_length); @@ -1443,7 +1470,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_EncryptAndSign_Response(result, out, out_length); break; } - case 10079: /* WTPI_VerifyAndDecrypt */ + case 10078: /* WTPI_VerifyAndDecrypt */ { size_t wrapped_length; OPK_Init_size_t((size_t*)&wrapped_length); @@ -1466,7 +1493,7 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_VerifyAndDecrypt_Response(result, out, out_length); break; } - case 10080: /* WTPI_VerifyAndDecryptUsageData_Legacy */ + case 10079: /* WTPI_VerifyAndDecryptUsageData_Legacy */ { size_t wrapped_length; OPK_Init_size_t((size_t*)&wrapped_length); diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.c b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.c index 090f634..233e677 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.c @@ -647,7 +647,7 @@ ODK_Message OPK_Pack_CreateAsymmetricKeyHandle_Response( } void OPK_Unpack_UnwrapIntoAsymmetricKeyHandle_Request( - ODK_Message* msg, uint8_t** input, size_t* input_length, + ODK_Message* msg, uint32_t* context, uint8_t** input, size_t* input_length, AsymmetricKeyType* key_type, WTPI_AsymmetricKey_Handle** key_handle, uint32_t** allowed_schemes) { uint32_t api_value = UINT32_MAX; @@ -657,6 +657,7 @@ void OPK_Unpack_UnwrapIntoAsymmetricKeyHandle_Request( uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); OPK_Unpack_size_t(msg, input_length); + OPK_Unpack_uint32_t(msg, context); OPK_UnpackInPlace(msg, (uint8_t**)input, OPK_FromSizeTPtr(input_length)); OPK_Unpack_AsymmetricKeyType(msg, key_type); *key_handle = (WTPI_AsymmetricKey_Handle*)OPK_UnpackAlloc( @@ -731,7 +732,8 @@ ODK_Message OPK_Pack_GetWrappedAsymmetricKeySize_Response( return msg; } -void OPK_Unpack_WrapAsymmetricKey_Request(ODK_Message* msg, uint8_t** output, +void OPK_Unpack_WrapAsymmetricKey_Request(ODK_Message* msg, uint32_t* context, + uint8_t** output, size_t* output_length, AsymmetricKeyType* key_type, uint8_t** clear_key, @@ -744,6 +746,7 @@ void OPK_Unpack_WrapAsymmetricKey_Request(ODK_Message* msg, uint8_t** output, OPK_Unpack_uint64_t(msg, ×tamp); OPK_Unpack_size_t(msg, output_length); OPK_Unpack_size_t(msg, clear_key_length); + OPK_Unpack_uint32_t(msg, context); *output = (uint8_t*)OPK_UnpackAllocBuffer( msg, OPK_FromSizeTPtr(output_length), sizeof(uint8_t)); OPK_Unpack_AsymmetricKeyType(msg, key_type); @@ -981,11 +984,55 @@ ODK_Message OPK_Pack_GetSignatureHashAlgorithm_Response( return msg; } +void OPK_Unpack_DeriveNewAsymmetricKeyHandle_Request( + ODK_Message* msg, uint8_t** deriving_key, size_t* deriving_key_length, + uint8_t** context, size_t* context_length, AsymmetricKeyType* key_type, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length) { + uint32_t api_value = UINT32_MAX; + OPK_Unpack_uint32_t(msg, &api_value); + if (api_value != 10035) + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); + uint64_t timestamp; + OPK_Unpack_uint64_t(msg, ×tamp); + OPK_Unpack_size_t(msg, deriving_key_length); + OPK_Unpack_size_t(msg, context_length); + OPK_UnpackNullable_size_t(msg, public_key_length); + OPK_UnpackInPlace(msg, (uint8_t**)deriving_key, + OPK_FromSizeTPtr(deriving_key_length)); + OPK_UnpackInPlace(msg, (uint8_t**)context, OPK_FromSizeTPtr(context_length)); + OPK_Unpack_AsymmetricKeyType(msg, key_type); + *private_key_handle = (WTPI_AsymmetricKey_Handle*)OPK_UnpackAlloc( + msg, sizeof(WTPI_AsymmetricKey_Handle)); + *public_key = (uint8_t*)OPK_UnpackAllocBuffer( + msg, OPK_FromSizeTPtrPtr(public_key_length), sizeof(uint8_t)); + OPK_UnpackEOM(msg); + OPK_SharedBuffer_FinalizeUnpacking(); +} + +ODK_Message OPK_Pack_DeriveNewAsymmetricKeyHandle_Response( + OEMCryptoResult result, const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length) { + uint32_t api_value = 10035; /* from _tee10035 */ + ODK_Message msg = TOS_Transport_GetResponse(); + OPK_Pack_uint32_t(&msg, &api_value); + OPK_PackNullable_size_t(&msg, public_key_length); + OPK_Pack_uint32_t(&msg, &result); + OPK_PackNullable_WTPI_AsymmetricKey_Handle(&msg, private_key_handle); + if (SuccessResult(result)) { + OPK_PackMemory(&msg, (const uint8_t*)public_key, + OPK_FromSizeTPtr(public_key_length)); + } + OPK_PackEOM(&msg); + OPK_SharedBuffer_FinalizePacking(); + return msg; +} + void OPK_Unpack_GetBootCertificateChain_Request(ODK_Message* msg, uint8_t** out, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10035) + if (api_value != 10036) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -998,7 +1045,7 @@ void OPK_Unpack_GetBootCertificateChain_Request(ODK_Message* msg, uint8_t** out, ODK_Message OPK_Pack_GetBootCertificateChain_Response( OEMCryptoResult result, const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10035; /* from _tee10035 */ + uint32_t api_value = 10036; /* from _tee10036 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, out_length); @@ -1015,7 +1062,7 @@ void OPK_Unpack_GetMaxBootCertificateChainSize_Request(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10036) + if (api_value != 10037) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1026,7 +1073,7 @@ void OPK_Unpack_GetMaxBootCertificateChainSize_Request(ODK_Message* msg, ODK_Message OPK_Pack_GetMaxBootCertificateChainSize_Response( OEMCryptoResult result, const size_t* out_length) { - uint32_t api_value = 10036; /* from _tee10036 */ + uint32_t api_value = 10037; /* from _tee10037 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1037,17 +1084,19 @@ ODK_Message OPK_Pack_GetMaxBootCertificateChainSize_Response( } void OPK_Unpack_GenerateRandomCertificateKeyPair_Request( - ODK_Message* msg, AsymmetricKeyType** key_type, - uint8_t** wrapped_private_key, size_t** wrapped_private_key_length, - uint8_t** public_key, size_t** public_key_length) { + ODK_Message* msg, CertSignatureType* cert_type, + AsymmetricKeyType** key_type, uint8_t** wrapped_private_key, + size_t** wrapped_private_key_length, uint8_t** public_key, + size_t** public_key_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10037) + if (api_value != 10038) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); OPK_UnpackNullable_size_t(msg, wrapped_private_key_length); OPK_UnpackNullable_size_t(msg, public_key_length); + OPK_Unpack_CertSignatureType(msg, cert_type); *key_type = (AsymmetricKeyType*)OPK_UnpackAlloc(msg, sizeof(AsymmetricKeyType)); *wrapped_private_key = (uint8_t*)OPK_UnpackAllocBuffer( @@ -1063,7 +1112,7 @@ ODK_Message OPK_Pack_GenerateRandomCertificateKeyPair_Response( const uint8_t* wrapped_private_key, const size_t* wrapped_private_key_length, const uint8_t* public_key, const size_t* public_key_length) { - uint32_t api_value = 10037; /* from _tee10037 */ + uint32_t api_value = 10038; /* from _tee10038 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, wrapped_private_key_length); @@ -1089,7 +1138,7 @@ void OPK_Unpack_GetSignedCsrPayload_Request( uint8_t** signed_csr_payload, size_t** signed_csr_payload_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10038) + if (api_value != 10039) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1109,7 +1158,7 @@ void OPK_Unpack_GetSignedCsrPayload_Request( ODK_Message OPK_Pack_GetSignedCsrPayload_Response( OEMCryptoResult result, const uint8_t* signed_csr_payload, const size_t* signed_csr_payload_length) { - uint32_t api_value = 10038; /* from _tee10038 */ + uint32_t api_value = 10039; /* from _tee10039 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, signed_csr_payload_length); @@ -1126,7 +1175,7 @@ ODK_Message OPK_Pack_GetSignedCsrPayload_Response( void OPK_Unpack_MaxDeviceInfoSize_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10039) + if (api_value != 10040) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1135,7 +1184,7 @@ void OPK_Unpack_MaxDeviceInfoSize_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_MaxDeviceInfoSize_Response(size_t result) { - uint32_t api_value = 10039; /* from _tee10039 */ + uint32_t api_value = 10040; /* from _tee10040 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_size_t(&msg, &result); @@ -1148,7 +1197,7 @@ void OPK_Unpack_GetDeviceInformation_Request(ODK_Message* msg, uint8_t** out, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10040) + if (api_value != 10041) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1162,7 +1211,7 @@ void OPK_Unpack_GetDeviceInformation_Request(ODK_Message* msg, uint8_t** out, ODK_Message OPK_Pack_GetDeviceInformation_Response(OEMCryptoResult result, const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10040; /* from _tee10040 */ + uint32_t api_value = 10041; /* from _tee10041 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, out_length); @@ -1181,7 +1230,7 @@ void OPK_Unpack_BccKeyCoseSign1_Request(ODK_Message* msg, uint8_t** message, size_t** signature_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10041) + if (api_value != 10042) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1197,7 +1246,7 @@ void OPK_Unpack_BccKeyCoseSign1_Request(ODK_Message* msg, uint8_t** message, ODK_Message OPK_Pack_BccKeyCoseSign1_Response(OEMCryptoResult result, const uint8_t* signature, const size_t* signature_length) { - uint32_t api_value = 10041; /* from _tee10041 */ + uint32_t api_value = 10042; /* from _tee10042 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, signature_length); @@ -1215,7 +1264,7 @@ void OPK_Unpack_GetMaxBccKeyCoseSign1Size_Request(ODK_Message* msg, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10042) + if (api_value != 10043) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1226,7 +1275,7 @@ void OPK_Unpack_GetMaxBccKeyCoseSign1Size_Request(ODK_Message* msg, ODK_Message OPK_Pack_GetMaxBccKeyCoseSign1Size_Response( OEMCryptoResult result, const size_t* out_length) { - uint32_t api_value = 10042; /* from _tee10042 */ + uint32_t api_value = 10043; /* from _tee10043 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1240,7 +1289,7 @@ void OPK_Unpack_GetDeviceFusedStatus_Request(ODK_Message* msg, bool** is_fused) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10043) + if (api_value != 10044) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1251,7 +1300,7 @@ void OPK_Unpack_GetDeviceFusedStatus_Request(ODK_Message* msg, ODK_Message OPK_Pack_GetDeviceFusedStatus_Response(OEMCryptoResult result, const bool* is_fused) { - uint32_t api_value = 10043; /* from _tee10043 */ + uint32_t api_value = 10044; /* from _tee10044 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1264,7 +1313,7 @@ ODK_Message OPK_Pack_GetDeviceFusedStatus_Response(OEMCryptoResult result, void OPK_Unpack_GetBCCSignatureType_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10044) + if (api_value != 10045) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1273,7 +1322,7 @@ void OPK_Unpack_GetBCCSignatureType_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_GetBCCSignatureType_Response(OPK_BCCSignatureType result) { - uint32_t api_value = 10044; /* from _tee10044 */ + uint32_t api_value = 10045; /* from _tee10045 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1286,7 +1335,7 @@ void OPK_Unpack_GenerateBCCSignature_Request(ODK_Message* msg, uint8_t** out, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10045) + if (api_value != 10046) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1300,7 +1349,7 @@ void OPK_Unpack_GenerateBCCSignature_Request(ODK_Message* msg, uint8_t** out, ODK_Message OPK_Pack_GenerateBCCSignature_Response(OEMCryptoResult result, const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10045; /* from _tee10045 */ + uint32_t api_value = 10046; /* from _tee10046 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, out_length); @@ -1317,7 +1366,7 @@ void OPK_Unpack_StoreBCCSignature_Request(ODK_Message* msg, uint8_t** signature, size_t* signature_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10046) + if (api_value != 10047) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1329,7 +1378,7 @@ void OPK_Unpack_StoreBCCSignature_Request(ODK_Message* msg, uint8_t** signature, } ODK_Message OPK_Pack_StoreBCCSignature_Response(OEMCryptoResult result) { - uint32_t api_value = 10046; /* from _tee10046 */ + uint32_t api_value = 10047; /* from _tee10047 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1342,7 +1391,7 @@ void OPK_Unpack_LoadBCCSignature_Request(ODK_Message* msg, uint8_t** signature, size_t** signature_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10047) + if (api_value != 10048) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1356,7 +1405,7 @@ void OPK_Unpack_LoadBCCSignature_Request(ODK_Message* msg, uint8_t** signature, ODK_Message OPK_Pack_LoadBCCSignature_Response(OEMCryptoResult result, const uint8_t* signature, const size_t* signature_length) { - uint32_t api_value = 10047; /* from _tee10047 */ + uint32_t api_value = 10048; /* from _tee10048 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, signature_length); @@ -1370,10 +1419,51 @@ ODK_Message OPK_Pack_LoadBCCSignature_Response(OEMCryptoResult result, return msg; } +void OPK_Unpack_CreateUDSDerivedAsymmetricKeyHandle_Request( + ODK_Message* msg, AsymmetricKeyType** key_type, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length) { + uint32_t api_value = UINT32_MAX; + OPK_Unpack_uint32_t(msg, &api_value); + if (api_value != 10049) + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); + uint64_t timestamp; + OPK_Unpack_uint64_t(msg, ×tamp); + OPK_UnpackNullable_size_t(msg, public_key_length); + *key_type = + (AsymmetricKeyType*)OPK_UnpackAlloc(msg, sizeof(AsymmetricKeyType)); + *private_key_handle = (WTPI_AsymmetricKey_Handle*)OPK_UnpackAlloc( + msg, sizeof(WTPI_AsymmetricKey_Handle)); + *public_key = (uint8_t*)OPK_UnpackAllocBuffer( + msg, OPK_FromSizeTPtrPtr(public_key_length), sizeof(uint8_t)); + OPK_UnpackEOM(msg); + OPK_SharedBuffer_FinalizeUnpacking(); +} + +ODK_Message OPK_Pack_CreateUDSDerivedAsymmetricKeyHandle_Response( + OEMCryptoResult result, const AsymmetricKeyType* key_type, + const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length) { + uint32_t api_value = 10049; /* from _tee10049 */ + ODK_Message msg = TOS_Transport_GetResponse(); + OPK_Pack_uint32_t(&msg, &api_value); + OPK_PackNullable_size_t(&msg, public_key_length); + OPK_Pack_uint32_t(&msg, &result); + OPK_PackNullable_AsymmetricKeyType(&msg, key_type); + OPK_PackNullable_WTPI_AsymmetricKey_Handle(&msg, private_key_handle); + if (SuccessResult(result)) { + OPK_PackMemory(&msg, (const uint8_t*)public_key, + OPK_FromSizeTPtr(public_key_length)); + } + OPK_PackEOM(&msg); + OPK_SharedBuffer_FinalizePacking(); + return msg; +} + void OPK_Unpack_Crc32Init_Request(ODK_Message* msg, uint32_t** initial_hash) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10048) + if (api_value != 10050) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1384,7 +1474,7 @@ void OPK_Unpack_Crc32Init_Request(ODK_Message* msg, uint32_t** initial_hash) { ODK_Message OPK_Pack_Crc32Init_Response(OEMCryptoResult result, const uint32_t* initial_hash) { - uint32_t api_value = 10048; /* from _tee10048 */ + uint32_t api_value = 10050; /* from _tee10050 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1399,7 +1489,7 @@ void OPK_Unpack_Crc32Cont_Request(ODK_Message* msg, uint8_t** in, uint32_t** new_crc) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10049) + if (api_value != 10051) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1413,7 +1503,7 @@ void OPK_Unpack_Crc32Cont_Request(ODK_Message* msg, uint8_t** in, ODK_Message OPK_Pack_Crc32Cont_Response(OEMCryptoResult result, const uint32_t* new_crc) { - uint32_t api_value = 10049; /* from _tee10049 */ + uint32_t api_value = 10051; /* from _tee10051 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1428,7 +1518,7 @@ void OPK_Unpack_Crc32Cont_OutputBuffer_Request( size_t* in_length, uint32_t* prev_crc, uint32_t** new_crc) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10050) + if (api_value != 10052) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1469,7 +1559,7 @@ void OPK_Unpack_Crc32Cont_OutputBuffer_Request( ODK_Message OPK_Pack_Crc32Cont_OutputBuffer_Response(OEMCryptoResult result, const uint32_t* new_crc) { - uint32_t api_value = 10050; /* from _tee10050 */ + uint32_t api_value = 10052; /* from _tee10052 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1482,7 +1572,7 @@ ODK_Message OPK_Pack_Crc32Cont_OutputBuffer_Response(OEMCryptoResult result, void OPK_Unpack_GetTrustedTime_Request(ODK_Message* msg, uint64_t** time_in_s) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10051) + if (api_value != 10053) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1493,7 +1583,7 @@ void OPK_Unpack_GetTrustedTime_Request(ODK_Message* msg, uint64_t** time_in_s) { ODK_Message OPK_Pack_GetTrustedTime_Response(OEMCryptoResult result, const uint64_t* time_in_s) { - uint32_t api_value = 10051; /* from _tee10051 */ + uint32_t api_value = 10053; /* from _tee10053 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1506,7 +1596,7 @@ ODK_Message OPK_Pack_GetTrustedTime_Response(OEMCryptoResult result, void OPK_Unpack_InitializeClock_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10052) + if (api_value != 10054) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1515,7 +1605,7 @@ void OPK_Unpack_InitializeClock_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_InitializeClock_Response(OEMCryptoResult result) { - uint32_t api_value = 10052; /* from _tee10052 */ + uint32_t api_value = 10054; /* from _tee10054 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1527,7 +1617,7 @@ ODK_Message OPK_Pack_InitializeClock_Response(OEMCryptoResult result) { void OPK_Unpack_TerminateClock_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10053) + if (api_value != 10055) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1536,7 +1626,7 @@ void OPK_Unpack_TerminateClock_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_TerminateClock_Response(OEMCryptoResult result) { - uint32_t api_value = 10053; /* from _tee10053 */ + uint32_t api_value = 10055; /* from _tee10055 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1548,7 +1638,7 @@ ODK_Message OPK_Pack_TerminateClock_Response(OEMCryptoResult result) { void OPK_Unpack_GetClockType_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10054) + if (api_value != 10056) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1558,7 +1648,7 @@ void OPK_Unpack_GetClockType_Request(ODK_Message* msg) { ODK_Message OPK_Pack_GetClockType_Response( OEMCrypto_Clock_Security_Level result) { - uint32_t api_value = 10054; /* from _tee10054 */ + uint32_t api_value = 10056; /* from _tee10056 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_OEMCrypto_Clock_Security_Level(&msg, &result); @@ -1570,7 +1660,7 @@ ODK_Message OPK_Pack_GetClockType_Response( void OPK_Unpack_GetSecurityLevel_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10055) + if (api_value != 10057) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1580,7 +1670,7 @@ void OPK_Unpack_GetSecurityLevel_Request(ODK_Message* msg) { ODK_Message OPK_Pack_GetSecurityLevel_Response( OEMCrypto_Security_Level result) { - uint32_t api_value = 10055; /* from _tee10055 */ + uint32_t api_value = 10057; /* from _tee10057 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_OEMCrypto_Security_Level(&msg, &result); @@ -1592,7 +1682,7 @@ ODK_Message OPK_Pack_GetSecurityLevel_Response( void OPK_Unpack_GetProvisioningMethod_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10056) + if (api_value != 10058) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1602,7 +1692,7 @@ void OPK_Unpack_GetProvisioningMethod_Request(ODK_Message* msg) { ODK_Message OPK_Pack_GetProvisioningMethod_Response( OEMCrypto_ProvisioningMethod result) { - uint32_t api_value = 10056; /* from _tee10056 */ + uint32_t api_value = 10058; /* from _tee10058 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_OEMCrypto_ProvisioningMethod(&msg, &result); @@ -1615,7 +1705,7 @@ void OPK_Unpack_GetBCCType_Request(ODK_Message* msg, OEMCrypto_BCCType** bcc_type) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10057) + if (api_value != 10059) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1627,7 +1717,7 @@ void OPK_Unpack_GetBCCType_Request(ODK_Message* msg, ODK_Message OPK_Pack_GetBCCType_Response(OEMCryptoResult result, const OEMCrypto_BCCType* bcc_type) { - uint32_t api_value = 10057; /* from _tee10057 */ + uint32_t api_value = 10059; /* from _tee10059 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1640,7 +1730,7 @@ ODK_Message OPK_Pack_GetBCCType_Response(OEMCryptoResult result, void OPK_Unpack_GetResourceRatingTier_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10058) + if (api_value != 10060) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1649,7 +1739,7 @@ void OPK_Unpack_GetResourceRatingTier_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_GetResourceRatingTier_Response(uint32_t result) { - uint32_t api_value = 10058; /* from _tee10058 */ + uint32_t api_value = 10060; /* from _tee10060 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1661,7 +1751,7 @@ ODK_Message OPK_Pack_GetResourceRatingTier_Response(uint32_t result) { void OPK_Unpack_IsTAAntiRollbackEnabled_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10059) + if (api_value != 10061) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1671,7 +1761,7 @@ void OPK_Unpack_IsTAAntiRollbackEnabled_Request(ODK_Message* msg) { ODK_Message OPK_Pack_IsTAAntiRollbackEnabled_Response( OPK_FeatureStatus result) { - uint32_t api_value = 10059; /* from _tee10059 */ + uint32_t api_value = 10061; /* from _tee10061 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -1683,7 +1773,7 @@ ODK_Message OPK_Pack_IsTAAntiRollbackEnabled_Response( void OPK_Unpack_IsProductionReady_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10060) + if (api_value != 10062) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1692,7 +1782,7 @@ void OPK_Unpack_IsProductionReady_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_IsProductionReady_Response(bool result) { - uint32_t api_value = 10060; /* from _tee10060 */ + uint32_t api_value = 10062; /* from _tee10062 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1704,7 +1794,7 @@ ODK_Message OPK_Pack_IsProductionReady_Response(bool result) { void OPK_Unpack_GetWatermarkingSupport_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10061) + if (api_value != 10063) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1714,7 +1804,7 @@ void OPK_Unpack_GetWatermarkingSupport_Request(ODK_Message* msg) { ODK_Message OPK_Pack_GetWatermarkingSupport_Response( OEMCrypto_WatermarkingSupport result) { - uint32_t api_value = 10061; /* from _tee10061 */ + uint32_t api_value = 10063; /* from _tee10063 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_OEMCrypto_WatermarkingSupport(&msg, &result); @@ -1723,35 +1813,10 @@ ODK_Message OPK_Pack_GetWatermarkingSupport_Response( return msg; } -void OPK_Unpack_GetCurrentSRMVersion_Request(ODK_Message* msg, - uint32_t** srm_version) { - uint32_t api_value = UINT32_MAX; - OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10062) - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); - uint64_t timestamp; - OPK_Unpack_uint64_t(msg, ×tamp); - *srm_version = (uint32_t*)OPK_UnpackAlloc(msg, sizeof(uint32_t)); - OPK_UnpackEOM(msg); - OPK_SharedBuffer_FinalizeUnpacking(); -} - -ODK_Message OPK_Pack_GetCurrentSRMVersion_Response( - OEMCryptoResult result, const uint32_t* srm_version) { - uint32_t api_value = 10062; /* from _tee10062 */ - ODK_Message msg = TOS_Transport_GetResponse(); - OPK_Pack_uint32_t(&msg, &api_value); - OPK_Pack_uint32_t(&msg, &result); - OPK_PackNullable_uint32_t(&msg, srm_version); - OPK_PackEOM(&msg); - OPK_SharedBuffer_FinalizePacking(); - return msg; -} - void OPK_Unpack_IsAntiRollbackHWPresent_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10063) + if (api_value != 10064) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1760,7 +1825,7 @@ void OPK_Unpack_IsAntiRollbackHWPresent_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_IsAntiRollbackHWPresent_Response(bool result) { - uint32_t api_value = 10063; /* from _tee10063 */ + uint32_t api_value = 10064; /* from _tee10064 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1772,7 +1837,7 @@ ODK_Message OPK_Pack_IsAntiRollbackHWPresent_Response(bool result) { void OPK_Unpack_IsCGMS_AActive_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10064) + if (api_value != 10065) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1781,7 +1846,7 @@ void OPK_Unpack_IsCGMS_AActive_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_IsCGMS_AActive_Response(bool result) { - uint32_t api_value = 10064; /* from _tee10064 */ + uint32_t api_value = 10065; /* from _tee10065 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1793,7 +1858,7 @@ ODK_Message OPK_Pack_IsCGMS_AActive_Response(bool result) { void OPK_Unpack_SupportsCGMS_A_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10065) + if (api_value != 10066) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1802,7 +1867,7 @@ void OPK_Unpack_SupportsCGMS_A_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_SupportsCGMS_A_Response(bool result) { - uint32_t api_value = 10065; /* from _tee10065 */ + uint32_t api_value = 10066; /* from _tee10066 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1814,7 +1879,7 @@ ODK_Message OPK_Pack_SupportsCGMS_A_Response(bool result) { void OPK_Unpack_HasAnalogDisplay_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10066) + if (api_value != 10067) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1823,7 +1888,7 @@ void OPK_Unpack_HasAnalogDisplay_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_HasAnalogDisplay_Response(bool result) { - uint32_t api_value = 10066; /* from _tee10066 */ + uint32_t api_value = 10067; /* from _tee10067 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1835,7 +1900,7 @@ ODK_Message OPK_Pack_HasAnalogDisplay_Response(bool result) { void OPK_Unpack_IsAnalogDisplayActive_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10067) + if (api_value != 10068) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1844,7 +1909,7 @@ void OPK_Unpack_IsAnalogDisplayActive_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_IsAnalogDisplayActive_Response(bool result) { - uint32_t api_value = 10067; /* from _tee10067 */ + uint32_t api_value = 10068; /* from _tee10068 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1856,7 +1921,7 @@ ODK_Message OPK_Pack_IsAnalogDisplayActive_Response(bool result) { void OPK_Unpack_CanDisableAnalogDisplay_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10068) + if (api_value != 10069) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1865,7 +1930,7 @@ void OPK_Unpack_CanDisableAnalogDisplay_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_CanDisableAnalogDisplay_Response(bool result) { - uint32_t api_value = 10068; /* from _tee10068 */ + uint32_t api_value = 10069; /* from _tee10069 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1877,7 +1942,7 @@ ODK_Message OPK_Pack_CanDisableAnalogDisplay_Response(bool result) { void OPK_Unpack_DisableAnalogDisplay_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10069) + if (api_value != 10070) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1886,7 +1951,7 @@ void OPK_Unpack_DisableAnalogDisplay_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_DisableAnalogDisplay_Response(bool result) { - uint32_t api_value = 10069; /* from _tee10069 */ + uint32_t api_value = 10070; /* from _tee10070 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -1896,27 +1961,6 @@ ODK_Message OPK_Pack_DisableAnalogDisplay_Response(bool result) { } void OPK_Unpack_MaxOutputSizeForDecrypt_Request(ODK_Message* msg) { - uint32_t api_value = UINT32_MAX; - OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10070) - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); - uint64_t timestamp; - OPK_Unpack_uint64_t(msg, ×tamp); - OPK_UnpackEOM(msg); - OPK_SharedBuffer_FinalizeUnpacking(); -} - -ODK_Message OPK_Pack_MaxOutputSizeForDecrypt_Response(size_t result) { - uint32_t api_value = 10070; /* from _tee10070 */ - ODK_Message msg = TOS_Transport_GetResponse(); - OPK_Pack_uint32_t(&msg, &api_value); - OPK_Pack_size_t(&msg, &result); - OPK_PackEOM(&msg); - OPK_SharedBuffer_FinalizePacking(); - return msg; -} - -void OPK_Unpack_CurrentHDCPCapability_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); if (api_value != 10071) @@ -1927,18 +1971,17 @@ void OPK_Unpack_CurrentHDCPCapability_Request(ODK_Message* msg) { OPK_SharedBuffer_FinalizeUnpacking(); } -ODK_Message OPK_Pack_CurrentHDCPCapability_Response( - OEMCrypto_HDCP_Capability result) { +ODK_Message OPK_Pack_MaxOutputSizeForDecrypt_Response(size_t result) { uint32_t api_value = 10071; /* from _tee10071 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); - OPK_Pack_OEMCrypto_HDCP_Capability(&msg, &result); + OPK_Pack_size_t(&msg, &result); OPK_PackEOM(&msg); OPK_SharedBuffer_FinalizePacking(); return msg; } -void OPK_Unpack_MaxHDCPCapability_Request(ODK_Message* msg) { +void OPK_Unpack_MaxBufferSizeForGenericCrypto_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); if (api_value != 10072) @@ -1949,30 +1992,8 @@ void OPK_Unpack_MaxHDCPCapability_Request(ODK_Message* msg) { OPK_SharedBuffer_FinalizeUnpacking(); } -ODK_Message OPK_Pack_MaxHDCPCapability_Response( - OEMCrypto_HDCP_Capability result) { - uint32_t api_value = 10072; /* from _tee10072 */ - ODK_Message msg = TOS_Transport_GetResponse(); - OPK_Pack_uint32_t(&msg, &api_value); - OPK_Pack_OEMCrypto_HDCP_Capability(&msg, &result); - OPK_PackEOM(&msg); - OPK_SharedBuffer_FinalizePacking(); - return msg; -} - -void OPK_Unpack_MaxBufferSizeForGenericCrypto_Request(ODK_Message* msg) { - uint32_t api_value = UINT32_MAX; - OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10073) - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); - uint64_t timestamp; - OPK_Unpack_uint64_t(msg, ×tamp); - OPK_UnpackEOM(msg); - OPK_SharedBuffer_FinalizeUnpacking(); -} - ODK_Message OPK_Pack_MaxBufferSizeForGenericCrypto_Response(size_t result) { - uint32_t api_value = 10073; /* from _tee10073 */ + uint32_t api_value = 10072; /* from _tee10072 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_size_t(&msg, &result); @@ -1984,7 +2005,7 @@ ODK_Message OPK_Pack_MaxBufferSizeForGenericCrypto_Response(size_t result) { void OPK_Unpack_MaxSampleSize_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10074) + if (api_value != 10073) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -1993,7 +2014,7 @@ void OPK_Unpack_MaxSampleSize_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_MaxSampleSize_Response(size_t result) { - uint32_t api_value = 10074; /* from _tee10074 */ + uint32_t api_value = 10073; /* from _tee10073 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_size_t(&msg, &result); @@ -2005,7 +2026,7 @@ ODK_Message OPK_Pack_MaxSampleSize_Response(size_t result) { void OPK_Unpack_SupportedCertificates_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10075) + if (api_value != 10074) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -2014,7 +2035,7 @@ void OPK_Unpack_SupportedCertificates_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_SupportedCertificates_Response(uint32_t result) { - uint32_t api_value = 10075; /* from _tee10075 */ + uint32_t api_value = 10074; /* from _tee10074 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -2026,7 +2047,7 @@ ODK_Message OPK_Pack_SupportedCertificates_Response(uint32_t result) { void OPK_Unpack_ContentDecryptBypassesTA_Request(ODK_Message* msg) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10076) + if (api_value != 10075) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -2035,7 +2056,7 @@ void OPK_Unpack_ContentDecryptBypassesTA_Request(ODK_Message* msg) { } ODK_Message OPK_Pack_ContentDecryptBypassesTA_Response(bool result) { - uint32_t api_value = 10076; /* from _tee10076 */ + uint32_t api_value = 10075; /* from _tee10075 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_bool(&msg, &result); @@ -2050,7 +2071,7 @@ void OPK_Unpack_GetEncryptAndSignSize_Request(ODK_Message* msg, size_t** wrapped_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10077) + if (api_value != 10076) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -2063,7 +2084,7 @@ void OPK_Unpack_GetEncryptAndSignSize_Request(ODK_Message* msg, ODK_Message OPK_Pack_GetEncryptAndSignSize_Response( OEMCryptoResult result, const size_t* wrapped_length) { - uint32_t api_value = 10077; /* from _tee10077 */ + uint32_t api_value = 10076; /* from _tee10076 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); @@ -2078,7 +2099,7 @@ void OPK_Unpack_EncryptAndSign_Request(ODK_Message* msg, uint32_t* context, uint8_t** out, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10078) + if (api_value != 10077) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -2095,7 +2116,7 @@ void OPK_Unpack_EncryptAndSign_Request(ODK_Message* msg, uint32_t* context, ODK_Message OPK_Pack_EncryptAndSign_Response(OEMCryptoResult result, const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10078; /* from _tee10078 */ + uint32_t api_value = 10077; /* from _tee10077 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, out_length); @@ -2114,7 +2135,7 @@ void OPK_Unpack_VerifyAndDecrypt_Request(ODK_Message* msg, uint32_t* context, size_t** out_length) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10079) + if (api_value != 10078) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -2131,7 +2152,7 @@ void OPK_Unpack_VerifyAndDecrypt_Request(ODK_Message* msg, uint32_t* context, ODK_Message OPK_Pack_VerifyAndDecrypt_Response(OEMCryptoResult result, const uint8_t* out, const size_t* out_length) { - uint32_t api_value = 10079; /* from _tee10079 */ + uint32_t api_value = 10078; /* from _tee10078 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_PackNullable_size_t(&msg, out_length); @@ -2149,7 +2170,7 @@ void OPK_Unpack_VerifyAndDecryptUsageData_Legacy_Request( uint8_t** signature, uint8_t** iv, uint8_t** out) { uint32_t api_value = UINT32_MAX; OPK_Unpack_uint32_t(msg, &api_value); - if (api_value != 10080) + if (api_value != 10079) ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); @@ -2164,7 +2185,7 @@ void OPK_Unpack_VerifyAndDecryptUsageData_Legacy_Request( ODK_Message OPK_Pack_VerifyAndDecryptUsageData_Legacy_Response( OEMCryptoResult result, const uint8_t* out) { - uint32_t api_value = 10080; /* from _tee10080 */ + uint32_t api_value = 10079; /* from _tee10079 */ ODK_Message msg = TOS_Transport_GetResponse(); OPK_Pack_uint32_t(&msg, &api_value); OPK_Pack_uint32_t(&msg, &result); diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.h b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.h index c50464c..8df5622 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/GEN_tee_serializer.h @@ -127,7 +127,7 @@ void OPK_Unpack_CreateAsymmetricKeyHandle_Request( ODK_Message OPK_Pack_CreateAsymmetricKeyHandle_Response( OEMCryptoResult result, const WTPI_AsymmetricKey_Handle* key_handle); void OPK_Unpack_UnwrapIntoAsymmetricKeyHandle_Request( - ODK_Message* msg, uint8_t** input, size_t* input_length, + ODK_Message* msg, uint32_t* context, uint8_t** input, size_t* input_length, AsymmetricKeyType* key_type, WTPI_AsymmetricKey_Handle** key_handle, uint32_t** allowed_schemes); ODK_Message OPK_Pack_UnwrapIntoAsymmetricKeyHandle_Response( @@ -141,7 +141,8 @@ void OPK_Unpack_GetWrappedAsymmetricKeySize_Request( AsymmetricKeyType* key_type, size_t** buffer_size); ODK_Message OPK_Pack_GetWrappedAsymmetricKeySize_Response( OEMCryptoResult result, const size_t* buffer_size); -void OPK_Unpack_WrapAsymmetricKey_Request(ODK_Message* msg, uint8_t** output, +void OPK_Unpack_WrapAsymmetricKey_Request(ODK_Message* msg, uint32_t* context, + uint8_t** output, size_t* output_length, AsymmetricKeyType* key_type, uint8_t** clear_key, @@ -192,6 +193,14 @@ void OPK_Unpack_GetSignatureHashAlgorithm_Request( ODK_Message OPK_Pack_GetSignatureHashAlgorithm_Response( OEMCryptoResult result, const OEMCrypto_SignatureHashAlgorithm* hash_algorithm); +void OPK_Unpack_DeriveNewAsymmetricKeyHandle_Request( + ODK_Message* msg, uint8_t** deriving_key, size_t* deriving_key_length, + uint8_t** context, size_t* context_length, AsymmetricKeyType* key_type, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length); +ODK_Message OPK_Pack_DeriveNewAsymmetricKeyHandle_Response( + OEMCryptoResult result, const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length); void OPK_Unpack_GetBootCertificateChain_Request(ODK_Message* msg, uint8_t** out, size_t** out_length); ODK_Message OPK_Pack_GetBootCertificateChain_Response(OEMCryptoResult result, @@ -202,9 +211,10 @@ void OPK_Unpack_GetMaxBootCertificateChainSize_Request(ODK_Message* msg, ODK_Message OPK_Pack_GetMaxBootCertificateChainSize_Response( OEMCryptoResult result, const size_t* out_length); void OPK_Unpack_GenerateRandomCertificateKeyPair_Request( - ODK_Message* msg, AsymmetricKeyType** key_type, - uint8_t** wrapped_private_key, size_t** wrapped_private_key_length, - uint8_t** public_key, size_t** public_key_length); + ODK_Message* msg, CertSignatureType* cert_type, + AsymmetricKeyType** key_type, uint8_t** wrapped_private_key, + size_t** wrapped_private_key_length, uint8_t** public_key, + size_t** public_key_length); ODK_Message OPK_Pack_GenerateRandomCertificateKeyPair_Response( OEMCryptoResult result, const AsymmetricKeyType* key_type, const uint8_t* wrapped_private_key, @@ -253,6 +263,14 @@ void OPK_Unpack_LoadBCCSignature_Request(ODK_Message* msg, uint8_t** signature, ODK_Message OPK_Pack_LoadBCCSignature_Response(OEMCryptoResult result, const uint8_t* signature, const size_t* signature_length); +void OPK_Unpack_CreateUDSDerivedAsymmetricKeyHandle_Request( + ODK_Message* msg, AsymmetricKeyType** key_type, + WTPI_AsymmetricKey_Handle** private_key_handle, uint8_t** public_key, + size_t** public_key_length); +ODK_Message OPK_Pack_CreateUDSDerivedAsymmetricKeyHandle_Response( + OEMCryptoResult result, const AsymmetricKeyType* key_type, + const WTPI_AsymmetricKey_Handle* private_key_handle, + const uint8_t* public_key, const size_t* public_key_length); void OPK_Unpack_Crc32Init_Request(ODK_Message* msg, uint32_t** initial_hash); ODK_Message OPK_Pack_Crc32Init_Response(OEMCryptoResult result, const uint32_t* initial_hash); @@ -294,10 +312,6 @@ ODK_Message OPK_Pack_IsProductionReady_Response(bool result); void OPK_Unpack_GetWatermarkingSupport_Request(ODK_Message* msg); ODK_Message OPK_Pack_GetWatermarkingSupport_Response( OEMCrypto_WatermarkingSupport result); -void OPK_Unpack_GetCurrentSRMVersion_Request(ODK_Message* msg, - uint32_t** srm_version); -ODK_Message OPK_Pack_GetCurrentSRMVersion_Response(OEMCryptoResult result, - const uint32_t* srm_version); void OPK_Unpack_IsAntiRollbackHWPresent_Request(ODK_Message* msg); ODK_Message OPK_Pack_IsAntiRollbackHWPresent_Response(bool result); void OPK_Unpack_IsCGMS_AActive_Request(ODK_Message* msg); @@ -314,12 +328,6 @@ void OPK_Unpack_DisableAnalogDisplay_Request(ODK_Message* msg); ODK_Message OPK_Pack_DisableAnalogDisplay_Response(bool result); void OPK_Unpack_MaxOutputSizeForDecrypt_Request(ODK_Message* msg); ODK_Message OPK_Pack_MaxOutputSizeForDecrypt_Response(size_t result); -void OPK_Unpack_CurrentHDCPCapability_Request(ODK_Message* msg); -ODK_Message OPK_Pack_CurrentHDCPCapability_Response( - OEMCrypto_HDCP_Capability result); -void OPK_Unpack_MaxHDCPCapability_Request(ODK_Message* msg); -ODK_Message OPK_Pack_MaxHDCPCapability_Response( - OEMCrypto_HDCP_Capability result); void OPK_Unpack_MaxBufferSizeForGenericCrypto_Request(ODK_Message* msg); ODK_Message OPK_Pack_MaxBufferSizeForGenericCrypto_Response(size_t result); void OPK_Unpack_MaxSampleSize_Request(ODK_Message* msg); diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.c b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.c index 5d48d92..07ff32e 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.c +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.c @@ -101,6 +101,12 @@ void OPK_Init_OEMCrypto_HDCP_Capability(OEMCrypto_HDCP_Capability* obj) { } } +void OPK_Init_CertSignatureType(CertSignatureType* obj) { + if (obj) { + memset(obj, 0, sizeof(CertSignatureType)); + } +} + void OPK_Unpack_WTPI_K1_SymmetricKey_Handle(ODK_Message* message, WTPI_K1_SymmetricKey_Handle* value); void OPK_Unpack_C1_HMAC_SHA256_Verify_Request(ODK_Message* msg, diff --git a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.h b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.h index dd2744c..587b81e 100644 --- a/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.h +++ b/oemcrypto/opk/oemcrypto_ta/wtpi_test/tee/tee_special_cases.h @@ -25,6 +25,7 @@ void OPK_Init_OEMCrypto_Security_Level(OEMCrypto_Security_Level* obj); void OPK_Init_OEMCrypto_ProvisioningMethod(OEMCrypto_ProvisioningMethod* obj); void OPK_Init_OEMCrypto_WatermarkingSupport(OEMCrypto_WatermarkingSupport* obj); void OPK_Init_OEMCrypto_HDCP_Capability(OEMCrypto_HDCP_Capability* obj); +void OPK_Init_CertSignatureType(CertSignatureType* obj); void OPK_Unpack_C1_HMAC_SHA256_Verify_Request(ODK_Message* msg, WTPI_K1_SymmetricKey_Handle* key, diff --git a/oemcrypto/opk/ports/linux/common/tos_secure_buffers.c b/oemcrypto/opk/ports/linux/common/tos_secure_buffers.c index 841c723..fb9351b 100644 --- a/oemcrypto/opk/ports/linux/common/tos_secure_buffers.c +++ b/oemcrypto/opk/ports/linux/common/tos_secure_buffers.c @@ -30,5 +30,7 @@ void TOS_SecureBuffer_Unpack(ODK_Message* message, bool TOS_SecureBuffer_CheckSize(void* handle, size_t size) { /* without real secure memory, there's nothing we can do here */ + (void)handle; + (void)size; return true; } diff --git a/oemcrypto/opk/ports/linux/common/tos_transport.cpp b/oemcrypto/opk/ports/linux/common/tos_transport.cpp index 8e39108..e8d431e 100644 --- a/oemcrypto/opk/ports/linux/common/tos_transport.cpp +++ b/oemcrypto/opk/ports/linux/common/tos_transport.cpp @@ -91,6 +91,7 @@ ODK_Message TOS_Transport_GetResponse() { void TOS_Transport_ReleaseMessage(ODK_Message* message) { // resources are static, nothing to do here + (void)message; } // Get the size of the message from the mailbox and return it diff --git a/oemcrypto/opk/ports/linux/rules.mk b/oemcrypto/opk/ports/linux/rules.mk index 2b1b100..e218fdc 100644 --- a/oemcrypto/opk/ports/linux/rules.mk +++ b/oemcrypto/opk/ports/linux/rules.mk @@ -108,8 +108,18 @@ clang-tidy-$(1): ${q}clang-tidy $(clang-tidy-flags) $(1) -- $(cflags) endef +define clang-tidy-rule-cpp +.PHONY: clang-tidy-$(1) +clang-tidy-$(1): + @$(cmd-echo-silent) ' CLANG-TIDY $(1)' + ${q}clang-tidy $(clang-tidy-flags) -extra-arg=-std=c++17 $(1) -- $(cflags) +endef + # Generate rules to run clang-tidy with each source file. -$(foreach src,$(clang-tidy-srcs),$(eval $(call clang-tidy-rule,$(src)))) +clang-tidy-srcs-c := $(filter %.c %.S, $(clang-tidy-srcs)) +$(foreach src,$(clang-tidy-srcs-c),$(eval $(call clang-tidy-rule,$(src)))) +clang-tidy-srcs-cpp := $(filter %.cpp %.cc, $(clang-tidy-srcs)) +$(foreach src,$(clang-tidy-srcs-cpp),$(eval $(call clang-tidy-rule-cpp,$(src)))) # Run clang-tidy with all source files. .PHONY: clang-tidy diff --git a/oemcrypto/opk/ports/linux/ta/common/tee_simulator.cpp b/oemcrypto/opk/ports/linux/ta/common/tee_simulator.cpp index 258f391..a0a1a9e 100644 --- a/oemcrypto/opk/ports/linux/ta/common/tee_simulator.cpp +++ b/oemcrypto/opk/ports/linux/ta/common/tee_simulator.cpp @@ -20,6 +20,7 @@ static pthread_t main_thread_tid; static bool thread_running = false; void signalHandler(int signum) { + (void)signum; // TODO(fredgc): this doesn't actually kill anything because the main loop is // stuck waiting for a new message. thread_running = false; @@ -32,6 +33,7 @@ void signalHandler(int signum) { static uint8_t local_buffer[OPK_TRANSPORT_MESSAGE_SIZE]; static void* MainLoop(void* arg) { + (void)arg; OPK_Initialize(); thread_running = true; while (thread_running) { @@ -74,7 +76,7 @@ static void* MainLoop(void* arg) { return nullptr; } -int main(int argc, char** argv) { +int main() { pthread_attr_t p_attr; int result = pthread_attr_init(&p_attr); diff --git a/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/sources.mk b/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/sources.mk index 40ef148..a8851f1 100644 --- a/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/sources.mk +++ b/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/sources.mk @@ -37,6 +37,7 @@ wtpi_impl_sources += \ $(wtpi_ref_dir)/wtpi_clock_and_gn_layer1.c \ $(wtpi_ref_dir)/wtpi_crc32.c \ $(wtpi_ref_dir)/wtpi_crypto_wrap_asymmetric.c \ + $(wtpi_ref_dir)/wtpi_hdcp.c \ $(wtpi_ref_dir)/wtpi_idle.c \ $(wtpi_ref_dir)/wtpi_device_renewal_layer1.c \ $(wtpi_ref_dir)/wtpi_device_renewal_layer2.c \ diff --git a/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/wtpi_test_impl.gyp b/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/wtpi_test_impl.gyp index 0a86c54..cc59c25 100644 --- a/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/wtpi_test_impl.gyp +++ b/oemcrypto/opk/ports/linux/ta/common/wtpi_impl/wtpi_test_impl.gyp @@ -40,6 +40,7 @@ '<(wtpi_stub_dir)/wtpi_secure_buffer_access.c', '<(wtpi_stub_dir)/wtpi_fused.c', '<(oemcrypto_ta_dir)/wtpi_reference/wtpi_config.c', + '<(oemcrypto_ta_dir)/wtpi_reference/wtpi_hdcp.c', ], 'conditions': [ ['reference_crypto_impl=="hardware"', { diff --git a/oemcrypto/opk/ports/optee/Makefile b/oemcrypto/opk/ports/optee/Makefile index 591b662..82aac33 100644 --- a/oemcrypto/opk/ports/optee/Makefile +++ b/oemcrypto/opk/ports/optee/Makefile @@ -45,8 +45,11 @@ IMPLEMENTER := your-name-here # This is copied to the OPK_CONFIG_PROVISIONING_METHOD macro OPTEE_PROVISIONING_METHOD ?= OEMCrypto_Keybox -# Set to ECC to generate an EC keypair instead of RSA + +# Key type generated by OEMCrypto_GenerateCertificateKeyPair() +# Options are "RSA" or "ECC" OEMCRYPTO_GEN_KEYPAIR_TYPE ?= RSA + # Set to 1 to use an older, non-NIST key derivation algorithm to convert the # device unique key to an asymmetric keypair for CoseSign1 operations. This is # new in v19. Older devices already using OPK v17 or v18 may want to set this diff --git a/oemcrypto/opk/ports/optee/host/rules.mk b/oemcrypto/opk/ports/optee/host/rules.mk index 4b108ef..80e0600 100644 --- a/oemcrypto/opk/ports/optee/host/rules.mk +++ b/oemcrypto/opk/ports/optee/host/rules.mk @@ -109,8 +109,18 @@ clang-tidy-$(1): ${q}clang-tidy $(clang-tidy-flags) $(1) -- $(cflags) endef +define clang-tidy-rule-cpp +.PHONY: clang-tidy-$(1) +clang-tidy-$(1): + @$(cmd-echo-silent) ' CLANG-TIDY $(1)' + ${q}clang-tidy $(clang-tidy-flags) -extra-arg=-std=c++17 $(1) -- $(cflags) +endef + # Generate rules to run clang-tidy with each source file. -$(foreach src,$(clang-tidy-srcs),$(eval $(call clang-tidy-rule,$(src)))) +clang-tidy-srcs-c := $(filter %.c %.S, $(clang-tidy-srcs)) +$(foreach src,$(clang-tidy-srcs-c),$(eval $(call clang-tidy-rule,$(src)))) +clang-tidy-srcs-cpp := $(filter %.cpp %.cc, $(clang-tidy-srcs)) +$(foreach src,$(clang-tidy-srcs-cpp),$(eval $(call clang-tidy-rule-cpp,$(src)))) # Run clang-tidy with all source files. .PHONY: clang-tidy diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_ecc.c b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_ecc.c index 382fd31..2c0fd9a 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_ecc.c +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_ecc.c @@ -8,6 +8,8 @@ #include "crypto_util.h" #include "oemcrypto_check_macros.h" #include "opk_config.h" +#include "wtpi_device_key_interface.h" +#include "wtpi_logging_interface.h" #include "wtpi_memory_interface.h" #include "wtpi_provisioning_4_interface.h" @@ -95,9 +97,9 @@ static OEMCryptoResult NewEccKeyPair(uint8_t* private_key_data, } OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( - AsymmetricKeyType* key_type, uint8_t* wrapped_private_key, - size_t* wrapped_private_key_length, uint8_t* public_key, - size_t* public_key_length) { + CertSignatureType cert_type, AsymmetricKeyType* key_type, + uint8_t* wrapped_private_key, size_t* wrapped_private_key_length, + uint8_t* public_key, size_t* public_key_length) { RETURN_INVALID_CONTEXT_IF_NULL(key_type); RETURN_INVALID_CONTEXT_IF_NULL(wrapped_private_key_length); RETURN_INVALID_CONTEXT_IF_NULL(public_key_length); @@ -139,13 +141,26 @@ OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( if (result != OEMCrypto_SUCCESS) goto cleanup; if (*wrapped_private_key_length < actual_wrapped_private_key_length) { // This should not happen as we have checked buffer size. + LOGE( + "wrapped_private_key_length=%zu, " + "WTPI_GetWrappedAsymmetricKeySize()=%zu, which should not happen", + *wrapped_private_key_length, actual_wrapped_private_key_length); *wrapped_private_key_length = actual_wrapped_private_key_length; result = OEMCrypto_ERROR_SHORT_BUFFER; goto cleanup; } + uint32_t context = 0; + if (cert_type == CERT_SIGNATURE_DRM) { + context = DEVICE_KEY_WRAP_DRM_CERT; + } else if (cert_type == CERT_SIGNATURE_OEM) { + context = DEVICE_KEY_WRAP_OEM_CERT; + } else { + goto cleanup; + } + *wrapped_private_key_length = actual_wrapped_private_key_length; - result = WTPI_WrapAsymmetricKey(wrapped_private_key, + result = WTPI_WrapAsymmetricKey(context, wrapped_private_key, *wrapped_private_key_length, *key_type, clear_private_key, clear_private_key_length); diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_rsa.c b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_rsa.c index e8459af..9276530 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_rsa.c +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/genkeypair_rsa.c @@ -8,13 +8,14 @@ #include "crypto_util.h" #include "oemcrypto_check_macros.h" #include "opk_config.h" +#include "wtpi_device_key_interface.h" #include "wtpi_memory_interface.h" #include "wtpi_provisioning_4_interface.h" OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( - AsymmetricKeyType* key_type, uint8_t* wrapped_private_key, - size_t* wrapped_private_key_length, uint8_t* public_key, - size_t* public_key_length) { + CertSignatureType cert_type, AsymmetricKeyType* key_type, + uint8_t* wrapped_private_key, size_t* wrapped_private_key_length, + uint8_t* public_key, size_t* public_key_length) { RETURN_INVALID_CONTEXT_IF_NULL(key_type); RETURN_INVALID_CONTEXT_IF_NULL(wrapped_private_key_length); RETURN_INVALID_CONTEXT_IF_NULL(public_key_length); @@ -133,9 +134,19 @@ OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( } *wrapped_private_key_length = required_size; - result = - WTPI_WrapAsymmetricKey(wrapped_private_key, *wrapped_private_key_length, - *key_type, encoded_priv, encoded_priv_len); + uint32_t context = 0; + if (cert_type == CERT_SIGNATURE_DRM) { + context = DEVICE_KEY_WRAP_DRM_CERT; + } else if (cert_type == CERT_SIGNATURE_OEM) { + context = DEVICE_KEY_WRAP_OEM_CERT; + } else { + WTPI_SecureZeroMemory(encoded_priv, sizeof(encoded_priv)); + return OEMCrypto_ERROR_INVALID_CONTEXT; + } + + result = WTPI_WrapAsymmetricKey(context, wrapped_private_key, + *wrapped_private_key_length, *key_type, + encoded_priv, encoded_priv_len); WTPI_SecureZeroMemory(encoded_priv, sizeof(encoded_priv)); return result; } diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/sources.mk b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/sources.mk index 81a15d5..9af604d 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/sources.mk +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/sources.mk @@ -65,6 +65,7 @@ wtpi_impl_sources += \ $(wtpi_ref_dir)/wtpi_crc32.c \ $(wtpi_ref_dir)/wtpi_crypto_wrap_asymmetric.c \ $(wtpi_ref_dir)/wtpi_device_key.c \ + $(wtpi_ref_dir)/wtpi_hdcp.c \ $(wtpi_ref_dir)/wtpi_idle.c \ $(wtpi_ref_dir)/wtpi_device_renewal_layer1.c \ $(wtpi_ref_dir)/wtpi_device_renewal_layer2.c \ diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util.h b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util.h index 2e2e294..359ca62 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util.h +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util.h @@ -35,6 +35,11 @@ typedef struct pkcs1_rsa { size_t coefficient_len; } pkcs1_rsa; +/* + * Free and erase a pkcs1_rsa. Does nothing if |key| is NULL. + */ +void Free_pkcs1_rsa(pkcs1_rsa* key); + /* * Parses |input| data, which is a DER-encoded PKCS8 RSA private key. Extracts * the RSA private key components such as modulus, exponents, primes, @@ -85,6 +90,11 @@ typedef struct rfc5915_eckey { uint32_t ecc_curve_type; } rfc5915_eckey; +/* + * Free and erase an rfc5915_eckey. Does nothing if |key| is NULL. + */ +void Free_rfc5915_eckey(rfc5915_eckey* key); + /* * Parses |input| data, which is a DER-encoded PKCS8 ECC keypair. Allocates * buffers for the pointer types in the output. @@ -132,7 +142,7 @@ OEMCryptoResult DeriveEccKey(const uint8_t* seed, size_t seed_length, * * Sets |output_length| to the number of bytes written. */ -OEMCryptoResult EncodeECCPublicKey(rfc5915_eckey* key, uint8_t* output, +OEMCryptoResult EncodeECCPublicKey(const rfc5915_eckey* key, uint8_t* output, size_t* output_length); /* @@ -142,7 +152,7 @@ OEMCryptoResult EncodeECCPublicKey(rfc5915_eckey* key, uint8_t* output, * * Sets |output_length| to number of bytes written. */ -OEMCryptoResult EncodeECCPrivateKey(rfc5915_eckey* key, uint8_t* output, +OEMCryptoResult EncodeECCPrivateKey(const rfc5915_eckey* key, uint8_t* output, size_t* output_length); #endif diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util_mbedtls.c b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util_mbedtls.c index 801c864..81e1fce 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util_mbedtls.c +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/util/crypto_util_mbedtls.c @@ -69,21 +69,43 @@ static OEMCryptoResult extract_mbedtls_mpi_param(mbedtls_mpi* src, return OEMCrypto_SUCCESS; } +void Free_pkcs1_rsa(pkcs1_rsa* key) { + if (key == NULL) { + return; + } + + if (key->private_exp != NULL) { + WTPI_SecureZeroMemory(key->private_exp, key->private_exp_len); + } + + TEE_Free(key->modulus); + TEE_Free(key->public_exp); + TEE_Free(key->private_exp); + TEE_Free(key->prime1); + TEE_Free(key->prime2); + TEE_Free(key->exp1); + TEE_Free(key->exp2); + TEE_Free(key->coefficient); + + TEE_MemFill(key, 0, sizeof(*key)); +} + OEMCryptoResult DecodePKCS8RSAPrivateKey(const uint8_t* input, size_t input_length, pkcs1_rsa* output) { - OEMCryptoResult res; - mbedtls_pk_context pk_ctx; mbedtls_pk_init(&pk_ctx); int ret = mbedtls_pk_parse_key(&pk_ctx, input, input_length, NULL, 0); if (ret != 0) { + mbedtls_pk_free(&pk_ctx); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - mbedtls_mpi N, P, Q, D, E, DP, DQ, QP; + OEMCryptoResult res; + TEE_MemFill(output, 0, sizeof(*output)); + mbedtls_mpi N, P, Q, D, E, DP, DQ, QP; mbedtls_mpi_init(&N); mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q); @@ -107,45 +129,50 @@ OEMCryptoResult DecodePKCS8RSAPrivateKey(const uint8_t* input, goto cleanup; } - if ((res = extract_mbedtls_mpi_param( - &N, &output->modulus, &output->modulus_len)) != OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&N, &output->modulus, &output->modulus_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } - if ((res = extract_mbedtls_mpi_param(&E, &output->public_exp, - &output->public_exp_len)) != - OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&E, &output->public_exp, + &output->public_exp_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } - if ((res = extract_mbedtls_mpi_param(&D, &output->private_exp, - &output->private_exp_len)) != - OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&D, &output->private_exp, + &output->private_exp_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } - if ((res = extract_mbedtls_mpi_param( - &P, &output->prime1, &output->prime1_len)) != OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&P, &output->prime1, &output->prime1_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } - if ((res = extract_mbedtls_mpi_param( - &Q, &output->prime2, &output->prime2_len)) != OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&Q, &output->prime2, &output->prime2_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } - if ((res = extract_mbedtls_mpi_param(&DP, &output->exp1, - &output->exp1_len)) != OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&DP, &output->exp1, &output->exp1_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } - if ((res = extract_mbedtls_mpi_param(&DQ, &output->exp2, - &output->exp2_len)) != OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&DQ, &output->exp2, &output->exp2_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } - if ((res = extract_mbedtls_mpi_param(&QP, &output->coefficient, - &output->coefficient_len)) != - OEMCrypto_SUCCESS) - goto cleanup; - - res = OEMCrypto_SUCCESS; + res = extract_mbedtls_mpi_param(&QP, &output->coefficient, + &output->coefficient_len); cleanup: + mbedtls_pk_free(&pk_ctx); + mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q); @@ -155,7 +182,9 @@ cleanup: mbedtls_mpi_free(&DQ); mbedtls_mpi_free(&QP); - mbedtls_pk_free(&pk_ctx); + if (res != OEMCrypto_SUCCESS) { + Free_pkcs1_rsa(output); + } return res; } @@ -369,37 +398,59 @@ static void zero_pad_and_realloc(uint8_t** src, size_t* src_size, *src_size = desired_size; } +void Free_rfc5915_eckey(rfc5915_eckey* key) { + if (key == NULL) { + return; + } + + if (key->private_val != NULL) { + WTPI_SecureZeroMemory(key->private_val, key->private_val_len); + } + + TEE_Free(key->private_val); + TEE_Free(key->public_x); + TEE_Free(key->public_y); + + TEE_MemFill(key, 0, sizeof(*key)); +} + OEMCryptoResult DecodePKCS8ECCPrivateKey(const uint8_t* input, size_t input_length, rfc5915_eckey* output) { - OEMCryptoResult res; - mbedtls_pk_context pk_ctx; mbedtls_pk_init(&pk_ctx); int ret = mbedtls_pk_parse_key(&pk_ctx, input, input_length, NULL, 0); if (ret != 0) { + mbedtls_pk_free(&pk_ctx); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } mbedtls_ecp_keypair* ec_ctx = mbedtls_pk_ec(pk_ctx); + TEE_MemFill(output, 0, sizeof(*output)); output->ecc_curve_type = GlobalPlatformCurveId(ec_ctx->grp.id); output->ecc_curve_bits = CurveNumBits(ec_ctx->grp.id); output->max_signature_size = ECCSignatureSize(output->ecc_curve_bits); - const size_t ecc_curve_bytes = (output->ecc_curve_bits + 7) / 8; - if ((res = extract_mbedtls_mpi_param(&(ec_ctx->d), &output->private_val, - &output->private_val_len)) != - OEMCrypto_SUCCESS) + OEMCryptoResult res = extract_mbedtls_mpi_param( + &ec_ctx->d, &output->private_val, &output->private_val_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; - if ((res = extract_mbedtls_mpi_param(&(ec_ctx->Q.X), &output->public_x, - &output->public_x_len)) != - OEMCrypto_SUCCESS) + } + + res = extract_mbedtls_mpi_param(&ec_ctx->Q.X, &output->public_x, + &output->public_x_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; - if ((res = extract_mbedtls_mpi_param(&(ec_ctx->Q.Y), &output->public_y, - &output->public_y_len)) != - OEMCrypto_SUCCESS) + } + + res = extract_mbedtls_mpi_param(&ec_ctx->Q.Y, &output->public_y, + &output->public_y_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } + + const size_t ecc_curve_bytes = (output->ecc_curve_bits + 7) / 8; zero_pad_and_realloc(&output->private_val, &output->private_val_len, ecc_curve_bytes); zero_pad_and_realloc(&output->public_x, &output->public_x_len, @@ -407,49 +458,58 @@ OEMCryptoResult DecodePKCS8ECCPrivateKey(const uint8_t* input, zero_pad_and_realloc(&output->public_y, &output->public_y_len, ecc_curve_bytes); - res = OEMCrypto_SUCCESS; - cleanup: mbedtls_pk_free(&pk_ctx); + + if (res != OEMCrypto_SUCCESS) { + Free_rfc5915_eckey(output); + } + return res; } OEMCryptoResult DecodeECCPublicKey(const uint8_t* input, size_t input_length, rfc5915_eckey* output) { - OEMCryptoResult res; - mbedtls_pk_context pk_ctx; mbedtls_pk_init(&pk_ctx); int ret = mbedtls_pk_parse_public_key(&pk_ctx, input, input_length); if (ret != 0) { + mbedtls_pk_free(&pk_ctx); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } mbedtls_ecp_keypair* ec_ctx = mbedtls_pk_ec(pk_ctx); + TEE_MemFill(output, 0, sizeof(*output)); output->ecc_curve_type = GlobalPlatformCurveId(ec_ctx->grp.id); output->ecc_curve_bits = CurveNumBits(ec_ctx->grp.id); output->max_signature_size = ECCSignatureSize(output->ecc_curve_bits); + + OEMCryptoResult res = extract_mbedtls_mpi_param( + &ec_ctx->Q.X, &output->public_x, &output->public_x_len); + if (res != OEMCrypto_SUCCESS) { + goto cleanup; + } + + res = extract_mbedtls_mpi_param(&ec_ctx->Q.Y, &output->public_y, + &output->public_y_len); + if (res != OEMCrypto_SUCCESS) { + goto cleanup; + } + const size_t ecc_curve_bytes = (output->ecc_curve_bits + 7) / 8; - - if ((res = extract_mbedtls_mpi_param(&(ec_ctx->Q.X), &output->public_x, - &output->public_x_len)) != - OEMCrypto_SUCCESS) - goto cleanup; - if ((res = extract_mbedtls_mpi_param(&(ec_ctx->Q.Y), &output->public_y, - &output->public_y_len)) != - OEMCrypto_SUCCESS) - goto cleanup; - zero_pad_and_realloc(&output->public_x, &output->public_x_len, ecc_curve_bytes); zero_pad_and_realloc(&output->public_y, &output->public_y_len, ecc_curve_bytes); - res = OEMCrypto_SUCCESS; - cleanup: mbedtls_pk_free(&pk_ctx); + + if (res != OEMCrypto_SUCCESS) { + Free_rfc5915_eckey(output); + } + return res; } @@ -517,8 +577,6 @@ OEMCryptoResult DeriveEccKey(const uint8_t* seed, size_t seed_length, return OEMCrypto_ERROR_INVALID_CONTEXT; } - OEMCryptoResult res = OEMCrypto_ERROR_UNKNOWN_FAILURE; - // grp will contain ECC generator point G mbedtls_ecp_group grp; mbedtls_ecp_group_init(&grp); @@ -541,39 +599,43 @@ OEMCryptoResult DeriveEccKey(const uint8_t* seed, size_t seed_length, #else // Using NIST SP 800 56Cr2 "One-step Key Derivation", where H=sha256 and // FixedInfo=curve_id + { + uint32_t counter = 0; + size_t input_length = sizeof(counter) + seed_length + sizeof(curve_id); + uint8_t* input = TEE_Malloc(input_length, TEE_MALLOC_FILL_ZERO); + if (input == NULL) { + return OEMCrypto_ERROR_INSUFFICIENT_RESOURCES; + } - uint32_t counter = 0; - size_t input_length = sizeof(counter) + seed_length + sizeof(curve_id); - uint8_t* input = TEE_Malloc(input_length, TEE_MALLOC_FILL_ZERO); - if (input == NULL) { - return OEMCrypto_ERROR_INSUFFICIENT_RESOURCES; + counter++; + uint8_t* addr = input; + uint32_t counter_be = oemcrypto_htobe32(counter); + TEE_MemMove(addr, &counter_be, sizeof(counter_be)); + addr = addr + sizeof(counter); + TEE_MemMove(addr, seed, seed_length); + addr = addr + seed_length; + TEE_MemMove(addr, &curve_id, sizeof(curve_id)); + mbedtls_sha256(input, input_length, derived, 0); + + counter++; + counter_be = oemcrypto_htobe32(counter); + addr = input; + TEE_MemMove(addr, &counter_be, sizeof(counter_be)); + mbedtls_sha256(input, input_length, derived + 32, 0); + TEE_Free(input); } - - counter++; - uint8_t* addr = input; - uint32_t counter_be = oemcrypto_htobe32(counter); - TEE_MemMove(addr, &counter_be, sizeof(counter_be)); - addr = addr + sizeof(counter); - TEE_MemMove(addr, seed, seed_length); - addr = addr + seed_length; - TEE_MemMove(addr, &curve_id, sizeof(curve_id)); - mbedtls_sha256(input, input_length, derived, 0); - - counter++; - counter_be = oemcrypto_htobe32(counter); - addr = input; - TEE_MemMove(addr, &counter_be, sizeof(counter_be)); - mbedtls_sha256(input, input_length, derived + 32, 0); - TEE_Free(input); - addr = NULL; #endif + OEMCryptoResult res; + TEE_MemFill(output, 0, sizeof(*output)); + // Copy derived result into mbedtls mpi struct, treat it as the private key mbedtls_ecp_group_id id = MbedTlsCurveId(curve_id); size_t curve_len_bits = CurveNumBits(id); size_t curve_len = (curve_len_bits + 7) / 8; int mbedtls_res = mbedtls_mpi_read_binary(&privkey, derived, curve_len); if (mbedtls_res < 0) { + res = OEMCrypto_ERROR_UNKNOWN_FAILURE; goto cleanup; } @@ -581,12 +643,14 @@ OEMCryptoResult DeriveEccKey(const uint8_t* seed, size_t seed_length, // mbedtls_ecp_group_load loads a known set of fields for a given curve mbedtls_res = mbedtls_ecp_group_load(&grp, id); if (mbedtls_res < 0) { + res = OEMCrypto_ERROR_UNKNOWN_FAILURE; goto cleanup; } // Multiply private val by G - mbedtls_res = mbedtls_ecp_mul(&grp, &pubkey, &privkey, &(grp.G), NULL, NULL); + mbedtls_res = mbedtls_ecp_mul(&grp, &pubkey, &privkey, &grp.G, NULL, NULL); if (mbedtls_res < 0) { + res = OEMCrypto_ERROR_UNKNOWN_FAILURE; goto cleanup; } @@ -595,35 +659,44 @@ OEMCryptoResult DeriveEccKey(const uint8_t* seed, size_t seed_length, output->ecc_curve_bits = curve_len_bits; output->max_signature_size = ECCSignatureSize(curve_len_bits); - if ((res = extract_mbedtls_mpi_param(&privkey, &output->private_val, - &output->private_val_len)) != - OEMCrypto_SUCCESS) + res = extract_mbedtls_mpi_param(&privkey, &output->private_val, + &output->private_val_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; - if ((res = extract_mbedtls_mpi_param(&(pubkey.X), &output->public_x, - &output->public_x_len)) != - OEMCrypto_SUCCESS) + } + + res = extract_mbedtls_mpi_param(&pubkey.X, &output->public_x, + &output->public_x_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; - if ((res = extract_mbedtls_mpi_param(&(pubkey.Y), &output->public_y, - &output->public_y_len)) != - OEMCrypto_SUCCESS) + } + + res = extract_mbedtls_mpi_param(&pubkey.Y, &output->public_y, + &output->public_y_len); + if (res != OEMCrypto_SUCCESS) { goto cleanup; + } + zero_pad_and_realloc(&output->private_val, &output->private_val_len, curve_len); zero_pad_and_realloc(&output->public_x, &output->public_x_len, curve_len); zero_pad_and_realloc(&output->public_y, &output->public_y_len, curve_len); - res = OEMCrypto_SUCCESS; - cleanup: mbedtls_ecp_group_free(&grp); mbedtls_ecp_point_free(&pubkey); mbedtls_mpi_free(&privkey); WTPI_SecureZeroMemory(derived, sizeof(derived)); + + if (res != OEMCrypto_SUCCESS) { + Free_rfc5915_eckey(output); + } + return res; } static OEMCryptoResult Helper_EncodeECCKey( - rfc5915_eckey* key, uint8_t* output, size_t* output_length, + const rfc5915_eckey* key, uint8_t* output, size_t* output_length, int (*mbedtls_write_fn)(mbedtls_pk_context* ctx, unsigned char* buf, size_t size)) { mbedtls_pk_context pk_ctx; @@ -693,7 +766,7 @@ static OEMCryptoResult Helper_EncodeECCKey( } // Encodes ECC public key as X509 SubjectPublicKeyInfo -OEMCryptoResult EncodeECCPublicKey(rfc5915_eckey* key, uint8_t* output, +OEMCryptoResult EncodeECCPublicKey(const rfc5915_eckey* key, uint8_t* output, size_t* output_length) { if (key == NULL || key->private_val == NULL || key->public_x == NULL || key->public_y == NULL || key->private_val_len == 0 || @@ -706,7 +779,7 @@ OEMCryptoResult EncodeECCPublicKey(rfc5915_eckey* key, uint8_t* output, mbedtls_pk_write_pubkey_der); } -OEMCryptoResult EncodeECCPrivateKey(rfc5915_eckey* key, uint8_t* output, +OEMCryptoResult EncodeECCPrivateKey(const rfc5915_eckey* key, uint8_t* output, size_t* output_length) { if (key == NULL || key->private_val == NULL || key->public_x == NULL || key->public_y == NULL || key->private_val_len == 0 || diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_and_key_management_layer1.c b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_and_key_management_layer1.c index 398cb08..b5afc77 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_and_key_management_layer1.c +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_and_key_management_layer1.c @@ -53,14 +53,10 @@ OEMCryptoResult Helper_AESEncryptBlock_ECB(WTPI_K1_SymmetricKey_Handle key, if (output_len != 128) { EMSG("output_len was changed to %zu", output_len); } - goto err; + return OEMCrypto_ERROR_UNKNOWN_FAILURE; } return OEMCrypto_SUCCESS; - -err: - - return OEMCrypto_ERROR_UNKNOWN_FAILURE; } static OEMCryptoResult Helper_AESCBC(WTPI_K1_SymmetricKey_Handle key, @@ -94,34 +90,35 @@ static OEMCryptoResult Helper_AESCBC(WTPI_K1_SymmetricKey_Handle key, } TEE_ObjectHandle key_handle = TEE_HANDLE_NULL; - TEE_Attribute attr; uint32_t algo = TEE_ALG_AES_CBC_NOPAD; uint32_t size = key_length_to_use * 8; + TEE_Result res = TEE_AllocateOperation(&op_handle, algo, mode, size); if (res != TEE_SUCCESS) { EMSG("TEE_AllocateOperation() failed with result 0x%x", res); - goto err; + goto cleanup; } res = TEE_AllocateTransientObject(TEE_TYPE_AES, size, &key_handle); if (res != TEE_SUCCESS) { EMSG("TEE_AllocateTransientObject() failed with result 0x%x", res); - goto err; + goto cleanup; } + TEE_Attribute attr; TEE_InitRefAttribute(&attr, TEE_ATTR_SECRET_VALUE, key->key, key_length_to_use); res = TEE_PopulateTransientObject(key_handle, &attr, 1); if (res != TEE_SUCCESS) { EMSG("TEE_PopulateTransientObject() failed with result 0x%x", res); - goto err; + goto cleanup; } res = TEE_SetOperationKey(op_handle, key_handle); if (res != TEE_SUCCESS) { EMSG("TEE_SetOperationKey() failed with result 0x%x", res); - goto err; + goto cleanup; } TEE_CipherInit(op_handle, iv, 16); @@ -132,17 +129,14 @@ static OEMCryptoResult Helper_AESCBC(WTPI_K1_SymmetricKey_Handle key, if (output_len != in_length) { EMSG("output_len was changed to %zu", output_len); } - return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); - if (key_handle != TEE_HANDLE_NULL) TEE_FreeTransientObject(key_handle); - return OEMCrypto_SUCCESS; -err: +cleanup: if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); if (key_handle != TEE_HANDLE_NULL) TEE_FreeTransientObject(key_handle); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + return res == TEE_SUCCESS ? OEMCrypto_SUCCESS + : OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult WTPI_C1_AESCBCDecrypt(WTPI_K1_SymmetricKey_Handle key, @@ -185,34 +179,36 @@ OEMCryptoResult WTPI_C1_HMAC_SHA1(WTPI_K1_SymmetricKey_Handle key, TEE_OperationHandle op_handle = TEE_HANDLE_NULL; TEE_ObjectHandle key_handle = TEE_HANDLE_NULL; - TEE_Attribute attr; size_t output_len = 32; uint32_t algo = TEE_ALG_HMAC_SHA1; uint32_t mode = TEE_MODE_MAC; uint32_t size = key->key_size * 8; + TEE_Result res = TEE_AllocateOperation(&op_handle, algo, mode, size); if (res != TEE_SUCCESS) { EMSG("Could not allocate op with result 0x%x", res); - goto err; + goto cleanup; } res = TEE_AllocateTransientObject(TEE_TYPE_HMAC_SHA1, size, &key_handle); if (res != TEE_SUCCESS) { EMSG("TEE_AllocateTransientObject() failed with result 0x%x", res); - goto err; + goto cleanup; } + + TEE_Attribute attr; TEE_InitRefAttribute(&attr, TEE_ATTR_SECRET_VALUE, key->key, key->key_size); res = TEE_PopulateTransientObject(key_handle, &attr, 1); if (res != TEE_SUCCESS) { EMSG("TEE_PopulateTransientObject() failed with result 0x%x", res); - goto err; + goto cleanup; } res = TEE_SetOperationKey(op_handle, key_handle); if (res != TEE_SUCCESS) { EMSG("TEE_SetOperationKey() failed with result 0x%x", res); - goto err; + goto cleanup; } TEE_MACInit(op_handle, NULL, 0); @@ -224,17 +220,14 @@ OEMCryptoResult WTPI_C1_HMAC_SHA1(WTPI_K1_SymmetricKey_Handle key, if (output_len != 32) { EMSG("output_len was changed to %zu", output_len); } - goto err; } - if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); - if (key_handle != TEE_HANDLE_NULL) TEE_FreeTransientObject(key_handle); - return OEMCrypto_SUCCESS; -err: +cleanup: if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); if (key_handle != TEE_HANDLE_NULL) TEE_FreeTransientObject(key_handle); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + return res == TEE_SUCCESS ? OEMCrypto_SUCCESS + : OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult WTPI_C1_SHA256(const uint8_t* message, size_t message_length, @@ -243,18 +236,17 @@ OEMCryptoResult WTPI_C1_SHA256(const uint8_t* message, size_t message_length, RETURN_INVALID_CONTEXT_IF_ZERO(message_length); RETURN_INVALID_CONTEXT_IF_NULL(out); - TEE_Result res; - TEE_OperationHandle op_handle = TEE_HANDLE_NULL; size_t chunk_len = 32; size_t remaining_len = message_length; size_t output_len = 32; uint32_t algo = TEE_ALG_SHA256; uint32_t mode = TEE_MODE_DIGEST; - res = TEE_AllocateOperation(&op_handle, algo, mode, 0); + + TEE_Result res = TEE_AllocateOperation(&op_handle, algo, mode, 0); if (res != TEE_SUCCESS) { EMSG("TEE_AllocateOperation() failed with result 0x%x", res); - goto err; + goto cleanup; } for (size_t i = 0; i < message_length; i += chunk_len) { @@ -271,17 +263,13 @@ OEMCryptoResult WTPI_C1_SHA256(const uint8_t* message, size_t message_length, if (output_len != 32) { EMSG("output_len was changed to %zu", output_len); } - goto err; } +cleanup: if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); - return OEMCrypto_SUCCESS; - -err: - if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); - - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + return res == TEE_SUCCESS ? OEMCrypto_SUCCESS + : OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult WTPI_C1_HMAC_SHA256(WTPI_K1_SymmetricKey_Handle key, @@ -310,7 +298,6 @@ OEMCryptoResult WTPI_C1_HMAC_SHA256(WTPI_K1_SymmetricKey_Handle key, TEE_OperationHandle op_handle = TEE_HANDLE_NULL; TEE_ObjectHandle key_handle = TEE_HANDLE_NULL; - TEE_Attribute attr; size_t output_len = 32; uint32_t algo = TEE_ALG_HMAC_SHA256; uint32_t mode = TEE_MODE_MAC; @@ -320,25 +307,28 @@ OEMCryptoResult WTPI_C1_HMAC_SHA256(WTPI_K1_SymmetricKey_Handle key, if (res != TEE_SUCCESS) { EMSG("Could not allocate op with result 0x%x, %u, %u, %u", res, algo, mode, size); - goto err; + goto cleanup; } res = TEE_AllocateTransientObject(TEE_TYPE_HMAC_SHA256, size, &key_handle); if (res != TEE_SUCCESS) { EMSG("TEE_AllocateTransientObject() failed with result 0x%x", res); - goto err; + goto cleanup; } + + TEE_Attribute attr; TEE_InitRefAttribute(&attr, TEE_ATTR_SECRET_VALUE, key->key, key->key_size); res = TEE_PopulateTransientObject(key_handle, &attr, 1); if (res != TEE_SUCCESS) { EMSG("TEE_PopulateTransientObject() failed with result 0x%x", res); - goto err; + goto cleanup; } + res = TEE_SetOperationKey(op_handle, key_handle); if (res != TEE_SUCCESS) { EMSG("Could not set op key with result 0x%x", res); - goto err; + goto cleanup; } TEE_MACInit(op_handle, NULL, 0); @@ -350,17 +340,14 @@ OEMCryptoResult WTPI_C1_HMAC_SHA256(WTPI_K1_SymmetricKey_Handle key, if (output_len != 32) { EMSG("output_len was changed to %zu", output_len); } - goto err; } - if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); - if (key_handle != TEE_HANDLE_NULL) TEE_FreeTransientObject(key_handle); - return OEMCrypto_SUCCESS; -err: +cleanup: if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); if (key_handle != TEE_HANDLE_NULL) TEE_FreeTransientObject(key_handle); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + return res == TEE_SUCCESS ? OEMCrypto_SUCCESS + : OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult WTPI_C1_HMAC_SHA256_Verify(WTPI_K1_SymmetricKey_Handle key, @@ -381,23 +368,22 @@ OEMCryptoResult WTPI_C1_HMAC_SHA256_Verify(WTPI_K1_SymmetricKey_Handle key, } OEMCryptoResult WTPI_C1_SHA512(const uint8_t* message, size_t message_length, - uint8_t* out){ + uint8_t* out) { RETURN_INVALID_CONTEXT_IF_NULL(message); RETURN_INVALID_CONTEXT_IF_ZERO(message_length); RETURN_INVALID_CONTEXT_IF_NULL(out); - TEE_Result res; - TEE_OperationHandle op_handle = TEE_HANDLE_NULL; size_t chunk_len = 64; size_t remaining_len = message_length; size_t output_len = 64; uint32_t algo = TEE_ALG_SHA512; uint32_t mode = TEE_MODE_DIGEST; - res = TEE_AllocateOperation(&op_handle, algo, mode, 0); + + TEE_Result res = TEE_AllocateOperation(&op_handle, algo, mode, 0); if (res != TEE_SUCCESS) { EMSG("TEE_AllocateOperation() failed with result 0x%x", res); - goto err; + goto cleanup; } for (size_t i = 0; i < message_length; i += chunk_len) { @@ -414,17 +400,13 @@ OEMCryptoResult WTPI_C1_SHA512(const uint8_t* message, size_t message_length, if (output_len != 32) { EMSG("output_len was changed to %zu", output_len); } - goto err; } +cleanup: if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); - return OEMCrypto_SUCCESS; - -err: - if (op_handle != TEE_HANDLE_NULL) TEE_FreeOperation(op_handle); - - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + return res == TEE_SUCCESS ? OEMCrypto_SUCCESS + : OEMCrypto_ERROR_UNKNOWN_FAILURE; } OEMCryptoResult WTPI_C1_CopyToOutputBuffer(const uint8_t* in, size_t size, @@ -440,14 +422,12 @@ OEMCryptoResult WTPI_C1_CopyToOutputBuffer(const uint8_t* in, size_t size, if (total_size > out->size) { return OEMCrypto_ERROR_INVALID_CONTEXT; } - OEMCryptoResult res = - OPK_CheckOutputBounds(out, output_offset, size); + OEMCryptoResult res = OPK_CheckOutputBounds(out, output_offset, size); if (res != OEMCrypto_SUCCESS) { LOGE("Output bounds check failed with result: %u", res); return res; } - uint8_t* dest = NULL; if (out->type == OPK_SECURE_OUTPUT_BUFFER) { OEMCryptoResult result = @@ -584,7 +564,6 @@ OEMCryptoResult WTPI_K1_CreateKeyHandle( err: WTPI_K1_FreeKeyHandle(sess); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; } @@ -713,14 +692,15 @@ OEMCryptoResult WTPI_K1_DeriveKeyFromKeyHandle( uint32_t size; OEMCryptoResult oemcrypto_res = WTPI_K1_GetKeySize(key, &size); if (oemcrypto_res != OEMCrypto_SUCCESS) { - return oemcrypto_res; + goto cleanup; } size = size * 8; TEE_Result tee_res = TEE_AllocateOperation(&op_handle, algo, mode, size); if (tee_res != TEE_SUCCESS) { EMSG("TEE_AllocateOperation() failed with result 0x%x", tee_res); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + oemcrypto_res = OEMCrypto_ERROR_UNKNOWN_FAILURE; + goto cleanup; } tee_res = TEE_AllocateTransientObject(TEE_TYPE_AES, size, &key_handle); @@ -729,6 +709,7 @@ OEMCryptoResult WTPI_K1_DeriveKeyFromKeyHandle( oemcrypto_res = OEMCrypto_ERROR_UNKNOWN_FAILURE; goto cleanup; } + TEE_Attribute attr; TEE_InitRefAttribute(&attr, TEE_ATTR_SECRET_VALUE, key->key, key->key_size); diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_asymmetric.c b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_asymmetric.c index 7180964..39e88c3 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_asymmetric.c +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_crypto_asymmetric.c @@ -20,7 +20,6 @@ #include "wtpi_abort_interface.h" #include "wtpi_crypto_asymmetric_interface.h" #include "wtpi_device_key_access_interface.h" -#include "wtpi_memory_interface.h" static OEMCryptoResult Helper_CreateRSAKeyHandle( const uint8_t* serialized_bytes, size_t size, @@ -87,19 +86,7 @@ static OEMCryptoResult Helper_CreateRSAKeyHandle( oemcrypto_res = OEMCrypto_SUCCESS; cleanup: - if (sess_key != NULL) { - TEE_Free(sess_key->modulus); - TEE_Free(sess_key->exp1); - TEE_Free(sess_key->exp2); - TEE_Free(sess_key->prime1); - TEE_Free(sess_key->prime2); - TEE_Free(sess_key->coefficient); - TEE_Free(sess_key->public_exp); - if (sess_key->private_exp != NULL) { - WTPI_SecureZeroMemory(sess_key->private_exp, sess_key->private_exp_len); - } - TEE_Free(sess_key->private_exp); - } + Free_pkcs1_rsa(sess_key); TEE_Free(sess_key); if (oemcrypto_res == OEMCrypto_SUCCESS) { @@ -183,14 +170,7 @@ static OEMCryptoResult Helper_CreateECCKeyHandle( oemcrypto_res = OEMCrypto_SUCCESS; cleanup: - if (sess_key != NULL) { - if (sess_key->private_val != NULL) { - WTPI_SecureZeroMemory(sess_key->private_val, sess_key->private_val_len); - } - TEE_Free(sess_key->private_val); - TEE_Free(sess_key->public_x); - TEE_Free(sess_key->public_y); - } + Free_rfc5915_eckey(sess_key); TEE_Free(sess_key); if (oemcrypto_res == OEMCrypto_SUCCESS) { @@ -551,13 +531,6 @@ OEMCryptoResult WTPI_ECCDeriveSessionKey(WTPI_AsymmetricKey_Handle key, RETURN_INVALID_CONTEXT_IF_NULL(key_source); RETURN_INVALID_CONTEXT_IF_NULL(session_key_length); - rfc5915_eckey ecc_key = {0}; - TEE_OperationHandle ecdh_op = TEE_HANDLE_NULL; - OEMCryptoResult result = OEMCrypto_SUCCESS; - TEE_Result res = TEE_SUCCESS; - TEE_Attribute attrs[2]; - TEE_ObjectHandle derived_key = TEE_HANDLE_NULL; - // Determine algorithm type and required key size based on incoming public key // curve parameters uint32_t alg_type = 0; @@ -586,41 +559,51 @@ OEMCryptoResult WTPI_ECCDeriveSessionKey(WTPI_AsymmetricKey_Handle key, return OEMCrypto_ERROR_SHORT_BUFFER; } + OEMCryptoResult oemcrypto_res; + TEE_OperationHandle ecdh_op = TEE_HANDLE_NULL; + rfc5915_eckey ecc_key = {0}; + TEE_ObjectHandle derived_key = TEE_HANDLE_NULL; + // Allocate operation handle for ECDH - res = TEE_AllocateOperation(&ecdh_op, alg_type, TEE_MODE_DERIVE, - key_size_bytes * 8); - if (res != TEE_SUCCESS) { - EMSG("TEE_AllocateOperation failed with result 0x%x, %d", res, alg_type); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + TEE_Result tee_res = TEE_AllocateOperation( + &ecdh_op, alg_type, TEE_MODE_DERIVE, key_size_bytes * 8); + if (tee_res != TEE_SUCCESS) { + EMSG("TEE_AllocateOperation failed with result 0x%x, %d", tee_res, + alg_type); + oemcrypto_res = OEMCrypto_ERROR_UNKNOWN_FAILURE; + goto cleanup; } // Assign private key to ECDH operation handle - res = TEE_SetOperationKey(ecdh_op, key->ecdh_key); - if (res != TEE_SUCCESS) { - EMSG("TEE_SetOperationKey failed with result 0x%x", res); + tee_res = TEE_SetOperationKey(ecdh_op, key->ecdh_key); + if (tee_res != TEE_SUCCESS) { + EMSG("TEE_SetOperationKey failed with result 0x%x", tee_res); + oemcrypto_res = OEMCrypto_ERROR_UNKNOWN_FAILURE; goto cleanup; } // Decode public key data into struct object defined by crypto_util.h // This step will allocate memory for public key x and y values, so be sure to // free them - result = DecodeECCPublicKey(key_source, key_source_length, &ecc_key); - if (result != OEMCrypto_SUCCESS) { - EMSG("DecodeECCPublicKey failed with result 0x%x", res); + oemcrypto_res = DecodeECCPublicKey(key_source, key_source_length, &ecc_key); + if (oemcrypto_res != OEMCrypto_SUCCESS) { + EMSG("DecodeECCPublicKey failed with result 0x%x", oemcrypto_res); goto cleanup; } // Copy public x and y values into attribute arrays + TEE_Attribute attrs[2]; TEE_InitRefAttribute(&attrs[0], TEE_ATTR_ECC_PUBLIC_VALUE_X, ecc_key.public_x, ecc_key.public_x_len); TEE_InitRefAttribute(&attrs[1], TEE_ATTR_ECC_PUBLIC_VALUE_Y, ecc_key.public_y, ecc_key.public_y_len); // Allocate object handle for derived key - res = + tee_res = TEE_AllocateTransientObject(TEE_TYPE_GENERIC_SECRET, 2048, &derived_key); - if (res != TEE_SUCCESS) { - EMSG("TEE_AllocateTransientObject failed with result 0x%x", res); + if (tee_res != TEE_SUCCESS) { + EMSG("TEE_AllocateTransientObject failed with result 0x%x", tee_res); + oemcrypto_res = OEMCrypto_ERROR_UNKNOWN_FAILURE; goto cleanup; } @@ -628,24 +611,18 @@ OEMCryptoResult WTPI_ECCDeriveSessionKey(WTPI_AsymmetricKey_Handle key, TEE_DeriveKey(ecdh_op, attrs, 2, derived_key); // Extract generated secret value from derived key handle - res = TEE_GetObjectBufferAttribute(derived_key, TEE_ATTR_SECRET_VALUE, - session_key, session_key_length); - TEE_FreeTransientObject(derived_key); - if (res != TEE_SUCCESS) { - EMSG("TEE_GetObjectBufferAttribute failed with result 0x%x", res); - goto cleanup; + tee_res = TEE_GetObjectBufferAttribute(derived_key, TEE_ATTR_SECRET_VALUE, + session_key, session_key_length); + if (tee_res != TEE_SUCCESS) { + EMSG("TEE_GetObjectBufferAttribute failed with result 0x%x", tee_res); + oemcrypto_res = OEMCrypto_ERROR_UNKNOWN_FAILURE; } - TEE_Free(ecc_key.public_x); - TEE_Free(ecc_key.public_y); - TEE_FreeOperation(ecdh_op); - return OEMCrypto_SUCCESS; - cleanup: - TEE_Free(ecc_key.public_x); - TEE_Free(ecc_key.public_y); TEE_FreeOperation(ecdh_op); - return OEMCrypto_ERROR_UNKNOWN_FAILURE; + Free_rfc5915_eckey(&ecc_key); + TEE_FreeTransientObject(derived_key); + return oemcrypto_res; } OEMCryptoResult WTPI_GetSignatureHashAlgorithm( @@ -681,3 +658,11 @@ OEMCryptoResult WTPI_GetSignatureHashAlgorithm( } return OEMCrypto_ERROR_UNKNOWN_FAILURE; } + +OEMCryptoResult WTPI_DeriveNewAsymmetricKeyHandle( + const uint8_t* deriving_key, size_t deriving_key_length, + const uint8_t* context, size_t context_length, AsymmetricKeyType key_type, + WTPI_AsymmetricKey_Handle* private_key_handle, uint8_t* public_key, + size_t* public_key_length){ + return OEMCrypto_ERROR_NOT_IMPLEMENTED; +} diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_provisioning_4.c b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_provisioning_4.c index 4de77ef..14efa14 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_provisioning_4.c +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_provisioning_4.c @@ -234,3 +234,9 @@ OEMCryptoResult WTPI_LoadBCCSignature(uint8_t* signature UNUSED, size_t* signature_length UNUSED) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } + +OEMCryptoResult WTPI_CreateUDSDerivedAsymmetricKeyHandle( + AsymmetricKeyType* key_type, WTPI_AsymmetricKey_Handle* private_key_handle, + uint8_t* public_key, size_t* public_key_length) { + return OEMCrypto_ERROR_NOT_IMPLEMENTED; +} diff --git a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_root_of_trust_layer1.c b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_root_of_trust_layer1.c index 5fc4f0d..9394a18 100644 --- a/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_root_of_trust_layer1.c +++ b/oemcrypto/opk/ports/optee/ta/common/wtpi_impl/wtpi_root_of_trust_layer1.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include "cose_util.h" @@ -21,6 +20,7 @@ #include "wtpi_crypto_and_key_management_interface_layer1.h" #include "wtpi_device_renewal_interface_layer1.h" #include "wtpi_logging_interface.h" +#include "wtpi_memory_interface.h" #include "wtpi_provisioning_4_interface.h" // This layer keeps a copy of the keybox in volatile memory. A more secure @@ -35,7 +35,7 @@ static uint8_t renewed_key_data[sizeof(gKeybox.data)]; static uint32_t GetSystemId(const uint8_t* key_data) { uint32_t nbo_system_id; - memcpy(&nbo_system_id, &key_data[4], sizeof(nbo_system_id)); + TEE_MemMove(&nbo_system_id, &key_data[4], sizeof(nbo_system_id)); return oemcrypto_be32toh(nbo_system_id); } @@ -55,11 +55,11 @@ static OEMCryptoResult CalculateRenewedKeyData(void) { // The new key data is the same as the old key data, but with the version // field at offset 0 and the system ID field at offset 4 modified. - memcpy(renewed_key_data, gKeybox.data, sizeof(renewed_key_data)); + TEE_MemMove(renewed_key_data, gKeybox.data, sizeof(renewed_key_data)); static const uint8_t kVersion3[4] = {0x00, 0x00, 0x00, 0x03}; - memcpy(&renewed_key_data[0], &kVersion3, sizeof(kVersion3)); + TEE_MemMove(&renewed_key_data[0], &kVersion3, sizeof(kVersion3)); const uint32_t nbo_system_id = oemcrypto_htobe32(new_system_id); - memcpy(&renewed_key_data[4], &nbo_system_id, sizeof(nbo_system_id)); + TEE_MemMove(&renewed_key_data[4], &nbo_system_id, sizeof(nbo_system_id)); return OEMCrypto_SUCCESS; } @@ -79,7 +79,7 @@ static OEMCryptoResult InitializeRenewal(void) { } OEMCryptoResult WTPI_InitializeKeybox(void) { - memset(&gKeybox, 0, sizeof(gKeybox)); + TEE_MemFill(&gKeybox, 0, sizeof(gKeybox)); size_t length = sizeof(gKeybox); OEMCryptoResult result = WTPI_LoadRootOfTrust((uint8_t*)&gKeybox, &length); if (result != OEMCrypto_SUCCESS) { @@ -100,17 +100,17 @@ OEMCryptoResult WTPI_InitializeKeybox(void) { result = InitializeRenewal(); cleanup: if (result != OEMCrypto_SUCCESS) { - memset(&gKeybox, 0, sizeof(gKeybox)); + WTPI_SecureZeroMemory(&gKeybox, sizeof(gKeybox)); perform_renewal = false; - memset(&renewed_key_data, 0, sizeof(renewed_key_data)); + WTPI_SecureZeroMemory(&renewed_key_data, sizeof(renewed_key_data)); } return result; } OEMCryptoResult WTPI_TerminateKeybox(void) { - memset(&gKeybox, 0, sizeof(gKeybox)); + WTPI_SecureZeroMemory(&gKeybox, sizeof(gKeybox)); perform_renewal = false; - memset(&renewed_key_data, 0, sizeof(renewed_key_data)); + WTPI_SecureZeroMemory(&renewed_key_data, sizeof(renewed_key_data)); return WTPI_TerminateDeviceRenewal(); } @@ -123,7 +123,7 @@ OEMCryptoResult WTPI_UnwrapValidateAndInstallKeybox(const uint8_t* input, goto cleanup; } // First, try the buffer as if is a clear keybox. - memcpy(&gKeybox, input, output_length); + TEE_MemMove(&gKeybox, input, output_length); result = WTPI_ValidateKeybox(); if (result != OEMCrypto_SUCCESS) { // If that didn't work, we unwrap the encrypted data that was in input, and @@ -137,7 +137,6 @@ OEMCryptoResult WTPI_UnwrapValidateAndInstallKeybox(const uint8_t* input, result = OEMCrypto_ERROR_SHORT_BUFFER; goto cleanup; } - if (result != OEMCrypto_SUCCESS) goto cleanup; // Use the layer above to validate the keybox. result = WTPI_ValidateKeybox(); if (result != OEMCrypto_SUCCESS) goto cleanup; @@ -160,12 +159,12 @@ cleanup: } OEMCryptoResult WTPI_ValidateKeybox(void) { - if (memcmp(gKeybox.magic, "kbox", 4) != 0) { + if (TEE_MemCompare(gKeybox.magic, "kbox", 4) != 0) { return OEMCrypto_ERROR_BAD_MAGIC; } uint32_t crc_computed; uint32_t crc_stored; - memcpy(&crc_stored, gKeybox.crc, sizeof(uint32_t)); + TEE_MemMove(&crc_stored, gKeybox.crc, sizeof(uint32_t)); crc_stored = oemcrypto_be32toh(crc_stored); OEMCryptoResult result = WTPI_Crc32Init(&crc_computed); if (OEMCrypto_SUCCESS != result) return result; @@ -200,7 +199,7 @@ static OEMCryptoResult GetProv4DeviceID(uint8_t* device_id, // (encoded) device public key from BCC. uint8_t* bcc_buffer = (uint8_t*)TEE_Malloc(required_bcc_payload_size, 0); if (bcc_buffer == NULL) return OEMCrypto_ERROR_UNKNOWN_FAILURE; - memset(bcc_buffer, 0, required_bcc_payload_size); + TEE_MemFill(bcc_buffer, 0, required_bcc_payload_size); size_t bcc_size = required_bcc_payload_size; result = WTPI_GetBootCertificateChain(bcc_buffer, &bcc_size); if (result != OEMCrypto_SUCCESS) { @@ -213,7 +212,7 @@ static OEMCryptoResult GetProv4DeviceID(uint8_t* device_id, TEE_Free(bcc_buffer); return OEMCrypto_ERROR_UNKNOWN_FAILURE; } - memset(dk_pub_buffer, 0, required_bcc_payload_size); + TEE_MemFill(dk_pub_buffer, 0, required_bcc_payload_size); size_t dk_pub_size = required_bcc_payload_size; result = GetDevicePublicKeyFromBcc(bcc_buffer, bcc_size, dk_pub_buffer, &dk_pub_size); @@ -242,7 +241,7 @@ OEMCryptoResult WTPI_GetDeviceID(uint8_t* device_id, size_t device_id_length) { if (device_id_length < KEYBOX_DEVICE_ID_SIZE) { return OEMCrypto_ERROR_INVALID_CONTEXT; } - memcpy(device_id, gKeybox.device_id, KEYBOX_DEVICE_ID_SIZE); + TEE_MemMove(device_id, gKeybox.device_id, KEYBOX_DEVICE_ID_SIZE); return OEMCrypto_SUCCESS; } @@ -264,9 +263,9 @@ OEMCryptoResult WTPI_GetKeyDataFromKeybox(uint8_t* key_data, size_t length) { if (key_data == NULL) return OEMCrypto_ERROR_INVALID_CONTEXT; if (length != sizeof(gKeybox.data)) return OEMCrypto_ERROR_INVALID_CONTEXT; if (perform_renewal) { - memcpy(key_data, renewed_key_data, length); + TEE_MemMove(key_data, renewed_key_data, length); } else { - memcpy(key_data, gKeybox.data, length); + TEE_MemMove(key_data, gKeybox.data, length); } return OEMCrypto_SUCCESS; } @@ -277,7 +276,7 @@ OEMCryptoResult WTPI_LoadTestKeybox(const uint8_t* test_keybox, size_t length) { LOGD("Wrong keybox size: %zu", length); return OEMCrypto_ERROR_INVALID_CONTEXT; } - memcpy(&gKeybox, test_keybox, length); + TEE_MemMove(&gKeybox, test_keybox, length); // Renewal is not used with the test keybox. perform_renewal = false; return OEMCrypto_SUCCESS; diff --git a/oemcrypto/opk/ports/optee/ta/oemcrypto_ta/oemcrypto_ta.c b/oemcrypto/opk/ports/optee/ta/oemcrypto_ta/oemcrypto_ta.c index 91db916..1640d4f 100644 --- a/oemcrypto/opk/ports/optee/ta/oemcrypto_ta/oemcrypto_ta.c +++ b/oemcrypto/opk/ports/optee/ta/oemcrypto_ta/oemcrypto_ta.c @@ -3,7 +3,8 @@ * source code may only be used and distributed under the Widevine * License Agreement. */ -#include + +#include #include #include @@ -117,7 +118,7 @@ static TEE_Result HandleRequest(uint32_t param_types, TEE_Param params[4]) { * so the contents can't be modified while being parsed. */ static uint8_t local_buffer[OPK_TRANSPORT_MESSAGE_SIZE]; - memcpy(local_buffer, transport_buffer_, request_size); + TEE_MemMove(local_buffer, transport_buffer_, request_size); ODK_Message request = ODK_Message_Create(local_buffer, request_size); ODK_Message_SetSize(&request, request_size); diff --git a/oemcrypto/opk/ports/optee/ta/wtpi_test_ta/wtpi_test_ta.c b/oemcrypto/opk/ports/optee/ta/wtpi_test_ta/wtpi_test_ta.c index af07f79..1351b7d 100644 --- a/oemcrypto/opk/ports/optee/ta/wtpi_test_ta/wtpi_test_ta.c +++ b/oemcrypto/opk/ports/optee/ta/wtpi_test_ta/wtpi_test_ta.c @@ -6,7 +6,7 @@ #include "wtpi_test_ta.h" -#include +#include #include #include @@ -104,7 +104,7 @@ static TEE_Result HandleRequest(uint32_t param_types, TEE_Param params[4]) { * so the contents can't be modified while being parsed. */ static uint8_t local_buffer[OPK_TRANSPORT_MESSAGE_SIZE]; - memcpy(local_buffer, transport_buffer_, request_size); + TEE_MemMove(local_buffer, transport_buffer_, request_size); DMSG("Request size is %zu\n", request_size); ODK_Message request = ODK_Message_Create(local_buffer, request_size); diff --git a/oemcrypto/opk/ports/trusty/ta/reference/interface_impls/wtpi_provisioning_4.c b/oemcrypto/opk/ports/trusty/ta/reference/interface_impls/wtpi_provisioning_4.c index 04c3e78..1bfa620 100644 --- a/oemcrypto/opk/ports/trusty/ta/reference/interface_impls/wtpi_provisioning_4.c +++ b/oemcrypto/opk/ports/trusty/ta/reference/interface_impls/wtpi_provisioning_4.c @@ -33,6 +33,7 @@ #include "ecc_util.h" #include "oemcrypto_check_macros.h" #include "wtpi_crypto_asymmetric_interface.h" +#include "wtpi_device_key_interface.h" #include "wtpi_logging_interface.h" #include "wtpi_memory_interface.h" @@ -71,9 +72,9 @@ OEMCryptoResult WTPI_GetMaxBootCertificateChainSize(size_t* out_length) { } OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( - AsymmetricKeyType* key_type, uint8_t* wrapped_private_key, - size_t* wrapped_private_key_length, uint8_t* public_key, - size_t* public_key_length) { + CertSignatureType cert_type, AsymmetricKeyType* key_type, + uint8_t* wrapped_private_key, size_t* wrapped_private_key_length, + uint8_t* public_key, size_t* public_key_length) { if (key_type == NULL || wrapped_private_key_length == NULL || public_key_length == NULL) { return OEMCrypto_ERROR_INVALID_CONTEXT; @@ -121,8 +122,17 @@ OEMCryptoResult WTPI_GenerateRandomCertificateKeyPair( goto cleanup; } + uint32_t context = 0; + if (cert_type == CERT_SIGNATURE_DRM) { + context = DEVICE_KEY_WRAP_DRM_CERT; + } else if (cert_type == CERT_SIGNATURE_OEM) { + context = DEVICE_KEY_WRAP_OEM_CERT; + } else { + return OEMCrypto_ERROR_INVALID_CONTEXT; + } + *wrapped_private_key_length = actual_wrapped_private_key_length; - result = WTPI_WrapAsymmetricKey(wrapped_private_key, + result = WTPI_WrapAsymmetricKey(context, wrapped_private_key, *wrapped_private_key_length, *key_type, clear_private_key, clear_private_key_length); diff --git a/oemcrypto/opk/ports/trusty/ta/reference/rules.mk b/oemcrypto/opk/ports/trusty/ta/reference/rules.mk index 0f38b8a..35d8c68 100644 --- a/oemcrypto/opk/ports/trusty/ta/reference/rules.mk +++ b/oemcrypto/opk/ports/trusty/ta/reference/rules.mk @@ -89,6 +89,7 @@ MODULE_SRCS += \ $(APP_DIR)/wtpi_reference/wtpi_crypto_wrap_asymmetric.c \ $(APP_DIR)/wtpi_reference/wtpi_device_renewal_layer1.c \ $(APP_DIR)/wtpi_reference/wtpi_decrypt_sample.c \ + $(APP_DIR)/wtpi_reference/wtpi_hdcp.c \ $(APP_DIR)/wtpi_reference/wtpi_idle.c \ $(APP_DIR)/wtpi_reference/wtpi_logging.c \ $(APP_DIR)/wtpi_reference/wtpi_memory.c \ diff --git a/oemcrypto/opk/serialization/common/GEN_common_serializer.c b/oemcrypto/opk/serialization/common/GEN_common_serializer.c index 881abc8..a5107b6 100644 --- a/oemcrypto/opk/serialization/common/GEN_common_serializer.c +++ b/oemcrypto/opk/serialization/common/GEN_common_serializer.c @@ -256,6 +256,7 @@ bool Is_Valid_OEMCrypto_ProvisioningMethod(uint32_t value) { case 2: /* OEMCrypto_Keybox */ case 3: /* OEMCrypto_OEMCertificate */ case 4: /* OEMCrypto_BootCertificateChain */ + case 5: /* OEMCrypto_DrmReprovisioning */ return true; default: return false; @@ -463,12 +464,20 @@ void OPK_Pack_OEMCrypto_KeyRefreshObject( void OPK_Unpack_OEMCrypto_Substring(ODK_Message* msg, OEMCrypto_Substring* obj) { + OEMCrypto_Substring tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_size_t(msg, &obj->offset); OPK_Unpack_size_t(msg, &obj->length); } void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_0( ODK_Message* msg, OEMCrypto_DTCP2_CMI_Descriptor_0* obj) { + OEMCrypto_DTCP2_CMI_Descriptor_0 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->id); OPK_Unpack_uint8_t(msg, &obj->extension); OPK_Unpack_uint16_t(msg, &obj->length); @@ -477,6 +486,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_0( void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_1( ODK_Message* msg, OEMCrypto_DTCP2_CMI_Descriptor_1* obj) { + OEMCrypto_DTCP2_CMI_Descriptor_1 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->id); OPK_Unpack_uint8_t(msg, &obj->extension); OPK_Unpack_uint16_t(msg, &obj->length); @@ -485,6 +498,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_1( void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_2( ODK_Message* msg, OEMCrypto_DTCP2_CMI_Descriptor_2* obj) { + OEMCrypto_DTCP2_CMI_Descriptor_2 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->id); OPK_Unpack_uint8_t(msg, &obj->extension); OPK_Unpack_uint16_t(msg, &obj->length); @@ -493,6 +510,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_2( void OPK_Unpack_OEMCrypto_DTCP2_CMI_Packet(ODK_Message* msg, OEMCrypto_DTCP2_CMI_Packet* obj) { + OEMCrypto_DTCP2_CMI_Packet tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_uint8_t(msg, &obj->dtcp2_required); OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_0(msg, &obj->cmi_descriptor_0); OPK_Unpack_OEMCrypto_DTCP2_CMI_Descriptor_1(msg, &obj->cmi_descriptor_1); @@ -501,6 +522,10 @@ void OPK_Unpack_OEMCrypto_DTCP2_CMI_Packet(ODK_Message* msg, void OPK_Unpack_OEMCrypto_KeyObject(ODK_Message* msg, OEMCrypto_KeyObject* obj) { + OEMCrypto_KeyObject tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_id); OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_data_iv); OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_data); @@ -510,8 +535,12 @@ void OPK_Unpack_OEMCrypto_KeyObject(ODK_Message* msg, void OPK_Unpack_OEMCrypto_InputOutputPair(ODK_Message* msg, OEMCrypto_InputOutputPair* obj) { + OEMCrypto_InputOutputPair tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_size_t(msg, &obj->input_data_length); - OEMCrypto_SharedMemory* input_data; + OEMCrypto_SharedMemory* input_data = NULL; OPK_UnpackSharedBuffer(msg, &input_data, OPK_ToLengthType(obj->input_data_length), /* map */ true, /* is_output */ false); @@ -521,6 +550,10 @@ void OPK_Unpack_OEMCrypto_InputOutputPair(ODK_Message* msg, void OPK_Unpack_OEMCrypto_SubSampleDescription( ODK_Message* msg, OEMCrypto_SubSampleDescription* obj) { + OEMCrypto_SubSampleDescription tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_size_t(msg, &obj->num_bytes_clear); OPK_Unpack_size_t(msg, &obj->num_bytes_encrypted); OPK_Unpack_uint8_t(msg, &obj->subsample_flags); @@ -529,10 +562,14 @@ void OPK_Unpack_OEMCrypto_SubSampleDescription( void OPK_Unpack_OEMCrypto_SampleDescription(ODK_Message* msg, OEMCrypto_SampleDescription* obj) { + OEMCrypto_SampleDescription tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_size_t(msg, &obj->subsamples_length); OPK_Unpack_OEMCrypto_InputOutputPair(msg, &obj->buffers); OPK_UnpackArray(msg, &obj->iv[0], sizeof(obj->iv)); - OEMCrypto_SubSampleDescription* subsamples; + OEMCrypto_SubSampleDescription* subsamples = NULL; /* unpack object array with unpacker function * OPK_Unpack_OEMCrypto_SubSampleDescription */ @@ -569,12 +606,20 @@ void OPK_Unpack_OEMCrypto_SampleDescription(ODK_Message* msg, void OPK_Unpack_OEMCrypto_CENCEncryptPatternDesc( ODK_Message* msg, OEMCrypto_CENCEncryptPatternDesc* obj) { + OEMCrypto_CENCEncryptPatternDesc tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_size_t(msg, &obj->encrypt); OPK_Unpack_size_t(msg, &obj->skip); } void OPK_Unpack_OEMCrypto_EntitledContentKeyObject( ODK_Message* msg, OEMCrypto_EntitledContentKeyObject* obj) { + OEMCrypto_EntitledContentKeyObject tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_OEMCrypto_Substring(msg, &obj->entitlement_key_id); OPK_Unpack_OEMCrypto_Substring(msg, &obj->content_key_id); OPK_Unpack_OEMCrypto_Substring(msg, &obj->content_key_data_iv); @@ -585,6 +630,10 @@ void OPK_Unpack_OEMCrypto_EntitledContentKeyObject( void OPK_Unpack_OEMCrypto_CENCEncryptPatternDesc_V15( ODK_Message* msg, OEMCrypto_CENCEncryptPatternDesc_V15* obj) { + OEMCrypto_CENCEncryptPatternDesc_V15 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_size_t(msg, &obj->encrypt); OPK_Unpack_size_t(msg, &obj->skip); OPK_Unpack_size_t(msg, &obj->offset); @@ -592,6 +641,10 @@ void OPK_Unpack_OEMCrypto_CENCEncryptPatternDesc_V15( void OPK_Unpack_OEMCrypto_EntitledContentKeyObject_V16( ODK_Message* msg, OEMCrypto_EntitledContentKeyObject_V16* obj) { + OEMCrypto_EntitledContentKeyObject_V16 tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_OEMCrypto_Substring(msg, &obj->entitlement_key_id); OPK_Unpack_OEMCrypto_Substring(msg, &obj->content_key_id); OPK_Unpack_OEMCrypto_Substring(msg, &obj->content_key_data_iv); @@ -600,6 +653,10 @@ void OPK_Unpack_OEMCrypto_EntitledContentKeyObject_V16( void OPK_Unpack_OEMCrypto_KeyRefreshObject(ODK_Message* msg, OEMCrypto_KeyRefreshObject* obj) { + OEMCrypto_KeyRefreshObject tmp_obj; + if (obj == NULL) { + obj = &tmp_obj; + } OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_id); OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_control_iv); OPK_Unpack_OEMCrypto_Substring(msg, &obj->key_control); @@ -613,9 +670,11 @@ void OPK_PackNullable_uint32_t(ODK_Message* msg, const uint32_t* value) { } void OPK_UnpackNullable_uint32_t(ODK_Message* msg, uint32_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_uint32_t(msg, *value); + } else { + OPK_Unpack_uint32_t(msg, NULL); } } void OPK_UnpackAlloc_uint32_t(ODK_Message* msg, uint32_t** value) { @@ -632,9 +691,11 @@ void OPK_PackNullable_size_t(ODK_Message* msg, const size_t* value) { } void OPK_UnpackNullable_size_t(ODK_Message* msg, size_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_size_t(msg, *value); + } else { + OPK_Unpack_size_t(msg, NULL); } } void OPK_UnpackAlloc_size_t(ODK_Message* msg, size_t** value) { @@ -653,9 +714,11 @@ void OPK_PackNullable_OEMCrypto_EntitledContentKeyObject( void OPK_UnpackNullable_OEMCrypto_EntitledContentKeyObject( ODK_Message* msg, OEMCrypto_EntitledContentKeyObject** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_OEMCrypto_EntitledContentKeyObject(msg, *value); + } else { + OPK_Unpack_OEMCrypto_EntitledContentKeyObject(msg, NULL); } } void OPK_PackNullable_OEMCrypto_CENCEncryptPatternDesc( @@ -668,9 +731,11 @@ void OPK_PackNullable_OEMCrypto_CENCEncryptPatternDesc( void OPK_UnpackNullable_OEMCrypto_CENCEncryptPatternDesc( ODK_Message* msg, OEMCrypto_CENCEncryptPatternDesc** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_OEMCrypto_CENCEncryptPatternDesc(msg, *value); + } else { + OPK_Unpack_OEMCrypto_CENCEncryptPatternDesc(msg, NULL); } } void OPK_PackNullable_OEMCrypto_DestBufferDesc( @@ -683,9 +748,11 @@ void OPK_PackNullable_OEMCrypto_DestBufferDesc( void OPK_UnpackNullable_OEMCrypto_DestBufferDesc( ODK_Message* msg, OEMCrypto_DestBufferDesc** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_OEMCrypto_DestBufferDesc(msg, *value); + } else { + OPK_Unpack_OEMCrypto_DestBufferDesc(msg, NULL); } } void OPK_PackNullable_uint16_t(ODK_Message* msg, const uint16_t* value) { @@ -696,9 +763,11 @@ void OPK_PackNullable_uint16_t(ODK_Message* msg, const uint16_t* value) { } void OPK_UnpackNullable_uint16_t(ODK_Message* msg, uint16_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_uint16_t(msg, *value); + } else { + OPK_Unpack_uint16_t(msg, NULL); } } void OPK_UnpackAlloc_uint16_t(ODK_Message* msg, uint16_t** value) { @@ -715,9 +784,11 @@ void OPK_PackNullable_int64_t(ODK_Message* msg, const int64_t* value) { } void OPK_UnpackNullable_int64_t(ODK_Message* msg, int64_t** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_int64_t(msg, *value); + } else { + OPK_Unpack_int64_t(msg, NULL); } } void OPK_UnpackAlloc_int64_t(ODK_Message* msg, int64_t** value) { @@ -742,9 +813,11 @@ void OPK_PackNullable_int(ODK_Message* msg, const int* value) { } void OPK_UnpackNullable_int(ODK_Message* msg, int** value) { if (OPK_UnpackIsNull(msg)) { - *value = NULL; - } else { + if (value) *value = NULL; + } else if (value) { OPK_Unpack_int(msg, *value); + } else { + OPK_Unpack_int(msg, NULL); } } void OPK_UnpackAlloc_int(ODK_Message* msg, int** value) { diff --git a/oemcrypto/opk/serialization/common/common_special_cases.c b/oemcrypto/opk/serialization/common/common_special_cases.c index edd2019..19d60f2 100644 --- a/oemcrypto/opk/serialization/common/common_special_cases.c +++ b/oemcrypto/opk/serialization/common/common_special_cases.c @@ -62,9 +62,9 @@ void OPK_Pack_OEMCrypto_DestBufferDesc(ODK_Message* message, */ void OPK_Unpack_OEMCrypto_DestBufferDesc(ODK_Message* message, OEMCrypto_DestBufferDesc* obj) { + OEMCrypto_DestBufferDesc temp_destbuf; if (obj == NULL) { - ODK_MESSAGE_SETSTATUS(message, MESSAGE_STATUS_NULL_POINTER_ERROR); - return; + obj = &temp_destbuf; } OPK_Unpack_uint32_t(message, (uint32_t*)&obj->type); switch (obj->type) { diff --git a/oemcrypto/opk/serialization/common/opk_serialization_base.c b/oemcrypto/opk/serialization/common/opk_serialization_base.c index 7fe4e72..7f7bfe9 100644 --- a/oemcrypto/opk/serialization/common/opk_serialization_base.c +++ b/oemcrypto/opk/serialization/common/opk_serialization_base.c @@ -269,11 +269,17 @@ static bool CheckTag(ODK_Message* message, TagType tag) { } void OPK_Unpack_bool(ODK_Message* message, bool* value) { - if (!CheckTag(message, TAG_BOOL)) return; - uint8_t b = 0; - UnpackBytes(message, &b, sizeof(b)); - assert(value); - *value = b ? true : false; + if (!CheckTag(message, TAG_BOOL)) { + OPK_Init_bool(value); + return; + } + if (value) { + uint8_t b = 0; + UnpackBytes(message, &b, sizeof(b)); + *value = b ? true : false; + } else { + UnpackBytes(message, NULL, sizeof(uint8_t)); + } } static uint64_t Unpack64(ODK_Message* message) { @@ -305,52 +311,88 @@ static int64_t UnpackInt64(ODK_Message* message) { } void OPK_Unpack_int(ODK_Message* message, int* value) { - if (!CheckTag(message, TAG_INT)) return; - assert(value); - *value = (int)Unpack64(message); + if (!CheckTag(message, TAG_INT)) { + OPK_Init_int(value); + return; + } + if (value) { + *value = (int)Unpack64(message); + } else { + Unpack64(message); + } } void OPK_Unpack_size_t(ODK_Message* message, size_t* value) { - if (!CheckTag(message, TAG_SIZE_T)) return; - assert(value); - *value = (size_t)Unpack64(message); + if (!CheckTag(message, TAG_SIZE_T)) { + OPK_Init_size_t(value); + return; + } + if (value) { + *value = (size_t)Unpack64(message); + } else { + Unpack64(message); + } } void OPK_Unpack_uint8_t(ODK_Message* message, uint8_t* value) { - if (!CheckTag(message, TAG_UINT8)) return; + if (!CheckTag(message, TAG_UINT8)) { + OPK_Init_uint8_t(value); + return; + } UnpackBytes(message, value, sizeof(*value)); } void OPK_Unpack_uint16_t(ODK_Message* message, uint16_t* value) { - if (!CheckTag(message, TAG_UINT16)) return; - assert(value); - uint8_t buf[sizeof(uint16_t)] = {0}; - UnpackBytes(message, buf, sizeof(buf)); - *value = buf[0]; - *value |= (uint16_t)buf[1] << 8; + if (!CheckTag(message, TAG_UINT16)) { + OPK_Init_uint16_t(value); + return; + } + if (value) { + uint8_t buf[sizeof(uint16_t)] = {0}; + UnpackBytes(message, buf, sizeof(buf)); + *value = buf[0]; + *value |= (uint16_t)buf[1] << 8; + } else { + UnpackBytes(message, NULL, sizeof(uint16_t)); + } } void OPK_Unpack_uint32_t(ODK_Message* message, uint32_t* value) { - if (!CheckTag(message, TAG_UINT32)) return; - assert(value); - uint8_t buf[sizeof(uint32_t)] = {0}; - UnpackBytes(message, buf, sizeof(buf)); - *value = buf[0]; - *value |= (uint32_t)buf[1] << 8; - *value |= (uint32_t)buf[2] << 16; - *value |= (uint32_t)buf[3] << 24; + if (!CheckTag(message, TAG_UINT32)) { + OPK_Init_uint32_t(value); + return; + } + if (value) { + uint8_t buf[sizeof(uint32_t)] = {0}; + UnpackBytes(message, buf, sizeof(buf)); + *value = buf[0]; + *value |= (uint32_t)buf[1] << 8; + *value |= (uint32_t)buf[2] << 16; + *value |= (uint32_t)buf[3] << 24; + } else { + UnpackBytes(message, NULL, sizeof(uint32_t)); + } } void OPK_Unpack_uint64_t(ODK_Message* message, uint64_t* value) { - if (!CheckTag(message, TAG_UINT64)) return; - assert(value); - *value = Unpack64(message); + if (!CheckTag(message, TAG_UINT64)) { + OPK_Init_uint64_t(value); + return; + } + if (value) { + *value = Unpack64(message); + } else { + Unpack64(message); + } } void OPK_Unpack_int64_t(ODK_Message* message, int64_t* value) { if (!CheckTag(message, TAG_INT64)) return; - assert(value); - *value = UnpackInt64(message); + if (value) { + *value = UnpackInt64(message); + } else { + UnpackInt64(message); + } } bool OPK_UnpackBoolValue(ODK_Message* message) { diff --git a/oemcrypto/opk/serialization/os_interfaces/tos_transport_interface.h b/oemcrypto/opk/serialization/os_interfaces/tos_transport_interface.h index 0f448ed..7e3087a 100644 --- a/oemcrypto/opk/serialization/os_interfaces/tos_transport_interface.h +++ b/oemcrypto/opk/serialization/os_interfaces/tos_transport_interface.h @@ -88,7 +88,7 @@ typedef enum { * This is the required size for OPK messages. It is predefined so * implementations can statically allocate the buffer. */ -#define OPK_TRANSPORT_MESSAGE_SIZE (32 * 1024) +#define OPK_TRANSPORT_MESSAGE_SIZE (34 * 1024) /** * Initialize the transport interface implementation. It is called by diff --git a/oemcrypto/opk/serialization/ree/GEN_oemcrypto_api.c b/oemcrypto/opk/serialization/ree/GEN_oemcrypto_api.c index 457c337..48db966 100644 --- a/oemcrypto/opk/serialization/ree/GEN_oemcrypto_api.c +++ b/oemcrypto/opk/serialization/ree/GEN_oemcrypto_api.c @@ -3168,3 +3168,38 @@ cleanup_and_return: pthread_mutex_unlock(&api_lock); return result; } + +OEMCRYPTO_API OEMCryptoResult OEMCrypto_GetEmbeddedDrmCertificate( + uint8_t* public_cert, size_t* public_cert_length) { + pthread_mutex_lock(&api_lock); + OEMCryptoResult result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + ODK_Message request = ODK_Message_Create(NULL, 0); + ODK_Message response = ODK_Message_Create(NULL, 0); + + API_Initialize(); + request = OPK_Pack_GetEmbeddedDrmCertificate_Request(public_cert, + public_cert_length); + if (ODK_Message_GetStatus(&request) != MESSAGE_STATUS_OK) { + if (ODK_Message_GetStatus(&request) == MESSAGE_STATUS_BUFFER_TOO_LARGE) { + api_result = OEMCrypto_ERROR_BUFFER_TOO_LARGE; + } else { + api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + } + goto cleanup_and_return; + } + response = API_Transact(&request); + if (api_result != OEMCrypto_SUCCESS) goto cleanup_and_return; + OPK_Unpack_GetEmbeddedDrmCertificate_Response( + &response, &result, &public_cert, &public_cert_length); + + if (ODK_Message_GetStatus(&response) != MESSAGE_STATUS_OK) { + api_result = OEMCrypto_ERROR_UNKNOWN_FAILURE; + } +cleanup_and_return: + TOS_Transport_ReleaseMessage(&request); + TOS_Transport_ReleaseMessage(&response); + + result = API_CheckResult(result); + pthread_mutex_unlock(&api_lock); + return result; +} diff --git a/oemcrypto/opk/serialization/ree/GEN_ree_serializer.c b/oemcrypto/opk/serialization/ree/GEN_ree_serializer.c index 60222cc..aa90b54 100644 --- a/oemcrypto/opk/serialization/ree/GEN_ree_serializer.c +++ b/oemcrypto/opk/serialization/ree/GEN_ree_serializer.c @@ -216,7 +216,11 @@ void OPK_Unpack_OpenSession_Response(ODK_Message* msg, OEMCryptoResult* result, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, session); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, session); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -278,7 +282,11 @@ void OPK_Unpack_GenerateNonce_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, nonce); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, nonce); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -658,7 +666,11 @@ void OPK_Unpack_CreateEntitledKeySession_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, key_session); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, key_session); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1318,11 +1330,15 @@ void OPK_Unpack_GetBCCType_Response(ODK_Message* msg, OEMCryptoResult* result, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, bcc_type); - if (*bcc_type) { - if (!Is_Valid_OEMCrypto_BCCType(**bcc_type)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, bcc_type); + if (*bcc_type) { + if (!Is_Valid_OEMCrypto_BCCType(**bcc_type)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } } + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); } OPK_UnpackEOM(msg); @@ -1696,17 +1712,25 @@ void OPK_Unpack_GetHDCPCapability_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, current); - if (*current) { - if (!Is_Valid_OEMCrypto_HDCP_Capability(**current)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, current); + if (*current) { + if (!Is_Valid_OEMCrypto_HDCP_Capability(**current)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } } + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); } - OPK_UnpackNullable_uint32_t(msg, maximum); - if (*maximum) { - if (!Is_Valid_OEMCrypto_HDCP_Capability(**maximum)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, maximum); + if (*maximum) { + if (!Is_Valid_OEMCrypto_HDCP_Capability(**maximum)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } } + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); } OPK_UnpackEOM(msg); @@ -1739,11 +1763,15 @@ void OPK_Unpack_GetDTCP2Capability_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, capability); - if (*capability) { - if (!Is_Valid_OEMCrypto_DTCP2_Capability(**capability)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, capability); + if (*capability) { + if (!Is_Valid_OEMCrypto_DTCP2_Capability(**capability)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } } + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); } OPK_UnpackEOM(msg); @@ -1840,7 +1868,11 @@ void OPK_Unpack_GetNumberOfOpenSessions_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_size_t(msg, count); + if (SuccessResult(*result)) { + OPK_UnpackNullable_size_t(msg, count); + } else { + OPK_UnpackNullable_size_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1871,7 +1903,11 @@ void OPK_Unpack_GetMaxNumberOfSessions_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_size_t(msg, max); + if (SuccessResult(*result)) { + OPK_UnpackNullable_size_t(msg, max); + } else { + OPK_UnpackNullable_size_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -1924,7 +1960,11 @@ void OPK_Unpack_GetCurrentSRMVersion_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint16_t(msg, version); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint16_t(msg, version); + } else { + OPK_UnpackNullable_uint16_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -2055,11 +2095,15 @@ void OPK_Unpack_GetSignatureHashAlgorithm_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, algorithm); - if (*algorithm) { - if (!Is_Valid_OEMCrypto_SignatureHashAlgorithm(**algorithm)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, algorithm); + if (*algorithm) { + if (!Is_Valid_OEMCrypto_SignatureHashAlgorithm(**algorithm)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } } + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); } OPK_UnpackEOM(msg); @@ -2450,7 +2494,11 @@ void OPK_Unpack_CreateNewUsageEntry_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, usage_entry_number); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, usage_entry_number); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -2687,14 +2735,26 @@ void OPK_Unpack_GetUsageEntryInfo_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, status); - if (*status) { - if (!Is_Valid_OEMCrypto_Usage_Entry_Status(**status)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, status); + if (*status) { + if (!Is_Valid_OEMCrypto_Usage_Entry_Status(**status)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } } + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_int64_t(msg, seconds_since_license_received); + } else { + OPK_UnpackNullable_int64_t(msg, NULL); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_int64_t(msg, seconds_since_first_decrypt); + } else { + OPK_UnpackNullable_int64_t(msg, NULL); } - OPK_UnpackNullable_int64_t(msg, seconds_since_license_received); - OPK_UnpackNullable_int64_t(msg, seconds_since_first_decrypt); OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -2895,11 +2955,15 @@ void OPK_Unpack_GenerateCertificateKeyPair_Response( OPK_SafeDerefSizeTPtrPtr(wrapped_private_key_length)); } } - OPK_UnpackNullable_uint32_t(msg, key_type); - if (*key_type) { - if (!Is_Valid_OEMCrypto_PrivateKeyType(**key_type)) { - ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, key_type); + if (*key_type) { + if (!Is_Valid_OEMCrypto_PrivateKeyType(**key_type)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } } + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); } OPK_UnpackEOM(msg); @@ -3142,7 +3206,11 @@ void OPK_Unpack_GetHashErrorCode_Response(ODK_Message* msg, if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_uint32_t(msg, failed_frame_number); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, failed_frame_number); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -3178,8 +3246,16 @@ void OPK_Unpack_AllocateSecureBuffer_Response( if (!Is_Valid_OEMCryptoResult(*result)) { ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); } - OPK_UnpackNullable_OEMCrypto_DestBufferDesc(msg, output_descriptor); - OPK_UnpackNullable_int(msg, secure_fd); + if (SuccessResult(*result)) { + OPK_UnpackNullable_OEMCrypto_DestBufferDesc(msg, output_descriptor); + } else { + OPK_UnpackNullable_OEMCrypto_DestBufferDesc(msg, NULL); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_int(msg, secure_fd); + } else { + OPK_UnpackNullable_int(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -3196,7 +3272,7 @@ ODK_Message OPK_Pack_FreeSecureBuffer_Request( uint64_t timestamp = time(0); OPK_Pack_uint64_t(&msg, ×tamp); OPK_Pack_uint32_t(&msg, &session); - OPK_PackIsNull(&msg, output_descriptor); + OPK_PackNullable_OEMCrypto_DestBufferDesc(&msg, output_descriptor); OPK_Pack_int(&msg, &secure_fd); OPK_PackEOM(&msg); OPK_SharedBuffer_FinalizePacking(); @@ -3252,8 +3328,16 @@ void OPK_Unpack_OPK_SerializationVersion_Response( } OPK_UnpackNullable_uint32_t(msg, ree_major); OPK_UnpackNullable_uint32_t(msg, ree_minor); - OPK_UnpackNullable_uint32_t(msg, tee_major); - OPK_UnpackNullable_uint32_t(msg, tee_minor); + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, tee_major); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } + if (SuccessResult(*result)) { + OPK_UnpackNullable_uint32_t(msg, tee_minor); + } else { + OPK_UnpackNullable_uint32_t(msg, NULL); + } OPK_UnpackEOM(msg); if (SuccessResult(*result)) { @@ -3340,3 +3424,43 @@ void OPK_Unpack_ProcessOTAKeybox_Response(ODK_Message* msg, OPK_SharedBuffer_FinalizeUnpacking(); } } + +ODK_Message OPK_Pack_GetEmbeddedDrmCertificate_Request( + const uint8_t* public_cert, const size_t* public_cert_length) { + uint32_t api_value = 151; /* from _oecc151 */ + ODK_Message msg = TOS_Transport_GetRequest(); + OPK_Pack_uint32_t(&msg, &api_value); + uint64_t timestamp = time(0); + OPK_Pack_uint64_t(&msg, ×tamp); + OPK_PackNullable_size_t(&msg, public_cert_length); + OPK_PackAlloc(&msg, public_cert); + OPK_PackEOM(&msg); + OPK_SharedBuffer_FinalizePacking(); + return msg; +} + +void OPK_Unpack_GetEmbeddedDrmCertificate_Response( + ODK_Message* msg, OEMCryptoResult* result, uint8_t** public_cert, + size_t** public_cert_length) { + uint32_t api_value = UINT32_MAX; + OPK_Unpack_uint32_t(msg, &api_value); + if (api_value != 151) + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); + OPK_UnpackNullable_size_t(msg, public_cert_length); + OPK_Unpack_uint32_t(msg, result); + if (!Is_Valid_OEMCryptoResult(*result)) { + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_INVALID_ENUM_VALUE); + } + if (SuccessResult(*result)) { + uint8_t* p; + OPK_UnpackInPlace(msg, &p, OPK_FromSizeTPtrPtr(public_cert_length)); + if (p && *public_cert) { + memcpy(*public_cert, p, OPK_SafeDerefSizeTPtrPtr(public_cert_length)); + } + } + OPK_UnpackEOM(msg); + + if (SuccessResult(*result)) { + OPK_SharedBuffer_FinalizeUnpacking(); + } +} diff --git a/oemcrypto/opk/serialization/ree/GEN_ree_serializer.h b/oemcrypto/opk/serialization/ree/GEN_ree_serializer.h index 4f739c9..d763086 100644 --- a/oemcrypto/opk/serialization/ree/GEN_ree_serializer.h +++ b/oemcrypto/opk/serialization/ree/GEN_ree_serializer.h @@ -483,6 +483,12 @@ ODK_Message OPK_Pack_ProcessOTAKeybox_Request(OEMCrypto_SESSION session, uint32_t use_test_key); void OPK_Unpack_ProcessOTAKeybox_Response(ODK_Message* msg, OEMCryptoResult* result); +ODK_Message OPK_Pack_GetEmbeddedDrmCertificate_Request( + const uint8_t* public_cert, const size_t* public_cert_length); +void OPK_Unpack_GetEmbeddedDrmCertificate_Response(ODK_Message* msg, + OEMCryptoResult* result, + uint8_t** public_cert, + size_t** public_cert_length); #ifdef __cplusplus } // extern "C" #endif diff --git a/oemcrypto/opk/serialization/tee/GEN_dispatcher.c b/oemcrypto/opk/serialization/tee/GEN_dispatcher.c index bb74672..14b58e7 100644 --- a/oemcrypto/opk/serialization/tee/GEN_dispatcher.c +++ b/oemcrypto/opk/serialization/tee/GEN_dispatcher.c @@ -83,7 +83,7 @@ void OPK_Init_OEMCrypto_KeyObject(OEMCrypto_KeyObject* obj) { void OPK_Init_OEMCrypto_InputOutputPair(OEMCrypto_InputOutputPair* obj) { OPK_Init_size_t((size_t*)&obj->input_data_length); - OEMCrypto_SharedMemory* input_data; + OEMCrypto_SharedMemory* input_data = NULL; input_data = (OEMCrypto_SharedMemory*)OPK_VarAlloc(obj->input_data_length); OPK_InitMemory((uint8_t*)input_data, obj->input_data_length); OPK_Init_OEMCrypto_DestBufferDesc( @@ -103,7 +103,7 @@ void OPK_Init_OEMCrypto_SampleDescription(OEMCrypto_SampleDescription* obj) { OPK_Init_size_t((size_t*)&obj->subsamples_length); OPK_Init_OEMCrypto_InputOutputPair((OEMCrypto_InputOutputPair*)&obj->buffers); OPK_InitMemory(&obj->iv[0], 16); - OEMCrypto_SubSampleDescription* subsamples; + OEMCrypto_SubSampleDescription* subsamples = NULL; subsamples = (OEMCrypto_SubSampleDescription*)OPK_VarAlloc( obj->subsamples_length * sizeof(OEMCrypto_SubSampleDescription)); if (subsamples) { @@ -1796,8 +1796,10 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, { OEMCrypto_SESSION session; OPK_Init_uint32_t((uint32_t*)&session); - OEMCrypto_DestBufferDesc* output_descriptor; - OPK_InitPointer((uint8_t**)&output_descriptor); + OEMCrypto_DestBufferDesc* output_descriptor = + (OEMCrypto_DestBufferDesc*)OPK_VarAlloc( + sizeof(OEMCrypto_DestBufferDesc)); + OPK_Init_OEMCrypto_DestBufferDesc(output_descriptor); int secure_fd; OPK_Init_int((int*)&secure_fd); OPK_Unpack_FreeSecureBuffer_Request(request, &session, &output_descriptor, @@ -1876,6 +1878,24 @@ ODK_MessageStatus OPK_DispatchMessage(ODK_Message* request, *response = OPK_Pack_ProcessOTAKeybox_Response(result); break; } + case 151: /* OEMCrypto_GetEmbeddedDrmCertificate */ + { + size_t* public_cert_length = (size_t*)OPK_VarAlloc(sizeof(size_t)); + OPK_Init_size_t(public_cert_length); + uint8_t* public_cert; + OPK_InitPointer((uint8_t**)&public_cert); + OPK_Unpack_GetEmbeddedDrmCertificate_Request(request, &public_cert, + &public_cert_length); + if (!ODK_Message_IsValid(request)) goto handle_invalid_request; + OEMCryptoResult result; + OPK_Init_uint32_t((uint32_t*)&result); + LOGD("GetEmbeddedDrmCertificate"); + result = + OEMCrypto_GetEmbeddedDrmCertificate(public_cert, public_cert_length); + *response = OPK_Pack_GetEmbeddedDrmCertificate_Response( + result, public_cert, public_cert_length); + break; + } default: return MESSAGE_STATUS_API_VALUE_ERROR; } diff --git a/oemcrypto/opk/serialization/tee/GEN_tee_serializer.c b/oemcrypto/opk/serialization/tee/GEN_tee_serializer.c index f385449..82eba68 100644 --- a/oemcrypto/opk/serialization/tee/GEN_tee_serializer.c +++ b/oemcrypto/opk/serialization/tee/GEN_tee_serializer.c @@ -2666,8 +2666,7 @@ void OPK_Unpack_FreeSecureBuffer_Request( uint64_t timestamp; OPK_Unpack_uint64_t(msg, ×tamp); OPK_Unpack_uint32_t(msg, session); - *output_descriptor = (OEMCrypto_DestBufferDesc*)OPK_UnpackAlloc( - msg, sizeof(OEMCrypto_DestBufferDesc)); + OPK_UnpackNullable_OEMCrypto_DestBufferDesc(msg, output_descriptor); OPK_Unpack_int(msg, secure_fd); OPK_UnpackEOM(msg); OPK_SharedBuffer_FinalizeUnpacking(); @@ -2786,3 +2785,36 @@ ODK_Message OPK_Pack_ProcessOTAKeybox_Response(OEMCryptoResult result) { OPK_SharedBuffer_FinalizePacking(); return msg; } + +void OPK_Unpack_GetEmbeddedDrmCertificate_Request(ODK_Message* msg, + uint8_t** public_cert, + size_t** public_cert_length) { + uint32_t api_value = UINT32_MAX; + OPK_Unpack_uint32_t(msg, &api_value); + if (api_value != 151) + ODK_MESSAGE_SETSTATUS(msg, MESSAGE_STATUS_API_VALUE_ERROR); + uint64_t timestamp; + OPK_Unpack_uint64_t(msg, ×tamp); + OPK_UnpackNullable_size_t(msg, public_cert_length); + *public_cert = (uint8_t*)OPK_UnpackAllocBuffer( + msg, OPK_FromSizeTPtrPtr(public_cert_length), sizeof(uint8_t)); + OPK_UnpackEOM(msg); + OPK_SharedBuffer_FinalizeUnpacking(); +} + +ODK_Message OPK_Pack_GetEmbeddedDrmCertificate_Response( + OEMCryptoResult result, const uint8_t* public_cert, + const size_t* public_cert_length) { + uint32_t api_value = 151; /* from _oecc151 */ + ODK_Message msg = TOS_Transport_GetResponse(); + OPK_Pack_uint32_t(&msg, &api_value); + OPK_PackNullable_size_t(&msg, public_cert_length); + OPK_Pack_uint32_t(&msg, &result); + if (SuccessResult(result)) { + OPK_PackMemory(&msg, (const uint8_t*)public_cert, + OPK_FromSizeTPtr(public_cert_length)); + } + OPK_PackEOM(&msg); + OPK_SharedBuffer_FinalizePacking(); + return msg; +} diff --git a/oemcrypto/opk/serialization/tee/GEN_tee_serializer.h b/oemcrypto/opk/serialization/tee/GEN_tee_serializer.h index c3efd54..2cdd351 100644 --- a/oemcrypto/opk/serialization/tee/GEN_tee_serializer.h +++ b/oemcrypto/opk/serialization/tee/GEN_tee_serializer.h @@ -467,6 +467,12 @@ void OPK_Unpack_ProcessOTAKeybox_Request(ODK_Message* msg, size_t* buffer_length, uint32_t* use_test_key); ODK_Message OPK_Pack_ProcessOTAKeybox_Response(OEMCryptoResult result); +void OPK_Unpack_GetEmbeddedDrmCertificate_Request(ODK_Message* msg, + uint8_t** public_cert, + size_t** public_cert_length); +ODK_Message OPK_Pack_GetEmbeddedDrmCertificate_Response( + OEMCryptoResult result, const uint8_t* public_cert, + const size_t* public_cert_length); #ifdef __cplusplus } // extern "C" #endif diff --git a/oemcrypto/test/GEN_api_lock_file.c b/oemcrypto/test/GEN_api_lock_file.c index b796610..1822df9 100644 --- a/oemcrypto/test/GEN_api_lock_file.c +++ b/oemcrypto/test/GEN_api_lock_file.c @@ -419,3 +419,9 @@ OEMCryptoResult _oecc148(OEMCrypto_SESSION session, // OEMCrypto_SetDecryptHash defined in v19.0 OEMCryptoResult _oecc143(OEMCrypto_SESSION session, uint32_t frame_number, uint32_t crc32); + +// OEMCrypto_GetEmbeddedDrmCertificate defined in v19.1 +OEMCryptoResult _oecc151(uint8_t* public_cert, size_t* public_cert_length); + +// OEMCrypto_UseSecondaryKey defined in v19.1 +OEMCryptoResult _oecc152(OEMCrypto_SESSION session_id, bool dual_key); diff --git a/oemcrypto/test/common.mk b/oemcrypto/test/common.mk index 48420a1..054127c 100644 --- a/oemcrypto/test/common.mk +++ b/oemcrypto/test/common.mk @@ -28,8 +28,12 @@ LOCAL_SRC_FILES:= \ oemcrypto_test_main.cpp \ ota_keybox_test.cpp \ ../../cdm/util/test/test_sleep.cpp \ + ../util/src/bcc_validator.cpp \ + ../util/src/cbor_validator.cpp \ + ../util/src/device_info_validator.cpp \ ../util/src/oemcrypto_ecc_key.cpp \ ../util/src/oemcrypto_rsa_key.cpp \ + ../util/src/signed_csr_payload_validator.cpp \ ../util/src/wvcrc.cpp \ LOCAL_C_INCLUDES += \ @@ -58,6 +62,7 @@ LOCAL_STATIC_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \ libbase \ + libcppbor_external \ libcrypto \ libdl \ libbinder_ndk \ diff --git a/oemcrypto/test/fuzz_tests/oemcrypto_fuzz_helper.cc b/oemcrypto/test/fuzz_tests/oemcrypto_fuzz_helper.cc index 50929b1..112f353 100644 --- a/oemcrypto/test/fuzz_tests/oemcrypto_fuzz_helper.cc +++ b/oemcrypto/test/fuzz_tests/oemcrypto_fuzz_helper.cc @@ -46,7 +46,6 @@ void SessionFuzz::Terminate() { void OEMCryptoLicenseAPIFuzz::Initialize() { session_fuzz_.Initialize(); session_fuzz_.InstallTestDrmKey(); - session_fuzz_.session().GenerateNonce(); } void OEMCryptoLicenseAPIFuzz::Terminate() { diff --git a/oemcrypto/test/oec_device_features.cpp b/oemcrypto/test/oec_device_features.cpp index 5047a39..0bd759f 100644 --- a/oemcrypto/test/oec_device_features.cpp +++ b/oemcrypto/test/oec_device_features.cpp @@ -151,6 +151,7 @@ void DeviceFeatures::PickDerivedKey() { derive_key_method = TEST_PROVISION_30; return; case OEMCrypto_DrmCertificate: + case OEMCrypto_DrmReprovisioning: if (OEMCrypto_ERROR_NOT_IMPLEMENTED != OEMCrypto_LoadTestRSAKey()) { derive_key_method = LOAD_TEST_RSA_KEY; } @@ -237,6 +238,8 @@ const char* ProvisioningMethodName(OEMCrypto_ProvisioningMethod method) { return "OEMCrypto_OEMCertificate"; case OEMCrypto_BootCertificateChain: return "OEMCrypto_BootCertificateChain"; + case OEMCrypto_DrmReprovisioning: + return "OEMCrypto_DrmReprovisioning"; } // Not reachable return ""; diff --git a/oemcrypto/test/oec_session_util.cpp b/oemcrypto/test/oec_session_util.cpp index 42eadd5..519ae37 100644 --- a/oemcrypto/test/oec_session_util.cpp +++ b/oemcrypto/test/oec_session_util.cpp @@ -114,7 +114,6 @@ OEMCryptoResult DecryptCTR(const vector& key_handle, } // namespace - // Encrypt a block of data using CTR mode. void EncryptCTR(const vector& in_buffer, const uint8_t* key, const uint8_t* starting_iv, vector* out_buffer) { @@ -219,9 +218,12 @@ class boringssl_ptr { Test_PST_Report::Test_PST_Report(const std::string& pst_in, OEMCrypto_Usage_Entry_Status status_in) - : status(status_in), pst(pst_in) { - time_created = wvutil::Clock().GetCurrentTime(); -} + : status(status_in), + seconds_since_license_received(0), + seconds_since_first_decrypt(0), + seconds_since_last_decrypt(0), + pst(pst_in), + time_created(wvutil::Clock().GetCurrentTime()) {} template @@ -583,12 +585,12 @@ void Provisioning40RoundTrip::PrepareSession(bool is_oem_key) { public_key.resize(public_key_size); if (is_oem_key) { - wrapped_oem_key_ = wrapped_private_key; - oem_public_key_ = public_key; + wrapped_oem_key_ = std::move(wrapped_private_key); + oem_public_key_ = std::move(public_key); oem_key_type_ = key_type; } else { - wrapped_drm_key_ = wrapped_private_key; - drm_public_key_ = public_key; + wrapped_drm_key_ = std::move(wrapped_private_key); + drm_public_key_ = std::move(public_key); drm_key_type_ = key_type; } } @@ -644,8 +646,8 @@ void Provisioning40CastRoundTrip::PrepareSession() { wrapped_private_key.resize(wrapped_private_key_size); public_key.resize(public_key_size); - wrapped_drm_key_ = wrapped_private_key; - drm_public_key_ = public_key; + wrapped_drm_key_ = std::move(wrapped_private_key); + drm_public_key_ = std::move(public_key); drm_key_type_ = key_type; } @@ -1264,11 +1266,11 @@ void EntitledMessage::MakeOneKey(size_t entitlement_key_index) { offsets->content_key_data_iv = FindSubstring( key_data->content_key_data_iv, sizeof(key_data->content_key_data_iv)); - EXPECT_EQ(1, GetRandBytes(key_data->content_iv, - sizeof(key_data->content_iv))); + EXPECT_EQ(1, + GetRandBytes(key_data->content_iv, sizeof(key_data->content_iv))); key_data->content_iv_length = sizeof(key_data->content_iv); - offsets->content_iv = FindSubstring( - key_data->content_iv, key_data->content_iv_length); + offsets->content_iv = + FindSubstring(key_data->content_iv, key_data->content_iv_length); } OEMCrypto_EntitledContentKeyObject* EntitledMessage::entitled_key_array() { @@ -1412,13 +1414,15 @@ void EntitledMessage::LoadCasKeys(bool load_even, bool load_odd, even_key.content_key_data_iv = entitled_key_array_[0].content_key_data_iv; even_key.content_key_data = entitled_key_array_[0].content_key_data; even_key.content_iv = entitled_key_array_[0].content_iv; + even_key.cipher_mode = OEMCrypto_CipherMode_CBC; } if (has_odd) { odd_key.entitlement_key_id = entitled_key_array_[1].entitlement_key_id; odd_key.content_key_id = entitled_key_array_[1].content_key_id; odd_key.content_key_data_iv = entitled_key_array_[1].content_key_data_iv; odd_key.content_key_data = entitled_key_array_[1].content_key_data; - even_key.content_iv = entitled_key_array_[1].content_iv; + odd_key.content_iv = entitled_key_array_[1].content_iv; + odd_key.cipher_mode = OEMCrypto_CipherMode_CBC; } OEMCryptoResult sts = OEMCrypto_LoadCasECMKeys( @@ -1499,6 +1503,7 @@ void EntitledMessage::VerifyDecrypt() { void RenewalRoundTrip::VerifyRequestSignature( const vector& data, const vector& generated_signature, size_t core_message_length) { + (void)core_message_length; ASSERT_EQ(HMAC_SHA256_SIGNATURE_SIZE, generated_signature.size()); std::vector expected_signature; session()->key_deriver().ClientSignBuffer(data, &expected_signature); @@ -1604,7 +1609,7 @@ OEMCryptoResult RenewalRoundTrip::LoadResponse(Session* session) { GetFileName("oemcrypto_load_renewal_fuzz_seed_corpus"); // Corpus for renewal response fuzzer should be in the format: // OEMCrypto_Renewal_Response_Fuzz + license_renewal_response. - OEMCrypto_Renewal_Response_Fuzz renewal_response_fuzz; + OEMCrypto_Renewal_Response_Fuzz renewal_response_fuzz = {}; renewal_response_fuzz.core_request = core_request_; renewal_response_fuzz.renewal_duration_seconds = renewal_duration_seconds_; AppendToFile(file_name, @@ -1624,6 +1629,7 @@ OEMCryptoResult RenewalRoundTrip::LoadResponse(Session* session) { void ReleaseRoundTrip::VerifyRequestSignature( const vector& data, const vector& generated_signature, size_t core_message_length) { + (void)core_message_length; ASSERT_EQ(HMAC_SHA256_SIGNATURE_SIZE, generated_signature.size()); std::vector expected_signature; session()->key_deriver().ClientSignBuffer(data, &expected_signature); @@ -1942,7 +1948,6 @@ void Session::LoadOEMCert(bool verify_cert) { util::RsaPublicKey::FromSslHandle(EVP_PKEY_get0_RSA(pubkey.get())); ASSERT_TRUE(public_rsa_) << "Failed to extract public RSA key from OEM certificate"; - return; } if (verify_cert) { vector buffer(80); diff --git a/oemcrypto/test/oec_session_util.h b/oemcrypto/test/oec_session_util.h index a8085a7..75204d5 100644 --- a/oemcrypto/test/oec_session_util.h +++ b/oemcrypto/test/oec_session_util.h @@ -337,9 +337,10 @@ class Provisioning40RoundTrip // Not used. Use Load*CertResponse() below to load OEM/DRM response // respectively. - void CreateDefaultResponse() override{}; - void EncryptAndSignResponse() override{}; + void CreateDefaultResponse() override {}; + void EncryptAndSignResponse() override {}; OEMCryptoResult LoadResponse(Session* session) override { + (void)session; return OEMCrypto_ERROR_NOT_IMPLEMENTED; } @@ -382,8 +383,10 @@ class Provisioning40CastRoundTrip /* ResponseData */ RSAPrivateKeyMessage> { public: Provisioning40CastRoundTrip(Session* session, - const std::vector& encoded_rsa_key) - : RoundTrip(session), encryptor_(), + const std::vector& encoded_rsa_key) + : RoundTrip(session), + allowed_schemes_(kSign_RSASSA_PSS), + encryptor_(), encoded_rsa_key_(encoded_rsa_key) {} void PrepareSession(); @@ -393,7 +396,8 @@ class Provisioning40CastRoundTrip void EncryptAndSignResponse() override; OEMCryptoResult LoadResponse() override { return LoadResponse(session_); } OEMCryptoResult LoadResponse(Session* session) override; - OEMCryptoResult LoadResponseNoRetry(Session* session, size_t* wrapped_key_length) ; + OEMCryptoResult LoadResponseNoRetry(Session* session, + size_t* wrapped_key_length); // Returned const std::vector& wrapped_drm_key() { return wrapped_drm_key_; } diff --git a/oemcrypto/test/oemcrypto_basic_test.cpp b/oemcrypto/test/oemcrypto_basic_test.cpp index e4239de..0d66926 100644 --- a/oemcrypto/test/oemcrypto_basic_test.cpp +++ b/oemcrypto/test/oemcrypto_basic_test.cpp @@ -159,7 +159,7 @@ std::string GetDeviceId() { TEST_F(OEMCryptoClientTest, FreeUnallocatedSecureBufferNoFailure) { Session s; s.open(); - OEMCrypto_DestBufferDesc output_descriptor; + OEMCrypto_DestBufferDesc output_descriptor = {}; int secure_fd = kHugeRandomNumber; ASSERT_NE(OEMCrypto_SUCCESS, OEMCrypto_FreeSecureBuffer(s.session_id(), &output_descriptor, @@ -180,7 +180,7 @@ TEST_F(OEMCryptoClientTest, FreeUnallocatedSecureBufferNoFailure) { */ TEST_F(OEMCryptoClientTest, VersionNumber) { const std::string log_message = - "OEMCrypto unit tests for API 19.0. Tests last updated 2023-12-14"; + "OEMCrypto unit tests for API 19.1. Tests last updated 2024-03-25"; cout << " " << log_message << "\n"; cout << " " << "These tests are part of Android U." @@ -189,7 +189,7 @@ TEST_F(OEMCryptoClientTest, VersionNumber) { // If any of the following fail, then it is time to update the log message // above. EXPECT_EQ(ODK_MAJOR_VERSION, 19); - EXPECT_EQ(ODK_MINOR_VERSION, 0); + EXPECT_EQ(ODK_MINOR_VERSION, 1); EXPECT_EQ(kCurrentAPI, static_cast(ODK_MAJOR_VERSION)); OEMCrypto_Security_Level level = OEMCrypto_SecurityLevel(); EXPECT_GT(level, OEMCrypto_Level_Unknown); @@ -365,7 +365,7 @@ TEST_F(OEMCryptoClientTest, CheckJsonBuildInformationAPI18) { // check for existence in map // check if value matches expectation // remove from map - for (int i = 0; i < jsmn_result; i++) { + for (int32_t i = 0; i < jsmn_result; i++) { jsmntok_t token = tokens[i]; std::string key = build_info.substr(token.start, token.end - token.start); if (expected.find(key) != expected.end()) { @@ -378,7 +378,7 @@ TEST_F(OEMCryptoClientTest, CheckJsonBuildInformationAPI18) { // if map is not empty, return false if (expected.size() > 0) { std::string missing; - for (auto e : expected) { + for (const auto& e : expected) { missing.append(e.first); missing.append(" "); } diff --git a/oemcrypto/test/oemcrypto_cast_test.h b/oemcrypto/test/oemcrypto_cast_test.h index a90c6b5..3317fb7 100644 --- a/oemcrypto/test/oemcrypto_cast_test.h +++ b/oemcrypto/test/oemcrypto_cast_test.h @@ -53,6 +53,9 @@ class OEMCryptoLoadsCertificateAlternates : public OEMCryptoLoadsCertificate { // If force is true, we assert that the key loads successfully. void LoadCastCertificateKey(bool force) { + if (!wvoec::global_features.cast_receiver) { + GTEST_SKIP() << "Cast not supported"; + } // Padding scheme used to sign cast data. constexpr uint32_t schemes = kSign_PKCS1_Block1; // prov 2 or prov 3 diff --git a/oemcrypto/test/oemcrypto_decrypt_test.cpp b/oemcrypto/test/oemcrypto_decrypt_test.cpp index 2d3cef6..6e7a49a 100644 --- a/oemcrypto/test/oemcrypto_decrypt_test.cpp +++ b/oemcrypto/test/oemcrypto_decrypt_test.cpp @@ -460,7 +460,7 @@ TEST_P(OEMCryptoSessionTestsDecryptTests, DecryptMaxSampleAPI16) { subsample_sizes.push_back({clear_size, encrypted_size}); bytes_remaining -= this_subsample_size; } - ASSERT_NO_FATAL_FAILURE(SetSubsampleSizes(subsample_sizes)); + ASSERT_NO_FATAL_FAILURE(SetSubsampleSizes(std::move(subsample_sizes))); ASSERT_NO_FATAL_FAILURE(LoadLicense()); ASSERT_NO_FATAL_FAILURE(MakeBuffers()); ASSERT_NO_FATAL_FAILURE(EncryptData()); @@ -474,7 +474,7 @@ TEST_P(OEMCryptoSessionTestsDecryptTests, while (number_of_subsamples-- > 0) { subsample_sizes.push_back({100, 100}); } - SetSubsampleSizes(subsample_sizes); + SetSubsampleSizes(std::move(subsample_sizes)); LoadLicense(); MakeBuffers(); EncryptData(); @@ -498,7 +498,7 @@ TEST_P(OEMCryptoSessionTestsDecryptTests, OEMCryptoMemoryCheckDecryptCENCStatusForHugeSubSample) { std::vector subsample_sizes; subsample_sizes.push_back({100000, 100000}); - SetSubsampleSizes(subsample_sizes); + SetSubsampleSizes(std::move(subsample_sizes)); LoadLicense(); MakeBuffers(); EncryptData(); diff --git a/oemcrypto/test/oemcrypto_decrypt_test.h b/oemcrypto/test/oemcrypto_decrypt_test.h index 9cd4b00..9c0e135 100644 --- a/oemcrypto/test/oemcrypto_decrypt_test.h +++ b/oemcrypto/test/oemcrypto_decrypt_test.h @@ -120,7 +120,7 @@ class OEMCryptoSessionTestsDecryptTests void SetSubsampleSizes(std::vector subsample_sizes) { // This is just sugar for having one sample with the given subsamples in it. - SetSampleSizes({subsample_sizes}); + SetSampleSizes({std::move(subsample_sizes)}); } void SetSampleSizes(std::vector> sample_sizes) { diff --git a/oemcrypto/test/oemcrypto_generic_crypto_test.cpp b/oemcrypto/test/oemcrypto_generic_crypto_test.cpp index 3ad1011..241c6dc 100644 --- a/oemcrypto/test/oemcrypto_generic_crypto_test.cpp +++ b/oemcrypto/test/oemcrypto_generic_crypto_test.cpp @@ -125,12 +125,12 @@ TEST_P(OEMCryptoGenericCryptoTest, GenericKeyDecryptSameBufferAPI12) { session_.license().keys[key_index].key_id, session_.license().keys[key_index].key_id_length, OEMCrypto_CipherMode_CENC, key_handle)); - vector buffer = encrypted; + vector resultant(encrypted.size()); ASSERT_EQ(OEMCrypto_SUCCESS, - GenericDecrypt(key_handle.data(), key_handle.size(), buffer.data(), - buffer.size(), iv_, OEMCrypto_AES_CBC_128_NO_PADDING, - buffer.data())); - ASSERT_EQ(clear_buffer_, buffer); + GenericDecrypt(key_handle.data(), key_handle.size(), + encrypted.data(), encrypted.size(), iv_, + OEMCrypto_AES_CBC_128_NO_PADDING, resultant.data())); + ASSERT_EQ(clear_buffer_, resultant); } /** Test that Generic_Decrypt fails to decrypt to an insecure buffer if the key diff --git a/oemcrypto/test/oemcrypto_license_test.h b/oemcrypto/test/oemcrypto_license_test.h index 1c0bac8..e80c22c 100644 --- a/oemcrypto/test/oemcrypto_license_test.h +++ b/oemcrypto/test/oemcrypto_license_test.h @@ -329,7 +329,7 @@ class LicenseWithUsageEntry { ASSERT_NO_FATAL_FAILURE(session_.GenerateReport(pst())); Test_PST_Report expected(pst(), status); ASSERT_NO_FATAL_FAILURE( - session_.VerifyReport(expected, time_license_received_, + session_.VerifyReport(std::move(expected), time_license_received_, time_first_decrypt_, time_last_decrypt_)); // The PST report was signed above. Below we verify that the entire message // that is sent to the server will be signed by the right mac keys. diff --git a/oemcrypto/test/oemcrypto_provisioning_test.cpp b/oemcrypto/test/oemcrypto_provisioning_test.cpp index 99897ae..fbb7a83 100644 --- a/oemcrypto/test/oemcrypto_provisioning_test.cpp +++ b/oemcrypto/test/oemcrypto_provisioning_test.cpp @@ -377,21 +377,13 @@ TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadAPI18) { if (wvoec::global_features.api_version < 18) { GTEST_SKIP() << "Test for versions 18 and up only."; } - std::vector challenge(64, 0xaa); - // TODO: add cppbor support for oemcrypto tests for all targets. Before that, - // use hex values which are equivalent of the commented cppbor statement. - // std::vector device_info = cppbor::Map() - // .add("manufacturer", "google") - // .add("fused", 0) - // .add("other", "ignored") - // .canonicalize() - // .encode(); - // - std::vector device_info = { - 0xa3, 0x65, 0x66, 0x75, 0x73, 0x65, 0x64, 0x0, 0x65, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x67, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x64, - 0x6c, 0x6d, 0x61, 0x6e, 0x75, 0x66, 0x61, 0x63, 0x74, 0x75, 0x72, - 0x65, 0x72, 0x66, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65}; + const std::vector challenge(64, 0xaa); + const std::vector device_info = cppbor::Map() + .add("manufacturer", "google") + .add("fused", 0) + .add("other", "ignored") + .canonicalize() + .encode(); std::vector signed_csr_payload; size_t signed_csr_payload_length = 0; OEMCryptoResult sts = OEMCrypto_GetDeviceSignedCsrPayload( @@ -416,12 +408,13 @@ TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadAPI18) { TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadInvalid) { std::vector signed_csr_payload; size_t signed_csr_payload_length = 0; - std::vector challenge(64, 0xaa); - std::vector device_info = { - 0xa3, 0x65, 0x66, 0x75, 0x73, 0x65, 0x64, 0x0, 0x65, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x67, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x64, - 0x6c, 0x6d, 0x61, 0x6e, 0x75, 0x66, 0x61, 0x63, 0x74, 0x75, 0x72, - 0x65, 0x72, 0x66, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65}; + const std::vector challenge(64, 0xaa); + const std::vector device_info = cppbor::Map() + .add("manufacturer", "google") + .add("fused", 0) + .add("other", "ignored") + .canonicalize() + .encode(); std::vector challenge_empty; OEMCryptoResult sts = OEMCrypto_GetDeviceSignedCsrPayload( challenge_empty.data(), challenge_empty.size(), device_info.data(), @@ -431,7 +424,7 @@ TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadInvalid) { ASSERT_EQ(sts, OEMCrypto_ERROR_INVALID_CONTEXT); // Oversized challenge - std::vector challenge_long(65, 0xaa); + const std::vector challenge_long(65, 0xaa); sts = OEMCrypto_GetDeviceSignedCsrPayload( challenge_long.data(), challenge_long.size(), device_info.data(), device_info.size(), signed_csr_payload.data(), diff --git a/oemcrypto/test/oemcrypto_test_android.cpp b/oemcrypto/test/oemcrypto_test_android.cpp index 29d4a02..9f1e891 100644 --- a/oemcrypto/test/oemcrypto_test_android.cpp +++ b/oemcrypto/test/oemcrypto_test_android.cpp @@ -46,8 +46,8 @@ TEST_F(OEMCryptoAndroidLMPTest, ValidKeyboxTest) { * or 4. */ TEST_F(OEMCryptoAndroidLMPTest, RewrapDeviceRSAKeyImplemented) { ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED, - OEMCrypto_LoadProvisioning(0, nullptr, 0, 0, nullptr, 0, nullptr, - nullptr)); + OEMCrypto_LoadProvisioning(0, nullptr, 0, nullptr, 0, 0, nullptr, 0, + nullptr, 0)); } /** The Generic Crypto API functions are required for Android. */ diff --git a/oemcrypto/test/oemcrypto_usage_table_test.cpp b/oemcrypto/test/oemcrypto_usage_table_test.cpp index ef28b45..fc6bd17 100644 --- a/oemcrypto/test/oemcrypto_usage_table_test.cpp +++ b/oemcrypto/test/oemcrypto_usage_table_test.cpp @@ -184,8 +184,13 @@ TEST_F(OEMCryptoSessionTests, MasterGeneration_IncrementCounterAPI18) { ASSERT_TRUE(prov_count2 == prov_count1); ASSERT_TRUE(lic_count2 > lic_count1); - ASSERT_TRUE(decrypt_count2 > decrypt_count1); ASSERT_TRUE(master_generation_number2 > master_generation_number1); + + // Log if decrypt counter hasn't gone up. Not a hard requirement, so don't + // assert for it. + if (decrypt_count2 <= decrypt_count1) { + LOGE("Decrypt count did not increase."); + } } TEST_P(OEMCryptoUsageTableTest, diff --git a/oemcrypto/util/src/signed_csr_payload_validator.cpp b/oemcrypto/util/src/signed_csr_payload_validator.cpp index 439b56a..c3923d5 100644 --- a/oemcrypto/util/src/signed_csr_payload_validator.cpp +++ b/oemcrypto/util/src/signed_csr_payload_validator.cpp @@ -131,7 +131,7 @@ CborMessageStatus SignedCsrPayloadValidator::ValidateProtectedParams( "Unsupported signature algorithm value: " + std::to_string(algo)); return message_status_; } - AddMessages(msg_ss_, {kv}, 1); + AddMessages(msg_ss_, {std::move(kv)}, 1); algo_found = true; } } @@ -196,7 +196,7 @@ CborMessageStatus SignedCsrPayloadValidator::ValidateDataToBeSigned( std::to_string(challenge->value().size()) + " bytes long."); } msg += wvutil::b2a_hex(challenge->value()); - AddMessages(msg_ss_, {msg}, 1); + AddMessages(msg_ss_, {std::move(msg)}, 1); // Element 1: CsrPayload. AddMessages(msg_ss_, {"- CsrPayload:"}, 1); diff --git a/util/include/wv_attributes.h b/util/include/wv_attributes.h index c817f1c..c890c93 100644 --- a/util/include/wv_attributes.h +++ b/util/include/wv_attributes.h @@ -13,4 +13,12 @@ # endif #endif +#ifndef WEAK +# if defined(__GNUC__) || defined(__clang__) +# define WEAK __attribute__((weak)) +# else +# define WEAK +# endif +#endif + #endif // WVCDM_UTIL_WV_ATTRIBUTES_H_ diff --git a/util/test/test_sleep.cpp b/util/test/test_sleep.cpp index 439a46d..f52e571 100644 --- a/util/test/test_sleep.cpp +++ b/util/test/test_sleep.cpp @@ -30,7 +30,7 @@ TestSleep::CallBack* TestSleep::callback_ = nullptr; int TestSleep::total_clock_rollback_seconds_ = 0; void TestSleep::Sleep(unsigned int seconds) { - int64_t milliseconds = 1000 * seconds; + int64_t milliseconds = 1000 * static_cast(seconds); if (real_sleep_) { // This next bit of logic is to avoid slow drift apart of the real clock and // the fake clock. We compute how far from the real clock has advanced in @@ -40,7 +40,8 @@ void TestSleep::Sleep(unsigned int seconds) { static const auto start_real = std::chrono::system_clock().now(); sleep(seconds); const auto now_real = std::chrono::system_clock().now(); - const int64_t rollback_adjustment = 1000 * total_clock_rollback_seconds_; + const int64_t rollback_adjustment = + 1000 * static_cast(total_clock_rollback_seconds_); const int64_t total_real = (now_real - start_real) / std::chrono::milliseconds(1) + rollback_adjustment; @@ -129,7 +130,9 @@ bool TestSleep::RollbackSystemTime(int seconds) { // For both real and fake sleep we still update the callback and we still keep // track of the total amount of time slept. total_clock_rollback_seconds_ += seconds; - if (callback_ != nullptr) callback_->ElapseTime(-1000 * seconds); + if (callback_ != nullptr) { + callback_->ElapseTime(-1000 * static_cast(seconds)); + } return true; }