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 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/CMakeLists.txt b/CMakeLists.txt index 84fdb754..4e037aae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,39 @@ 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) + +option(L1_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..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() 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); } 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 2a2edb60..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,21 +155,21 @@ namespace Implementation { ~RPCCipherImpl() override = default; BEGIN_INTERFACE_MAP(RPCCipherImpl) - INTERFACE_ENTRY(Cryptography::ICipher) + INTERFACE_ENTRY(Exchange::ICipher) END_INTERFACE_MAP 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; @@ -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,12 +201,12 @@ namespace Implementation { ~RPCHashImpl() override = default; BEGIN_INTERFACE_MAP(RPCHashImpl) - INTERFACE_ENTRY(Cryptography::IHash) + INTERFACE_ENTRY(Exchange::IHash) END_INTERFACE_MAP 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); @@ -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; @@ -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 @@ -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; @@ -644,22 +644,22 @@ 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: 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 3d1f8387..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 uint16_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 uint16_t inputLength, const uint8_t input[] /* @in @length:inputLength */, - const uint16_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; - }; - - 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..be384c6c 100644 --- a/Source/cryptography/NetflixSecurity.cpp +++ b/Source/cryptography/NetflixSecurity.cpp @@ -20,14 +20,14 @@ #include "Module.h" -#include +#include #include "implementation/netflix_security_implementation.h" 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/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/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/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/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..42b08bbe 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,14 +30,12 @@ #include #include -#include "ICryptography.h" -#include "INetflixSecurity.h" #include "Helpers.h" #include "Test.h" -static WPEFramework::Cryptography::IVault* vault = nullptr; -static WPEFramework::Cryptography::INetflixSecurity* nfSecurity = nullptr; +static WPEFramework::Exchange::IVault* vault = nullptr; +static WPEFramework::Exchange::INetflixSecurity* nfSecurity = nullptr; TEST(NetflixSecurity, Security) @@ -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)); @@ -260,13 +260,13 @@ TEST(NetflixSecurity, AuthenticatedDerive) int main() { - nfSecurity = WPEFramework::Cryptography::INetflixSecurity::Instance(); + nfSecurity = WPEFramework::Exchange::INetflixSecurity::Instance(); 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(); 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/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..b9ba9de9 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 @@ -112,11 +113,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; 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 ) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt new file mode 100644 index 00000000..e2b4494e --- /dev/null +++ b/Tests/CMakeLists.txt @@ -0,0 +1,27 @@ +# 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() + +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); +} + diff --git a/Tests/ocdmtest/CMakeLists.txt b/Tests/ocdmtest/CMakeLists.txt new file mode 100644 index 00000000..238a4675 --- /dev/null +++ b/Tests/ocdmtest/CMakeLists.txt @@ -0,0 +1,45 @@ +# 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) + +if(NOT TARGET ocdm::ocdm) + find_package(ocdm REQUIRED) +endif() + +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; +}