From 85f9a4c57e21908179e6b694d86ca3521a0bff3d Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Mon, 29 Aug 2022 17:02:38 +0200 Subject: [PATCH 01/37] Development/ocdm enhancements (#145) * [OCDM] Extension for the new functionalities. * Forgot to add the capabilities. Added * [CAPSPARSER] Add a GstCapsParser for getting stream data. * [OCDM] Add a caps parse contributed by Comcast. * Add version 2 of decrypt. * Change GST_BUFFER to GST_ARRAY * Revert previious change * [OCDM] OCDM Enhancements * Review comments from Doug * Changes after more review * Address Review comments Co-authored-by: Santhosh Ramani --- Source/ocdm/CMakeLists.txt | 2 + Source/ocdm/CapsParser.cpp | 121 ++++++++++ Source/ocdm/CapsParser.h | 61 +++++ .../broadcom-svp-secbuf/open_cdm_adapter.cpp | 228 ------------------ .../adapter/gstreamer/open_cdm_adapter.cpp | 215 +++++++++++++++-- Source/ocdm/adapter/open_cdm_adapter.h | 45 +++- Source/ocdm/open_cdm.cpp | 28 ++- Source/ocdm/open_cdm.h | 56 +++++ Source/ocdm/open_cdm_impl.h | 49 ++-- 9 files changed, 533 insertions(+), 272 deletions(-) create mode 100644 Source/ocdm/CapsParser.cpp create mode 100644 Source/ocdm/CapsParser.h delete mode 100644 Source/ocdm/adapter/broadcom-svp-secbuf/open_cdm_adapter.cpp diff --git a/Source/ocdm/CMakeLists.txt b/Source/ocdm/CMakeLists.txt index 2581b4de..b7526a03 100644 --- a/Source/ocdm/CMakeLists.txt +++ b/Source/ocdm/CMakeLists.txt @@ -41,6 +41,7 @@ option(CDMI_ADAPTER_IMPLEMENTATION "Defines which implementation is used." "None add_library(${TARGET} SHARED + CapsParser.cpp open_cdm.cpp open_cdm_ext.cpp ) @@ -49,6 +50,7 @@ set(PUBLIC_HEADERS open_cdm.h adapter/open_cdm_adapter.h open_cdm_ext.h + CapsParser.h Module.h ) diff --git a/Source/ocdm/CapsParser.cpp b/Source/ocdm/CapsParser.cpp new file mode 100644 index 00000000..8145142d --- /dev/null +++ b/Source/ocdm/CapsParser.cpp @@ -0,0 +1,121 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CapsParser.h" + +static constexpr TCHAR StartingCharacter = ')'; +static constexpr TCHAR EndingCharacter = ','; +static constexpr TCHAR WidthTag[] = _T("width"); +static constexpr TCHAR HeightTag[] = _T("height"); +static constexpr TCHAR MediaTag[] = _T("original-media-type"); + +namespace WPEFramework { + namespace Plugin { + + CapsParser::CapsParser() + : _lastHash(0) + , _mediaType(CDMi::Unknown) + , _width(0) + , _height(0) { + } + + CapsParser::~CapsParser() { + } + + void CapsParser::Parse(const uint8_t* info, const uint16_t infoLength) /* override */ + { + if(infoLength > 0) { + std::string infoStr(reinterpret_cast(info), infoLength); + + std::hash<::string> hash_fn; + size_t info_hash = hash_fn(infoStr); + if(_lastHash != info_hash) { + _lastHash = info_hash; + + // Parse the data + std::string result = FindMarker(infoStr, MediaTag); + if(!result.empty()) { + if(result.find("video") != ::string::npos) { + _mediaType = CDMi::Video; + } + else if(result.find("audio") != ::string::npos) { + _mediaType = CDMi::Audio; + } + else { + TRACE(Trace::Error, (Core::Format(_T("Found and unknown media type %s\n"), result.c_str()))); + _mediaType = CDMi::Unknown; + } + } + else { + TRACE(Trace::Warning, (_T("No result for media type"))); + } + + if(_mediaType == CDMi::Video) { + + result = FindMarker(infoStr, WidthTag); + + if (result.length() > 0) { + _width = Core::NumberType(result.c_str(), result.length(), NumberBase::BASE_DECIMAL); + } + else { + _width = 0; + TRACE(Trace::Warning, (_T("No result for width"))); + } + + result = FindMarker(infoStr, HeightTag); + + if (result.length() > 0) { + _height = Core::NumberType(result.c_str(), result.length(), NumberBase::BASE_DECIMAL); + } + else { + _height = 0; + TRACE(Trace::Warning, (_T("No result for height"))); + } + } + else { + // Audio + _width = 0; + _height = 0; + } + } + } + } + + std::string CapsParser::FindMarker(const std::string& data, const TCHAR tag[]) const + { + std::string retVal; + + size_t found = data.find(tag); + TRACE(Trace::Warning, (Core::Format(_T("Found tag <%s> in <%s> at location %d"), tag, data.c_str(), found))); + if(found != ::string::npos) { + // Found the marker + // Find the end of the gst caps type identifier + size_t start = data.find(StartingCharacter, found) + 1; // step over the ")" + size_t end = data.find(EndingCharacter, start); + if(end == ::string::npos) { + // Went past the end of the string + end = data.length(); + } + retVal = data.substr(start, end - start); + TRACE(Trace::Warning, (Core::Format(_T("Found substr <%s>"), retVal.c_str()))); + } + return retVal; + } + } +} diff --git a/Source/ocdm/CapsParser.h b/Source/ocdm/CapsParser.h new file mode 100644 index 00000000..2eb5a387 --- /dev/null +++ b/Source/ocdm/CapsParser.h @@ -0,0 +1,61 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "Module.h" + +#include + +namespace WPEFramework { + namespace Plugin { + + class CapsParser { + public: + CapsParser(const CapsParser&) = delete; + CapsParser& operator= (const CapsParser&) = delete; + + CapsParser(); + ~CapsParser(); + + public: + void Parse(const uint8_t* info, const uint16_t infoLength); + + uint16_t GetHeight() const { + return _height; + } + uint16_t GetWidth() const { + return _width; + } + CDMi::MediaType GetMediaType() const { + return _mediaType; + } + + private: + std::string FindMarker(const std::string& data, const TCHAR* tag) const; + + private: + size_t _lastHash; + + CDMi::MediaType _mediaType; + uint16_t _width; + uint16_t _height; + }; + } +} diff --git a/Source/ocdm/adapter/broadcom-svp-secbuf/open_cdm_adapter.cpp b/Source/ocdm/adapter/broadcom-svp-secbuf/open_cdm_adapter.cpp deleted file mode 100644 index 52d74e56..00000000 --- a/Source/ocdm/adapter/broadcom-svp-secbuf/open_cdm_adapter.cpp +++ /dev/null @@ -1,228 +0,0 @@ - /* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2020 Metrological - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "open_cdm_adapter.h" - -#include -#include - -#include -#include "b_secbuf.h" - -struct Rpc_Secbuf_Info { - uint8_t *ptr; - uint32_t type; - size_t size; - void *token; -}; -OpenCDMError opencdm_gstreamer_session_decrypt_v2(struct OpenCDMSession* session, GstBuffer* buffer, GstBuffer* subSampleBuffer, const uint32_t subSampleCount, - const EncryptionScheme encScheme, const EncryptionPattern pattern, - GstBuffer* IV, GstBuffer* keyID, uint32_t initWithLast15) -{ - OpenCDMError result (ERROR_INVALID_SESSION); - - struct Rpc_Secbuf_Info sb_info; - - if (session != nullptr) { - GstMapInfo dataMap; - if (gst_buffer_map(buffer, &dataMap, (GstMapFlags) GST_MAP_READWRITE) == false) { - fprintf(stderr, "Invalid buffer.\n"); - return (ERROR_INVALID_DECRYPT_BUFFER); - } - - GstMapInfo ivMap; - if (gst_buffer_map(IV, &ivMap, (GstMapFlags) GST_MAP_READ) == false) { - gst_buffer_unmap(buffer, &dataMap); - fprintf(stderr, "Invalid IV buffer.\n"); - return (ERROR_INVALID_DECRYPT_BUFFER); - } - - GstMapInfo keyIDMap; - if (gst_buffer_map(keyID, &keyIDMap, (GstMapFlags) GST_MAP_READ) == false) { - gst_buffer_unmap(buffer, &dataMap); - gst_buffer_unmap(IV, &ivMap); - fprintf(stderr, "Invalid keyID buffer.\n"); - return (ERROR_INVALID_DECRYPT_BUFFER); - } - - uint8_t *mappedData = reinterpret_cast(dataMap.data); - uint32_t mappedDataSize = static_cast(dataMap.size); - uint8_t *mappedIV = reinterpret_cast(ivMap.data); - uint32_t mappedIVSize = static_cast(ivMap.size); - uint8_t *mappedKeyID = reinterpret_cast(keyIDMap.data); - uint32_t mappedKeyIDSize = static_cast(keyIDMap.size); - - if (subSampleBuffer != nullptr) { - GstMapInfo sampleMap; - - if (gst_buffer_map(subSampleBuffer, &sampleMap, GST_MAP_READ) == false) { - fprintf(stderr, "Invalid subsample buffer.\n"); - gst_buffer_unmap(keyID, &keyIDMap); - gst_buffer_unmap(IV, &ivMap); - gst_buffer_unmap(buffer, &dataMap); - return (ERROR_INVALID_DECRYPT_BUFFER); - } - uint8_t *mappedSubSample = reinterpret_cast(sampleMap.data); - uint32_t mappedSubSampleSize = static_cast(sampleMap.size); - - GstByteReader* reader = gst_byte_reader_new(mappedSubSample, mappedSubSampleSize); - uint16_t inClear = 0; - uint32_t inEncrypted = 0; - uint32_t totalEncrypted = 0; - for (unsigned int position = 0; position < subSampleCount; position++) { - - gst_byte_reader_get_uint16_be(reader, &inClear); - gst_byte_reader_get_uint32_be(reader, &inEncrypted); - totalEncrypted += inEncrypted; - } - gst_byte_reader_set_pos(reader, 0); - - if(totalEncrypted > 0) - { - svp_meta_data_t * ptr = (svp_meta_data_t *) g_malloc(sizeof(svp_meta_data_t)); - if (ptr) { - uint32_t chunks_cnt = 0; - enc_chunk_data_t * ci = NULL; - - memset((uint8_t *)ptr, 0, sizeof(svp_meta_data_t)); - // The next line need to change to assign the opaque handle after calling ->processPayload() - ptr->secure_memory_ptr = NULL; //pData; - chunks_cnt = subSampleCount; - ptr->num_chunks = chunks_cnt; - if (chunks_cnt) { - ci = (enc_chunk_data_t *)g_malloc(chunks_cnt * sizeof(enc_chunk_data_t)); - ptr->info = ci; - } - } - - totalEncrypted += sizeof(Rpc_Secbuf_Info); //make sure enough data for metadata - - uint8_t* encryptedData = reinterpret_cast (g_malloc(totalEncrypted)); - uint8_t* encryptedDataIter = encryptedData; - - uint32_t index = 0; - for (unsigned int position = 0; position < subSampleCount; position++) { - - gst_byte_reader_get_uint16_be(reader, &inClear); - gst_byte_reader_get_uint32_be(reader, &inEncrypted); - - memcpy(encryptedDataIter, mappedData + index + inClear, inEncrypted); - index += inClear + inEncrypted; - encryptedDataIter += inEncrypted; - - if (ptr && ptr->num_chunks > 0 && ptr->info) { - enc_chunk_data_t * ci = ptr->info; - ci[position].clear_data_size = inClear; - ci[position].enc_data_size = inEncrypted; - } - } - gst_byte_reader_set_pos(reader, 0); - - result = opencdm_session_decrypt(session, encryptedData, totalEncrypted, encScheme, pattern, mappedIV, mappedIVSize, mappedKeyID, mappedKeyIDSize, initWithLast15); - - if(ptr && (result == ERROR_NONE)) { - memcpy(&sb_info, encryptedData, sizeof(Rpc_Secbuf_Info)); - if (B_Secbuf_AllocWithToken(sb_info.size, (B_Secbuf_Type)sb_info.type, sb_info.token, (void**)&sb_info.ptr)) { - fprintf(stderr, "B_Secbuf_AllocWithToken() failed!\n"); - fprintf(stderr, "%u subsamples, totalEncrypted: %u, sb_inf: ptr=%p, type=%i, size=%i, token=%p\n", subSampleCount, totalEncrypted, sb_info.ptr, sb_info.type, sb_info.size, sb_info.token); - } - - ptr->secure_memory_ptr = (uintptr_t) sb_info.ptr; //assign the handle here! - gst_buffer_append_svp_metadata(buffer, ptr); - g_free(ptr->info); - g_free(ptr); - } - g_free(encryptedData); - } else { - // no encrypted data, skip decryption... - result = ERROR_NONE; - } - - gst_byte_reader_free(reader); - gst_buffer_unmap(subSampleBuffer, &sampleMap); - } else { - uint8_t* encryptedData = NULL; - uint8_t* fEncryptedData = NULL; - uint32_t totalEncryptedSize = 0; - - svp_meta_data_t * ptr = (svp_meta_data_t *) g_malloc(sizeof(svp_meta_data_t)); - if (ptr) { - enc_chunk_data_t *ci = NULL; - memset((uint8_t *)ptr, 0, sizeof(svp_meta_data_t)); - // The next line need to change to assign the opaque handle after calling ->processPayload() - ptr->secure_memory_ptr = NULL; //pData; - ptr->num_chunks = 1; - - ci = (enc_chunk_data_t *)g_malloc(sizeof(enc_chunk_data_t)); - ptr->info = ci; - ci[0].clear_data_size = 0; - ci[0].enc_data_size = mappedDataSize; - - totalEncryptedSize = mappedDataSize + sizeof(Rpc_Secbuf_Info); //make sure it is enough for metadata - encryptedData = (uint8_t*) g_malloc(totalEncryptedSize); - fEncryptedData = encryptedData; - memcpy(encryptedData, mappedData, mappedDataSize); - - result = opencdm_session_decrypt(session, encryptedData, totalEncryptedSize, encScheme, pattern, mappedIV, mappedIVSize, mappedKeyID, mappedKeyIDSize, initWithLast15); - - if(result == ERROR_NONE){ - memcpy(&sb_info, fEncryptedData, sizeof(Rpc_Secbuf_Info)); - if (B_Secbuf_AllocWithToken(sb_info.size, (B_Secbuf_Type)sb_info.type, sb_info.token, (void**)&sb_info.ptr)) { - fprintf(stderr, "B_Secbuf_AllocWithToken() failed!\n"); - fprintf(stderr, "no subsamples, encrypted size: %u, sb_inf: ptr=%p, type=%i, size=%i, token=%p\n", totalEncryptedSize, sb_info.ptr, sb_info.type, sb_info.size, sb_info.token); - } - - ptr->secure_memory_ptr = (uintptr_t) sb_info.ptr; //assign the handle here! - gst_buffer_append_svp_metadata(buffer, ptr); - g_free(ptr->info); - g_free(ptr); - } - g_free(fEncryptedData); - } - } - - gst_buffer_unmap(keyID, &keyIDMap); - gst_buffer_unmap(IV, &ivMap); - gst_buffer_unmap(buffer, &dataMap); - } - - return (result); -} - -OpenCDMError opencdm_gstreamer_session_decrypt(struct OpenCDMSession* session, GstBuffer* buffer, GstBuffer* subSample, const uint32_t subSampleCount, - GstBuffer* IV, GstBuffer* keyID, uint32_t initWithLast15){ - //Set the Encryption Scheme and Pattern to defaults. - EncryptionScheme encScheme = AesCtr_Cenc; - EncryptionPattern pattern = {0}; - - //Lets try to get Enc Scheme and Pattern from the Protection Metadata. - GstProtectionMeta* protectionMeta = reinterpret_cast(gst_buffer_get_protection_meta(buffer)); - if (protectionMeta != NULL) { - const char* cipherModeBuf = gst_structure_get_string(protectionMeta->info, "cipher-mode"); - if(g_strcmp0(cipherModeBuf,"cbcs") == 0) { - encScheme = AesCbc_Cbcs; - } - - gst_structure_get_uint(protectionMeta->info, "crypt_byte_block", &pattern.encrypted_blocks); - gst_structure_get_uint(protectionMeta->info, "skip_byte_block", &pattern.clear_blocks); - } - - return(opencdm_gstreamer_session_decrypt_v2(session, buffer, subSample, subSampleCount, encScheme, pattern, IV, keyID, initWithLast15)); -} - diff --git a/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp b/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp index c5509d70..5ea3d93b 100644 --- a/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp +++ b/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp @@ -18,13 +18,28 @@ */ #include "open_cdm_adapter.h" - #include #include #include +#include "../CapsParser.h" + + +inline bool mappedBuffer(GstBuffer *buffer, bool writable, uint8_t **data, uint32_t *size) +{ + GstMapInfo map; + + if (!gst_buffer_map (buffer, &map, writable ? GST_MAP_WRITE : GST_MAP_READ)) { + return false; + } + + *data = reinterpret_cast(map.data); + *size = static_cast(map.size); + gst_buffer_unmap (buffer, &map); -OpenCDMError opencdm_gstreamer_session_decrypt_v2(struct OpenCDMSession* session, GstBuffer* buffer, GstBuffer* subSampleBuffer, const uint32_t subSampleCount, - const EncryptionScheme encScheme, const EncryptionPattern pattern, + return true; +} + +OpenCDMError opencdm_gstreamer_session_decrypt(struct OpenCDMSession* session, GstBuffer* buffer, GstBuffer* subSampleBuffer, const uint32_t subSampleCount, GstBuffer* IV, GstBuffer* keyID, uint32_t initWithLast15) { OpenCDMError result (ERROR_INVALID_SESSION); @@ -59,6 +74,22 @@ OpenCDMError opencdm_gstreamer_session_decrypt_v2(struct OpenCDMSession* session mappedKeyIDSize = static_cast(keyIDMap.size); } + //Set the Encryption Scheme and Pattern to defaults. + EncryptionScheme encScheme = AesCtr_Cenc; + EncryptionPattern pattern = {0, 0}; + + //Lets try to get Enc Scheme and Pattern from the Protection Metadata. + GstProtectionMeta* protectionMeta = reinterpret_cast(gst_buffer_get_protection_meta(buffer)); + if (protectionMeta != NULL) { + const char* cipherModeBuf = gst_structure_get_string(protectionMeta->info, "cipher-mode"); + if(g_strcmp0(cipherModeBuf,"cbcs") == 0) { + encScheme = AesCbc_Cbcs; + } + + gst_structure_get_uint(protectionMeta->info, "crypt_byte_block", &pattern.encrypted_blocks); + gst_structure_get_uint(protectionMeta->info, "skip_byte_block", &pattern.clear_blocks); + } + uint8_t *mappedData = reinterpret_cast(dataMap.data); uint32_t mappedDataSize = static_cast(dataMap.size); uint8_t *mappedIV = reinterpret_cast(ivMap.data); @@ -135,23 +166,171 @@ OpenCDMError opencdm_gstreamer_session_decrypt_v2(struct OpenCDMSession* session return (result); } -OpenCDMError opencdm_gstreamer_session_decrypt(struct OpenCDMSession* session, GstBuffer* buffer, GstBuffer* subSample, const uint32_t subSampleCount, - GstBuffer* IV, GstBuffer* keyID, uint32_t initWithLast15){ - //Set the Encryption Scheme and Pattern to defaults. - EncryptionScheme encScheme = AesCtr_Cenc; - EncryptionPattern pattern = {0, 0}; - - //Lets try to get Enc Scheme and Pattern from the Protection Metadata. - GstProtectionMeta* protectionMeta = reinterpret_cast(gst_buffer_get_protection_meta(buffer)); - if (protectionMeta != NULL) { - const char* cipherModeBuf = gst_structure_get_string(protectionMeta->info, "cipher-mode"); - if(g_strcmp0(cipherModeBuf,"cbcs") == 0) { - encScheme = AesCbc_Cbcs; + +OpenCDMError opencdm_gstreamer_session_decrypt_buffer(struct OpenCDMSession* session, GstBuffer* buffer, GstCaps* caps) { + + OpenCDMError result (ERROR_INVALID_SESSION); + + if (session != nullptr) { + + uint8_t *mappedData = nullptr; + uint32_t mappedDataSize = 0; + if (mappedBuffer(buffer, true, &mappedData, &mappedDataSize) == false) { + + TRACE_L1("opencdm_gstreamer_session_decrypt_buffer: Invalid buffer."); + result = ERROR_INVALID_DECRYPT_BUFFER; + goto exit; + } + + //Check if Protection Metadata is available in Buffer + GstProtectionMeta* protectionMeta = reinterpret_cast(gst_buffer_get_protection_meta(buffer)); + if (protectionMeta != nullptr) { + const GValue* value; + + //Get Subsample mapping + unsigned subSampleCount = 0; + GstBuffer* subSample = nullptr; + if (!gst_structure_get_uint(protectionMeta->info, "subsample_count", &subSampleCount)) { + TRACE_L1("No Subsample Count."); + } + uint8_t *mappedSubSample = nullptr; + uint32_t mappedSubSampleSize = 0; + + if (subSampleCount > 0) { + value = gst_structure_get_value(protectionMeta->info, "subsamples"); + if (!value) { + TRACE_L1("opencdm_gstreamer_session_decrypt_buffer: No subsample buffer."); + result = ERROR_INVALID_DECRYPT_BUFFER; + goto exit; + } + subSample = gst_value_get_buffer(value); + if (subSample != nullptr && mappedBuffer(subSample, false, &mappedSubSample, &mappedSubSampleSize) == false) { + TRACE_L1("opencdm_gstreamer_session_decrypt_buffer: Invalid subsample buffer."); + result = ERROR_INVALID_DECRYPT_BUFFER; + goto exit; + } + ASSERT(mappedSubSampleSize==subSampleCount); + } + + //Get IV + value = gst_structure_get_value(protectionMeta->info, "iv"); + if (!value) { + TRACE_L1("opencdm_gstreamer_session_decrypt_buffer: Missing IV buffer."); + result = ERROR_INVALID_DECRYPT_BUFFER; + goto exit; + } + GstBuffer* IV = gst_value_get_buffer(value); + uint8_t *mappedIV = nullptr; //Set the Encryption Scheme and Pattern to defaults. + uint32_t mappedIVSize = 0; + if (mappedBuffer(IV, false, &mappedIV, &mappedIVSize) == false) { + TRACE_L1("opencdm_gstreamer_session_decrypt_buffer: Invalid IV buffer."); + result = ERROR_INVALID_DECRYPT_BUFFER; + goto exit; + } + + //Get Key ID + value = gst_structure_get_value(protectionMeta->info, "kid"); + if (!value) { + TRACE_L1("opencdm_gstreamer_session_decrypt_buffer: Missing KeyId buffer."); + result = ERROR_INVALID_DECRYPT_BUFFER; + goto exit; + } + GstBuffer* keyID = gst_value_get_buffer(value); + uint8_t *mappedKeyID = nullptr; + uint32_t mappedKeyIDSize = 0; + if (keyID != nullptr && mappedBuffer(keyID, false, &mappedKeyID, &mappedKeyIDSize) == false) { + TRACE_L1("Invalid keyID buffer."); + result = ERROR_INVALID_DECRYPT_BUFFER; + goto exit; + } + + //Get Encryption Scheme and Pattern + EncryptionScheme encScheme = AesCtr_Cenc; + EncryptionPattern pattern = {0, 0}; + const char* cipherModeBuf = gst_structure_get_string(protectionMeta->info, "cipher-mode"); + if(g_strcmp0(cipherModeBuf,"cbcs") == 0) { + encScheme = AesCbc_Cbcs; + } + gst_structure_get_uint(protectionMeta->info, "crypt_byte_block", &pattern.encrypted_blocks); + gst_structure_get_uint(protectionMeta->info, "skip_byte_block", &pattern.clear_blocks); + + //Create a SubSampleInfo Array with mapping + SubSampleInfo * subSampleInfoPtr = nullptr; + if (subSample != nullptr) { + GstByteReader* reader = gst_byte_reader_new(mappedSubSample, mappedSubSampleSize); + subSampleInfoPtr = reinterpret_cast(malloc(subSampleCount * sizeof(SubSampleInfo))); + for (unsigned int position = 0; position < subSampleCount; position++) { + + gst_byte_reader_get_uint16_be(reader, &subSampleInfoPtr[position].clear_bytes); + gst_byte_reader_get_uint32_be(reader, &subSampleInfoPtr[position].encrypted_bytes); + } + gst_byte_reader_set_pos(reader, 0); + gst_byte_reader_free(reader); + } + + //Get Stream Properties from GstCaps + MediaProperties *spPtr = nullptr; + if(caps != nullptr){ + gchar *capsStr = gst_caps_to_string (caps); + if (capsStr != nullptr) { + WPEFramework::Plugin::CapsParser capsParser; + MediaProperties streamProperties; + capsParser.Parse(reinterpret_cast(capsStr), strlen(capsStr)); + streamProperties.height = capsParser.GetHeight(); + streamProperties.width = capsParser.GetWidth(); + switch (capsParser.GetMediaType()) { + case CDMi::MediaType::Video: + streamProperties.media_type = MediaType_Video; + break; + + case CDMi::MediaType::Audio: + streamProperties.media_type = MediaType_Audio; + break; + + case CDMi::MediaType::Data: + streamProperties.media_type = MediaType_Data; + break; + + default: + streamProperties.media_type = MediaType_Unknown; + break; + } + spPtr = &streamProperties; + g_free(capsStr); + } else { + TRACE_L1("Could not convert caps to string"); + } + } + + SampleInfo sampleInfo; + sampleInfo.subSample = subSampleInfoPtr; + sampleInfo.subSampleCount = subSampleCount; + sampleInfo.scheme = encScheme; + sampleInfo.pattern.clear_blocks = pattern.clear_blocks; + sampleInfo.pattern.encrypted_blocks = pattern.encrypted_blocks; + sampleInfo.iv = mappedIV; + sampleInfo.ivLength = mappedIVSize; + sampleInfo.keyId = mappedKeyID; + sampleInfo.keyIdLength = mappedKeyIDSize; + + result = opencdm_session_decrypt_v2(session, + mappedData, + mappedDataSize, + &sampleInfo, + spPtr); + + //Clean up + if(subSampleInfoPtr != nullptr) { + free(subSampleInfoPtr); + } + } else { + TRACE_L1("opencdm_gstreamer_session_decrypt_buffer: Missing Protection Metadata."); + result = ERROR_INVALID_DECRYPT_BUFFER; } - gst_structure_get_uint(protectionMeta->info, "crypt_byte_block", &pattern.encrypted_blocks); - gst_structure_get_uint(protectionMeta->info, "skip_byte_block", &pattern.clear_blocks); } - return(opencdm_gstreamer_session_decrypt_v2(session, buffer, subSample, subSampleCount, encScheme, pattern, IV, keyID, initWithLast15)); +exit: + return (result); } + diff --git a/Source/ocdm/adapter/open_cdm_adapter.h b/Source/ocdm/adapter/open_cdm_adapter.h index 24f017b9..e48858d0 100644 --- a/Source/ocdm/adapter/open_cdm_adapter.h +++ b/Source/ocdm/adapter/open_cdm_adapter.h @@ -25,6 +25,9 @@ struct _GstBuffer; typedef struct _GstBuffer GstBuffer; +struct _GstCaps; +typedef struct _GstCaps GstCaps; + #ifdef __cplusplus extern "C" { #endif @@ -41,6 +44,15 @@ extern "C" { * \param subSampleCount count of subsamples * \param IV Gstreamer buffer containing initial vector (IV) used during decryption. * \param keyID Gstreamer buffer containing keyID to use for decryption + * + * This method handles the Subsample mapping by consolidating all the encrypted data into one buffer before decrypting. This means the Subsample mappings are + * not passed on to the DRM implementation side. + * + * For CBCS support, EncryptionScheme and EncryptionPattern information can be added as part of the ProtectionMeta in the given format below + * "cipher-mode" G_TYPE_STRING (One of the Four Character Code (FOURCC) Protection schemes as defined in https://www.iso.org/obp/ui/#iso:std:iso-iec:23001:-7:ed-3:v1:en) + * "crypt_byte_block" G_TYPE_UINT (Present only if cipher-mode is "cbcs") + * "skip_byte_block" G_TYPE_UINT (Present only cipher-mode is "cbcs") + * \return Zero on success, non-zero on error. */ EXTERNAL OpenCDMError opencdm_gstreamer_session_decrypt(struct OpenCDMSession* session, GstBuffer* buffer, GstBuffer* subSample, const uint32_t subSampleCount, @@ -49,23 +61,34 @@ extern "C" { /** * \brief Performs decryption based on adapter implementation. * - * This version 2 method accepts encrypted data and will typically decrypt it out-of-process (for security reasons). The actual data copying is performed + * This version 3 method accepts encrypted data and will typically decrypt it out-of-process (for security reasons). The actual data copying is performed * using a memory-mapped file (for performance reasons). If the DRM system allows access to decrypted data (i.e. decrypting is not - * performed in a TEE), the decryption is performed in-place. EncryptionScheme and Pattern can be passed. + * performed in a TEE), the decryption is performed in-place. + * This version assumes all data required is attached as metadata to the buffer. Specification for this data is as follows: + * + * Typically, the caller would parse the protection information for a video/audio frame from its input data and use this information to populate the + * GstStructure info field, which is then encapsulated in a GstProtectionMeta object and attached to the corresponding GstBuffer using the + * gst_buffer_add_protection_meta function. + * + * gst_structure [application/x-cenc] + * "iv" GST_TYPE_BUFFER + * "kid" GST_TYPE_BUFFER + * "subsample_count" G_TYPE_UINT + * "subsamples" GST_TYPE_BUFFER + * "cipher-mode" G_TYPE_STRING (One of the Four Character Code (FOURCC) Protection schemes as defined in https://www.iso.org/obp/ui/#iso:std:iso-iec:23001:-7:ed-3:v1:en) + * "crypt_byte_block" G_TYPE_UINT (Present only if cipher-mode is "cbcs") + * "skip_byte_block" G_TYPE_UINT (Present only cipher-mode is "cbcs") + * + * This method passes on the subsample mapping to the DRM implementation and assumes that the DRM implementaion will handle the decryption based on subsample mapping. + * * \param session \ref OpenCDMSession instance. * \param buffer Gstreamer buffer containing encrypted data and related meta data. If applicable, decrypted data will be stored here after this call returns. - * \param subSample Gstreamer buffer containing subsamples size which has been parsed from protection meta data. - * \param subSampleCount count of subsamples - * \param encScheme CENC Schemes as defined in EncryptionScheme enum - * \param pattern struct containing number of encrypted_blocks and clear_blocks - * \param IV Gstreamer buffer containing initial vector (IV) used during decryption. - * \param keyID Gstreamer buffer containing keyID to use for decryption * \return Zero on success, non-zero on error. */ - EXTERNAL OpenCDMError opencdm_gstreamer_session_decrypt_v2(struct OpenCDMSession* session, GstBuffer* buffer, GstBuffer* subSampleBuffer, const uint32_t subSampleCount, - const EncryptionScheme encScheme, const EncryptionPattern pattern, - GstBuffer* IV, GstBuffer* keyID, uint32_t initWithLast15); + EXTERNAL OpenCDMError opencdm_gstreamer_session_decrypt_buffer(struct OpenCDMSession* session, GstBuffer* buffer, GstCaps* caps); + + #ifdef __cplusplus } #endif diff --git a/Source/ocdm/open_cdm.cpp b/Source/ocdm/open_cdm.cpp index 24cfe4f3..76dd9a39 100644 --- a/Source/ocdm/open_cdm.cpp +++ b/Source/ocdm/open_cdm.cpp @@ -481,10 +481,36 @@ OpenCDMError opencdm_session_decrypt(struct OpenCDMSession* session, uint32_t initWithLast15 /* = 0 */) { OpenCDMError result(ERROR_INVALID_SESSION); + if (session != nullptr) { + SampleInfo sampleInfo; + sampleInfo.subSample = nullptr; + sampleInfo.subSampleCount = 0; + sampleInfo.scheme = encScheme; + sampleInfo.pattern.clear_blocks = pattern.clear_blocks; + sampleInfo.pattern.encrypted_blocks = pattern.encrypted_blocks; + sampleInfo.iv = const_cast(IV); + sampleInfo.ivLength = IVLength; + sampleInfo.keyId = const_cast(keyId); + sampleInfo.keyIdLength = keyIdLength; + result = encryptedLength > 0 ? static_cast(session->Decrypt( + encrypted, encryptedLength, const_cast(&sampleInfo), initWithLast15, nullptr)) : ERROR_NONE; + } + + return (result); +} + +OpenCDMError opencdm_session_decrypt_v2(struct OpenCDMSession* session, + uint8_t encrypted[], + const uint32_t encryptedLength, + const SampleInfo* sampleInfo, + const MediaProperties* properties) { + + OpenCDMError result(ERROR_INVALID_SESSION); if (session != nullptr) { + uint32_t initWithLast15 = 0; result = encryptedLength > 0 ? static_cast(session->Decrypt( - encrypted, encryptedLength, encScheme, pattern, IV, IVLength, keyId, keyIdLength, initWithLast15)) : ERROR_NONE; + encrypted, encryptedLength, sampleInfo, initWithLast15, properties)) : ERROR_NONE; } return (result); diff --git a/Source/ocdm/open_cdm.h b/Source/ocdm/open_cdm.h index 4907f8df..b265de13 100644 --- a/Source/ocdm/open_cdm.h +++ b/Source/ocdm/open_cdm.h @@ -118,12 +118,43 @@ typedef enum { AesCbc_Cbcs // AES-CBC mode and Sub-Sample + patterned encryption + Constant IV } EncryptionScheme; +typedef enum +{ + MediaType_Unknown = 0, + MediaType_Video, + MediaType_Audio, + MediaType_Data +} MediaType; + //CENC3.0 pattern is a number of encrypted blocks followed a number of clear blocks after which the pattern repeats. typedef struct { uint32_t encrypted_blocks; uint32_t clear_blocks; } EncryptionPattern; +typedef struct { + uint16_t clear_bytes; + uint32_t encrypted_bytes; +} SubSampleInfo; + +typedef struct { + EncryptionScheme scheme; // Encryption scheme used in this sample + EncryptionPattern pattern; // Encryption Pattern used in this sample + uint8_t* iv; // Initialization vector(IV) to decrypt this sample. Can be NULL, in that case and IV of all zeroes is assumed. + uint8_t ivLength; // Length of IV + uint8_t* keyId; // ID of Key required to decrypt this sample + uint8_t keyIdLength; // Length of KeyId + uint8_t subSampleCount; // Number or Sub-Samples in this sample + SubSampleInfo* subSample; // SubSample mapping - Repeating pair of Clear bytes and Encrypted Bytes representing each subsample. +} SampleInfo; + +// Provides information about the current stream +typedef struct { + uint16_t height; + uint16_t width; + MediaType media_type; +} MediaProperties; + /** * Key status. @@ -524,6 +555,7 @@ EXTERNAL OpenCDMError opencdm_session_decrypt(struct OpenCDMSession* session, const uint8_t* IV, uint16_t IVLength, const uint8_t* keyId, const uint16_t keyIdLength, uint32_t initWithLast15 = 0); + #else EXTERNAL OpenCDMError opencdm_session_decrypt(struct OpenCDMSession* session, uint8_t encrypted[], @@ -535,6 +567,30 @@ EXTERNAL OpenCDMError opencdm_session_decrypt(struct OpenCDMSession* session, uint32_t initWithLast15); #endif // __cplusplus + +/** + * \brief Performs decryption. + * + * This method accepts encrypted data and will typically decrypt it + * out-of-process (for security reasons). The actual data copying is performed + * using a memory-mapped file (for performance reasons). If the DRM system + * allows access to decrypted data (i.e. decrypting is not + * performed in a TEE), the decryption is performed in-place. + * \param session \ref OpenCDMSession instance. + * \param encrypted Buffer containing encrypted data. If applicable, decrypted + * data will be stored here after this call returns. + * \param encryptedLength Length of encrypted data buffer (in bytes). + * \param sampleInfo Per Sample information needed to decrypt this sample + * \param streamProperties Provides info about current stream + * \return Zero on success, non-zero on error. + */ + +EXTERNAL OpenCDMError opencdm_session_decrypt_v2(struct OpenCDMSession* session, + uint8_t encrypted[], + const uint32_t encryptedLength, + const SampleInfo* sampleInfo, + const MediaProperties* streamProperties); + /** * @brief Close the cached open connection if it exists. * diff --git a/Source/ocdm/open_cdm_impl.h b/Source/ocdm/open_cdm_impl.h index 2308c506..03a1d024 100644 --- a/Source/ocdm/open_cdm_impl.h +++ b/Source/ocdm/open_cdm_impl.h @@ -399,11 +399,9 @@ struct OpenCDMSession { public: uint32_t Decrypt(uint8_t* encryptedData, uint32_t encryptedDataLength, - const EncryptionScheme encScheme, - const EncryptionPattern& pattern, - const uint8_t* ivData, uint16_t ivDataLength, - const uint8_t* keyId, uint16_t keyIdLength, - uint32_t initWithLast15 /* = 0 */) + const ::SampleInfo* sampleInfo, + uint32_t initWithLast15, + const ::MediaProperties* properties) { int ret = 0; @@ -421,11 +419,37 @@ struct OpenCDMSession { if (RequestProduce(Core::infinite) == Core::ERROR_NONE) { + CDMi::SubSampleInfo* subSample = nullptr; + uint8_t subSampleCount = 0; + CDMi::EncryptionScheme encScheme = CDMi::EncryptionScheme::AesCtr_Cenc; + CDMi::EncryptionPattern pattern = {0 , 0}; + uint8_t* ivData = nullptr; + uint8_t ivDataLength = 0; + uint8_t* keyId = nullptr; + uint8_t keyIdLength = 0; + + if(sampleInfo != nullptr) { + subSample = reinterpret_cast(sampleInfo->subSample); + subSampleCount = sampleInfo->subSampleCount; + ivData = sampleInfo->iv; + ivDataLength = sampleInfo->ivLength; + keyId = sampleInfo->keyId; + keyIdLength = sampleInfo->keyIdLength; + encScheme = static_cast(sampleInfo->scheme); + pattern.clear_blocks = sampleInfo->pattern.clear_blocks; + pattern.encrypted_blocks = sampleInfo->pattern.encrypted_blocks; + } + SetIV(static_cast(ivDataLength), ivData); KeyId(static_cast(keyIdLength), keyId); + SubSample(subSampleCount, subSample); SetEncScheme(static_cast(encScheme)); SetEncPattern(pattern.encrypted_blocks,pattern.clear_blocks); InitWithLast15(initWithLast15); + if(properties != nullptr) { + SetMediaProperties(properties->height, properties->width, properties->media_type); + } + Write(encryptedDataLength, encryptedData); // This will trigger the OpenCDMIServer to decrypt this memory... @@ -601,11 +625,9 @@ POP_WARNING() _session->Update(pbResponse, cbResponse); } uint32_t Decrypt(uint8_t* encryptedData, const uint32_t encryptedDataLength, - const EncryptionScheme encScheme, - const EncryptionPattern& pattern, - const uint8_t* ivData, uint16_t ivDataLength, - const uint8_t* keyId, const uint16_t keyIdLength, - uint32_t initWithLast15) + const ::SampleInfo* sampleInfo, + uint32_t initWithLast15, + const ::MediaProperties* properties) { uint32_t result = OpenCDMError::ERROR_INVALID_DECRYPT_BUFFER; @@ -619,10 +641,9 @@ POP_WARNING() if (decryptSession != nullptr) { result = decryptSession->Decrypt(encryptedData, encryptedDataLength, - encScheme,pattern, - ivData,ivDataLength, - keyId, keyIdLength, - initWithLast15); + sampleInfo, + initWithLast15, + properties); if(result) { TRACE_L1("Decrypt() failed with return code: %x", result); From df2aa956d4eeccd1d22e2e59ec338b7d186f5447 Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Wed, 7 Dec 2022 18:33:07 +0100 Subject: [PATCH 02/37] localtracer: Fixes for Messaging refactors (#176) * localtracer: Fixes for Messaging refactors * localtracer: use saver mkdtemp --- Source/localtracer/example/main.cpp | 33 ++++++++- .../include/localtracer/localtracer.h | 68 +++++++++---------- 2 files changed, 64 insertions(+), 37 deletions(-) diff --git a/Source/localtracer/example/main.cpp b/Source/localtracer/example/main.cpp index 26321fb9..1f924ea8 100644 --- a/Source/localtracer/example/main.cpp +++ b/Source/localtracer/example/main.cpp @@ -12,6 +12,30 @@ using namespace WPEFramework; constexpr char module[] = "LocalTraceTest"; +namespace { +class SleepObject { +public: + SleepObject(const SleepObject&) = delete; + SleepObject& operator=(const SleepObject&) = delete; + + SleepObject() + { + TRACE(Trace::Error, ("Constructing %s.... ", __FUNCTION__)); + } + + ~SleepObject() + { + TRACE(Trace::Error, ("Destructing %s.... ", __FUNCTION__)); + } + + void Sleep(uint8_t time) + { + TRACE(Trace::Information, ("Sleep for %ds ", time)); + sleep(time); + TRACE(Trace::Information, ("Hello again!")); + } +}; +} int main(int /*argc*/, const char* argv[]) { Messaging::LocalTracer& tracer = Messaging::LocalTracer::Open(); @@ -24,11 +48,14 @@ int main(int /*argc*/, const char* argv[]) tracer.EnableMessage(module, "Error", true); tracer.EnableMessage(module, "Information", true); - TRACE(Trace::Information, ("%s - build: %s", executableName, __TIMESTAMP__)); + TRACE_GLOBAL(Trace::Information, ("%s - build: %s", executableName, __TIMESTAMP__)); - sleep(5); + { + SleepObject object; + object.Sleep(5); + } - TRACE(Trace::Error, ("Exiting.... ")); + TRACE_GLOBAL(Trace::Error, ("Exiting.... ")); } tracer.Close(); diff --git a/Source/localtracer/include/localtracer/localtracer.h b/Source/localtracer/include/localtracer/localtracer.h index b22fd027..18dc3ac9 100644 --- a/Source/localtracer/include/localtracer/localtracer.h +++ b/Source/localtracer/include/localtracer/localtracer.h @@ -11,23 +11,27 @@ namespace Messaging { class EXTERNAL LocalTracer { public: struct EXTERNAL ICallback { - virtual void Output(const Core::Messaging::Information& info, const Core::Messaging::IEvent* message) = 0; + virtual void Output(const Core::Messaging::IStore::Information& info, const Core::Messaging::IEvent* message) = 0; }; private: - std::string DispatcherIdentifier() - { - string result; - Core::SystemInfo::GetEnvironment(Core::Messaging::MessageUnit::MESSAGE_DISPACTHER_IDENTIFIER_ENV, result); - return result; - } + class MessageSettings : public Messaging::MessageUnit::Settings { + private: + MessageSettings() + { + Messaging::MessageUnit::Settings::Load(); + }; - std::string DispatcherBasePath() - { - string result; - Core::SystemInfo::GetEnvironment(Core::Messaging::MessageUnit::MESSAGE_DISPATCHER_PATH_ENV, result); - return result; - } + public: + MessageSettings(const MessageSettings&) = delete; + MessageSettings& operator=(const MessageSettings&) = delete; + + static MessageSettings& Instance() + { + static MessageSettings singleton; + return (singleton); + } + }; private: class WorkerThread : private Core::Thread { @@ -73,7 +77,7 @@ namespace Messaging { void Close() { - Core::Messaging::MessageUnit::Instance().Close(); + Messaging::MessageUnit::Instance().Close(); Core::Directory(_path.c_str()).Destroy(); @@ -94,16 +98,15 @@ namespace Messaging { if (singleton == nullptr) { - char path[25]; - strcpy(path, "/tmp/localtracer.XXXXXX"); - mktemp(path); + char dir[] = "/tmp/localTracer.XXXXXX"; + + string Path(::mkdtemp(dir)); - Core::Directory(path).CreatePath(); + Core::Directory(Path.c_str()).CreatePath(); - Core::Messaging::MessageUnit::Instance().IsBackground(false); - Core::Messaging::MessageUnit::Instance().Open(path); + Messaging::MessageUnit::Instance().Open(Path, 0, "", false, Messaging::MessageUnit::FLUSH); - singleton = new LocalTracer(path); + singleton = new LocalTracer(Path); } LockSingleton(false); @@ -127,12 +130,12 @@ namespace Messaging { : _adminLock() , _path(path) , _worker(*this) - , _client(DispatcherIdentifier(), DispatcherBasePath()) + , _client(MessageSettings::Instance().Identifier(), MessageSettings::Instance().BasePath(), MessageSettings::Instance().SocketPort()) , _factory() , _callback(nullptr) { _client.AddInstance(0); - _client.AddFactory(Core::Messaging::MetaData::MessageType::TRACING, &_factory); + _client.AddFactory(Core::Messaging::Metadata::type::TRACING, &_factory); _worker.Start(); @@ -145,7 +148,7 @@ namespace Messaging { { Core::SafeSyncType scopedLock(_adminLock); - Core::Messaging::MetaData metaData(Core::Messaging::MetaData::MessageType::TRACING, categoryName, moduleName); + Core::Messaging::Metadata metaData(Core::Messaging::Metadata::type::TRACING, categoryName, moduleName); _client.Enable(metaData, enable); @@ -155,7 +158,7 @@ namespace Messaging { void Dispatch() { _client.WaitForUpdates(Core::infinite); - _client.PopMessagesAndCall([this](const Core::Messaging::Information& info, const Core::ProxyType& message) { + _client.PopMessagesAndCall([this](const Core::Messaging::IStore::Information& info, const Core::ProxyType& message) { Output(info, message.Origin()); }); } @@ -170,7 +173,7 @@ namespace Messaging { } private: - void Output(const Core::Messaging::Information& info, const Core::Messaging::IEvent* message) + void Output(const Core::Messaging::IStore::Information& info, const Core::Messaging::IEvent* message) { Core::SafeSyncType scopedLock(_adminLock); @@ -222,30 +225,27 @@ namespace Messaging { } virtual ~ConsolePrinter() = default; - void Output(const Core::Messaging::Information& info, const Core::Messaging::IEvent* message) override + void Output(const Core::Messaging::IStore::Information& info, const Core::Messaging::IEvent* message) override { IosFlagSaver saveUs(std::cout); std::ostringstream output; - std::string deserializedMessage; output.str(""); output.clear(); - message->ToString(deserializedMessage); - Core::Time now(info.TimeStamp()); if (_abbreviated == true) { std::string time(now.ToTimeOnly(true)); output << '[' << time.c_str() << ']' - << '[' << info.MessageMetaData().Module() << "]" - << '[' << info.MessageMetaData().Category() << "]: " - << deserializedMessage << std::endl; + << '[' << info.Module() << "]" + << '[' << info.Category() << "]: " + << message->Data().c_str() << std::endl; } else { std::string time(now.ToRFC1123(true)); output << '[' << time.c_str() << "]:[" << Core::FileNameOnly(info.FileName().c_str()) << ':' << info.LineNumber() << "] " - << info.MessageMetaData().Category() << ": " << deserializedMessage << std::endl; + << info.Category() << ": " << message->Data().c_str() << std::endl; } std::cout << output.str() << std::flush; From 29e141c7a8fe36669cd96860987aa2cb123ea8cb Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Fri, 9 Dec 2022 22:43:34 +0530 Subject: [PATCH 03/37] Cryptography:test app made it compilable again (#175) --- Source/cryptography/CMakeLists.txt | 3 ++- .../implementation/cipher_implementation.h | 9 +++---- .../diffiehellman_implementation.h | 4 +-- .../implementation/hash_implementation.h | 11 ++++---- .../netflix_security_implementation.h | 12 ++++----- .../persistent_implementation.h | 9 +++---- .../implementation/vault_implementation.h | 26 ++++++++++++++----- .../tests/cryptography_test/CMakeLists.txt | 13 +++++++--- .../tests/cryptography_test/Module.h | 2 +- 9 files changed, 52 insertions(+), 37 deletions(-) diff --git a/Source/cryptography/CMakeLists.txt b/Source/cryptography/CMakeLists.txt index ce49c8f1..d519b69f 100644 --- a/Source/cryptography/CMakeLists.txt +++ b/Source/cryptography/CMakeLists.txt @@ -29,7 +29,7 @@ message("Setup ${TARGET} v${PROJECT_VERSION}") set(CMAKE_POSITION_INDEPENDENT_CODE ON) -# remove the -as-needed flag because it can lead to losing dependencies when we're mixing static and shared libs +# remove the -as-needed flag because it can lead to losing dependencies when we're mixing static and shared libs string(REPLACE "-Wl,--as-needed" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed") @@ -61,6 +61,7 @@ target_link_libraries(${TARGET} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core ${NAMESPACE}COM::${NAMESPACE}COM + CompileSettingsDebug::CompileSettingsDebug -Wl,--whole-archive implementation -Wl,--no-whole-archive ) diff --git a/Source/cryptography/implementation/cipher_implementation.h b/Source/cryptography/implementation/cipher_implementation.h index 716a3915..a9112d1c 100644 --- a/Source/cryptography/implementation/cipher_implementation.h +++ b/Source/cryptography/implementation/cipher_implementation.h @@ -39,15 +39,14 @@ typedef enum { struct CipherImplementation; -struct CipherImplementation* cipher_create_aes(const struct VaultImplementation* vault, const aes_mode mode, const uint32_t key_id); +EXTERNAL struct CipherImplementation* cipher_create_aes(const struct VaultImplementation* vault, const aes_mode mode, const uint32_t key_id); -void cipher_destroy(struct CipherImplementation* cipher); +EXTERNAL void cipher_destroy(struct CipherImplementation* cipher); - -int32_t cipher_encrypt(const struct CipherImplementation* cipher, const uint8_t iv_length, const uint8_t iv[], +EXTERNAL int32_t cipher_encrypt(const struct CipherImplementation* cipher, const uint8_t iv_length, const uint8_t iv[], const uint32_t input_length, const uint8_t input[], const uint32_t max_output_length, uint8_t output[]); -int32_t cipher_decrypt(const struct CipherImplementation* cipher, const uint8_t iv_length, const uint8_t iv[], +EXTERNAL int32_t cipher_decrypt(const struct CipherImplementation* cipher, const uint8_t iv_length, const uint8_t iv[], const uint32_t input_length, const uint8_t input[], const uint32_t max_output_length, uint8_t output[]); #ifdef __cplusplus diff --git a/Source/cryptography/implementation/diffiehellman_implementation.h b/Source/cryptography/implementation/diffiehellman_implementation.h index e874f11b..c5a51745 100644 --- a/Source/cryptography/implementation/diffiehellman_implementation.h +++ b/Source/cryptography/implementation/diffiehellman_implementation.h @@ -26,11 +26,11 @@ extern "C" { #endif -uint32_t diffiehellman_generate(struct VaultImplementation* vault, +EXTERNAL uint32_t diffiehellman_generate(struct VaultImplementation* vault, const uint8_t generator, const uint16_t modulusSize, const uint8_t modulus[], uint32_t* private_key_id, uint32_t* public_key_id); -uint32_t diffiehellman_derive(struct VaultImplementation* vault, +EXTERNAL uint32_t diffiehellman_derive(struct VaultImplementation* vault, const uint32_t private_key_id, const uint32_t peer_public_key_id, uint32_t* secret_id); #ifdef __cplusplus diff --git a/Source/cryptography/implementation/hash_implementation.h b/Source/cryptography/implementation/hash_implementation.h index 5e93833c..e57daa80 100644 --- a/Source/cryptography/implementation/hash_implementation.h +++ b/Source/cryptography/implementation/hash_implementation.h @@ -37,16 +37,15 @@ typedef enum { struct HashImplementation; -struct HashImplementation* hash_create(const hash_type type); +EXTERNAL struct HashImplementation* hash_create(const hash_type type); -struct HashImplementation* hash_create_hmac(const struct VaultImplementation* vault, const hash_type type, const uint32_t secret_id); +EXTERNAL struct HashImplementation* hash_create_hmac(const struct VaultImplementation* vault, const hash_type type, const uint32_t secret_id); -void hash_destroy(struct HashImplementation* signing); +EXTERNAL void hash_destroy(struct HashImplementation* signing); +EXTERNAL uint32_t hash_ingest(struct HashImplementation* signing, const uint32_t length, const uint8_t data[]); -uint32_t hash_ingest(struct HashImplementation* signing, const uint32_t length, const uint8_t data[]); - -uint8_t hash_calculate(struct HashImplementation* signing, const uint8_t max_length, uint8_t data[]); +EXTERNAL uint8_t hash_calculate(struct HashImplementation* signing, const uint8_t max_length, uint8_t data[]); #ifdef __cplusplus } // extern "C" diff --git a/Source/cryptography/implementation/netflix_security_implementation.h b/Source/cryptography/implementation/netflix_security_implementation.h index 3cea9048..70fbf7a6 100644 --- a/Source/cryptography/implementation/netflix_security_implementation.h +++ b/Source/cryptography/implementation/netflix_security_implementation.h @@ -27,13 +27,13 @@ extern "C" { /* Note: These calls adhere to the CRYPTOGRAPHY_VAULT_NETFLIX vault only. */ -uint16_t netflix_security_esn(const uint16_t max_length, uint8_t data[]); +EXTERNAL uint16_t netflix_security_esn(const uint16_t max_length, uint8_t data[]); -uint32_t netflix_security_encryption_key(void); +EXTERNAL uint32_t netflix_security_encryption_key(void); -uint32_t netflix_security_hmac_key(void); +EXTERNAL uint32_t netflix_security_hmac_key(void); -uint32_t netflix_security_wrapping_key(void); +EXTERNAL uint32_t netflix_security_wrapping_key(void); /* Derive encryption keys based on an authenticated Diffie-Hellman procedure : 1) secret = dh_shared_secret(private_key, peer_public_key) @@ -42,8 +42,8 @@ uint32_t netflix_security_wrapping_key(void); 4) hmacKey = vector[16..47] ; HMAC-256 5) wrappingKey = HMAC-256(809f82a7addf548d3ea9dd067ff9bb91, HMAC-256(vector, 027617984f6227539a630b897c017d69))[0..15] ; AES-128 */ -uint32_t netflix_security_derive_keys(const uint32_t private_dh_key_id, const uint32_t peer_public_dh_key_id, const uint32_t derivation_key_id, - uint32_t* encryption_key_id, uint32_t* hmac_key_id, uint32_t* wrapping_key_id); +EXTERNAL uint32_t netflix_security_derive_keys(const uint32_t private_dh_key_id, const uint32_t peer_public_dh_key_id, + const uint32_t derivation_key_id, uint32_t* encryption_key_id, uint32_t* hmac_key_id, uint32_t* wrapping_key_id); #ifdef __cplusplus } // extern "C" diff --git a/Source/cryptography/implementation/persistent_implementation.h b/Source/cryptography/implementation/persistent_implementation.h index 37265e0f..4b74092c 100644 --- a/Source/cryptography/implementation/persistent_implementation.h +++ b/Source/cryptography/implementation/persistent_implementation.h @@ -36,14 +36,13 @@ typedef enum { HMAC256 }key_type; -uint32_t persistent_key_exists( struct VaultImplementation* vault ,const char locator[],bool* result); +EXTERNAL uint32_t persistent_key_exists( struct VaultImplementation* vault ,const char locator[],bool* result); -uint32_t persistent_key_load(struct VaultImplementation* vault,const char locator[],uint32_t* id); +EXTERNAL uint32_t persistent_key_load(struct VaultImplementation* vault,const char locator[],uint32_t* id); -uint32_t persistent_key_create( struct VaultImplementation* vault,const char locator[],const key_type keyType,uint32_t* id); - -uint32_t persistent_flush(struct VaultImplementation* vault); +EXTERNAL uint32_t persistent_key_create( struct VaultImplementation* vault,const char locator[],const key_type keyType,uint32_t* id); +EXTERNAL uint32_t persistent_flush(struct VaultImplementation* vault); #ifdef __cplusplus } // extern "C" diff --git a/Source/cryptography/implementation/vault_implementation.h b/Source/cryptography/implementation/vault_implementation.h index 85a44e44..6704bac2 100644 --- a/Source/cryptography/implementation/vault_implementation.h +++ b/Source/cryptography/implementation/vault_implementation.h @@ -23,6 +23,18 @@ #include #include "cryptography_vault_ids.h" +#undef EXTERNAL +#if defined(WIN32) || defined(_WINDOWS) || defined (__CYGWIN__) || defined(_WIN64) +#ifdef DEVICEINFO_EXPORTS +#define EXTERNAL __declspec(dllexport) +#else +#define EXTERNAL __declspec(dllimport) +#pragma comment(lib, "crypto.lib") +#endif +#else +#define EXTERNAL __attribute__((visibility("default"))) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -30,19 +42,19 @@ extern "C" { struct VaultImplementation; -struct VaultImplementation* vault_instance(const enum cryptographyvault id); +EXTERNAL struct VaultImplementation* vault_instance(const enum cryptographyvault id); -uint16_t vault_size(const struct VaultImplementation* vault, const uint32_t id); +EXTERNAL uint16_t vault_size(const struct VaultImplementation* vault, const uint32_t id); -uint32_t vault_import(struct VaultImplementation* vault, const uint16_t length, const uint8_t blob[]); +EXTERNAL uint32_t vault_import(struct VaultImplementation* vault, const uint16_t length, const uint8_t blob[]); -uint16_t vault_export(const struct VaultImplementation* vault, const uint32_t id, const uint16_t max_length, uint8_t blob[]); +EXTERNAL uint16_t vault_export(const struct VaultImplementation* vault, const uint32_t id, const uint16_t max_length, uint8_t blob[]); -uint32_t vault_set(struct VaultImplementation* vault, const uint16_t length, const uint8_t blob[]); +EXTERNAL uint32_t vault_set(struct VaultImplementation* vault, const uint16_t length, const uint8_t blob[]); -uint16_t vault_get(const struct VaultImplementation* vault, const uint32_t id, const uint16_t max_length, uint8_t blob[]); +EXTERNAL uint16_t vault_get(const struct VaultImplementation* vault, const uint32_t id, const uint16_t max_length, uint8_t blob[]); -bool vault_delete(struct VaultImplementation* vault, const uint32_t id); +EXTERNAL bool vault_delete(struct VaultImplementation* vault, const uint32_t id); #ifdef __cplusplus diff --git a/Source/cryptography/tests/cryptography_test/CMakeLists.txt b/Source/cryptography/tests/cryptography_test/CMakeLists.txt index ddf94bf4..b6191d6f 100644 --- a/Source/cryptography/tests/cryptography_test/CMakeLists.txt +++ b/Source/cryptography/tests/cryptography_test/CMakeLists.txt @@ -17,7 +17,7 @@ option(BUILD_NETFLIX_VAULT_GENERATOR "Build Netflix Vault generator" OFF) - +find_package(${NAMESPACE}Core REQUIRED) include_directories(${CMAKE_CURRENT_LIST_DIR}/../../../../Source) set(CMAKE_CXX_STANDARD 11) @@ -35,12 +35,17 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/../../../cryptography) include_directories(${CMAKE_CURRENT_LIST_DIR}/../../../cryptography/implementation) include_directories($) +set_target_properties(cgimptests PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + ) + target_link_libraries(cgimptests PRIVATE ${NAMESPACE}Cryptography + ${NAMESPACE}Core::${NAMESPACE}Core ssl crypto - -Wl,--warn-unresolved-symbols ) @@ -64,9 +69,9 @@ set_target_properties(cgfacetests PROPERTIES target_link_libraries(cgfacetests PRIVATE ${NAMESPACE}Cryptography + ${NAMESPACE}Core::${NAMESPACE}Core ssl crypto - -Wl,--warn-unresolved-symbols ) add_executable(cgnfsecuritytests @@ -87,9 +92,9 @@ set_target_properties(cgnfsecuritytests PROPERTIES target_link_libraries(cgnfsecuritytests PRIVATE ${NAMESPACE}Cryptography + ${NAMESPACE}Core::${NAMESPACE}Core ssl crypto - -Wl,--warn-unresolved-symbols ) install(TARGETS cgimptests DESTINATION bin) diff --git a/Source/cryptography/tests/cryptography_test/Module.h b/Source/cryptography/tests/cryptography_test/Module.h index 2fc6fd8d..2fffba85 100644 --- a/Source/cryptography/tests/cryptography_test/Module.h +++ b/Source/cryptography/tests/cryptography_test/Module.h @@ -23,7 +23,7 @@ #define MODULE_NAME CryptographyTest #endif -#include +#include #undef EXTERNAL #define EXTERNAL From 1d1d8ed4dae404a9fdb06baf43dee4df78c70370 Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Thu, 15 Dec 2022 17:26:37 +0100 Subject: [PATCH 04/37] fix height typo's --- Source/displayinfo/include/displayinfo.h | 2 +- Source/ocdm/open_cdm_ext.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/displayinfo/include/displayinfo.h b/Source/displayinfo/include/displayinfo.h index 67e1bb81..102adca2 100644 --- a/Source/displayinfo/include/displayinfo.h +++ b/Source/displayinfo/include/displayinfo.h @@ -444,7 +444,7 @@ EXTERNAL uint32_t displayinfo_edid_vic_to_standard_timing(const displayinfo_edid EXTERNAL uint32_t displayinfo_width_in_centimeters( uint8_t* width); /** - * @brief Get the heigth of the connected display in centimaters + * @brief Get the height of the connected display in centimaters * * @param instance Instance of @ref displayinfo_type * @param height The current height in centimeters diff --git a/Source/ocdm/open_cdm_ext.cpp b/Source/ocdm/open_cdm_ext.cpp index d30c0371..703ced13 100644 --- a/Source/ocdm/open_cdm_ext.cpp +++ b/Source/ocdm/open_cdm_ext.cpp @@ -390,7 +390,7 @@ OpenCDMError opencdm_system_ext_get_properties(struct PlayLevels* system, const , _compressedAudio() , _uncompressedAudio() , _maxDecodeWidth() - , _maxDecodeHeigth() + , _maxDecodeHeight() { Add(_T("compressed-video"), &_compressedVideo); Add(_T("uncompressed-video"), &_uncompressedVideo); @@ -398,7 +398,7 @@ OpenCDMError opencdm_system_ext_get_properties(struct PlayLevels* system, const Add(_T("compressed-audio"), &_compressedAudio); Add(_T("uncompressed-audio"), &_uncompressedAudio); Add(_T("max-decode-width"), &_maxDecodeWidth); - Add(_T("max-decode-height"), &_maxDecodeHeigth); + Add(_T("max-decode-height"), &_maxDecodeHeight); } public: @@ -408,7 +408,7 @@ OpenCDMError opencdm_system_ext_get_properties(struct PlayLevels* system, const JSON::DecUInt16 _compressedAudio; JSON::DecUInt16 _uncompressedAudio; JSON::DecUInt32 _maxDecodeWidth; - JSON::DecUInt32 _maxDecodeHeigth; + JSON::DecUInt32 _maxDecodeHeight; }; ASSERT(system != nullptr); @@ -427,7 +427,7 @@ OpenCDMError opencdm_system_ext_get_properties(struct PlayLevels* system, const system->_compressedDigitalAudioLevel = playlevelJson._compressedAudio.Value(); system->_uncompressedDigitalAudioLevel = playlevelJson._uncompressedAudio.Value(); system->_maxResDecodeWidth = playlevelJson._maxDecodeWidth.Value(); - system->_maxResDecodeHeight = playlevelJson._maxDecodeHeigth.Value(); + system->_maxResDecodeHeight = playlevelJson._maxDecodeHeight.Value(); result = OpenCDMError::ERROR_NONE; } From f57047b24ef295c239d11d4d4b6035116c627a23 Mon Sep 17 00:00:00 2001 From: MFransen69 <39826971+MFransen69@users.noreply.github.com> Date: Thu, 15 Dec 2022 17:30:30 +0100 Subject: [PATCH 05/37] Merge pull request #178 from rdkcentral/fix/fix-small-typo's fix height typo's From 040e68ae3f8938b6dda1cc37b1c7c9f620e5dbc0 Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Mon, 19 Dec 2022 19:03:03 +0100 Subject: [PATCH 06/37] LocalTracer: Fix line echo. --- Source/localtracer/include/localtracer/localtracer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/localtracer/include/localtracer/localtracer.h b/Source/localtracer/include/localtracer/localtracer.h index 18dc3ac9..f9768cd8 100644 --- a/Source/localtracer/include/localtracer/localtracer.h +++ b/Source/localtracer/include/localtracer/localtracer.h @@ -104,7 +104,7 @@ namespace Messaging { Core::Directory(Path.c_str()).CreatePath(); - Messaging::MessageUnit::Instance().Open(Path, 0, "", false, Messaging::MessageUnit::FLUSH); + Messaging::MessageUnit::Instance().Open(Path, 0, "", false, Messaging::MessageUnit::OFF); singleton = new LocalTracer(Path); } From 165452b080a5f10e81dec1286e013323da17af60 Mon Sep 17 00:00:00 2001 From: sebaszm <45654185+sebaszm@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:20:12 +0100 Subject: [PATCH 07/37] DeviceInfo/DisplayInfo stress tests (#181) * displayinfo: Add stress test option * deviceinfo: Add stress tests * Update main.c --- Source/deviceinfo/device_info/main.c | 29 ++++++++++++++++++++++++++ Source/displayinfo/display_info/main.c | 14 +++++++++++++ 2 files changed, 43 insertions(+) diff --git a/Source/deviceinfo/device_info/main.c b/Source/deviceinfo/device_info/main.c index a853e960..326de44d 100644 --- a/Source/deviceinfo/device_info/main.c +++ b/Source/deviceinfo/device_info/main.c @@ -74,6 +74,9 @@ void ShowMenu() "\tP : Get platform name\n" "\tS : Get summary of available audio outputs\n" "\tV : Get summary of available video outputs\n" + "\t1 : Stress test 1\n" + "\t2 : Stress test 2\n" + "\tQ : Quit\n" ); } @@ -416,6 +419,32 @@ int main() } break; } + case '1': { + char bufferstr[150]; + uint8_t bufferLength = sizeof(bufferstr); + uint32_t count = 500000; + while (count-- != 0) { + bufferLength = sizeof(bufferstr); + memset(bufferstr, 0, bufferLength); + result = deviceinfo_id_str(bufferstr, &bufferLength); + if (result==0) { + Trace("%i: ID[%d]: %s", count, bufferLength, bufferstr); + } else if (result == 16) { + Trace("Buffer too small, should be at least of size %d ",bufferLength); + } else { + Trace("Instance or buffer is null. Error code = %d ", result); + } + } + break; + } + case '2': { + uint32_t count = 500000; + while (count-- != 0) { + deviceinfo_output_resolution_t res = DEVICEINFO_RESOLUTION_UNKNOWN; + deviceinfo_maximum_output_resolution(&res); + Trace("%i: Output Resolution: %d", count, res); + } + } case '?': { ShowMenu(); break; diff --git a/Source/displayinfo/display_info/main.c b/Source/displayinfo/display_info/main.c index 944d8214..35fa0c1d 100644 --- a/Source/displayinfo/display_info/main.c +++ b/Source/displayinfo/display_info/main.c @@ -162,6 +162,7 @@ void ShowMenu() "\tT : Get total gpu ram\n" "\tF : Get free gpu ram\n" "\tX : Get display dimensions in centimeters \n" + "\tS : Stress test\n" "\t? : Help\n" "\tQ : Quit\n", __TIMESTAMP__); @@ -296,6 +297,19 @@ int main() break; } + case 'S': { + uint32_t width = 0, height = 0; + uint32_t count = 50000; + while (count-- != 0) { + if (displayinfo_width(&width) == 0 && displayinfo_height(&height) == 0) { + Trace("%i: Display resolution %dhx%dw", count, width, height); + } else { + Trace("Instance or width/height param is NULL, or invalid connection"); + } + } + + break; + } case 'V': { uint32_t vertical_frequency = 0; if (displayinfo_vertical_frequency(&vertical_frequency) == 0) { From 96939a1a6f3badc434202aa7e0f3cb7cecb8ab97 Mon Sep 17 00:00:00 2001 From: Marcel Fransen Date: Fri, 23 Dec 2022 14:06:13 +0100 Subject: [PATCH 08/37] [DevInfo] fix build --- Source/deviceinfo/device_info/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/deviceinfo/device_info/main.c b/Source/deviceinfo/device_info/main.c index 326de44d..f4604476 100644 --- a/Source/deviceinfo/device_info/main.c +++ b/Source/deviceinfo/device_info/main.c @@ -441,7 +441,7 @@ int main() uint32_t count = 500000; while (count-- != 0) { deviceinfo_output_resolution_t res = DEVICEINFO_RESOLUTION_UNKNOWN; - deviceinfo_maximum_output_resolution(&res); + deviceinfo_maximum_output_resolution(DEVICEINFO_VIDEO_DISPLAYPORT, &res); Trace("%i: Output Resolution: %d", count, res); } } From d0644267c634af90509705d20cce583a51afda5d Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Fri, 23 Dec 2022 14:14:06 +0100 Subject: [PATCH 09/37] Merge pull request #182 from rdkcentral/development/fixdevinfo [DevInfo] fix build From c846aeeb282c1920686a9c17d9e0d1bfa7e0d10c Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Wed, 28 Dec 2022 13:40:22 +0530 Subject: [PATCH 10/37] Update C header files with generic ifndef-define structure instead pragma once (#183) --- Source/cryptography/cryptography.h | 5 ++++- Source/cryptography/cryptography_vault_ids.h | 5 ++++- .../cryptography/implementation/cipher_implementation.h | 5 ++++- .../implementation/diffiehellman_implementation.h | 5 ++++- Source/cryptography/implementation/hash_implementation.h | 5 ++++- .../implementation/netflix_security_implementation.h | 5 ++++- .../implementation/persistent_implementation.h | 4 +++- .../cryptography/implementation/vault_implementation.h | 5 ++++- Source/cryptography/tests/cryptography_test/Helpers.h | 4 +++- Source/deviceinfo/deviceinfo.h | 5 ++++- Source/displayinfo/include/displayinfo.h | 5 ++++- Source/ocdm/open_cdm.h | 5 +++-- Source/ocdm/open_cdm_ext.h | 9 +++------ Source/playerinfo/include/playerinfo.h | 5 ++++- Source/securityagent/securityagent.h | 4 +++- Source/virtualinput/virtualinput.h | 5 ++++- 16 files changed, 59 insertions(+), 22 deletions(-) diff --git a/Source/cryptography/cryptography.h b/Source/cryptography/cryptography.h index 1ef4f56e..9a339066 100644 --- a/Source/cryptography/cryptography.h +++ b/Source/cryptography/cryptography.h @@ -17,7 +17,10 @@ * limitations under the License. */ -#pragma once +#ifndef CRYPTOGRAPHY_H +#define CRYPTOGRAPHY_H #include "ICryptography.h" #include "INetflixSecurity.h" + +#endif // CRYPTOGRAPHY_H diff --git a/Source/cryptography/cryptography_vault_ids.h b/Source/cryptography/cryptography_vault_ids.h index 0d3fb20d..b089cbc5 100644 --- a/Source/cryptography/cryptography_vault_ids.h +++ b/Source/cryptography/cryptography_vault_ids.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef CRYPTOGRAPHY_VAULT_IDS_H +#define CRYPTOGRAPHY_VAULT_IDS_H #include @@ -30,3 +31,5 @@ extern "C" CRYPTOGRAPHY_VAULT_PROVISIONING = 0x10, CRYPTOGRAPHY_VAULT_NETFLIX = 0x11 }; + +#endif // CRYPTOGRAPHY_VAULT_IDS_H diff --git a/Source/cryptography/implementation/cipher_implementation.h b/Source/cryptography/implementation/cipher_implementation.h index a9112d1c..303065f5 100644 --- a/Source/cryptography/implementation/cipher_implementation.h +++ b/Source/cryptography/implementation/cipher_implementation.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef CIPHER_IMPLEMENTATION_H +#define CIPHER_IMPLEMENTATION_H #include #include "vault_implementation.h" @@ -52,3 +53,5 @@ EXTERNAL int32_t cipher_decrypt(const struct CipherImplementation* cipher, const #ifdef __cplusplus } // extern "C" #endif + +#endif // CIPHER_IMPLEMENTATION_H diff --git a/Source/cryptography/implementation/diffiehellman_implementation.h b/Source/cryptography/implementation/diffiehellman_implementation.h index c5a51745..e857a6ef 100644 --- a/Source/cryptography/implementation/diffiehellman_implementation.h +++ b/Source/cryptography/implementation/diffiehellman_implementation.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef DIFFIEHELLMAN_IMPLEMENTATION_H +#define DIFFIEHELLMAN_IMPLEMENTATION_H #include #include "vault_implementation.h" @@ -36,3 +37,5 @@ EXTERNAL uint32_t diffiehellman_derive(struct VaultImplementation* vault, #ifdef __cplusplus } // extern "C" #endif + +#endif // DIFFIEHELLMAN_IMPLEMENTATION_H diff --git a/Source/cryptography/implementation/hash_implementation.h b/Source/cryptography/implementation/hash_implementation.h index e57daa80..b04133ea 100644 --- a/Source/cryptography/implementation/hash_implementation.h +++ b/Source/cryptography/implementation/hash_implementation.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef HASH_IMPLEMENTATION_H +#define HASH_IMPLEMENTATION_H #include #include "vault_implementation.h" @@ -50,3 +51,5 @@ EXTERNAL uint8_t hash_calculate(struct HashImplementation* signing, const uint8_ #ifdef __cplusplus } // extern "C" #endif + +#endif // HASH_IMPLEMENTATION_H diff --git a/Source/cryptography/implementation/netflix_security_implementation.h b/Source/cryptography/implementation/netflix_security_implementation.h index 70fbf7a6..bf3d5668 100644 --- a/Source/cryptography/implementation/netflix_security_implementation.h +++ b/Source/cryptography/implementation/netflix_security_implementation.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef NETFLIX_SECURITY_IMPL_H +#define NETFLIX_SECURITY_IMPL_H #include @@ -48,3 +49,5 @@ EXTERNAL uint32_t netflix_security_derive_keys(const uint32_t private_dh_key_id, #ifdef __cplusplus } // extern "C" #endif + +#endif // NETFLIX_SECURITY_IMPL_H diff --git a/Source/cryptography/implementation/persistent_implementation.h b/Source/cryptography/implementation/persistent_implementation.h index 4b74092c..9fc4a566 100644 --- a/Source/cryptography/implementation/persistent_implementation.h +++ b/Source/cryptography/implementation/persistent_implementation.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef PERSISTENT_IMPLEMENTATION_H +#define PERSISTENT_IMPLEMENTATION_H #include #include @@ -48,3 +49,4 @@ EXTERNAL uint32_t persistent_flush(struct VaultImplementation* vault); } // extern "C" #endif +#endif // PERSISTENT_IMPLEMENTATION_H diff --git a/Source/cryptography/implementation/vault_implementation.h b/Source/cryptography/implementation/vault_implementation.h index 6704bac2..91e358ba 100644 --- a/Source/cryptography/implementation/vault_implementation.h +++ b/Source/cryptography/implementation/vault_implementation.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef VAULT_IMPLEMENTATION_H +#define VAULT_IMPLEMENTATION_H #include #include @@ -60,3 +61,5 @@ EXTERNAL bool vault_delete(struct VaultImplementation* vault, const uint32_t id) #ifdef __cplusplus } // extern "C" #endif + +#endif // VAULT_IMPLEMENTATION_H diff --git a/Source/cryptography/tests/cryptography_test/Helpers.h b/Source/cryptography/tests/cryptography_test/Helpers.h index 18bbfb47..b346fc83 100644 --- a/Source/cryptography/tests/cryptography_test/Helpers.h +++ b/Source/cryptography/tests/cryptography_test/Helpers.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef HELPERS_H +#define HELPERS_H #include "Module.h" @@ -48,3 +49,4 @@ bool DHAuthenticatedDerive(DH* dh, const uint16_t secretSize, const uint8_t secr } #endif +#endif // HELPERS_H diff --git a/Source/deviceinfo/deviceinfo.h b/Source/deviceinfo/deviceinfo.h index b6c754c1..d484dc76 100644 --- a/Source/deviceinfo/deviceinfo.h +++ b/Source/deviceinfo/deviceinfo.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef DEVICEINFO_H +#define DEVICEINFO_H #include #include @@ -441,3 +442,5 @@ EXTERNAL void deviceinfo_dispose(); #ifdef __cplusplus } // extern "C" #endif + +#endif // DEVICEINFO_H diff --git a/Source/displayinfo/include/displayinfo.h b/Source/displayinfo/include/displayinfo.h index 102adca2..feffeb96 100644 --- a/Source/displayinfo/include/displayinfo.h +++ b/Source/displayinfo/include/displayinfo.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef DISPLAYINFO_H +#define DISPLAYINFO_H #include #include @@ -470,3 +471,5 @@ EXTERNAL void displayinfo_dispose(); #ifdef __cplusplus } // extern "C" #endif + +#endif // DISPLAYINFO_H diff --git a/Source/ocdm/open_cdm.h b/Source/ocdm/open_cdm.h index 9411c130..367279c5 100644 --- a/Source/ocdm/open_cdm.h +++ b/Source/ocdm/open_cdm.h @@ -15,7 +15,8 @@ * limitations under the License. */ -#pragma once +#ifndef OPEN_CDM_H +#define OPEN_CDM_H // WPEWebkit implementation is using the following header file to integrate // their solution with @@ -597,4 +598,4 @@ EXTERNAL void opencdm_dispose(); } #endif - +#endif // OPEN_CDM_H diff --git a/Source/ocdm/open_cdm_ext.h b/Source/ocdm/open_cdm_ext.h index fa9965c5..24a85e46 100644 --- a/Source/ocdm/open_cdm_ext.h +++ b/Source/ocdm/open_cdm_ext.h @@ -15,11 +15,11 @@ * limitations under the License. */ -#pragma once +#ifndef OPEN_CDM_EXT_H +#define OPEN_CDM_EXT_H #include "open_cdm.h" - #ifdef __cplusplus extern "C" { #endif @@ -239,7 +239,4 @@ EXTERNAL OpenCDMError opencdm_system_ext_get_properties(struct PlayLevels* syste } // extern "C" #endif - - - - +#endif // OPEN_CDM_EXT_H diff --git a/Source/playerinfo/include/playerinfo.h b/Source/playerinfo/include/playerinfo.h index 9c330af0..c27ccfe5 100644 --- a/Source/playerinfo/include/playerinfo.h +++ b/Source/playerinfo/include/playerinfo.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef PLAYERINFO_H +#define PLAYERINFO_H #include #include @@ -291,3 +292,5 @@ EXTERNAL void playerinfo_dispose(); #ifdef __cplusplus } // extern "C" #endif + +#endif // PLAYERINFO_H diff --git a/Source/securityagent/securityagent.h b/Source/securityagent/securityagent.h index 8e02370c..b129a645 100644 --- a/Source/securityagent/securityagent.h +++ b/Source/securityagent/securityagent.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef SECURITYAGENT_H +#define SECURITYAGENT_H #ifndef EXTERNAL #ifdef _MSVC_LANG @@ -65,3 +66,4 @@ extern "C" { #ifdef __cplusplus } #endif +#endif // SECURITYAGENT_H diff --git a/Source/virtualinput/virtualinput.h b/Source/virtualinput/virtualinput.h index 9faf7336..044b22a3 100644 --- a/Source/virtualinput/virtualinput.h +++ b/Source/virtualinput/virtualinput.h @@ -17,7 +17,8 @@ * limitations under the License. */ -#pragma once +#ifndef VIRTUALINPUT_H +#define VIRTUALINPUT_H #include @@ -87,3 +88,5 @@ EXTERNAL void virtualinput_dispose(); #ifdef __cplusplus } #endif + +#endif // VIRTUALINPUT_H From 4a300a62c4f2a0ce62097af92ea375cb497a265a Mon Sep 17 00:00:00 2001 From: Neeraj Deshpande Date: Tue, 3 Jan 2023 15:10:27 +0530 Subject: [PATCH 11/37] Modified to check mime type in protection metadata to detect encryption scheme. (#180) --- Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp b/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp index 3dda3d51..f58f5e43 100644 --- a/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp +++ b/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp @@ -87,6 +87,8 @@ OpenCDMError opencdm_gstreamer_session_decrypt(struct OpenCDMSession* session, G const char* cipherModeBuf = gst_structure_get_string(protectionMeta->info, "cipher-mode"); if(g_strcmp0(cipherModeBuf,"cbcs") == 0) { encScheme = AesCbc_Cbcs; + } else if (gst_structure_has_name(protectionMeta->info, "application/x-cbcs")) { + encScheme = AesCbc_Cbcs; } gst_structure_get_uint(protectionMeta->info, "crypt_byte_block", &pattern.encrypted_blocks); @@ -253,6 +255,8 @@ OpenCDMError opencdm_gstreamer_session_decrypt_buffer(struct OpenCDMSession* ses const char* cipherModeBuf = gst_structure_get_string(protectionMeta->info, "cipher-mode"); if(g_strcmp0(cipherModeBuf,"cbcs") == 0) { encScheme = AesCbc_Cbcs; + } else if (gst_structure_has_name(protectionMeta->info, "application/x-cbcs")) { + encScheme = AesCbc_Cbcs; } gst_structure_get_uint(protectionMeta->info, "crypt_byte_block", &pattern.encrypted_blocks); gst_structure_get_uint(protectionMeta->info, "skip_byte_block", &pattern.clear_blocks); From 36c1855f5718900a5f8af39c53710b4f30df1ebe Mon Sep 17 00:00:00 2001 From: Neeraj Deshpande Date: Tue, 10 Jan 2023 18:30:55 +0530 Subject: [PATCH 12/37] Modified to fetch secbuf OCDM adapater from external repository. (#184) --- Source/ocdm/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/ocdm/CMakeLists.txt b/Source/ocdm/CMakeLists.txt index fe22bbfa..79451fd8 100644 --- a/Source/ocdm/CMakeLists.txt +++ b/Source/ocdm/CMakeLists.txt @@ -73,7 +73,7 @@ target_include_directories( ${TARGET} $ ) -if("${CDMI_ADAPTER_IMPLEMENTATION}" STREQUAL "broadcom-svp") +if(("${CDMI_ADAPTER_IMPLEMENTATION}" STREQUAL "broadcom-svp") OR ("${CDMI_ADAPTER_IMPLEMENTATION}" STREQUAL "broadcom-svp-secbuf")) if (OCDM_IMPLEMENTATION_PATH) target_sources(${TARGET} PRIVATE ${OCDM_IMPLEMENTATION_PATH}/open_cdm_adapter.cpp) else() @@ -85,7 +85,11 @@ if("${CDMI_ADAPTER_IMPLEMENTATION}" STREQUAL "broadcom-svp") GIT_VERSION ${OCDM_IMPLEMENTATION_VERSION} SOURCE_DIR "adapter/broadcom-svp" ) - target_sources(${TARGET} PRIVATE adapter/broadcom-svp/open_cdm_adapter.cpp) + if("${CDMI_ADAPTER_IMPLEMENTATION}" STREQUAL "broadcom-svp") + target_sources(${TARGET} PRIVATE adapter/broadcom-svp/open_cdm_adapter.cpp) + else() + target_sources(${TARGET} PRIVATE adapter/broadcom-svp/open_cdm_adapter-secbuf.cpp) + endif() endif() else() target_sources(${TARGET} PRIVATE adapter/${CDMI_ADAPTER_IMPLEMENTATION}/open_cdm_adapter.cpp) From 09689520670fcb3d34ba4703e6f823b87e64fa43 Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Tue, 10 Jan 2023 14:11:15 +0100 Subject: [PATCH 13/37] [WINDOWS] Get it compiling under windows again.. --- Source/cryptography/Cryptography.vcxproj | 8 ++++---- Source/cryptography/implementation/vault_implementation.h | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/cryptography/Cryptography.vcxproj b/Source/cryptography/Cryptography.vcxproj index 22d9e222..1a0cab53 100644 --- a/Source/cryptography/Cryptography.vcxproj +++ b/Source/cryptography/Cryptography.vcxproj @@ -135,7 +135,7 @@ Windows true - $(OutDir);$(WindowsLibraries)\static_x64 + $(OutDir);$(WindowsLibraries)static_x64 libcrypto.lib;libssl.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(IntDir)$(TargetName).pdb @@ -164,7 +164,7 @@ Windows true - $(OutDir);$(WindowsLibraries)\static_x32 + $(OutDir);$(WindowsLibraries)static_x32 libcrypto.lib;libssl.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(IntDir)$(TargetName).pdb @@ -197,7 +197,7 @@ true true true - $(OutDir);$(WindowsLibraries)\static_x32 + $(OutDir);$(WindowsLibraries)static_x32 libcrypto.lib;libssl.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(IntDir)$(TargetName).pdb @@ -230,7 +230,7 @@ true true true - $(OutDir);$(WindowsLibraries)\static_x64 + $(OutDir);$(WindowsLibraries)static_x64 libcrypto.lib;libssl.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(IntDir)$(TargetName).pdb diff --git a/Source/cryptography/implementation/vault_implementation.h b/Source/cryptography/implementation/vault_implementation.h index 91e358ba..04e45edd 100644 --- a/Source/cryptography/implementation/vault_implementation.h +++ b/Source/cryptography/implementation/vault_implementation.h @@ -26,11 +26,11 @@ #undef EXTERNAL #if defined(WIN32) || defined(_WINDOWS) || defined (__CYGWIN__) || defined(_WIN64) -#ifdef DEVICEINFO_EXPORTS +#ifdef CRYPTOGRAPHY_EXPORTS #define EXTERNAL __declspec(dllexport) #else #define EXTERNAL __declspec(dllimport) -#pragma comment(lib, "crypto.lib") +#pragma comment(lib, "cryptography.lib") #endif #else #define EXTERNAL __attribute__((visibility("default"))) @@ -40,7 +40,6 @@ extern "C" { #endif - struct VaultImplementation; EXTERNAL struct VaultImplementation* vault_instance(const enum cryptographyvault id); From de62484edecf2e641b5da6256b4319ab61b73857 Mon Sep 17 00:00:00 2001 From: VeithMetro <121170681+VeithMetro@users.noreply.github.com> Date: Fri, 10 Feb 2023 11:32:43 +0100 Subject: [PATCH 14/37] Creating GitHub Actions to build ThunderClientLibraries (#188) --- .../Build ThunderClientLibraries.yml | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/Build ThunderClientLibraries.yml diff --git a/.github/workflows/Build ThunderClientLibraries.yml b/.github/workflows/Build ThunderClientLibraries.yml new file mode 100644 index 00000000..8869440b --- /dev/null +++ b/.github/workflows/Build ThunderClientLibraries.yml @@ -0,0 +1,88 @@ +name: CMake ThunderClientLibraries + +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] + +jobs: + ThunderInterfaces: + uses: rdkcentral/ThunderInterfaces/.github/workflows/Build ThunderInterfaces.yml@master + + Interfaces: + needs: ThunderInterfaces + + runs-on: ubuntu-latest + + strategy: + matrix: + build_type: [Debug, Release, MinSizeRel] + + name: Build type - ${{matrix.build_type}} + steps: + - name: Install necessary packages + uses: nick-fields/retry@v2 + with: + timeout_minutes: 10 + max_attempts: 10 + command: | + sudo gem install apt-spy2 + sudo apt-spy2 fix --commit --launchpad --country=US + sudo apt-get update + sudo apt install python3-pip + pip install jsonref + sudo apt install build-essential cmake ninja-build libusb-1.0-0-dev zlib1g-dev libssl-dev + + - name: Checkout Thunder + uses: actions/checkout@v3 + with: + path: Thunder + repository: ${{github.repository_owner}}/Thunder + + - name: Checkout ThunderInterfaces + uses: actions/checkout@v3 + with: + path: ThunderInterfaces + repository: ${{github.repository_owner}}/ThunderInterfaces + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: ThunderInterfaces-${{matrix.build_type}}-artifact + path: ${{matrix.build_type}} + + - name: Unpack files + run: | + tar -xvzf ${{matrix.build_type}}/${{matrix.build_type}}.tar.gz + rm ${{matrix.build_type}}/${{matrix.build_type}}.tar.gz + + - name: Checkout ThunderClientLibraries + uses: actions/checkout@v3 + with: + path: ThunderClientLibraries + repository: ${{github.repository_owner}}/ThunderClientLibraries + + - name: Build ThunderClientLibraries + run: | + cmake -G Ninja -S ThunderClientLibraries -B ${{matrix.build_type}}/build/ThunderClientLibraries \ + -DCMAKE_INSTALL_PREFIX="${{matrix.build_type}}/install/usr" \ + -DCMAKE_MODULE_PATH="${PWD}/${{matrix.build_type}}/install/usr/include/WPEFramework/Modules" \ + -DBLUETOOTHAUDIOSINK=ON \ + -DDEVICEINFO=ON \ + -DDISPLAYINFO=ON \ + -DLOCALTRACER=ON \ + -DSECURITYAGENT=ON \ + -DPLAYERINFO=ON \ + -DPROTOCOLS=ON \ + -DVIRTUALINPUT=ON + cmake --build ${{matrix.build_type}}/build/ThunderClientLibraries --target install + + - name: Tar files + run: tar -czvf ${{matrix.build_type}}.tar.gz ${{matrix.build_type}} + + - name: Upload + uses: actions/upload-artifact@v3 + with: + name: ThunderClientLibraries-${{matrix.build_type}}-artifact + path: ${{matrix.build_type}}.tar.gz From c9e2142f23a7a8fdcea3fd8537a7fb71bcade384 Mon Sep 17 00:00:00 2001 From: VeithMetro <121170681+VeithMetro@users.noreply.github.com> Date: Wed, 15 Feb 2023 14:45:39 +0100 Subject: [PATCH 15/37] Fixing OCDM project file (#189) --- Source/ocdm/ocdm.vcxproj | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Source/ocdm/ocdm.vcxproj b/Source/ocdm/ocdm.vcxproj index 4591b5ad..fff1a26f 100644 --- a/Source/ocdm/ocdm.vcxproj +++ b/Source/ocdm/ocdm.vcxproj @@ -88,11 +88,13 @@ false $(SolutionDir)..\artifacts\$(Configuration)\ $(OutDir)WebBridge\$(TargetName)\ + true $(SolutionDir)..\artifacts\$(Configuration)\ $(OutDir)WebBridge\$(TargetName)\ + true @@ -104,6 +106,7 @@ false $(SolutionDir)..\artifacts\$(Configuration)\ $(OutDir)WebBridge\$(TargetName)\ + @@ -127,10 +130,12 @@ $(IntDir)$(TargetName).pdb - python "$(ToolPath)\ProxyStubGenerator\StubGenerator.py" --namespace OCDM "$(ProjectDir)IOCDM.h" + + - ProxyStub + + @@ -151,10 +156,12 @@ $(IntDir)$(TargetName).pdb - python "$(ToolPath)\ProxyStubGenerator\StubGenerator.py" --namespace OCDM "$(ProjectDir)IOCDM.h" + + - ProxyStub + + @@ -205,10 +212,12 @@ $(IntDir)$(TargetName).pdb - python "$(ToolPath)\ProxyStubGenerator\StubGenerator.py" --namespace OCDM "$(ProjectDir)IOCDM.h" + + - ProxyStub + + From 9fc2043832b4c44d14984465775ff9bc0455d555 Mon Sep 17 00:00:00 2001 From: Neeraj Deshpande Date: Thu, 23 Feb 2023 17:37:04 +0530 Subject: [PATCH 16/37] Modified gstreamer ocdm adapter for MediaProperties related fix. (#192) --- Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp b/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp index f58f5e43..669b8994 100644 --- a/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp +++ b/Source/ocdm/adapter/gstreamer/open_cdm_adapter.cpp @@ -277,11 +277,11 @@ OpenCDMError opencdm_gstreamer_session_decrypt_buffer(struct OpenCDMSession* ses //Get Stream Properties from GstCaps MediaProperties *spPtr = nullptr; + MediaProperties streamProperties; if(caps != nullptr){ gchar *capsStr = gst_caps_to_string (caps); if (capsStr != nullptr) { WPEFramework::Plugin::CapsParser capsParser; - MediaProperties streamProperties; capsParser.Parse(reinterpret_cast(capsStr), strlen(capsStr)); streamProperties.height = capsParser.GetHeight(); streamProperties.width = capsParser.GetWidth(); From b80f2083dc81d4d35f617125a8e6f1cd60eac30c Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Tue, 14 Mar 2023 12:01:48 +0100 Subject: [PATCH 17/37] [METRICS] Add a new metrics punch through on the OCDM framework. (#196) --- Source/ocdm/open_cdm.cpp | 67 ++++++++++++++++++++++++++++++++----- Source/ocdm/open_cdm.h | 40 +++++++++++++++++++++- Source/ocdm/open_cdm_impl.h | 13 +++++-- 3 files changed, 109 insertions(+), 11 deletions(-) diff --git a/Source/ocdm/open_cdm.cpp b/Source/ocdm/open_cdm.cpp index e1097d3e..d88b1f33 100644 --- a/Source/ocdm/open_cdm.cpp +++ b/Source/ocdm/open_cdm.cpp @@ -41,12 +41,12 @@ OpenCDMError StringToAllocatedBuffer(const std::string& source, char* destinatio if(destinationBuffer == nullptr) { bufferSize = sizeneeded; - result = ERROR_MORE_DATA_AVAILBALE; + result = ERROR_MORE_DATA_AVAILABLE; } else if ( bufferSize < sizeneeded ) { strncpy(destinationBuffer, source.c_str(), bufferSize-1); destinationBuffer[bufferSize-1] = '\0'; bufferSize = sizeneeded; - result = ERROR_MORE_DATA_AVAILBALE; + result = ERROR_MORE_DATA_AVAILABLE; } else { // buffersize >= sizeneeded strncpy(destinationBuffer, source.c_str(), sizeneeded-1); destinationBuffer[sizeneeded-1] = '\0'; @@ -161,11 +161,11 @@ OpenCDMError opencdm_is_type_supported(const char keySystem[], * \param metadata, buffer to write metadata into, always 0 terminated (also when not large enough to hold all data) except when metadata is * Null of course. Null allowed to retrieve required size needed for this buffer in metadataSize to be able to allocate required buffer * for subsequent call to opencdm_is_type_supported - * \param metadataSize, in: size of metadata buffer, out: required size to hold all data available when return value is ERROR_MORE_DATA_AVAILBALE, + * \param metadataSize, in: size of metadata buffer, out: required size to hold all data available when return value is ERROR_MORE_DATA_AVAILABLE, * , number of characters written into metadata (incl 0 terminator) otherwise. Note in case metadata could not hold all data but was not of zero - * length it is filled up to the maximum size (still zero terminated) but also ERROR_MORE_DATA_AVAILBALE is returned with the required size needed + * length it is filled up to the maximum size (still zero terminated) but also ERROR_MORE_DATA_AVAILABLE is returned with the required size needed * to hold all data - * \return Zero on success, non-zero on error. ERROR_MORE_DATA_AVAILBALE when the buffer was not large enough to hold all the data available. + * \return Zero on success, non-zero on error. ERROR_MORE_DATA_AVAILABLE when the buffer was not large enough to hold all the data available. */ OpenCDMError opencdm_system_get_metadata(struct OpenCDMSystem* system, char metadata[], @@ -179,6 +179,31 @@ OpenCDMError opencdm_system_get_metadata(struct OpenCDMSystem* system, return result; } +/** + * \brief Get metrics associated with a DRM system. + * + * Some DRMs (e.g. WideVine) offer metric data that can be used for any + * analyses. This function retrieves the metric data of the passed in + * system. It is up to the callee to interpret the baniary data correctly. + * \param system Instance of \ref OpenCDMAccessor. + * \param bufferLength Actual buffer length of the buffer parameter, on return + * it holds the number of bytes actually written in it. + * \param buffer Buffer length of buffer that can hold the metric data. + * \return Zero on success, non-zero on error. + */ + +EXTERNAL OpenCDMError opencdm_get_metric_system_data(struct OpenCDMSystem* system, + uint32_t* bufferLength, + uint8_t* buffer) { + OpenCDMError result(ERROR_INVALID_ACCESSOR); + OpenCDMAccessor* accessor = OpenCDMAccessor::Instance(); + + if (accessor != nullptr) { + result = static_cast(accessor->Metricdata(system->keySystem(), *bufferLength, buffer)); + } + + return (result); +} /** * \brief Maps key ID to \ref OpenCDMSession instance. @@ -292,11 +317,11 @@ OpenCDMError opencdm_session_load(struct OpenCDMSession* session) * \param metadata, buffer to write metadata into, always 0 terminated (also when not large enough to hold all data) except when metadata is * Null of course. Null allowed to retrieve required size needed for this buffer in metadataSize to be able to allocate required buffer * for subsequent call to opencdm_session_metadata - * \param metadataSize, in: size of metadata buffer, out: required size to hold all data available when return value is ERROR_MORE_DATA_AVAILBALE, + * \param metadataSize, in: size of metadata buffer, out: required size to hold all data available when return value is ERROR_MORE_DATA_AVAILABLE, * , number of characters written into metadata (incl 0 terminator) otherwise. Note in case metadata could not hold all data but was not of zero - * length it is filled up to the maximum size (still zero terminated) but also ERROR_MORE_DATA_AVAILBALE is returned with the required size needed + * length it is filled up to the maximum size (still zero terminated) but also ERROR_MORE_DATA_AVAILABLE is returned with the required size needed * to hold all data - * \return Zero on success, non-zero on error. ERROR_MORE_DATA_AVAILBALE when the buffer was not large enough to hold all the data available. + * \return Zero on success, non-zero on error. ERROR_MORE_DATA_AVAILABLE when the buffer was not large enough to hold all the data available. */ OpenCDMError opencdm_session_metadata(const struct OpenCDMSession* session, @@ -547,6 +572,32 @@ OpenCDMError opencdm_session_decrypt_v2(struct OpenCDMSession* session, return (result); } +/** + * \brief Get metrics associated with a DRM session. + * + * Some DRMs (e.g. WideVine) offer metric data that can be used for any + * analyses. This function retrieves the metric data of the passed in + * system. It is up to the callee to interpret the baniary data correctly. + * \param session Instance of \ref OpenCDMSession. + * \param bufferLength Actual buffer length of the buffer parameter, on return + * it holds the number of bytes actually written in it. + * \param buffer Buffer length of buffer that can hold the metric data. + * \return Zero on success, non-zero on error. + */ + +OpenCDMError opencdm_get_metric_session_data(struct OpenCDMSession* session, + uint32_t* bufferLength, + uint8_t* buffer) { + OpenCDMError result(ERROR_INVALID_SESSION); + if (session != nullptr) { + result = static_cast(session->Metricdata( + *bufferLength, buffer)); + } + + return (result); +} + + void opencdm_dispose() { Core::Singleton::Dispose(); diff --git a/Source/ocdm/open_cdm.h b/Source/ocdm/open_cdm.h index 367279c5..063f2cb0 100644 --- a/Source/ocdm/open_cdm.h +++ b/Source/ocdm/open_cdm.h @@ -178,17 +178,22 @@ typedef enum { typedef enum { ERROR_NONE = 0, ERROR_UNKNOWN = 1, - ERROR_MORE_DATA_AVAILBALE=2, + ERROR_MORE_DATA_AVAILABLE = 2, + ERROR_INTERFACE_NOT_IMPLEMENTED = 3, + ERROR_BUFFER_TOO_SMALL = 4, ERROR_INVALID_ACCESSOR = 0x80000001, ERROR_KEYSYSTEM_NOT_SUPPORTED = 0x80000002, ERROR_INVALID_SESSION = 0x80000003, ERROR_INVALID_DECRYPT_BUFFER = 0x80000004, ERROR_OUT_OF_MEMORY = 0x80000005, + ERROR_METHOD_NOT_IMPLEMENTED = 0x80000006, ERROR_FAIL = 0x80004005, ERROR_INVALID_ARG = 0x80070057, ERROR_SERVER_INTERNAL_ERROR = 0x8004C600, ERROR_SERVER_INVALID_MESSAGE = 0x8004C601, ERROR_SERVER_SERVICE_SPECIFIC = 0x8004C604, + ERROR_BUSY_CANNOT_INITIALIZE = 0x8004DD00 + } OpenCDMError; /** @@ -383,6 +388,23 @@ EXTERNAL OpenCDMError opencdm_system_set_server_certificate( struct OpenCDMSystem* system, const uint8_t serverCertificate[], const uint16_t serverCertificateLength); +/** + * \brief Get metrics associated with a DRM system. + * + * Some DRMs (e.g. WideVine) offer metric data that can be used for any + * analyses. This function retrieves the metric data of the passed in + * system. It is up to the callee to interpret the baniary data correctly. + * \param system Instance of \ref OpenCDMAccessor. + * \param bufferLength Actual buffer length of the buffer parameter, on return + * it holds the number of bytes actually written in it. + * \param buffer Buffer length of buffer that can hold the metric data. + * \return Zero on success, non-zero on error. + */ + +EXTERNAL OpenCDMError opencdm_get_metric_system_data(struct OpenCDMSystem* system, + uint32_t* bufferLength, + uint8_t* buffer); + /** * \brief Create DRM session (for actual decrypting of data). * @@ -564,6 +586,22 @@ EXTERNAL OpenCDMError opencdm_session_decrypt(struct OpenCDMSession* session, uint32_t initWithLast15); #endif // __cplusplus +/** + * \brief Get metrics associated with a DRM session. + * + * Some DRMs (e.g. WideVine) offer metric data that can be used for any + * analyses. This function retrieves the metric data of the passed in + * system. It is up to the callee to interpret the baniary data correctly. + * \param session Instance of \ref OpenCDMSession. + * \param bufferLength Actual buffer length of the buffer parameter, on return + * it holds the number of bytes actually written in it. + * \param buffer Buffer length of buffer that can hold the metric data. + * \return Zero on success, non-zero on error. + */ + +EXTERNAL OpenCDMError opencdm_get_metric_session_data(struct OpenCDMSession* session, + uint32_t* bufferLength, + uint8_t* buffer); /** * \brief Performs decryption. diff --git a/Source/ocdm/open_cdm_impl.h b/Source/ocdm/open_cdm_impl.h index 29863fbf..1a060c63 100644 --- a/Source/ocdm/open_cdm_impl.h +++ b/Source/ocdm/open_cdm_impl.h @@ -149,12 +149,15 @@ struct OpenCDMAccessor : public Exchange::IAccessorOCDM { return result; } - virtual Exchange::OCDM_RESULT Metadata(const std::string& keySystem, - std::string& metadata) const override + virtual Exchange::OCDM_RESULT Metadata(const string& keySystem, string& metadata) const override { return(_remote->Metadata(keySystem, metadata)); } + virtual Exchange::OCDM_RESULT Metricdata(const string& keySystem, uint32_t& length, uint8_t buffer[]) const override { + return(_remote->Metricdata(keySystem, length, buffer)); + } + // Create a MediaKeySession using the supplied init data and CDM data. virtual Exchange::OCDM_RESULT CreateSession(const string& keySystem, const int32_t licenseType, @@ -558,6 +561,12 @@ POP_WARNING() return _session->Metadata(); } + inline uint32_t Metricdata(uint32_t& bufferSize, uint8_t buffer[]) + { + ASSERT(_session != nullptr); + + return _session->Metricdata(bufferSize, buffer); + } inline const string& BufferId() const { static string EmptyString; From c68c9f50c54cbffb2059e93cd2ef819fc825ffd2 Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Wed, 8 Mar 2023 17:17:12 +0100 Subject: [PATCH 18/37] [WINDOWS] Fixes for windows (#195) --- Source/displayinfo/display_info/main.c | 2 +- cmake/FindGBM.cmake | 44 +++++++++++------------ cmake/FindLibDRM.cmake | 48 ++++++++++++-------------- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/Source/displayinfo/display_info/main.c b/Source/displayinfo/display_info/main.c index 35fa0c1d..e8c60fbb 100644 --- a/Source/displayinfo/display_info/main.c +++ b/Source/displayinfo/display_info/main.c @@ -187,7 +187,7 @@ void binary_print(size_t const size, void const * const ptr) void print_edid_info(displayinfo_edid_base_info_t* edid_info) { puts(""); Trace("EDID Base Info : "); - Trace("Manufacturer ID: %.*s", sizeof(edid_info->manufacturer_id), edid_info->manufacturer_id); + Trace("Manufacturer ID: %.*s", (uint32_t)(sizeof(edid_info->manufacturer_id)), edid_info->manufacturer_id); Trace("Serial Number: %u" , edid_info->serial_number); Trace("Product Code : %u" , edid_info->product_code); Trace("Week of manufacture : %u" , edid_info->manufacture_week); diff --git a/cmake/FindGBM.cmake b/cmake/FindGBM.cmake index c3d0ed65..78206e4d 100644 --- a/cmake/FindGBM.cmake +++ b/cmake/FindGBM.cmake @@ -20,10 +20,10 @@ cmake_minimum_required(VERSION 3.7) # Be compatible even if a newer CMake version is available cmake_policy(VERSION 3.7...3.12) -if(GBM_FIND_QUIETLY) - set(_GBM_MODE QUIET) -elseif(GBM_FIND_REQUIRED) - set(_GBM_MODE REQUIRED) +if(gbm_FIND_QUIETLY) + set(_gbm_MODE QUIET) +elseif(gbm_FIND_REQUIRED) + set(_gbm_MODE REQUIRED) endif() find_package(PkgConfig) @@ -31,12 +31,12 @@ if(${PKG_CONFIG_FOUND}) # Just check if the gbm.pc exist, and create the PkgConfig::gbm target # No version requirement (yet) - pkg_check_modules(PC_GBM ${_GBM_MODE} IMPORTED_TARGET gbm) - find_library(GBM_ACTUAL_LIBRARY NAMES gbm - HINTS ${PC_GBM_LIBRARY_DIRS}) + pkg_check_modules(gbm ${_gbm_MODE} IMPORTED_TARGET gbm) + find_library(gbm_ACTUAL_LIBRARY NAMES gbm + HINTS ${gbm_LIBRARY_DIRS}) - find_path(GBM_INCLUDE_DIR NAMES gbm.h - HINTS ${PC_GBM_INCLUDEDIR} ${PC_GBM_INCLUDE_DIRS}) + find_path(gbm_INCLUDE_DIR NAMES gbm.h + HINTS ${gbm_INCLUDEDIR} ${gbm_INCLUDE_DIRS}) else() message(FATAL_ERROR "Unable to locate PkgConfig") endif() @@ -44,22 +44,22 @@ endif() include(FindPackageHandleStandardArgs) # Sets the FOUND variable to TRUE if all required variables are present and set find_package_handle_standard_args( - GBM + gbm REQUIRED_VARS - GBM_ACTUAL_LIBRARY - PC_GBM_LIBRARIES - GBM_INCLUDE_DIR + gbm_ACTUAL_LIBRARY + gbm_LIBRARIES + gbm_INCLUDE_DIR VERSION_VAR - GBM_VERSION + gbm_VERSION ) -mark_as_advanced(GBM_INCLUDE_DIR PC_GBM_LIBRARIES GBM_ACTUAL_LIBRARY) +mark_as_advanced(gbm_INCLUDE_DIR gbm_LIBRARIES gbm_ACTUAL_LIBRARY) -if(GBM_FOUND AND NOT TARGET GBM::GBM) - add_library(GBM::GBM UNKNOWN IMPORTED) - set_target_properties(GBM::GBM PROPERTIES - IMPORTED_LOCATION "${GBM_ACTUAL_LIBRARY}" - INTERFACE_LINK_LIBRARIES "${PC_GBM_LIBRARIES}" - INTERFACE_COMPILE_OPTIONS "${PC_GBM_CFLAGS}" - INTERFACE_INCLUDE_DIRECTORIES "${GBM_INCLUDE_DIR}" +if(gbm_FOUND AND NOT TARGET gbm::gbm) + add_library(gbm::gbm UNKNOWN IMPORTED) + set_target_properties(gbm::gbm PROPERTIES + IMPORTED_LOCATION "${gbm_ACTUAL_LIBRARY}" + INTERFACE_LINK_LIBRARIES "${gbm_LIBRARIES}" + INTERFACE_COMPILE_OPTIONS "${gbm_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${gbm_INCLUDE_DIR}" ) endif() diff --git a/cmake/FindLibDRM.cmake b/cmake/FindLibDRM.cmake index 3909b746..21953e99 100644 --- a/cmake/FindLibDRM.cmake +++ b/cmake/FindLibDRM.cmake @@ -20,10 +20,10 @@ cmake_minimum_required(VERSION 3.7) # Be compatible even if a newer CMake version is available cmake_policy(VERSION 3.7...3.12) -if(LibDRM_FIND_QUIETLY) - set(_LIBDRM_MODE QUIET) -elseif(LibDRM_FIND_REQUIRED) - set(_LIBDRM_MODE REQUIRED) +if(libdrm_FIND_QUIETLY) + set(_libdrm_MODE QUIET) +elseif(libdrm_FIND_REQUIRED) + set(_libdrm_MODE REQUIRED) endif() find_package(PkgConfig) @@ -31,41 +31,39 @@ if(${PKG_CONFIG_FOUND}) # Just check if the libdrm.pc exist, and create the PkgConfig::libdrm target # No version requirement (yet) - pkg_check_modules(LIBDRM ${_LIBDRM_MODE} IMPORTED_TARGET libdrm) + pkg_check_modules(libdrm ${_libdrm_MODE} IMPORTED_TARGET libdrm) - find_library(LIBDRM_ACTUAL_LIBRARY NAMES drm - HINTS ${LIBDRM_LIBRARY_DIRS} ) + find_library(libdrm_ACTUAL_LIBRARY NAMES drm + HINTS ${libdrm_LIBRARY_DIRS} ) include(FindPackageHandleStandardArgs) # Sets the FOUND variable to TRUE if all required variables are present and set find_package_handle_standard_args( - LibDRM + libdrm REQUIRED_VARS - LIBDRM_INCLUDE_DIRS - LIBDRM_CFLAGS - LIBDRM_LDFLAGS - LIBDRM_LIBRARIES - LIBDRM_ACTUAL_LIBRARY + libdrm_INCLUDE_DIRS + libdrm_CFLAGS + libdrm_LDFLAGS + libdrm_LIBRARIES + libdrm_ACTUAL_LIBRARY VERSION_VAR - LIBDRM_VERSION + libdrm_VERSION ) - mark_as_advanced(LIBDRM_INCLUDE_DIRS LIBDRM_LIBRARIES) - set(LIBDRM_FOUND ${LibDRM_FOUND}) + mark_as_advanced(libdrm_INCLUDE_DIRS libdrm_LIBRARIES) + set(libdrm_FOUND ${libdrm_FOUND}) - if(LibDRM_FOUND AND NOT TARGET LibDRM::LibDRM) - add_library(LibDRM::LibDRM UNKNOWN IMPORTED) - set_target_properties(LibDRM::LibDRM PROPERTIES - IMPORTED_LOCATION "${LIBDRM_ACTUAL_LIBRARY}" - INTERFACE_LINK_LIBRARIES "${LIBDRM_LIBRARIES}" - INTERFACE_COMPILE_OPTIONS "${LIBDRM_CFLAGS}" - INTERFACE_INCLUDE_DIRECTORIES "${LIBDRM_INCLUDE_DIRS}" + if(libdrm_FOUND AND NOT TARGET libdrm::libdrm) + add_library(libdrm::libdrm UNKNOWN IMPORTED) + set_target_properties(libdrm::libdrm PROPERTIES + IMPORTED_LOCATION "${libdrm_ACTUAL_LIBRARY}" + INTERFACE_LINK_LIBRARIES "${libdrm_LIBRARIES}" + INTERFACE_COMPILE_OPTIONS "${libdrm_CFLAGS}" + INTERFACE_INCLUDE_DIRECTORIES "${libdrm_INCLUDE_DIRS}" ) else() message(STATUS "Some required variable(s) is (are) not found / set! Does libdrm.pc exist?") endif() else() - message(STATUS "Unable to locate PkgConfig") - endif() From beaf4067a6fb70491b16a71e7bab9cbb905b6c6a Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Tue, 14 Mar 2023 12:01:48 +0100 Subject: [PATCH 19/37] [METRICS] Add a new metrics punch through on the OCDM framework. (#196) From 35f6af27896a55fd583223eaba6dc39d4860d2f2 Mon Sep 17 00:00:00 2001 From: Danny Carr Date: Tue, 2 May 2023 09:26:14 -0400 Subject: [PATCH 20/37] Fixing libdrm target name in compositorclient/RPI/CMakeLists.txt (#205) Broken by target name change in [5aca10](https://github.com/rdkcentral/ThunderClientLibraries/commit/5aca10) --- Source/compositorclient/RPI/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/compositorclient/RPI/CMakeLists.txt b/Source/compositorclient/RPI/CMakeLists.txt index ee9b2f86..bdbb73ea 100644 --- a/Source/compositorclient/RPI/CMakeLists.txt +++ b/Source/compositorclient/RPI/CMakeLists.txt @@ -44,7 +44,7 @@ target_link_libraries(${PLUGIN_COMPOSITOR_IMPLEMENTATION} if(VC6) target_link_libraries(${PLUGIN_COMPOSITOR_IMPLEMENTATION} PUBLIC - LibDRM::LibDRM + libdrm::libdrm ) endif() From ff80452329b454fa5e2a946a6745646bd56b26ed Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Wed, 19 Apr 2023 12:15:34 +0200 Subject: [PATCH 21/37] [WARNINGFREE] Suppress the ABI changes. We always build full stack. (#204) --- Source/compositorclient/RPI/CMakeLists.txt | 2 ++ Source/ocdm/CMakeLists.txt | 2 ++ Source/provisionproxy/CMakeLists.txt | 6 ++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/compositorclient/RPI/CMakeLists.txt b/Source/compositorclient/RPI/CMakeLists.txt index bdbb73ea..70809c6c 100644 --- a/Source/compositorclient/RPI/CMakeLists.txt +++ b/Source/compositorclient/RPI/CMakeLists.txt @@ -55,6 +55,8 @@ set_target_properties(${PLUGIN_COMPOSITOR_IMPLEMENTATION} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) +target_compile_options (${PLUGIN_COMPOSITOR_IMPLEMENTATION} PRIVATE -Wno-psabi) + target_include_directories(${PLUGIN_COMPOSITOR_IMPLEMENTATION} PUBLIC $ diff --git a/Source/ocdm/CMakeLists.txt b/Source/ocdm/CMakeLists.txt index 79451fd8..4c856e03 100644 --- a/Source/ocdm/CMakeLists.txt +++ b/Source/ocdm/CMakeLists.txt @@ -54,6 +54,8 @@ set(PUBLIC_HEADERS Module.h ) +target_compile_options (${TARGET} PRIVATE -Wno-psabi) + target_link_libraries(${TARGET} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core diff --git a/Source/provisionproxy/CMakeLists.txt b/Source/provisionproxy/CMakeLists.txt index 12664cff..ba44e386 100644 --- a/Source/provisionproxy/CMakeLists.txt +++ b/Source/provisionproxy/CMakeLists.txt @@ -47,10 +47,6 @@ target_link_libraries(${TARGET} ${NAMESPACE}Core::${NAMESPACE}Core ${NAMESPACE}COM::${NAMESPACE}COM libprovision::libprovision - ) - -target_link_libraries(${TARGET} - PRIVATE CompileSettingsDebug::CompileSettingsDebug ) @@ -64,6 +60,8 @@ set_target_properties(${TARGET} PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE ON ) +target_compile_options (${TARGET} PRIVATE -Wno-psabi) + target_include_directories( ${TARGET} PUBLIC $ From 97052d8fe2a0c6d3db507f1b71c64bb43918486b Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Wed, 24 May 2023 09:07:47 +0200 Subject: [PATCH 22/37] [DRM] Renaming of the library for CMake (cherry pick did not work on pull 205) (#206) --- Source/compositorclient/RPI/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/compositorclient/RPI/CMakeLists.txt b/Source/compositorclient/RPI/CMakeLists.txt index 70809c6c..679bae3d 100644 --- a/Source/compositorclient/RPI/CMakeLists.txt +++ b/Source/compositorclient/RPI/CMakeLists.txt @@ -44,7 +44,7 @@ target_link_libraries(${PLUGIN_COMPOSITOR_IMPLEMENTATION} if(VC6) target_link_libraries(${PLUGIN_COMPOSITOR_IMPLEMENTATION} PUBLIC - libdrm::libdrm + Libdrm::Libdrm ) endif() From 2813b8f981c722d0d11f3039c1fbf1d403400653 Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Thu, 25 May 2023 13:13:55 +0200 Subject: [PATCH 23/37] fixing naming convention find cmakes (#207) --- Source/compositorclient/RPI/CMakeLists.txt | 6 +++--- cmake/{FindGBM.cmake => Findgbm.cmake} | 0 cmake/{FindLibDRM.cmake => Findlibdrm.cmake} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename cmake/{FindGBM.cmake => Findgbm.cmake} (100%) rename cmake/{FindLibDRM.cmake => Findlibdrm.cmake} (100%) diff --git a/Source/compositorclient/RPI/CMakeLists.txt b/Source/compositorclient/RPI/CMakeLists.txt index 679bae3d..9a92a7a3 100644 --- a/Source/compositorclient/RPI/CMakeLists.txt +++ b/Source/compositorclient/RPI/CMakeLists.txt @@ -24,8 +24,8 @@ find_package(${NAMESPACE}COM REQUIRED) add_library(${PLUGIN_COMPOSITOR_IMPLEMENTATION} OBJECT Implementation.cpp) if(VC6) - find_package(GBM REQUIRED) - find_package(LibDRM REQUIRED) + find_package(gbm REQUIRED) + find_package(libdrm REQUIRED) target_sources(${PLUGIN_COMPOSITOR_IMPLEMENTATION} PRIVATE ModeSet.cpp) target_compile_definitions(${PLUGIN_COMPOSITOR_IMPLEMENTATION} PRIVATE VC6) @@ -44,7 +44,7 @@ target_link_libraries(${PLUGIN_COMPOSITOR_IMPLEMENTATION} if(VC6) target_link_libraries(${PLUGIN_COMPOSITOR_IMPLEMENTATION} PUBLIC - Libdrm::Libdrm + libdrm::libdrm ) endif() diff --git a/cmake/FindGBM.cmake b/cmake/Findgbm.cmake similarity index 100% rename from cmake/FindGBM.cmake rename to cmake/Findgbm.cmake diff --git a/cmake/FindLibDRM.cmake b/cmake/Findlibdrm.cmake similarity index 100% rename from cmake/FindLibDRM.cmake rename to cmake/Findlibdrm.cmake From c88346f7e58e6df731d5e8fd1541ee0544491f30 Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Thu, 25 May 2023 13:48:08 +0200 Subject: [PATCH 24/37] localtracer: Align with latest messaging changes (#208) Co-authored-by: Pierre Wielders --- Source/localtracer/CMakeLists.txt | 4 +- Source/localtracer/example/CMakeLists.txt | 4 +- .../include/localtracer/localtracer.h | 79 ++++++++----------- 3 files changed, 39 insertions(+), 48 deletions(-) diff --git a/Source/localtracer/CMakeLists.txt b/Source/localtracer/CMakeLists.txt index 818b07a7..802a30a2 100644 --- a/Source/localtracer/CMakeLists.txt +++ b/Source/localtracer/CMakeLists.txt @@ -43,6 +43,4 @@ HeaderOnlyInstallPackageConfig(TARGET ${MODULE_NAME} HeaderOnlyInstallCMakeConfig(TARGET ${MODULE_NAME} TREAT_AS_NORMAL) -if(EXAMPLE_LOCALTRACER) - add_subdirectory(example) -endif() \ No newline at end of file +add_subdirectory(example) diff --git a/Source/localtracer/example/CMakeLists.txt b/Source/localtracer/example/CMakeLists.txt index 7f4fe84c..a9e45ac4 100644 --- a/Source/localtracer/example/CMakeLists.txt +++ b/Source/localtracer/example/CMakeLists.txt @@ -13,4 +13,6 @@ target_link_libraries(local_trace_test PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core ${NAMESPACE}LocalTracer::${NAMESPACE}LocalTracer) -install(TARGETS local_trace_test DESTINATION bin) +if(EXAMPLE_LOCALTRACER) + install(TARGETS local_trace_test DESTINATION bin) +endif() \ No newline at end of file diff --git a/Source/localtracer/include/localtracer/localtracer.h b/Source/localtracer/include/localtracer/localtracer.h index f9768cd8..6463ecab 100644 --- a/Source/localtracer/include/localtracer/localtracer.h +++ b/Source/localtracer/include/localtracer/localtracer.h @@ -11,7 +11,9 @@ namespace Messaging { class EXTERNAL LocalTracer { public: struct EXTERNAL ICallback { - virtual void Output(const Core::Messaging::IStore::Information& info, const Core::Messaging::IEvent* message) = 0; + virtual ~ICallback() = default; + + virtual void Message(const Core::Messaging::Metadata& metadata, const string& message) = 0; }; private: @@ -67,7 +69,7 @@ namespace Messaging { LocalTracer(const LocalTracer&) = delete; LocalTracer& operator=(const LocalTracer&) = delete; - ~LocalTracer() + virtual ~LocalTracer() { _worker.Stop(); @@ -77,6 +79,10 @@ namespace Messaging { void Close() { + _adminLock.Lock(); + _callback = nullptr; + _adminLock.Unlock(); + Messaging::MessageUnit::Instance().Close(); Core::Directory(_path.c_str()).Destroy(); @@ -158,8 +164,8 @@ namespace Messaging { void Dispatch() { _client.WaitForUpdates(Core::infinite); - _client.PopMessagesAndCall([this](const Core::Messaging::IStore::Information& info, const Core::ProxyType& message) { - Output(info, message.Origin()); + _client.PopMessagesAndCall([this](const Core::Messaging::Metadata& metadata, const Core::ProxyType& message) { + Message(metadata, message->Data()); }); } @@ -173,12 +179,12 @@ namespace Messaging { } private: - void Output(const Core::Messaging::IStore::Information& info, const Core::Messaging::IEvent* message) + void Message(const Core::Messaging::Metadata& metadata, const string& message) { Core::SafeSyncType scopedLock(_adminLock); if (_callback != nullptr) { - _callback->Output(info, message); + _callback->Message(metadata, message); } } @@ -194,27 +200,6 @@ namespace Messaging { }; class ConsolePrinter : public Messaging::LocalTracer::ICallback { - private: - class IosFlagSaver { - public: - explicit IosFlagSaver(std::ostream& _ios) - : ios(_ios) - , f(_ios.flags()) - { - } - ~IosFlagSaver() - { - ios.flags(f); - } - - IosFlagSaver(const IosFlagSaver&) = delete; - IosFlagSaver& operator=(const IosFlagSaver&) = delete; - - private: - std::ostream& ios; - std::ios::fmtflags f; - }; - public: ConsolePrinter(const ConsolePrinter&) = delete; ConsolePrinter& operator=(const ConsolePrinter&) = delete; @@ -225,30 +210,36 @@ namespace Messaging { } virtual ~ConsolePrinter() = default; - void Output(const Core::Messaging::IStore::Information& info, const Core::Messaging::IEvent* message) override + void Message(const Core::Messaging::Metadata& metadata, const string& message) override { - IosFlagSaver saveUs(std::cout); - - std::ostringstream output; + string output; - output.str(""); - output.clear(); + ASSERT(metadata.Type() == Core::Messaging::Metadata::type::TRACING); - Core::Time now(info.TimeStamp()); + ASSERT(dynamic_cast(&metadata) != nullptr); + const Core::Messaging::IStore::Tracing& trace = static_cast(metadata); + const Core::Time now(trace.TimeStamp()); if (_abbreviated == true) { - std::string time(now.ToTimeOnly(true)); - output << '[' << time.c_str() << ']' - << '[' << info.Module() << "]" - << '[' << info.Category() << "]: " - << message->Data().c_str() << std::endl; + const string time(now.ToTimeOnly(true)); + output = Core::Format("[%s]:[%s]:[%s]: %s", + time.c_str(), + metadata.Module().c_str(), + metadata.Category().c_str(), + message.c_str()); } else { - std::string time(now.ToRFC1123(true)); - output << '[' << time.c_str() << "]:[" << Core::FileNameOnly(info.FileName().c_str()) << ':' << info.LineNumber() << "] " - << info.Category() << ": " << message->Data().c_str() << std::endl; + const string time(now.ToRFC1123(true)); + output = Core::Format("[%s]:[%s]:[%s:%u]:[%s]:[%s]: %s", + time.c_str(), + metadata.Module().c_str(), + Core::FileNameOnly(trace.FileName().c_str()), + trace.LineNumber(), + trace.ClassName().c_str(), + metadata.Category().c_str(), + message.c_str()); } - - std::cout << output.str() << std::flush; + std::cout << output << std::endl + << std::flush; } private: From adffa5c356cae44bfa498edf48b624575e6f07a5 Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Fri, 23 Jun 2023 18:59:46 +0530 Subject: [PATCH 25/37] compositorclient:RPI: Remove Announcements calls, since it is removed from thunder (#209) --- Source/compositorclient/RPI/Implementation.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/compositorclient/RPI/Implementation.cpp b/Source/compositorclient/RPI/Implementation.cpp index cd3787d6..523f5aee 100644 --- a/Source/compositorclient/RPI/Implementation.cpp +++ b/Source/compositorclient/RPI/Implementation.cpp @@ -776,7 +776,6 @@ class Display : public Compositor::IDisplay { _compositerServerRPCConnection = Core::ProxyType::Create(Connector(), Core::ProxyType(engine)); ASSERT(_compositerServerRPCConnection.IsValid() == true); - engine->Announcements(_compositerServerRPCConnection->Announcement()); } else { // Seems we are not in a process space initiated from the Main framework process or its hosting process. // Nothing more to do than to create a workerpool for RPC our selves ! @@ -786,7 +785,6 @@ class Display : public Compositor::IDisplay { _compositerServerRPCConnection = Core::ProxyType::Create(Connector(), Core::ProxyType(engine)); ASSERT(_compositerServerRPCConnection.IsValid() == true); - engine->Announcements(_compositerServerRPCConnection->Announcement()); } uint32_t result = _compositerServerRPCConnection->Open(RPC::CommunicationTimeOut); From 4b5701508ad974474a8d2eeee932fc4db759fc21 Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Wed, 5 Jul 2023 20:17:45 +0530 Subject: [PATCH 26/37] Revert the uint32_t -> uint16_t on IHash and ICryptography (#211) --- Source/cryptography/Cryptography.cpp | 26 +++++++++++++------------- Source/cryptography/ICryptography.h | 10 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/cryptography/Cryptography.cpp b/Source/cryptography/Cryptography.cpp index 2a2edb60..e22d25a9 100644 --- a/Source/cryptography/Cryptography.cpp +++ b/Source/cryptography/Cryptography.cpp @@ -160,16 +160,16 @@ namespace Implementation { public: int32_t Encrypt(const uint8_t ivLength, const uint8_t iv[], - const uint16_t inputLength, const uint8_t input[], - const uint16_t maxOutputLength, uint8_t output[]) const override + const uint32_t inputLength, const uint8_t input[], + const uint32_t maxOutputLength, uint8_t output[]) const override { Core::SafeSyncType lock(_adminLock); return (_accessor != nullptr) ? _accessor->Encrypt(ivLength, iv, inputLength, input, maxOutputLength, output) : 0; } int32_t Decrypt(const uint8_t ivLength, const uint8_t iv[], - const uint16_t inputLength, const uint8_t input[], - const uint16_t maxOutputLength, uint8_t output[]) const override + const uint32_t inputLength, const uint8_t input[], + const uint32_t maxOutputLength, uint8_t output[]) const override { Core::SafeSyncType lock(_adminLock); return (_accessor != nullptr) ? _accessor->Decrypt(ivLength, iv, inputLength, input, maxOutputLength, output) : 0; @@ -206,7 +206,7 @@ namespace Implementation { public: /* Ingest data into the hash calculator (multiple calls possible) */ - uint32_t Ingest(const uint16_t length, const uint8_t data[] /* @length:length */) override + uint32_t Ingest(const uint32_t length, const uint8_t data[] /* @length:length */) override { Core::SafeSyncType lock(_adminLock); return (_accessor != nullptr ? _accessor->Ingest(length, data) : 0); @@ -504,9 +504,9 @@ namespace Implementation { } public: - uint32_t Ingest(const uint16_t length, const uint8_t data[]) override + uint32_t Ingest(const uint32_t length, const uint8_t data[]) override { - return (hash_ingest(_implementation, static_cast(length), data)); + return (hash_ingest(_implementation, length, data)); } uint8_t Calculate(const uint8_t maxLength, uint8_t data[]) override @@ -644,17 +644,17 @@ namespace Implementation { public: int32_t Encrypt(const uint8_t ivLength, const uint8_t iv[], - const uint16_t inputLength, const uint8_t input[], - const uint16_t maxOutputLength, uint8_t output[]) const override + const uint32_t inputLength, const uint8_t input[], + const uint32_t maxOutputLength, uint8_t output[]) const override { - return (cipher_encrypt(_implementation, ivLength, iv, static_cast(inputLength), input, static_cast(maxOutputLength), output)); + return (cipher_encrypt(_implementation, ivLength, iv, inputLength, input, maxOutputLength, output)); } int32_t Decrypt(const uint8_t ivLength, const uint8_t iv[], - const uint16_t inputLength, const uint8_t input[], - const uint16_t maxOutputLength, uint8_t output[]) const override + const uint32_t inputLength, const uint8_t input[], + const uint32_t maxOutputLength, uint8_t output[]) const override { - return (cipher_decrypt(_implementation, ivLength, iv, static_cast(inputLength), input, static_cast(maxOutputLength), output)); + return (cipher_decrypt(_implementation, ivLength, iv, inputLength, input, maxOutputLength, output)); } public: diff --git a/Source/cryptography/ICryptography.h b/Source/cryptography/ICryptography.h index 3d1f8387..2a4bd6a0 100644 --- a/Source/cryptography/ICryptography.h +++ b/Source/cryptography/ICryptography.h @@ -65,7 +65,7 @@ namespace Cryptography { ~IHash() override = default; /* Ingest data into the hash calculator (multiple calls possible) */ - virtual uint32_t Ingest(const uint16_t length, const uint8_t data[] /* @in @length:length */) = 0; + virtual uint32_t Ingest(const uint32_t length, const uint8_t data[] /* @in @length:length */) = 0; /* Calculate the hash from all ingested data */ virtual uint8_t Calculate(const uint8_t maxLength, uint8_t data[] /* @out @maxlength:maxLength */) = 0; @@ -83,13 +83,13 @@ namespace Cryptography { /* Encrypt data */ virtual int32_t Encrypt(const uint8_t ivLength, const uint8_t iv[] /* @in @length:ivLength */, - const uint16_t inputLength, const uint8_t input[] /* @in @length:inputLength */, - const uint16_t maxOutputLength, uint8_t output[] /* @out @maxlength:maxOutputLength */) const = 0; + const uint32_t inputLength, const uint8_t input[] /* @in @length:inputLength */, + const uint32_t maxOutputLength, uint8_t output[] /* @out @maxlength:maxOutputLength */) const = 0; /* Decrypt data */ virtual int32_t Decrypt(const uint8_t ivLength, const uint8_t iv[] /* @in @length:ivLength */, - const uint16_t inputLength, const uint8_t input[] /* @in @length:inputLength */, - const uint16_t maxOutputLength, uint8_t output[] /* @out @maxlength:maxOutputLength */) const = 0; + const uint32_t inputLength, const uint8_t input[] /* @in @length:inputLength */, + const uint32_t maxOutputLength, uint8_t output[] /* @out @maxlength:maxOutputLength */) const = 0; }; struct EXTERNAL IDiffieHellman : virtual public Core::IUnknown { From 2b3c14e74db03616356f5ded5ea906ed395ca1e5 Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Fri, 4 Aug 2023 20:59:53 +0530 Subject: [PATCH 27/37] cryptography: move ICryptography.h & INetflixSecurity.h to interfaces (#215) --- .gitignore | 3 + Source/cryptography/CMakeLists.txt | 13 -- Source/cryptography/Cryptography.cpp | 142 ++++++------- Source/cryptography/Cryptography.vcxproj | 16 +- .../cryptography/Cryptography.vcxproj.filters | 8 +- Source/cryptography/ICryptography.h | 197 ------------------ Source/cryptography/INetflixSecurity.h | 55 ----- Source/cryptography/NetflixSecurity.cpp | 2 +- Source/cryptography/cryptography.h | 4 +- Source/cryptography/cryptography_vault_ids.h | 35 ---- .../implementation/SecApi/Vault.h | 1 - .../implementation/Thunder/CMakeLists.txt | 2 + .../implementation/Thunder/Cipher.cpp | 1 - .../implementation/Thunder/Signing.cpp | 1 - .../implementation/Thunder/Vault.cpp | 1 - .../persistent_implementation.h | 1 - .../implementation/vault_implementation.h | 8 +- Source/cryptography/tests/CMakeLists.txt | 2 +- .../tests/cryptography_test/Helpers.cpp | 4 +- .../cryptography_test/InterfaceTests.cpp | 36 ++-- .../NetflixSecurityTests.cpp | 16 +- .../rpc_cryptography_test/CMakeLists.txt | 2 + .../rpc_cryptography_test.cpp | 78 +++---- 23 files changed, 158 insertions(+), 470 deletions(-) delete mode 100644 Source/cryptography/ICryptography.h delete mode 100644 Source/cryptography/INetflixSecurity.h delete mode 100644 Source/cryptography/cryptography_vault_ids.h diff --git a/.gitignore b/.gitignore index 1a8f4b51..9ed30d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ install_manifest.txt Source/deviceinfo/device_info/device_info Source/displayinfo/display_info/display_info Source/playerinfo/player_info/player_info +*/*/*/*/*tests +*/*/generated +*/*/*/*/lib*.a diff --git a/Source/cryptography/CMakeLists.txt b/Source/cryptography/CMakeLists.txt index d519b69f..9039fced 100644 --- a/Source/cryptography/CMakeLists.txt +++ b/Source/cryptography/CMakeLists.txt @@ -35,26 +35,16 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed") option(INCLUDE_SOFTWARE_CRYPTOGRAPHY_LIBRARY "Include explicitly a software based cryptography library" OFF) -find_package(ProxyStubGenerator REQUIRED) - find_package(CompileSettingsDebug CONFIG REQUIRED) find_package(${NAMESPACE}Core REQUIRED) find_package(${NAMESPACE}COM REQUIRED) -ProxyStubGenerator( - NAMESPACE "WPEFramework::Cryptography" - INPUT "${CMAKE_CURRENT_LIST_DIR}" - OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated/proxystubs" -) - add_subdirectory(implementation) add_library(${TARGET} SHARED Module.cpp Cryptography.cpp NetflixSecurity.cpp - "${CMAKE_CURRENT_BINARY_DIR}/generated/proxystubs/ProxyStubs_Cryptography.cpp" - "${CMAKE_CURRENT_BINARY_DIR}/generated/proxystubs/ProxyStubs_NetflixSecurity.cpp" ) target_link_libraries(${TARGET} @@ -73,11 +63,8 @@ target_include_directories(${TARGET} ) set(PUBLIC_HEADERS - $ $ - $ $ - $ ) set_target_properties(${TARGET} PROPERTIES diff --git a/Source/cryptography/Cryptography.cpp b/Source/cryptography/Cryptography.cpp index e22d25a9..a7286b65 100644 --- a/Source/cryptography/Cryptography.cpp +++ b/Source/cryptography/Cryptography.cpp @@ -19,7 +19,7 @@ #include "Module.h" -#include +#include #include "implementation/cipher_implementation.h" #include "implementation/diffiehellman_implementation.h" @@ -70,11 +70,11 @@ namespace Implementation { delete _singleton; } } - Cryptography::ICryptography* Acquire(const Core::NodeId& nodeId) + Exchange::ICryptography* Acquire(const Core::NodeId& nodeId) { - return BaseClass::Acquire(3000, nodeId, _T(""), ~0); + return BaseClass::Acquire(3000, nodeId, _T(""), ~0); } - Cryptography::ICryptography* Cryptography(const std::string& connectionPoint); + Exchange::ICryptography* Cryptography(const std::string& connectionPoint); template Core::ProxyType Register(Args&&... args) @@ -99,9 +99,9 @@ namespace Implementation { CryptographyLink* CryptographyLink::_singleton = nullptr; - class RPCDiffieHellmanImpl : public Cryptography::IDiffieHellman { + class RPCDiffieHellmanImpl : public Exchange::IDiffieHellman { public: - RPCDiffieHellmanImpl(Cryptography::IDiffieHellman* iface) + RPCDiffieHellmanImpl(Exchange::IDiffieHellman* iface) : _accessor(iface) { if (_accessor != nullptr) { @@ -111,7 +111,7 @@ namespace Implementation { ~RPCDiffieHellmanImpl() override = default; BEGIN_INTERFACE_MAP(RPCDiffieHellmanImpl) - INTERFACE_ENTRY(Cryptography::IDiffieHellman) + INTERFACE_ENTRY(Exchange::IDiffieHellman) END_INTERFACE_MAP public: @@ -140,12 +140,12 @@ namespace Implementation { private: Core::CriticalSection _adminLock; - Cryptography::IDiffieHellman* _accessor; + Exchange::IDiffieHellman* _accessor; }; - class RPCCipherImpl : public Cryptography::ICipher { + class RPCCipherImpl : public Exchange::ICipher { public: - RPCCipherImpl(Cryptography::ICipher* iface) + RPCCipherImpl(Exchange::ICipher* iface) : _accessor(iface) { if (_accessor != nullptr) { @@ -155,7 +155,7 @@ namespace Implementation { ~RPCCipherImpl() override = default; BEGIN_INTERFACE_MAP(RPCCipherImpl) - INTERFACE_ENTRY(Cryptography::ICipher) + INTERFACE_ENTRY(Exchange::ICipher) END_INTERFACE_MAP public: @@ -186,12 +186,12 @@ namespace Implementation { private: mutable Core::CriticalSection _adminLock; - Cryptography::ICipher* _accessor; + Exchange::ICipher* _accessor; }; - class RPCHashImpl : public Cryptography::IHash { + class RPCHashImpl : public Exchange::IHash { public: - RPCHashImpl(Cryptography::IHash* hash) + RPCHashImpl(Exchange::IHash* hash) : _accessor(hash) { if (_accessor != nullptr) { @@ -201,7 +201,7 @@ namespace Implementation { ~RPCHashImpl() override = default; BEGIN_INTERFACE_MAP(RPCHashImpl) - INTERFACE_ENTRY(Cryptography::IHash) + INTERFACE_ENTRY(Exchange::IHash) END_INTERFACE_MAP public: @@ -230,12 +230,12 @@ namespace Implementation { private: Core::CriticalSection _adminLock; - Cryptography::IHash* _accessor; + Exchange::IHash* _accessor; }; - class RPCVaultImpl : public Cryptography::IVault { + class RPCVaultImpl : public Exchange::IVault { public: - RPCVaultImpl(Cryptography::IVault* vault) + RPCVaultImpl(Exchange::IVault* vault) : _accessor(vault) { if (_accessor != nullptr) { @@ -245,7 +245,7 @@ namespace Implementation { ~RPCVaultImpl() override = default; BEGIN_INTERFACE_MAP(RPCVaultImpl) - INTERFACE_ENTRY(Cryptography::IVault) + INTERFACE_ENTRY(Exchange::IVault) END_INTERFACE_MAP public: @@ -297,9 +297,9 @@ namespace Implementation { // ----------------------------------------------------- // Retrieve a HMAC calculator - Cryptography::IHash* HMAC(const Cryptography::hashtype hashType, const uint32_t keyId) override + Exchange::IHash* HMAC(const Exchange::hashtype hashType, const uint32_t keyId) override { - Cryptography::IHash* iface = nullptr; + Exchange::IHash* iface = nullptr; Core::SafeSyncType lock(_adminLock); @@ -314,7 +314,7 @@ namespace Implementation { iface->Release(); - iface = reinterpret_cast(object->QueryInterface(Cryptography::IHash::ID)); + iface = reinterpret_cast(object->QueryInterface(Exchange::IHash::ID)); } } @@ -322,9 +322,9 @@ namespace Implementation { } // Retrieve an AES encryptor/decryptor - Cryptography::ICipher* AES(const Cryptography::aesmode aesMode, const uint32_t keyId) override + Exchange::ICipher* AES(const Exchange::aesmode aesMode, const uint32_t keyId) override { - Cryptography::ICipher* iface = nullptr; + Exchange::ICipher* iface = nullptr; Core::SafeSyncType lock(_adminLock); @@ -339,7 +339,7 @@ namespace Implementation { iface->Release(); - iface = reinterpret_cast(object->QueryInterface(Cryptography::ICipher::ID)); + iface = reinterpret_cast(object->QueryInterface(Exchange::ICipher::ID)); } } @@ -347,9 +347,9 @@ namespace Implementation { } // Retrieve a Diffie-Hellman key creator - Cryptography::IDiffieHellman* DiffieHellman() override + Exchange::IDiffieHellman* DiffieHellman() override { - Cryptography::IDiffieHellman* iface = nullptr; + Exchange::IDiffieHellman* iface = nullptr; Core::SafeSyncType lock(_adminLock); @@ -364,7 +364,7 @@ namespace Implementation { iface->Release(); - iface = reinterpret_cast(object->QueryInterface(Cryptography::IDiffieHellman::ID)); + iface = reinterpret_cast(object->QueryInterface(Exchange::IDiffieHellman::ID)); } } @@ -382,16 +382,16 @@ namespace Implementation { private: mutable Core::CriticalSection _adminLock; - Cryptography::IVault* _accessor; + Exchange::IVault* _accessor; }; - class RPCCryptographyImpl : public Cryptography::ICryptography { + class RPCCryptographyImpl : public Exchange::ICryptography { public: RPCCryptographyImpl() = delete; RPCCryptographyImpl(const RPCCryptographyImpl&) = delete; RPCCryptographyImpl& operator=(const RPCCryptographyImpl&) = delete; - RPCCryptographyImpl(Cryptography::ICryptography* iface) + RPCCryptographyImpl(Exchange::ICryptography* iface) : _accessor(iface) { _accessor->AddRef(); @@ -399,14 +399,14 @@ namespace Implementation { ~RPCCryptographyImpl() override = default; BEGIN_INTERFACE_MAP(RPCCryptographyImpl) - INTERFACE_ENTRY(Cryptography::ICryptography) + INTERFACE_ENTRY(Exchange::ICryptography) END_INTERFACE_MAP public: // Retrieve a hash calculator - Cryptography::IHash* Hash(const Cryptography::hashtype hashType) override + Exchange::IHash* Hash(const Exchange::hashtype hashType) override { - Cryptography::IHash* iface = nullptr; + Exchange::IHash* iface = nullptr; Core::SafeSyncType lock(_adminLock); @@ -421,7 +421,7 @@ namespace Implementation { iface->Release(); - iface = reinterpret_cast(object->QueryInterface(Cryptography::IHash::ID)); + iface = reinterpret_cast(object->QueryInterface(Exchange::IHash::ID)); } } @@ -429,9 +429,9 @@ namespace Implementation { } // Retrieve a vault (TEE identified by ID) - Cryptography::IVault* Vault(const cryptographyvault id) override + Exchange::IVault* Vault(const Exchange::CryptographyVault id) override { - Cryptography::IVault* iface = nullptr; + Exchange::IVault* iface = nullptr; Core::SafeSyncType lock(_adminLock); @@ -446,7 +446,7 @@ namespace Implementation { iface->Release(); - iface = reinterpret_cast(object->QueryInterface(Cryptography::IVault::ID)); + iface = reinterpret_cast(object->QueryInterface(Exchange::IVault::ID)); } } @@ -464,12 +464,12 @@ namespace Implementation { private: mutable Core::CriticalSection _adminLock; - Cryptography::ICryptography* _accessor; + Exchange::ICryptography* _accessor; }; - Cryptography::ICryptography* CryptographyLink::Cryptography(const std::string& connectionPoint) + Exchange::ICryptography* CryptographyLink::Cryptography(const std::string& connectionPoint) { - Cryptography::ICryptography* iface = BaseClass::Acquire(3000, Core::NodeId(connectionPoint.c_str()), _T(""), ~0); + Exchange::ICryptography* iface = BaseClass::Acquire(3000, Core::NodeId(connectionPoint.c_str()), _T(""), ~0); // Core::SafeSyncType lock(_adminLock); @@ -480,13 +480,13 @@ namespace Implementation { iface->Release(); - iface = reinterpret_cast(object->QueryInterface(Cryptography::ICryptography::ID)); + iface = reinterpret_cast(object->QueryInterface(Exchange::ICryptography::ID)); } return iface; } - class HashImpl : public WPEFramework::Cryptography::IHash { + class HashImpl : public WPEFramework::Exchange::IHash { public: HashImpl() = delete; HashImpl(const HashImpl&) = delete; @@ -516,14 +516,14 @@ namespace Implementation { public: BEGIN_INTERFACE_MAP(HashImpl) - INTERFACE_ENTRY(WPEFramework::Cryptography::IHash) + INTERFACE_ENTRY(WPEFramework::Exchange::IHash) END_INTERFACE_MAP private: HashImplementation* _implementation; }; // class HashImpl - class VaultImpl : public WPEFramework::Cryptography::IVault, public WPEFramework::Cryptography::IPersistent { + class VaultImpl : public WPEFramework::Exchange::IVault, public WPEFramework::Exchange::IPersistent { public: VaultImpl() = delete; VaultImpl(const VaultImpl&) = delete; @@ -621,7 +621,7 @@ namespace Implementation { VaultImpl* _vault; }; // class HMACImpl - class CipherImpl : public WPEFramework::Cryptography::ICipher { + class CipherImpl : public WPEFramework::Exchange::ICipher { public: CipherImpl() = delete; CipherImpl(const CipherImpl&) = delete; @@ -659,7 +659,7 @@ namespace Implementation { public: BEGIN_INTERFACE_MAP(CipherImpl) - INTERFACE_ENTRY(WPEFramework::Cryptography::ICipher) + INTERFACE_ENTRY(WPEFramework::Exchange::ICipher) END_INTERFACE_MAP private: @@ -667,7 +667,7 @@ namespace Implementation { CipherImplementation* _implementation; }; // class CipherImpl - class DiffieHellmanImpl : public WPEFramework::Cryptography::IDiffieHellman { + class DiffieHellmanImpl : public WPEFramework::Exchange::IDiffieHellman { public: DiffieHellmanImpl() = delete; DiffieHellmanImpl(const DiffieHellmanImpl&) = delete; @@ -699,22 +699,22 @@ namespace Implementation { public: BEGIN_INTERFACE_MAP(DiffieHellmanImpl) - INTERFACE_ENTRY(WPEFramework::Cryptography::IDiffieHellman) + INTERFACE_ENTRY(WPEFramework::Exchange::IDiffieHellman) END_INTERFACE_MAP private: VaultImpl* _vault; }; // class DiffieHellmanImpl - WPEFramework::Cryptography::IHash* HMAC(const WPEFramework::Cryptography::hashtype hashType, + WPEFramework::Exchange::IHash* HMAC(const WPEFramework::Exchange::hashtype hashType, const uint32_t secretId) override { - WPEFramework::Cryptography::IHash* hmac(nullptr); + WPEFramework::Exchange::IHash* hmac(nullptr); HashImplementation* impl = hash_create_hmac(_implementation, static_cast(hashType), secretId); if (impl != nullptr) { - hmac = WPEFramework::Core::Service::Create(this, impl); + hmac = WPEFramework::Core::Service::Create(this, impl); ASSERT(hmac != nullptr); if (hmac == nullptr) { @@ -725,15 +725,15 @@ namespace Implementation { return (hmac); } - WPEFramework::Cryptography::ICipher* AES(const WPEFramework::Cryptography::aesmode aesMode, + WPEFramework::Exchange::ICipher* AES(const WPEFramework::Exchange::aesmode aesMode, const uint32_t keyId) override { - WPEFramework::Cryptography::ICipher* cipher(nullptr); + WPEFramework::Exchange::ICipher* cipher(nullptr); CipherImplementation* impl = cipher_create_aes(_implementation, static_cast(aesMode), keyId); if (impl != nullptr) { - cipher = Core::Service::Create(this, impl); + cipher = Core::Service::Create(this, impl); ASSERT(cipher != nullptr); if (cipher == nullptr) { @@ -744,24 +744,24 @@ namespace Implementation { return (cipher); } - WPEFramework::Cryptography::IDiffieHellman* DiffieHellman() override + WPEFramework::Exchange::IDiffieHellman* DiffieHellman() override { - WPEFramework::Cryptography::IDiffieHellman* dh = Core::Service::Create(this); + WPEFramework::Exchange::IDiffieHellman* dh = Core::Service::Create(this); ASSERT(dh != nullptr); return (dh); } public: BEGIN_INTERFACE_MAP(VaultImpl) - INTERFACE_ENTRY(WPEFramework::Cryptography::IVault) - INTERFACE_ENTRY(WPEFramework::Cryptography::IPersistent) + INTERFACE_ENTRY(WPEFramework::Exchange::IVault) + INTERFACE_ENTRY(WPEFramework::Exchange::IPersistent) END_INTERFACE_MAP private: VaultImplementation* _implementation; }; // class VaultImpl - class CryptographyImpl : public WPEFramework::Cryptography::ICryptography { + class CryptographyImpl : public WPEFramework::Exchange::ICryptography { public: CryptographyImpl(const CryptographyImpl&) = delete; CryptographyImpl& operator=(const CryptographyImpl&) = delete; @@ -769,13 +769,13 @@ namespace Implementation { ~CryptographyImpl() override = default; public: - WPEFramework::Cryptography::IHash* Hash(const WPEFramework::Cryptography::hashtype hashType) override + WPEFramework::Exchange::IHash* Hash(const WPEFramework::Exchange::hashtype hashType) override { - WPEFramework::Cryptography::IHash* hash(nullptr); + WPEFramework::Exchange::IHash* hash(nullptr); HashImplementation* impl = hash_create(static_cast(hashType)); if (impl != nullptr) { - hash = WPEFramework::Core::Service::Create(impl); + hash = WPEFramework::Core::Service::Create(impl); ASSERT(hash != nullptr); if (hash == nullptr) { @@ -786,13 +786,13 @@ namespace Implementation { return (hash); } - WPEFramework::Cryptography::IVault* Vault(const cryptographyvault id) override + WPEFramework::Exchange::IVault* Vault(const Exchange::CryptographyVault id) override { - WPEFramework::Cryptography::IVault* vault(nullptr); - VaultImplementation* impl = vault_instance(id); + WPEFramework::Exchange::IVault* vault(nullptr); + VaultImplementation* impl = vault_instance(static_cast(id)); if (impl != nullptr) { - vault = WPEFramework::Core::Service::Create(impl); + vault = WPEFramework::Core::Service::Create(impl); ASSERT(vault != nullptr); } @@ -801,18 +801,18 @@ namespace Implementation { public: BEGIN_INTERFACE_MAP(CryptographyImpl) - INTERFACE_ENTRY(WPEFramework::Cryptography::ICryptography) + INTERFACE_ENTRY(WPEFramework::Exchange::ICryptography) END_INTERFACE_MAP }; // class CryptographyImpl } // namespace Implementation -/* static */ Cryptography::ICryptography* Cryptography::ICryptography::Instance(const std::string& connectionPoint) +/* static */ Exchange::ICryptography* Exchange::ICryptography::Instance(const std::string& connectionPoint) { - Cryptography::ICryptography* result(nullptr); + Exchange::ICryptography* result(nullptr); if (connectionPoint.empty() == true) { - result = Core::Service::Create(); + result = Core::Service::Create(); } else { // Seems we received a connection point result = Implementation::CryptographyLink::Instance().Cryptography(connectionPoint); diff --git a/Source/cryptography/Cryptography.vcxproj b/Source/cryptography/Cryptography.vcxproj index 1a0cab53..7fecbbff 100644 --- a/Source/cryptography/Cryptography.vcxproj +++ b/Source/cryptography/Cryptography.vcxproj @@ -20,7 +20,6 @@ - @@ -28,7 +27,6 @@ - @@ -143,9 +141,6 @@ $(SolutionDir)..\artifacts\$(Configuration)\ true - - python "$(ToolPath)\ProxyStubGenerator\StubGenerator.py" --namespace "WPEFramework::Cryptography" -I "$(ProjectDir)" "$(ProjectDir)ICryptography.h" "$(ProjectDir)INetflixSecurity.h" - ProxyStub Generation @@ -172,9 +167,6 @@ $(SolutionDir)..\artifacts\$(Configuration)\ true - - python "$(ToolPath)\ProxyStubGenerator\StubGenerator.py" --namespace "WPEFramework::Cryptography" -I "$(ProjectDir)" "$(ProjectDir)ICryptography.h" "$(ProjectDir)INetflixSecurity.h" - ProxyStub Generation @@ -205,9 +197,6 @@ $(SolutionDir)..\artifacts\$(Configuration)\ true - - python "$(ToolPath)\ProxyStubGenerator\StubGenerator.py" --namespace "WPEFramework::Cryptography" -I "$(ProjectDir)" "$(ProjectDir)ICryptography.h" "$(ProjectDir)INetflixSecurity.h" - ProxyStub Generation @@ -238,9 +227,6 @@ $(SolutionDir)..\artifacts\$(Configuration)\ true - - python "$(ToolPath)\ProxyStubGenerator\StubGenerator.py" --namespace "WPEFramework::Cryptography" -I "$(ProjectDir)" "$(ProjectDir)ICryptography.h" "$(ProjectDir)INetflixSecurity.h" - ProxyStub Generation @@ -248,4 +234,4 @@ - \ No newline at end of file + diff --git a/Source/cryptography/Cryptography.vcxproj.filters b/Source/cryptography/Cryptography.vcxproj.filters index 63090f44..09971f38 100644 --- a/Source/cryptography/Cryptography.vcxproj.filters +++ b/Source/cryptography/Cryptography.vcxproj.filters @@ -27,12 +27,6 @@ Header Files - - Header Files - - - Header Files - Header Files @@ -81,4 +75,4 @@ Implementation\Source Files - \ No newline at end of file + diff --git a/Source/cryptography/ICryptography.h b/Source/cryptography/ICryptography.h deleted file mode 100644 index 2a4bd6a0..00000000 --- a/Source/cryptography/ICryptography.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2020 Metrological - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "Module.h" - -#include "cryptography_vault_ids.h" - -/* @stubgen:include "cryptography_vault_ids.h" */ - -namespace WPEFramework { - -namespace Cryptography { - - enum IDs : uint32_t { - ID_HASH = 0x00001100, - ID_VAULT, - ID_CIPHER, - ID_DIFFIE_HELLMAN, - ID_CRYPTOGRAPHY, - ID_PERSISTENT - }; - - enum aesmode : uint8_t { - ECB, - CBC, - OFB, - CFB1, - CFB8, - CFB128, - CTR - }; - - enum hashtype : uint8_t { - SHA1 = 20, - SHA224 = 28, - SHA256 = 32, - SHA384 = 48, - SHA512 = 64 - }; - - - - struct EXTERNAL IHash : virtual public Core::IUnknown { - - enum { ID = ID_HASH }; - - ~IHash() override = default; - - /* Ingest data into the hash calculator (multiple calls possible) */ - virtual uint32_t Ingest(const uint32_t length, const uint8_t data[] /* @in @length:length */) = 0; - - /* Calculate the hash from all ingested data */ - virtual uint8_t Calculate(const uint8_t maxLength, uint8_t data[] /* @out @maxlength:maxLength */) = 0; - }; - - struct EXTERNAL ICipher : virtual public Core::IUnknown { - - enum { ID = ID_CIPHER }; - - ~ICipher() override = default; - - // Encryption and decryption, might require more bytes of data to complete succefully (like padding) to indicate the - // the encryption or decryption failed due to a lack of storage space, a negative length is returned. The abs(length) - // indicates the number of bytes required in the output buffer to succefully complete. - - /* Encrypt data */ - virtual int32_t Encrypt(const uint8_t ivLength, const uint8_t iv[] /* @in @length:ivLength */, - const uint32_t inputLength, const uint8_t input[] /* @in @length:inputLength */, - const uint32_t maxOutputLength, uint8_t output[] /* @out @maxlength:maxOutputLength */) const = 0; - - /* Decrypt data */ - virtual int32_t Decrypt(const uint8_t ivLength, const uint8_t iv[] /* @in @length:ivLength */, - const uint32_t inputLength, const uint8_t input[] /* @in @length:inputLength */, - const uint32_t maxOutputLength, uint8_t output[] /* @out @maxlength:maxOutputLength */) const = 0; - }; - - struct EXTERNAL IDiffieHellman : virtual public Core::IUnknown { - - enum { ID = ID_DIFFIE_HELLMAN }; - - ~IDiffieHellman() override = default; - - /* Generate DH private/public keys */ - virtual uint32_t Generate(const uint8_t generator, const uint16_t modulusSize, const uint8_t modulus[]/* @in @length:modulusSize */ , - uint32_t& privKeyId /* @out */, uint32_t& pubKeyId /* @out */) = 0; - - /* Calculate a DH shared secret */ - virtual uint32_t Derive(const uint32_t privateKey, const uint32_t peerPublicKeyId, uint32_t& secretId /* @out */) = 0; - }; - - struct IPersistent : virtual public Core::IUnknown { - - enum { ID = ID_PERSISTENT }; - - enum keytype { - AES128, - AES256, - HMAC128, - HMAC160, - HMAC256 - }; - - virtual ~IPersistent() { } - - //Check if a named key exists in peristent storage - virtual uint32_t Exists(const string& locator, bool& result /* @out */) const =0; - - //Load persistent key details to vault - virtual uint32_t Load(const string& locator, uint32_t& id /* @out */) = 0; - - //Create a new key on persistent storage - virtual uint32_t Create(const string& locator, const keytype keyType, uint32_t& id /* @out */) = 0 ; - - //To explicitly flush resources at the backend - virtual uint32_t Flush() = 0; - - }; - - - struct EXTERNAL IVault : virtual public Core::IUnknown { - - enum { ID = ID_VAULT }; - - ~IVault() override = default; - - // Operations manipulating items in the vault - // --------------------------------------------------- - - // Return size of a vault data blob - // (-1 if the blob exists in the vault but is not extractable and 0 if the ID does not exist) - virtual uint16_t Size(const uint32_t id) const = 0; - - // Import unencrypted data blob into the vault (returns blob ID) - // Note: User IDs are always greater than 0x80000000, values below 0x80000000 are reserved for implementation-specific internal data blobs. - virtual uint32_t Import(const uint16_t length, const uint8_t blob[] /* @in @length:length */) = 0; - - // Export unencrypted data blob out of the vault (returns blob ID), only public blobs are exportable - virtual uint16_t Export(const uint32_t id, const uint16_t maxLength, uint8_t blob[] /* @out @maxlength:maxLength */) const = 0; - - // Set encrypted data blob in the vault (returns blob ID) - virtual uint32_t Set(const uint16_t length, const uint8_t blob[] /* @in @length:length */) = 0; - - // Get encrypted data blob out of the vault (data identified by ID, returns size of the retrieved data) - virtual uint16_t Get(const uint32_t id, const uint16_t maxLength, uint8_t blob[] /* @out @maxlength:maxLength */) const = 0; - - // Delete a data blob from the vault - virtual bool Delete(const uint32_t id) = 0; - - - // Crypto operations using the vault for key storage - // ----------------------------------------------------- - - // Retrieve a HMAC calculator - virtual IHash* HMAC(const hashtype hashType, const uint32_t keyId) = 0; - - // Retrieve an AES encryptor/decryptor - virtual ICipher* AES(const aesmode aesMode, const uint32_t keyId) = 0; - - // Retrieve a Diffie-Hellman key creator - virtual IDiffieHellman* DiffieHellman() = 0; - }; - - struct EXTERNAL ICryptography : virtual public Core::IUnknown { - enum { ID = ID_CRYPTOGRAPHY }; - - ~ICryptography() override = default; - - static ICryptography* Instance(const std::string& connectionPoint); - - // Retrieve a hash calculator - virtual IHash* Hash(const hashtype hashType) = 0; - - // Retrieve a vault (TEE identified by ID) - virtual IVault* Vault(const cryptographyvault id) = 0; - }; - -} // namespace Cryptography - -} diff --git a/Source/cryptography/INetflixSecurity.h b/Source/cryptography/INetflixSecurity.h deleted file mode 100644 index 8f0fd3d0..00000000 --- a/Source/cryptography/INetflixSecurity.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2020 Metrological - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "Module.h" - -namespace WPEFramework { - -namespace Cryptography { - -struct EXTERNAL INetflixSecurity : public Core::IUnknown -{ - enum { ID = 0x00001200 }; - - virtual ~INetflixSecurity() { } - - /* Retrieve the ESN */ - virtual std::string ESN() const = 0; - - /* Retrieve the pre-shared encryption key */ - virtual uint32_t EncryptionKey() const = 0; - - /* Retrieve the pre-shared HMAC key */ - virtual uint32_t HMACKey() const = 0; - - /* Retrieve the pre-shared wrapping key */ - virtual uint32_t WrappingKey() const = 0; - - /* Derive encryption keys based on an authenticated Diffie-Hellman procedure */ - virtual uint32_t DeriveKeys(const uint32_t privateDhKeyId, const uint32_t peerPublicDhKeyId, const uint32_t derivationKeyId, - uint32_t& encryptionKeyId /* @out */, uint32_t& hmacKeyId /* @out */, uint32_t& wrappingKeyId /* @out */) = 0; - - static INetflixSecurity* Instance(); -}; - -} // namespace Cryptography - -} diff --git a/Source/cryptography/NetflixSecurity.cpp b/Source/cryptography/NetflixSecurity.cpp index 33b4dc9d..49f2a0a1 100644 --- a/Source/cryptography/NetflixSecurity.cpp +++ b/Source/cryptography/NetflixSecurity.cpp @@ -20,7 +20,7 @@ #include "Module.h" -#include +#include #include "implementation/netflix_security_implementation.h" namespace WPEFramework { diff --git a/Source/cryptography/cryptography.h b/Source/cryptography/cryptography.h index 9a339066..bb1cef71 100644 --- a/Source/cryptography/cryptography.h +++ b/Source/cryptography/cryptography.h @@ -20,7 +20,7 @@ #ifndef CRYPTOGRAPHY_H #define CRYPTOGRAPHY_H -#include "ICryptography.h" -#include "INetflixSecurity.h" +#include +#include #endif // CRYPTOGRAPHY_H diff --git a/Source/cryptography/cryptography_vault_ids.h b/Source/cryptography/cryptography_vault_ids.h deleted file mode 100644 index b089cbc5..00000000 --- a/Source/cryptography/cryptography_vault_ids.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2020 Metrological - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CRYPTOGRAPHY_VAULT_IDS_H -#define CRYPTOGRAPHY_VAULT_IDS_H - -#include - -#ifdef __cplusplus -extern "C" -#endif - enum cryptographyvault : uint8_t { - CRYPTOGRAPHY_VAULT_DEFAULT = 0, - CRYPTOGRAPHY_VAULT_PLATFORM = 1, - CRYPTOGRAPHY_VAULT_PROVISIONING = 0x10, - CRYPTOGRAPHY_VAULT_NETFLIX = 0x11 - }; - -#endif // CRYPTOGRAPHY_VAULT_IDS_H diff --git a/Source/cryptography/implementation/SecApi/Vault.h b/Source/cryptography/implementation/SecApi/Vault.h index 49f1ba10..aa72cae1 100644 --- a/Source/cryptography/implementation/SecApi/Vault.h +++ b/Source/cryptography/implementation/SecApi/Vault.h @@ -29,7 +29,6 @@ #include #include "../../Module.h" -#include "cryptography_vault_ids.h" #include "vault_implementation.h" #include "persistent_implementation.h" diff --git a/Source/cryptography/implementation/Thunder/CMakeLists.txt b/Source/cryptography/implementation/Thunder/CMakeLists.txt index 2d5a2d98..248dd47a 100644 --- a/Source/cryptography/implementation/Thunder/CMakeLists.txt +++ b/Source/cryptography/implementation/Thunder/CMakeLists.txt @@ -17,6 +17,8 @@ set(TARGET implementation) +find_package(${NAMESPACE}Cryptalgo REQUIRED) + add_library(${TARGET} STATIC Signing.cpp Vault.cpp diff --git a/Source/cryptography/implementation/Thunder/Cipher.cpp b/Source/cryptography/implementation/Thunder/Cipher.cpp index f6e4f0ae..7bd9c75a 100644 --- a/Source/cryptography/implementation/Thunder/Cipher.cpp +++ b/Source/cryptography/implementation/Thunder/Cipher.cpp @@ -19,7 +19,6 @@ #include "../../Module.h" -#include #include #include diff --git a/Source/cryptography/implementation/Thunder/Signing.cpp b/Source/cryptography/implementation/Thunder/Signing.cpp index a159caac..fe300d1a 100644 --- a/Source/cryptography/implementation/Thunder/Signing.cpp +++ b/Source/cryptography/implementation/Thunder/Signing.cpp @@ -19,7 +19,6 @@ #include "../../Module.h" -#include #include #include diff --git a/Source/cryptography/implementation/Thunder/Vault.cpp b/Source/cryptography/implementation/Thunder/Vault.cpp index f5f02ef1..8621fbfc 100644 --- a/Source/cryptography/implementation/Thunder/Vault.cpp +++ b/Source/cryptography/implementation/Thunder/Vault.cpp @@ -19,7 +19,6 @@ #include "../../Module.h" -#include #include #include diff --git a/Source/cryptography/implementation/persistent_implementation.h b/Source/cryptography/implementation/persistent_implementation.h index 9fc4a566..4eb0c05c 100644 --- a/Source/cryptography/implementation/persistent_implementation.h +++ b/Source/cryptography/implementation/persistent_implementation.h @@ -22,7 +22,6 @@ #include #include -#include "cryptography_vault_ids.h" #include "vault_implementation.h" #ifdef __cplusplus diff --git a/Source/cryptography/implementation/vault_implementation.h b/Source/cryptography/implementation/vault_implementation.h index 04e45edd..35462a2e 100644 --- a/Source/cryptography/implementation/vault_implementation.h +++ b/Source/cryptography/implementation/vault_implementation.h @@ -22,7 +22,6 @@ #include #include -#include "cryptography_vault_ids.h" #undef EXTERNAL #if defined(WIN32) || defined(_WINDOWS) || defined (__CYGWIN__) || defined(_WIN64) @@ -40,6 +39,13 @@ extern "C" { #endif +enum cryptographyvault : uint8_t { + CRYPTOGRAPHY_VAULT_DEFAULT = 0, + CRYPTOGRAPHY_VAULT_PLATFORM = 1, + CRYPTOGRAPHY_VAULT_PROVISIONING = 0x10, + CRYPTOGRAPHY_VAULT_NETFLIX = 0x11 +}; + struct VaultImplementation; EXTERNAL struct VaultImplementation* vault_instance(const enum cryptographyvault id); diff --git a/Source/cryptography/tests/CMakeLists.txt b/Source/cryptography/tests/CMakeLists.txt index d1f33d4e..91de5fa6 100644 --- a/Source/cryptography/tests/CMakeLists.txt +++ b/Source/cryptography/tests/CMakeLists.txt @@ -14,7 +14,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -option(BUILD_CRYPTOGRAPHY_TESTS "Build cryptography test" OFF) +option(BUILD_CRYPTOGRAPHY_TESTS "Build cryptography test" ON) option(BUILD_CRYPTOGRAPHY_RPC_TESTS "Build cryptography rpc test" OFF) if (BUILD_CRYPTOGRAPHY_TESTS) diff --git a/Source/cryptography/tests/cryptography_test/Helpers.cpp b/Source/cryptography/tests/cryptography_test/Helpers.cpp index 5369a1d5..f267563a 100644 --- a/Source/cryptography/tests/cryptography_test/Helpers.cpp +++ b/Source/cryptography/tests/cryptography_test/Helpers.cpp @@ -28,9 +28,7 @@ #include "Helpers.h" #include "Test.h" -#include "core/core.h" -#include "ICryptography.h" -#include "INetflixSecurity.h" +#include extern "C" { diff --git a/Source/cryptography/tests/cryptography_test/InterfaceTests.cpp b/Source/cryptography/tests/cryptography_test/InterfaceTests.cpp index 0db7348b..dc9449c3 100644 --- a/Source/cryptography/tests/cryptography_test/InterfaceTests.cpp +++ b/Source/cryptography/tests/cryptography_test/InterfaceTests.cpp @@ -17,16 +17,18 @@ * limitations under the License. */ +#include "Module.h" +#include +#include +#include #include #include "Helpers.h" #include "Test.h" -#include "ICryptography.h" -#include "INetflixSecurity.h" -#include -static WPEFramework::Cryptography::ICryptography* cg; -static WPEFramework::Cryptography::IVault *vault = nullptr; + +static WPEFramework::Exchange::ICryptography* cg; +static WPEFramework::Exchange::IVault *vault = nullptr; static const uint8_t testVector[] = { 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x74, 0x7 }; @@ -115,7 +117,7 @@ TEST(Hash, Hash) 0x03, 0xCD, 0x78, 0x1D, 0x2E, 0x85, 0x13, 0x11, 0x72, 0x7D, 0xCE, 0x8E, 0xD7, 0x25, 0x51, 0x0F, 0xE1, 0x3B, 0x78, 0x35 }; - WPEFramework::Cryptography::IHash* hashImpl = cg->Hash(WPEFramework::Cryptography::hashtype::SHA256); + WPEFramework::Exchange::IHash* hashImpl = cg->Hash(WPEFramework::Exchange::hashtype::SHA256); EXPECT_NE(hashImpl, nullptr); if (hashImpl != nullptr) { uint8_t* output = new uint8_t[sizeof(hash_sha256)]; @@ -144,7 +146,7 @@ TEST(Hash, Hash) 0xED, 0xD3, 0x47, 0x09, 0x7B, 0xC2, 0x4C, 0xB1, 0x78, 0x32, 0x41, 0xF8, 0x8A, 0x9D, 0x3D, 0x91, 0xB6, 0xD6, 0x4D, 0x60}; - WPEFramework::Cryptography::IHash* lhashImpl = cg->Hash(WPEFramework::Cryptography::hashtype::SHA256); + WPEFramework::Exchange::IHash* lhashImpl = cg->Hash(WPEFramework::Exchange::hashtype::SHA256); EXPECT_NE(lhashImpl, nullptr); if (lhashImpl != nullptr) { uint8_t* output = new uint8_t[sizeof(lhash_sha256)]; @@ -173,7 +175,7 @@ TEST(Hash, HMAC) uint32_t keyId = vault->Import(sizeof(password), password); EXPECT_NE(keyId, 0); if (keyId != 0) { - WPEFramework::Cryptography::IHash* hashImpl = vault->HMAC(WPEFramework::Cryptography::hashtype::SHA256, keyId); + WPEFramework::Exchange::IHash* hashImpl = vault->HMAC(WPEFramework::Exchange::hashtype::SHA256, keyId); EXPECT_NE(hashImpl, nullptr); if (hashImpl != nullptr) { uint8_t* output = new uint8_t[128]; @@ -224,7 +226,7 @@ TEST(Cipher, AES) uint32_t key128Id = vault->Import(sizeof(key128), key128); EXPECT_NE(key128Id, 0); if (key128Id != 0) { - WPEFramework::Cryptography::ICipher* aes = vault->AES(WPEFramework::Cryptography::aesmode::CBC, key128Id); + WPEFramework::Exchange::ICipher* aes = vault->AES(WPEFramework::Exchange::aesmode::CBC, key128Id); EXPECT_NE(aes, nullptr); if (aes) { uint8_t* output = new uint8_t[bufferSize]; @@ -267,7 +269,7 @@ static bool GenerateDHKeyPair(const uint32_t generator, const uint8_t modulus[], uint32_t dhPrivateKey = 0; uint32_t dhPublicKey = 0; - WPEFramework::Cryptography::IDiffieHellman* dh = vault->DiffieHellman(); + WPEFramework::Exchange::IDiffieHellman* dh = vault->DiffieHellman(); EXPECT_NE(dh, nullptr); if (dh != nullptr) { uint32_t DHStatus = dh->Generate(generator, modulusSize, modulus, dhPrivateKey, dhPublicKey); @@ -330,7 +332,7 @@ TEST(DH, Generate) int main(int argc, char **argv) { - cg = WPEFramework::Cryptography::ICryptography::Instance(""); + cg = WPEFramework::Exchange::ICryptography::Instance(""); int len; if (cg != nullptr) { @@ -340,31 +342,31 @@ int main(int argc, char **argv) if ( (len == 9) && !strncmp( (const char*)argv[i], "--netflix", len) ) { printf("\nAcquiring Netflix instance\n"); - vault = cg->Vault(cryptographyvault::CRYPTOGRAPHY_VAULT_NETFLIX); + vault = cg->Vault(WPEFramework::Exchange::CryptographyVault::CRYPTOGRAPHY_VAULT_NETFLIX); } else if ( (len == 9) && !strncmp( (const char*)argv[i], "--default", len) ) { printf("\nAcquiring DEFAULT instance\n"); - vault = cg->Vault(cryptographyvault::CRYPTOGRAPHY_VAULT_DEFAULT); + vault = cg->Vault(WPEFramework::Exchange::CryptographyVault::CRYPTOGRAPHY_VAULT_DEFAULT); } else if ( (len == 10) && !strncmp( (const char*)argv[i], "--platform", len) ) { printf("\nAcquiring PLATFORM instance\n"); - vault = cg->Vault(cryptographyvault::CRYPTOGRAPHY_VAULT_PLATFORM); + vault = cg->Vault(WPEFramework::Exchange::CryptographyVault::CRYPTOGRAPHY_VAULT_PLATFORM); } else if ( (len == 21) && !strncmp( (const char*)argv[i], "--testdefaultinstance", len) ) { #ifdef SecApi printf("\nAcquiring DEFAULT instance for SecApi\n"); - vault = cg->Vault(cryptographyvault::CRYPTOGRAPHY_VAULT_DEFAULT); + vault = cg->Vault(WPEFramework::Exchange::CryptographyVault::CRYPTOGRAPHY_VAULT_DEFAULT); #else printf("\nAcquiring PLATFORM instance\n"); - vault = cg->Vault(cryptographyvault::CRYPTOGRAPHY_VAULT_PLATFORM); + vault = cg->Vault(WPEFramework::Exchange::CryptographyVault::CRYPTOGRAPHY_VAULT_PLATFORM); #endif } } if (vault == nullptr) - vault = cg->Vault(cryptographyvault::CRYPTOGRAPHY_VAULT_NETFLIX); + vault = cg->Vault(WPEFramework::Exchange::CryptographyVault::CRYPTOGRAPHY_VAULT_NETFLIX); if (vault != nullptr) { CALL(Vault, ImportExport); diff --git a/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp b/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp index 8449c10a..d32d1f9a 100644 --- a/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp +++ b/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp @@ -20,6 +20,8 @@ #include "Module.h" #include +#include +#include #include #include @@ -28,13 +30,11 @@ #include #include -#include "ICryptography.h" -#include "INetflixSecurity.h" #include "Helpers.h" #include "Test.h" -static WPEFramework::Cryptography::IVault* vault = nullptr; +static WPEFramework::Exchange::IVault* vault = nullptr; static WPEFramework::Cryptography::INetflixSecurity* nfSecurity = nullptr; @@ -76,7 +76,7 @@ static void TestAuthenticatedDerive(const uint16_t hostPskSize, const uint8_t ho DH *hostPrivKey = DHGenerate(generator, prime1024, sizeof(prime1024)); assert(hostPrivKey != nullptr); - WPEFramework::Cryptography::IDiffieHellman *idh = vault->DiffieHellman(); + WPEFramework::Exchange::IDiffieHellman *idh = vault->DiffieHellman(); EXPECT_NE(idh, nullptr); if (idh != nullptr) { @@ -158,7 +158,7 @@ static void TestAuthenticatedDerive(const uint16_t hostPskSize, const uint8_t ho DumpBuffer(encBuf, (uint32_t)encLen); uint8_t decBuf[32] = { 0 }; - WPEFramework::Cryptography::ICipher *cipher = vault->AES(WPEFramework::Cryptography::aesmode::CBC, teeEncKeyId); + WPEFramework::Exchange::ICipher *cipher = vault->AES(WPEFramework::Exchange::aesmode::CBC, teeEncKeyId); EXPECT_NE(cipher, nullptr); if (cipher != nullptr) { uint32_t decLen = 0; @@ -179,7 +179,7 @@ static void TestAuthenticatedDerive(const uint16_t hostPskSize, const uint8_t ho printf("Host HMAC using hmacKey:\n"); DumpBuffer(hostHmac, sizeof(hostHmac)); - WPEFramework::Cryptography::IHash *hash = vault->HMAC(WPEFramework::Cryptography::hashtype::SHA256, teeHmacKeyId); + WPEFramework::Exchange::IHash *hash = vault->HMAC(WPEFramework::Exchange::hashtype::SHA256, teeHmacKeyId); EXPECT_NE(hash, nullptr); if (hash != nullptr) { EXPECT_EQ(hash->Ingest(sizeof(testStr), (uint8_t*)testStr), sizeof(testStr)); @@ -264,9 +264,9 @@ int main() if (nfSecurity != nullptr) { CALL(NetflixSecurity, Security); - WPEFramework::Cryptography::ICryptography* cg = WPEFramework::Cryptography::ICryptography::Instance(""); + WPEFramework::Exchange::ICryptography* cg = WPEFramework::Exchange::ICryptography::Instance(""); if (cg != nullptr) { - vault = cg->Vault(CRYPTOGRAPHY_VAULT_NETFLIX); + vault = cg->Vault(WPEFramework::Exchange::CryptographyVault::CRYPTOGRAPHY_VAULT_NETFLIX); if (vault != nullptr) { CALL(NetflixSecurity, AuthenticatedDerive); vault->Release(); diff --git a/Source/cryptography/tests/rpc_cryptography_test/CMakeLists.txt b/Source/cryptography/tests/rpc_cryptography_test/CMakeLists.txt index 54751206..e5e14bd1 100644 --- a/Source/cryptography/tests/rpc_cryptography_test/CMakeLists.txt +++ b/Source/cryptography/tests/rpc_cryptography_test/CMakeLists.txt @@ -18,6 +18,7 @@ option(COMRPCVAULT "Include Com RPC Vault test tool" ON) find_package(GTest REQUIRED) +find_package(${NAMESPACE}Core REQUIRED) set(TARGET rpc_cryptography_test) @@ -32,6 +33,7 @@ target_link_libraries(${TARGET} PRIVATE GTest::GTest ${NAMESPACE}Cryptography + ${NAMESPACE}Core::${NAMESPACE}Core ${NAMESPACE}COM ) diff --git a/Source/cryptography/tests/rpc_cryptography_test/rpc_cryptography_test.cpp b/Source/cryptography/tests/rpc_cryptography_test/rpc_cryptography_test.cpp index 2abb6a27..22f51535 100644 --- a/Source/cryptography/tests/rpc_cryptography_test/rpc_cryptography_test.cpp +++ b/Source/cryptography/tests/rpc_cryptography_test/rpc_cryptography_test.cpp @@ -171,7 +171,7 @@ class BasicTest : public ::testing::Test { virtual void SetUp() { - cryptography = Thunder::Cryptography::ICryptography::Instance(TestData::nodeId); + cryptography = Thunder::Exchange::ICryptography::Instance(TestData::nodeId); } virtual void TearDown() @@ -182,7 +182,7 @@ class BasicTest : public ::testing::Test { } } - Thunder::Cryptography::ICryptography* cryptography; + Thunder::Exchange::ICryptography* cryptography; Controller controller; }; @@ -218,7 +218,7 @@ TEST_F(BasicTest, Vault) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); @@ -238,7 +238,7 @@ TEST_F(BasicTest, VaultImportExport) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); @@ -272,7 +272,7 @@ TEST_F(BasicTest, VaultSetGet) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); @@ -302,11 +302,11 @@ TEST_F(BasicTest, VaultDiffieHellman) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); - Thunder::Cryptography::IDiffieHellman* dh = vault->DiffieHellman(); + Thunder::Exchange::IDiffieHellman* dh = vault->DiffieHellman(); EXPECT_NE(nullptr, dh); @@ -327,13 +327,13 @@ TEST_F(BasicTest, VaultHMAC) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); uint32_t keyId = vault->Import(sizeof(TestData::cipherkey), reinterpret_cast(TestData::cipherkey)); - Thunder::Cryptography::IHash* iface = vault->HMAC(Thunder::Cryptography::SHA1, keyId); + Thunder::Exchange::IHash* iface = vault->HMAC(Thunder::Exchange::SHA1, keyId); EXPECT_NE(nullptr, iface); @@ -364,13 +364,13 @@ TEST_F(BasicTest, VaultHMACIngestCalculate) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); uint32_t keyId = vault->Import(sizeof(TestData::cipherkey), TestData::cipherkey); - Thunder::Cryptography::IHash* iface = vault->HMAC(Thunder::Cryptography::SHA1, keyId); + Thunder::Exchange::IHash* iface = vault->HMAC(Thunder::Exchange::SHA1, keyId); if (vault != nullptr) { vault->Release(); @@ -385,7 +385,7 @@ TEST_F(BasicTest, VaultHMACIngestCalculate) ingestSize = iface->Calculate(sizeof(hashBuffer), hashBuffer); - EXPECT_EQ(ingestSize, Thunder::Cryptography::SHA1); + EXPECT_EQ(ingestSize, Thunder::Exchange::SHA1); EXPECT_TRUE(ArraysMatch(hashBuffer, hashExpected)); @@ -404,13 +404,13 @@ TEST_F(BasicTest, VaultHMACIngest65K) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); uint32_t keyId = vault->Import(sizeof(TestData::cipherkey), TestData::cipherkey); - Thunder::Cryptography::IHash* iface = vault->HMAC(Thunder::Cryptography::SHA1, keyId); + Thunder::Exchange::IHash* iface = vault->HMAC(Thunder::Exchange::SHA1, keyId); if (vault != nullptr) { vault->Release(); @@ -428,7 +428,7 @@ TEST_F(BasicTest, VaultHMACIngest65K) ingestSize = iface->Calculate(sizeof(hashBuffer), hashBuffer); - EXPECT_EQ(ingestSize, Thunder::Cryptography::SHA1); + EXPECT_EQ(ingestSize, Thunder::Exchange::SHA1); if (iface != nullptr) { iface->Release(); @@ -442,13 +442,13 @@ TEST_F(BasicTest, VaultAES) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); uint32_t keyId = vault->Import(sizeof(TestData::cipherkey), TestData::cipherkey); - Thunder::Cryptography::ICipher* iface = vault->AES(Thunder::Cryptography::CBC, keyId); + Thunder::Exchange::ICipher* iface = vault->AES(Thunder::Exchange::CBC, keyId); ASSERT_NE(nullptr, iface); @@ -468,7 +468,7 @@ TEST_F(BasicTest, VaultAESEncryptDecrypt) uint8_t encryptBuffer[128]; uint8_t clearBuffer[128]; - Thunder::Cryptography::ICipher* iface = nullptr; + Thunder::Exchange::ICipher* iface = nullptr; memset(encryptBuffer, 0x00, sizeof(encryptBuffer)); memset(clearBuffer, 0x00, sizeof(clearBuffer)); @@ -477,13 +477,13 @@ TEST_F(BasicTest, VaultAESEncryptDecrypt) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); uint32_t keyId = vault->Import(sizeof(TestData::cipherkey), TestData::cipherkey); - iface = vault->AES(Thunder::Cryptography::CBC, keyId); + iface = vault->AES(Thunder::Exchange::CBC, keyId); ASSERT_NE(nullptr, iface); @@ -523,7 +523,7 @@ TEST_F(BasicTest, VaultAESEncryptDecryptDisablePlugin) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); cryptography->Release(); cryptography = nullptr; @@ -532,7 +532,7 @@ TEST_F(BasicTest, VaultAESEncryptDecryptDisablePlugin) uint32_t keyId = vault->Import(sizeof(TestData::cipherkey), TestData::cipherkey); - Thunder::Cryptography::ICipher* iface = vault->AES(Thunder::Cryptography::CBC, keyId); + Thunder::Exchange::ICipher* iface = vault->AES(Thunder::Exchange::CBC, keyId); ASSERT_NE(nullptr, iface); @@ -571,7 +571,7 @@ TEST_F(BasicTest, Hash) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IHash* hash = cryptography->Hash(Thunder::Cryptography::SHA1); + Thunder::Exchange::IHash* hash = cryptography->Hash(Thunder::Exchange::SHA1); ASSERT_NE(nullptr, hash); @@ -583,20 +583,20 @@ TEST_F(BasicTest, Hash) TEST_F(BasicTest, HashSHA1Calculate) { - uint8_t exportBuffer[Thunder::Cryptography::SHA1]; + uint8_t exportBuffer[Thunder::Exchange::SHA1]; memset(exportBuffer, 0, sizeof(exportBuffer)); ASSERT_EQ(controller.ActivatePlugin(TestData::plugin), Thunder::Core::ERROR_NONE); ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IHash* hash = cryptography->Hash(Thunder::Cryptography::SHA1); + Thunder::Exchange::IHash* hash = cryptography->Hash(Thunder::Exchange::SHA1); ASSERT_NE(nullptr, hash); EXPECT_EQ(hash->Ingest(sizeof(TestData::data), reinterpret_cast(TestData::data)), sizeof(TestData::data)); - EXPECT_EQ(hash->Calculate(sizeof(exportBuffer), exportBuffer), Thunder::Cryptography::SHA1); + EXPECT_EQ(hash->Calculate(sizeof(exportBuffer), exportBuffer), Thunder::Exchange::SHA1); EXPECT_TRUE(ArraysMatch(exportBuffer, TestData::expectedSHA1HashOfData)); @@ -608,14 +608,14 @@ TEST_F(BasicTest, HashSHA1Calculate) TEST_F(BasicTest, HashSHA1CalculateDeactivate) { - uint8_t exportBuffer[Thunder::Cryptography::SHA1]; + uint8_t exportBuffer[Thunder::Exchange::SHA1]; memset(exportBuffer, 0, sizeof(exportBuffer)); ASSERT_EQ(controller.ActivatePlugin(TestData::plugin), Thunder::Core::ERROR_NONE); ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IHash* hash = cryptography->Hash(Thunder::Cryptography::SHA1); + Thunder::Exchange::IHash* hash = cryptography->Hash(Thunder::Exchange::SHA1); ASSERT_NE(nullptr, hash); @@ -635,14 +635,14 @@ TEST_F(BasicTest, HashSHA1CalculateDeactivate) TEST_F(BasicTest, HashSHA1CalculateDeactivateAndRecover) { - uint8_t exportBuffer[Thunder::Cryptography::SHA1]; + uint8_t exportBuffer[Thunder::Exchange::SHA1]; memset(exportBuffer, 0, sizeof(exportBuffer)); ASSERT_EQ(controller.ActivatePlugin(TestData::plugin), Thunder::Core::ERROR_NONE); ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IHash* hash = cryptography->Hash(Thunder::Cryptography::SHA1); + Thunder::Exchange::IHash* hash = cryptography->Hash(Thunder::Exchange::SHA1); ASSERT_NE(nullptr, hash); EXPECT_EQ(hash->Ingest(sizeof(TestData::data), reinterpret_cast(TestData::data)), sizeof(TestData::data)); @@ -657,15 +657,15 @@ TEST_F(BasicTest, HashSHA1CalculateDeactivateAndRecover) ASSERT_EQ(controller.ActivatePlugin(TestData::plugin), Thunder::Core::ERROR_NONE); ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); - cryptography = Thunder::Cryptography::ICryptography::Instance(TestData::nodeId); + cryptography = Thunder::Exchange::ICryptography::Instance(TestData::nodeId); ASSERT_NE(nullptr, cryptography); - hash = cryptography->Hash(Thunder::Cryptography::SHA1); + hash = cryptography->Hash(Thunder::Exchange::SHA1); ASSERT_NE(nullptr, hash); EXPECT_EQ(hash->Ingest(sizeof(TestData::data), reinterpret_cast(TestData::data)), sizeof(TestData::data)); - EXPECT_EQ(hash->Calculate(sizeof(exportBuffer), exportBuffer), Thunder::Cryptography::SHA1); + EXPECT_EQ(hash->Calculate(sizeof(exportBuffer), exportBuffer), Thunder::Exchange::SHA1); EXPECT_TRUE(ArraysMatch(exportBuffer, TestData::expectedSHA1HashOfData)); @@ -681,13 +681,13 @@ TEST_F(BasicTest, VaultDiffieHellmanDeavtivated) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); EXPECT_EQ(controller.DeactivatePlugin(TestData::plugin), Thunder::Core::ERROR_NONE); - Thunder::Cryptography::IDiffieHellman* df = vault->DiffieHellman(); + Thunder::Exchange::IDiffieHellman* df = vault->DiffieHellman(); EXPECT_EQ(nullptr, df); @@ -705,11 +705,11 @@ TEST_F(BasicTest, VaultDiffieHellmanGenerate) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); - Thunder::Cryptography::IDiffieHellman* dh = vault->DiffieHellman(); + Thunder::Exchange::IDiffieHellman* dh = vault->DiffieHellman(); vault->Release(); vault = nullptr; @@ -739,11 +739,11 @@ TEST_F(BasicTest, VaultDiffieHellmanGenerateDeactivatedPlugin) ASSERT_TRUE(controller.IsPluginActive(TestData::plugin)); ASSERT_NE(nullptr, cryptography); - Thunder::Cryptography::IVault* vault = cryptography->Vault(CRYPTOGRAPHY_VAULT_PLATFORM); + Thunder::Exchange::IVault* vault = cryptography->Vault(Thunder::Exchange::CRYPTOGRAPHY_VAULT_PLATFORM); ASSERT_NE(nullptr, vault); - Thunder::Cryptography::IDiffieHellman* dh = vault->DiffieHellman(); + Thunder::Exchange::IDiffieHellman* dh = vault->DiffieHellman(); if (vault != nullptr) { vault->Release(); From ba00103274f680bf72d525f31bd83795cd574b5c Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Tue, 8 Aug 2023 18:01:27 +0530 Subject: [PATCH 28/37] update INetflixSecurity namespace based on interface change (#218) --- Source/cryptography/NetflixSecurity.cpp | 8 ++++---- Source/cryptography/tests/CMakeLists.txt | 2 +- .../tests/cryptography_test/NetflixSecurityTests.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/cryptography/NetflixSecurity.cpp b/Source/cryptography/NetflixSecurity.cpp index 49f2a0a1..be384c6c 100644 --- a/Source/cryptography/NetflixSecurity.cpp +++ b/Source/cryptography/NetflixSecurity.cpp @@ -27,7 +27,7 @@ namespace WPEFramework { namespace Implementation { - class NetflixSecurity : public Cryptography::INetflixSecurity { + class NetflixSecurity : public Exchange::INetflixSecurity { public: NetflixSecurity(const NetflixSecurity&) = delete; NetflixSecurity& operator=(const NetflixSecurity&) = delete; @@ -76,15 +76,15 @@ namespace Implementation { public: BEGIN_INTERFACE_MAP(NetflixSecurity) - INTERFACE_ENTRY(Cryptography::INetflixSecurity) + INTERFACE_ENTRY(Exchange::INetflixSecurity) END_INTERFACE_MAP }; // class NetflixSecurity } // namespace Implementation -/* static */ Cryptography::INetflixSecurity* Cryptography::INetflixSecurity::Instance() +/* static */ Exchange::INetflixSecurity* Exchange::INetflixSecurity::Instance() { - return (Core::Service::Create()); + return (Core::Service::Create()); } } diff --git a/Source/cryptography/tests/CMakeLists.txt b/Source/cryptography/tests/CMakeLists.txt index 91de5fa6..d1f33d4e 100644 --- a/Source/cryptography/tests/CMakeLists.txt +++ b/Source/cryptography/tests/CMakeLists.txt @@ -14,7 +14,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -option(BUILD_CRYPTOGRAPHY_TESTS "Build cryptography test" ON) +option(BUILD_CRYPTOGRAPHY_TESTS "Build cryptography test" OFF) option(BUILD_CRYPTOGRAPHY_RPC_TESTS "Build cryptography rpc test" OFF) if (BUILD_CRYPTOGRAPHY_TESTS) diff --git a/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp b/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp index d32d1f9a..42b08bbe 100644 --- a/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp +++ b/Source/cryptography/tests/cryptography_test/NetflixSecurityTests.cpp @@ -35,7 +35,7 @@ static WPEFramework::Exchange::IVault* vault = nullptr; -static WPEFramework::Cryptography::INetflixSecurity* nfSecurity = nullptr; +static WPEFramework::Exchange::INetflixSecurity* nfSecurity = nullptr; TEST(NetflixSecurity, Security) @@ -260,7 +260,7 @@ TEST(NetflixSecurity, AuthenticatedDerive) int main() { - nfSecurity = WPEFramework::Cryptography::INetflixSecurity::Instance(); + nfSecurity = WPEFramework::Exchange::INetflixSecurity::Instance(); if (nfSecurity != nullptr) { CALL(NetflixSecurity, Security); From 0deedc7cca69bef17531b89f374e681b43aae6d2 Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Thu, 13 Apr 2023 15:23:03 +0200 Subject: [PATCH 29/37] Development/small cmake fixes (#203) * Cryptography: switch off provisioning option by default * ProvisionProxy: make sure -fPIC in in the pc file From 699f6c5f83aaffafdfdb75c01b281f292287f6ce Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:48:48 +0530 Subject: [PATCH 30/37] [DEPENDENCIES]Provision proxy was missing Messaging library dependency (#227) Co-authored-by: Volkan Aslan --- Source/provisionproxy/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/provisionproxy/CMakeLists.txt b/Source/provisionproxy/CMakeLists.txt index ba44e386..8b5b96f8 100644 --- a/Source/provisionproxy/CMakeLists.txt +++ b/Source/provisionproxy/CMakeLists.txt @@ -30,6 +30,7 @@ message("Setup ${TARGET} v${PROJECT_VERSION}") find_package(CompileSettingsDebug CONFIG REQUIRED) find_package(${NAMESPACE}Core REQUIRED) find_package(${NAMESPACE}COM REQUIRED) +find_package(${NAMESPACE}Messaging REQUIRED) find_package(libprovision REQUIRED) # Construct a library object @@ -46,6 +47,7 @@ target_link_libraries(${TARGET} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core ${NAMESPACE}COM::${NAMESPACE}COM + ${NAMESPACE}Messaging::${NAMESPACE}Messaging libprovision::libprovision CompileSettingsDebug::CompileSettingsDebug ) From 474894bb4a247f3be7f544d152a374ec9d163137 Mon Sep 17 00:00:00 2001 From: MFransen69 <39826971+MFransen69@users.noreply.github.com> Date: Wed, 13 Dec 2023 09:24:12 +0100 Subject: [PATCH 31/37] [ocdm] Dispose improvements (#232) --- Source/ocdm/open_cdm.cpp | 13 ++++++++----- Source/ocdm/open_cdm_impl.h | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/ocdm/open_cdm.cpp b/Source/ocdm/open_cdm.cpp index d88b1f33..d14e36a4 100644 --- a/Source/ocdm/open_cdm.cpp +++ b/Source/ocdm/open_cdm.cpp @@ -72,7 +72,13 @@ OpenCDMError StringToAllocatedBuffer(const std::string& source, char* destinatio Core::SingletonType::Create(connector.c_str()); } ~TheOne() { - Core::SingletonType::Dispose(); + + if( Core::SingletonType::Dispose() == true ) { + // if the accessor was disposed here because the destructor of the static instance was called there + // was no proper dispose before (opencdm_dispose and/or Singleton::Dispose). + // The static dispose might be incomplete or have side effects (e.g. Threads could already be killed) + TRACE_L1(_T("OpenCDM Accessor was not disposed properly")); + } } public: @@ -83,7 +89,6 @@ OpenCDMError StringToAllocatedBuffer(const std::string& source, char* destinatio } singleton; OpenCDMAccessor& result = singleton.Instance(); - result.Reconnect(); return &result; } @@ -597,10 +602,8 @@ OpenCDMError opencdm_get_metric_session_data(struct OpenCDMSession* session, return (result); } - - void opencdm_dispose() { - Core::Singleton::Dispose(); + Core::SingletonType::Dispose(); } bool OpenCDMAccessor::WaitForKey(const uint8_t keyLength, const uint8_t keyId[], diff --git a/Source/ocdm/open_cdm_impl.h b/Source/ocdm/open_cdm_impl.h index 1a060c63..8adb9279 100644 --- a/Source/ocdm/open_cdm_impl.h +++ b/Source/ocdm/open_cdm_impl.h @@ -63,6 +63,7 @@ struct OpenCDMAccessor : public Exchange::IAccessorOCDM { , _sessionKeys() { TRACE_L1("Trying to open an OCDM connection @ %s\n", domainName); + Reconnect(); // make sure ResourceMonitor singleton is created before OpenCDMAccessor so the destruction order is correct } void Reconnect() const From c832de86ec299fab8a66c06f3de63a2a89a6b612 Mon Sep 17 00:00:00 2001 From: MFransen69 <39826971+MFransen69@users.noreply.github.com> Date: Wed, 13 Dec 2023 09:39:50 +0100 Subject: [PATCH 32/37] Merge pull request #233 from rdkcentral/development/ocdmtest [ocdm] add test app --- CMakeLists.txt | 28 +++++++++++++++ Source/CMakeLists.txt | 1 + Source/ocdm/CMakeLists.txt | 1 + Tests/CMakeLists.txt | 22 ++++++++++++ Tests/ocdmtest/CMakeLists.txt | 41 ++++++++++++++++++++++ Tests/ocdmtest/main.cpp | 64 +++++++++++++++++++++++++++++++++++ 6 files changed, 157 insertions(+) create mode 100644 Tests/CMakeLists.txt create mode 100644 Tests/ocdmtest/CMakeLists.txt create mode 100644 Tests/ocdmtest/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 84fdb754..ace9de77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,37 @@ cmake_minimum_required(VERSION 3.3) project(ClientLibraries) +find_package(WPEFramework) + +option(BLUETOOTHAUDIOSINK + "Include the bluetoothaudiosink library." OFF) +option(BLUETOOTHAUDIOSOURCE + "Include the bluetoothaudiosource library." OFF) +option(PROTOCOLS + "Include the protocols library." ON) +option(COMPOSITORCLIENT + "Include a graphics backend abstraction for external applications." OFF) +option(DEVICEINFO + "Include the deviceinfo COMRPC abstraction library." OFF) +option(DISPLAYINFO + "Include the displayinfo COMRPC abstraction library." OFF) +option(SECURITYAGENT + "Include the securityagent library." OFF) +option(PLAYERINFO + "Include the playerinfo COMRPC abstraction library." OFF) +option(PROVISIONPROXY + "Include the provisionproxy library." OFF) +option(CDMI + "Include OpenCDM interface." OFF) +option(CRYPTOGRAPHY + "Include the cryptography library." OFF) + +option(INSTALL_TESTS "Install the test applications" OFF) + if (BUILD_REFERENCE) add_definitions (-DBUILD_REFERENCE=${BUILD_REFERENCE}) endif() add_subdirectory(Source) +add_subdirectory(Tests) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 2380dcb1..df761ac1 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -81,3 +81,4 @@ endif() if(LOCALTRACER) add_subdirectory(localtracer) endif() + diff --git a/Source/ocdm/CMakeLists.txt b/Source/ocdm/CMakeLists.txt index 4c856e03..bf06f865 100644 --- a/Source/ocdm/CMakeLists.txt +++ b/Source/ocdm/CMakeLists.txt @@ -67,6 +67,7 @@ target_link_libraries(${TARGET} target_include_directories( ${TARGET} PUBLIC $ + $ ) target_include_directories( ${TARGET} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt new file mode 100644 index 00000000..a9286436 --- /dev/null +++ b/Tests/CMakeLists.txt @@ -0,0 +1,22 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2020 Metrological +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if(CDMI) + add_subdirectory(ocdmtest) +endif() + + diff --git a/Tests/ocdmtest/CMakeLists.txt b/Tests/ocdmtest/CMakeLists.txt new file mode 100644 index 00000000..548c757f --- /dev/null +++ b/Tests/ocdmtest/CMakeLists.txt @@ -0,0 +1,41 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2021 Metrological +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +project(ocdmtest) + +set(TARGET ${PROJECT_NAME}) + +cmake_minimum_required(VERSION 3.0) + +find_package(${NAMESPACE}Core REQUIRED) +find_package(ocdm REQUIRED) +find_package(CompileSettingsDebug CONFIG REQUIRED) + +add_executable(${PROJECT_NAME} + main.cpp +) + +target_link_libraries(${TARGET} + PRIVATE + ${NAMESPACE}Core::${NAMESPACE}Core + CompileSettingsDebug::CompileSettingsDebug + ocdm::ocdm +) + +if(INSTALL_TESTS) + install(TARGETS ${PROJECT_NAME} DESTINATION bin) +endif() diff --git a/Tests/ocdmtest/main.cpp b/Tests/ocdmtest/main.cpp new file mode 100644 index 00000000..f3b6ad58 --- /dev/null +++ b/Tests/ocdmtest/main.cpp @@ -0,0 +1,64 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2021 Metrological + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MODULE_NAME +#define MODULE_NAME OpenCDMTest +#endif + +#include + +#include +#include + +using namespace std; +using namespace WPEFramework; + +int main(int argc, const char* argv []) +{ + cout << " <0,1,2,3> [1=ocdm dispose, 2=singleton dispose, 3=both, 0 is none]" << endl; + + if( argc < 3) { + cout << "invalid args" << endl; + return -1; + } + + cout << "using system " << argv[1] << endl; + + char o = argv[2][0]; + cout << "using option " << o << endl; + + struct OpenCDMSystem* s = opencdm_create_system(argv[1]); + + if( s != nullptr) { + cout << "ocdm system created" << endl; + opencdm_destruct_system(s); + } else { + cout << "ocdm system could not be created" << endl; + } + + if(o == '1' || o == '3') { + cout << "opencdm dispose" << endl; + opencdm_dispose(); + } + if(o == '2' || o == '3') { + cout << "singleton dispose" << endl; + Core::Singleton::Dispose(); + } + return 0; +} From 2594a8e092f3ab5686e90c3656fc847dbf8bbe4f Mon Sep 17 00:00:00 2001 From: Volkan Aslan Date: Wed, 13 Dec 2023 12:11:16 +0100 Subject: [PATCH 33/37] Fixing the conflict of cherry pick --- Source/CMakeLists.txt | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index df761ac1..af7578a5 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -15,29 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -option(BLUETOOTHAUDIOSINK - "Include the bluetoothaudiosink library." OFF) -option(PROTOCOLS - "Include the protocols library." ON) -option(COMPOSITORCLIENT - "Include a graphics backend abstraction for external applications." OFF) -option(DEVICEINFO - "Include the deviceinfo COMRPC abstraction library." OFF) -option(DISPLAYINFO - "Include the displayinfo COMRPC abstraction library." OFF) -option(SECURITYAGENT - "Include the securityagent library." OFF) -option(PLAYERINFO - "Include the playerinfo COMRPC abstraction library." OFF) -option(PROVISIONPROXY - "Include the provisionproxy library." OFF) -option(CDMI - "Include OpenCDM interface." OFF) -option(CRYPTOGRAPHY - "Include the cryptography library." OFF) -option(LOCALTRACER - "Header only library to locally print traces coming from Messaging without the need of running Thunder/WPEFramework." OFF) - if(BLUETOOTHAUDIOSINK) add_subdirectory(bluetoothaudiosink) endif() @@ -81,4 +58,3 @@ endif() if(LOCALTRACER) add_subdirectory(localtracer) endif() - From 7e58718e6eeaebc1d0d4ae26229a40a7d3b2c376 Mon Sep 17 00:00:00 2001 From: Volkan Aslan <83580341+volkan-aslan@users.noreply.github.com> Date: Wed, 20 Dec 2023 09:32:46 +0100 Subject: [PATCH 34/37] Merge pull request #235 from rdkcentral/development/ocdmtest Correction for CMakeLists.txt of ocdmtest --- Tests/ocdmtest/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/ocdmtest/CMakeLists.txt b/Tests/ocdmtest/CMakeLists.txt index 548c757f..238a4675 100644 --- a/Tests/ocdmtest/CMakeLists.txt +++ b/Tests/ocdmtest/CMakeLists.txt @@ -22,7 +22,11 @@ set(TARGET ${PROJECT_NAME}) cmake_minimum_required(VERSION 3.0) find_package(${NAMESPACE}Core REQUIRED) -find_package(ocdm REQUIRED) + +if(NOT TARGET ocdm::ocdm) + find_package(ocdm REQUIRED) +endif() + find_package(CompileSettingsDebug CONFIG REQUIRED) add_executable(${PROJECT_NAME} From 3600cce59aab873c49bcb74e90b2c33e589e5493 Mon Sep 17 00:00:00 2001 From: Pierre Wielders Date: Mon, 5 Feb 2024 14:26:52 +0100 Subject: [PATCH 35/37] Development/reference counting (#242) * Update Client.h * Update Implementation.cpp * Updated all AddRef to the new standard --------- Co-authored-by: Volkan Aslan --- Source/compositorclient/Client.h | 12 ++++++------ Source/compositorclient/Mesa/Implementation.cpp | 6 +++--- Source/compositorclient/RPI/Implementation.cpp | 4 ++-- Source/compositorclient/Wayland/Implementation.h | 9 +++++---- Source/compositorclient/Wayland/Westeros.cpp | 6 +++--- Source/compositorclient/Wayland/Weston.cpp | 6 +++--- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Source/compositorclient/Client.h b/Source/compositorclient/Client.h index a7da2b8a..0bb30989 100644 --- a/Source/compositorclient/Client.h +++ b/Source/compositorclient/Client.h @@ -58,7 +58,7 @@ namespace Compositor { }; // Lifetime management - virtual void AddRef() const = 0; + virtual uint32_t AddRef() const = 0; virtual uint32_t Release() const = 0; // Methods @@ -78,7 +78,7 @@ namespace Compositor { }; // Lifetime management - virtual void AddRef() const = 0; + virtual uint32_t AddRef() const = 0; virtual uint32_t Release() const = 0; // Methods @@ -90,7 +90,7 @@ namespace Compositor { virtual ~IWheel() {} // Lifetime management - virtual void AddRef() const = 0; + virtual uint32_t AddRef() const = 0; virtual uint32_t Release() const = 0; // Methods @@ -107,7 +107,7 @@ namespace Compositor { }; // Lifetime management - virtual void AddRef() const = 0; + virtual uint32_t AddRef() const = 0; virtual uint32_t Release() const = 0; // Methods @@ -118,7 +118,7 @@ namespace Compositor { virtual ~ISurface(){}; // Lifetime management - virtual void AddRef() const = 0; + virtual uint32_t AddRef() const = 0; virtual uint32_t Release() const = 0; // Methods @@ -187,7 +187,7 @@ namespace Compositor { virtual ~IDisplay() {} // Lifetime management - virtual void AddRef() const = 0; + virtual uint32_t AddRef() const = 0; virtual uint32_t Release() const = 0; // Methods diff --git a/Source/compositorclient/Mesa/Implementation.cpp b/Source/compositorclient/Mesa/Implementation.cpp index 52d8b78b..da13ca6e 100644 --- a/Source/compositorclient/Mesa/Implementation.cpp +++ b/Source/compositorclient/Mesa/Implementation.cpp @@ -702,12 +702,12 @@ namespace Linux { return (*result); } - void AddRef() const override + uint32_t AddRef() const override { if (Core::InterlockedIncrement(_refCount) == 1) { const_cast(this)->Initialize(); } - return; + return Core::ERROR_NONE; } uint32_t Release() const override { @@ -724,7 +724,7 @@ namespace Linux { const_cast(this)->Deinitialize(); - return (Core::ERROR_CONNECTION_CLOSED); + return (Core::ERROR_DESTRUCTION_SUCCEEDED); } return (Core::ERROR_NONE); } diff --git a/Source/compositorclient/RPI/Implementation.cpp b/Source/compositorclient/RPI/Implementation.cpp index 523f5aee..fff508e9 100644 --- a/Source/compositorclient/RPI/Implementation.cpp +++ b/Source/compositorclient/RPI/Implementation.cpp @@ -703,12 +703,12 @@ class Display : public Compositor::IDisplay { return (*result); } - void AddRef() const override + uint32_t AddRef() const override { if (Core::InterlockedIncrement(_refCount) == 1) { const_cast(this)->Initialize(); } - return; + return (Core::ERROR_NONE); } uint32_t Release() const override diff --git a/Source/compositorclient/Wayland/Implementation.h b/Source/compositorclient/Wayland/Implementation.h index ab3b6a5c..4b055d19 100644 --- a/Source/compositorclient/Wayland/Implementation.h +++ b/Source/compositorclient/Wayland/Implementation.h @@ -120,17 +120,18 @@ namespace Wayland { virtual ~SurfaceImplementation(); public: - void AddRef() const override + uint32_t AddRef() const override { _refcount++; - return; + return Core::ERROR_NONE; } uint32_t Release() const override { if (--_refcount == 0) { delete const_cast(this); + return Core::ERROR_DESTRUCTION_SUCCEEDED; } - return (0); + return Core::ERROR_NONE; } EGLNativeWindowType Native() const override { @@ -531,7 +532,7 @@ namespace Wayland { public: // Lifetime management - virtual void AddRef() const; + virtual uint32_t AddRef() const; virtual uint32_t Release() const; // Methods diff --git a/Source/compositorclient/Wayland/Westeros.cpp b/Source/compositorclient/Wayland/Westeros.cpp index b8b1fc24..d79e9978 100644 --- a/Source/compositorclient/Wayland/Westeros.cpp +++ b/Source/compositorclient/Wayland/Westeros.cpp @@ -1212,12 +1212,12 @@ namespace Wayland { return result; } - void Display::AddRef() const + uint32_t Display::AddRef() const { if (Core::InterlockedIncrement(_refCount) == 1) { const_cast(this)->Initialize(); } - return; + return Core::ERROR_NONE; } uint32_t Display::Release() const @@ -1226,7 +1226,7 @@ namespace Wayland { const_cast(this)->Deinitialize(); //Indicate Wayland connection is closed properly - return (Core::ERROR_CONNECTION_CLOSED); + return (Core::ERROR_DESTRUCTION_SUCCEEDED); } return (Core::ERROR_NONE); } diff --git a/Source/compositorclient/Wayland/Weston.cpp b/Source/compositorclient/Wayland/Weston.cpp index 308b6f39..40b52e58 100644 --- a/Source/compositorclient/Wayland/Weston.cpp +++ b/Source/compositorclient/Wayland/Weston.cpp @@ -1078,12 +1078,12 @@ namespace Wayland { return result; } - void Display::AddRef() const + uint32_t Display::AddRef() const { if (Core::InterlockedIncrement(_refCount) == 1) { const_cast(this)->Initialize(); } - return; + return Core::ERROR_NONE; } uint32_t Display::Release() const @@ -1092,7 +1092,7 @@ namespace Wayland { const_cast(this)->Deinitialize(); //Indicate Wayland connection is closed properly - return (Core::ERROR_CONNECTION_CLOSED); + return (Core::ERROR_DESTRUCTION_SUCCEEDED); } return (Core::ERROR_NONE); } From 087ae89c4a5d00854f5d000f7fc8acab8a8d8ad0 Mon Sep 17 00:00:00 2001 From: Bram Oosterhuis Date: Fri, 2 Feb 2024 10:08:51 +0100 Subject: [PATCH 36/37] cryptography: force deprecation declarations to be a warning again (#241) * cryptography: force deprecation declarations to be a warning again * Update open_cdm_impl.h Move up to the new AddRef() --------- Co-authored-by: Pierre Wielders --- .../implementation/OpenSSL/CMakeLists.txt | 12 ++++++++++++ Source/ocdm/open_cdm_impl.h | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/cryptography/implementation/OpenSSL/CMakeLists.txt b/Source/cryptography/implementation/OpenSSL/CMakeLists.txt index 64f401fa..03be2d8d 100644 --- a/Source/cryptography/implementation/OpenSSL/CMakeLists.txt +++ b/Source/cryptography/implementation/OpenSSL/CMakeLists.txt @@ -21,6 +21,18 @@ find_package(OpenSSL REQUIRED) option(USE_PROVISIONING "Load Netflix data from a provisioning label" OFF) +# FIXME: As of OpenSSL 3.0 the low level low-level key exchange and object +# creation functions are deprecated. We should mirgrate to use +# the high-level EVP_PKEY API. +# +# More info: +# https://www.openssl.org/docs/man3.0/man7/migration_guide.html#Deprecated-low-level-object-creation +# https://jira.rdkcentral.com/jira/projects/METROL/issues/METROL-506 +# +# For now force deprecated declarations to be a warning. +add_compile_options( + -Wno-deprecated-declarations) + add_library(${TARGET} STATIC Vault.cpp Hash.cpp diff --git a/Source/ocdm/open_cdm_impl.h b/Source/ocdm/open_cdm_impl.h index 1a060c63..c7b7c113 100644 --- a/Source/ocdm/open_cdm_impl.h +++ b/Source/ocdm/open_cdm_impl.h @@ -112,11 +112,12 @@ struct OpenCDMAccessor : public Exchange::IAccessorOCDM { std::string& sessionId, OpenCDMSystem* system = nullptr) const; public: - virtual void AddRef() const override + uint32_t AddRef() const override { Core::InterlockedIncrement(_refCount); + return (Core::ERROR_NONE); } - virtual uint32_t Release() const override + uint32_t Release() const override { uint32_t result = Core::ERROR_NONE; From 985156c75193e62fecb3cd237d84b9dc5f6e3e23 Mon Sep 17 00:00:00 2001 From: nkader321 Date: Wed, 13 Nov 2024 19:10:29 +0530 Subject: [PATCH 37/37] RDK-53574 OCDM client l1test framework Reason for change : L1 test framework for ocdm and run scripts added Test procedure: Run run.sh and check tests are executed and reports generated Risks: Low Signed-off-by: nkader321 --- CMakeLists.txt | 2 + Tests/CMakeLists.txt | 5 ++ Tests/L1Tests/CMakeLists.txt | 56 ++++++++++++++++++++++ Tests/L1Tests/gtest_main.cpp | 26 ++++++++++ Tests/L1Tests/run.sh | 24 ++++++++++ Tests/L1Tests/tests/open_cdm_ext_tests.cpp | 43 +++++++++++++++++ Tests/L1Tests/tests/open_cdm_tests.cpp | 39 +++++++++++++++ 7 files changed, 195 insertions(+) create mode 100644 Tests/L1Tests/CMakeLists.txt create mode 100755 Tests/L1Tests/gtest_main.cpp create mode 100755 Tests/L1Tests/run.sh create mode 100644 Tests/L1Tests/tests/open_cdm_ext_tests.cpp create mode 100644 Tests/L1Tests/tests/open_cdm_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ace9de77..4e037aae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,8 @@ option(CRYPTOGRAPHY option(INSTALL_TESTS "Install the test applications" OFF) +option(L1_TESTS "Install the test applications" OFF) + if (BUILD_REFERENCE) add_definitions (-DBUILD_REFERENCE=${BUILD_REFERENCE}) endif() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index a9286436..e2b4494e 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -19,4 +19,9 @@ if(CDMI) add_subdirectory(ocdmtest) endif() +if(L1_TESTS) + add_subdirectory(L1Tests) +endif() + + diff --git a/Tests/L1Tests/CMakeLists.txt b/Tests/L1Tests/CMakeLists.txt new file mode 100644 index 00000000..02afc48d --- /dev/null +++ b/Tests/L1Tests/CMakeLists.txt @@ -0,0 +1,56 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2024 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.8) +project(L1Test) + +set(CMAKE_CXX_STANDARD 11) + +find_package(Thunder) +find_package(ClientOCDM REQUIRED) +find_package(${NAMESPACE}Core REQUIRED) +find_package(${NAMESPACE}COM REQUIRED) +find_package(${NAMESPACE}Messaging REQUIRED) +find_package(CompileSettingsDebug CONFIG REQUIRED) +find_package(GTest REQUIRED) +include(CTest) + +file(GLOB TESTS tests/*.cpp) + +add_executable(${PROJECT_NAME} + gtest_main.cpp + ${TESTS} + ) + +include_directories(../../Source/ocdm) +link_directories(../../Source/ocdm) + +target_link_libraries(${PROJECT_NAME} + ${NAMESPACE}Core::${NAMESPACE}Core + ${NAMESPACE}COM::${NAMESPACE}COM + ${NAMESPACE}Messaging::${NAMESPACE}Messaging + CompileSettingsDebug::CompileSettingsDebug + ClientOCDM::ClientOCDM + GTest::GTest + ) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + +gtest_add_tests(TARGET ${PROJECT_NAME}) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/Tests/L1Tests/gtest_main.cpp b/Tests/L1Tests/gtest_main.cpp new file mode 100755 index 00000000..056ecef8 --- /dev/null +++ b/Tests/L1Tests/gtest_main.cpp @@ -0,0 +1,26 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 RDK Management +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/Tests/L1Tests/run.sh b/Tests/L1Tests/run.sh new file mode 100755 index 00000000..fc8e5b06 --- /dev/null +++ b/Tests/L1Tests/run.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# This script will build and run the L1 tests + +rm -rf build + +mkdir build + +cd build + +export GTEST_OUTPUT="json" + +cmake .. + +make + +./L1Test + +#Generate coverage report +if [ "$1" != "" ] && [ $1 = "-c" ]; then + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' --output-file coverage.info + lcov --list coverage.info + genhtml coverage.info --output-directory coverage_report +fi diff --git a/Tests/L1Tests/tests/open_cdm_ext_tests.cpp b/Tests/L1Tests/tests/open_cdm_ext_tests.cpp new file mode 100644 index 00000000..621929e6 --- /dev/null +++ b/Tests/L1Tests/tests/open_cdm_ext_tests.cpp @@ -0,0 +1,43 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 RDK Management +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "open_cdm_impl.h" +#include "open_cdm_ext.h" +#include +using namespace testing; + +class OpenCDMExtTest : public ::testing::Test { +protected: + + void SetUp() override { + } + + void TearDown() override { + } +}; + +TEST_F(OpenCDMExtTest, opencdmCreateSystem) +{ + int status = 0; + const char keySystem[] = "playready"; + struct OpenCDMSystem* result; + result = opencdm_create_system(keySystem); + EXPECT_EQ(result, nullptr); +} + diff --git a/Tests/L1Tests/tests/open_cdm_tests.cpp b/Tests/L1Tests/tests/open_cdm_tests.cpp new file mode 100644 index 00000000..feea384e --- /dev/null +++ b/Tests/L1Tests/tests/open_cdm_tests.cpp @@ -0,0 +1,39 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 RDK Management +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "open_cdm.h" +#include +using namespace testing; + +class OpenCDMTest : public ::testing::Test { +protected: + + void SetUp() override { + } + + void TearDown() override { + } +}; + +TEST_F(OpenCDMTest, status) +{ + int status = 1; + EXPECT_EQ(status, 1); +} +