LCOV - code coverage report
Current view: top level - source - open_cdm_ext.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 145 145
Test Date: 2025-07-07 09:31:15 Functions: 100.0 % 18 18

            Line data    Source code
       1              : /*
       2              :  * If not stated otherwise in this file or this component's LICENSE file the
       3              :  * following copyright and licenses apply:
       4              :  *
       5              :  * Copyright 2022 Sky UK
       6              :  *
       7              :  * Licensed under the Apache License, Version 2.0 (the "License");
       8              :  * you may not use this file except in compliance with the License.
       9              :  * You may obtain a copy of the License at
      10              :  *
      11              :  * http://www.apache.org/licenses/LICENSE-2.0
      12              :  *
      13              :  * Unless required by applicable law or agreed to in writing, software
      14              :  * distributed under the License is distributed on an "AS IS" BASIS,
      15              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16              :  * See the License for the specific language governing permissions and
      17              :  * limitations under the License.
      18              :  */
      19              : 
      20              : #include "Logger.h"
      21              : #include "OpenCDMSession.h"
      22              : #include "OpenCDMSystem.h"
      23              : #include <opencdm/open_cdm_ext.h>
      24              : 
      25              : namespace
      26              : {
      27              : const Logger kLog{"open_cdm_ext"};
      28              : } // namespace
      29              : 
      30            4 : OpenCDMError opencdm_system_ext_get_ldl_session_limit(struct OpenCDMSystem *system, uint32_t *ldlLimit)
      31              : {
      32            4 :     kLog << debug << __func__;
      33            4 :     if (!system || !ldlLimit)
      34              :     {
      35            2 :         kLog << error << "Failed to get ldl session limit - System is NULL";
      36            2 :         return ERROR_FAIL;
      37              :     }
      38              : 
      39            2 :     if (!system->getLdlSessionsLimit(*ldlLimit))
      40              :     {
      41            1 :         kLog << error << "Failed to get LDL Session limit";
      42            1 :         return ERROR_FAIL;
      43              :     }
      44            1 :     return ERROR_NONE;
      45              : }
      46              : 
      47            1 : uint32_t opencdm_system_ext_is_secure_stop_enabled(struct OpenCDMSystem *system)
      48              : {
      49            1 :     kLog << warn << "Secure stop not supported";
      50            1 :     return 0;
      51              : }
      52              : 
      53            1 : OpenCDMError opencdm_system_ext_enable_secure_stop(struct OpenCDMSystem *system, uint32_t use)
      54              : {
      55            1 :     kLog << warn << "Secure stop not supported";
      56            1 :     return ERROR_FAIL;
      57              : }
      58              : 
      59            1 : uint32_t opencdm_system_ext_reset_secure_stop(struct OpenCDMSystem *system)
      60              : {
      61            1 :     kLog << warn << "Reset secure stop not supported";
      62            1 :     return 0;
      63              : }
      64              : 
      65            1 : OpenCDMError opencdm_system_ext_get_secure_stop_ids(struct OpenCDMSystem *system, uint8_t Ids[], uint16_t idsLength,
      66              :                                                     uint32_t *count)
      67              : {
      68            1 :     kLog << warn << "Failed to get secure stop ids - not supported";
      69            1 :     return ERROR_FAIL;
      70              : }
      71              : 
      72            1 : OpenCDMError opencdm_system_ext_get_secure_stop(struct OpenCDMSystem *system, const uint8_t sessionID[],
      73              :                                                 uint32_t sessionIDLength, uint8_t rawData[], uint16_t *rawSize)
      74              : {
      75            1 :     kLog << warn << "Failed to get secure stop - not supported";
      76            1 :     return ERROR_FAIL;
      77              : }
      78              : 
      79            1 : OpenCDMError opencdm_system_ext_commit_secure_stop(struct OpenCDMSystem *system, const uint8_t sessionID[],
      80              :                                                    uint32_t sessionIDLength, const uint8_t serverResponse[],
      81              :                                                    uint32_t serverResponseLength)
      82              : {
      83            1 :     kLog << warn << "Failed to commit secure stop - not supported";
      84            1 :     return ERROR_FAIL;
      85              : }
      86              : 
      87            5 : OpenCDMError opencdm_get_key_store_hash_ext(struct OpenCDMSystem *system, uint8_t keyStoreHash[],
      88              :                                             uint32_t keyStoreHashLength)
      89              : {
      90            5 :     kLog << debug << __func__;
      91            5 :     if (!system || 0 == keyStoreHashLength)
      92              :     {
      93            2 :         kLog << error << "Failed to get key store hash - arguments are not valid";
      94            2 :         return ERROR_FAIL;
      95              :     }
      96            3 :     std::vector<uint8_t> keyStoreHashVec;
      97            3 :     if (!system->getKeyStoreHash(keyStoreHashVec))
      98              :     {
      99            1 :         kLog << error << "Failed to get key store hash - operation failed";
     100            1 :         return ERROR_FAIL;
     101              :     }
     102            2 :     if (keyStoreHashVec.size() > keyStoreHashLength)
     103              :     {
     104            2 :         kLog << error << "Failed to get key store hash - return of size " << keyStoreHashVec.size()
     105            1 :              << " does not fit in buffer of size " << keyStoreHashLength;
     106            1 :         return ERROR_FAIL;
     107              :     }
     108            1 :     memcpy(keyStoreHash, keyStoreHashVec.data(), keyStoreHashVec.size());
     109            1 :     return ERROR_NONE;
     110            3 : }
     111              : 
     112            5 : OpenCDMError opencdm_get_secure_store_hash_ext(struct OpenCDMSystem *system, uint8_t secureStoreHash[],
     113              :                                                uint32_t secureStoreHashLength)
     114              : {
     115            5 :     kLog << debug << __func__;
     116            5 :     if (!system || 0 == secureStoreHashLength)
     117              :     {
     118            2 :         kLog << error << "Failed to get secure store hash - arguments are not valid";
     119            2 :         return ERROR_FAIL;
     120              :     }
     121            3 :     std::vector<uint8_t> secureStoreHashVec;
     122            3 :     if (!system->getDrmStoreHash(secureStoreHashVec))
     123              :     {
     124            1 :         kLog << error << "Failed to get secure store hash - operation failed";
     125            1 :         return ERROR_FAIL;
     126              :     }
     127            2 :     if (secureStoreHashVec.size() > secureStoreHashLength)
     128              :     {
     129            2 :         kLog << error << "Failed to get key store hash - return size " << secureStoreHashVec.size()
     130            1 :              << " does not fit in buffer of size " << secureStoreHashLength;
     131            1 :         return ERROR_FAIL;
     132              :     }
     133            1 :     memcpy(secureStoreHash, secureStoreHashVec.data(), secureStoreHashVec.size());
     134            1 :     return ERROR_NONE;
     135            3 : }
     136              : 
     137            3 : OpenCDMError opencdm_delete_key_store(struct OpenCDMSystem *system)
     138              : {
     139            3 :     kLog << debug << __func__;
     140            3 :     if (!system)
     141              :     {
     142            1 :         kLog << error << "Failed to delete key store - arguments are not valid";
     143            1 :         return ERROR_FAIL;
     144              :     }
     145            2 :     if (!system->deleteKeyStore())
     146              :     {
     147            1 :         kLog << error << "Failed to delete key store - operation failed";
     148            1 :         return ERROR_FAIL;
     149              :     }
     150            1 :     return ERROR_NONE;
     151              : }
     152              : 
     153            3 : OpenCDMError opencdm_delete_secure_store(struct OpenCDMSystem *system)
     154              : {
     155            3 :     kLog << debug << __func__;
     156            3 :     if (!system)
     157              :     {
     158            1 :         kLog << error << "Failed to delete secure store - arguments are not valid";
     159            1 :         return ERROR_FAIL;
     160              :     }
     161            2 :     if (!system->deleteDrmStore())
     162              :     {
     163            1 :         kLog << error << "Failed to delete secure store - operation failed";
     164            1 :         return ERROR_FAIL;
     165              :     }
     166            1 :     return ERROR_NONE;
     167              : }
     168              : 
     169            3 : OpenCDMError opencdm_session_set_drm_header(struct OpenCDMSession *opencdmSession, const uint8_t drmHeader[],
     170              :                                             uint32_t drmHeaderSize)
     171              : {
     172            3 :     kLog << debug << __func__;
     173            3 :     if (nullptr == opencdmSession)
     174              :     {
     175            1 :         kLog << error << "Failed to set Drm Header - session is NULL";
     176            1 :         return ERROR_FAIL;
     177              :     }
     178            2 :     std::vector<uint8_t> drmHeaderVec(drmHeader, drmHeader + drmHeaderSize);
     179            2 :     if (!opencdmSession->setDrmHeader(drmHeaderVec))
     180              :     {
     181            1 :         kLog << error << "Failed to set Drm Header - operation returned NOK status";
     182            1 :         return ERROR_FAIL;
     183              :     }
     184            1 :     return ERROR_NONE;
     185            2 : }
     186              : 
     187            6 : OpenCDMError opencdm_session_get_challenge_data(struct OpenCDMSession *mOpenCDMSession, uint8_t *challenge,
     188              :                                                 uint32_t *challengeSize, uint32_t isLDL)
     189              : {
     190            6 :     kLog << debug << __func__;
     191            6 :     if (nullptr == mOpenCDMSession || nullptr == challengeSize)
     192              :     {
     193            2 :         kLog << error << "Failed to get challenge data - arguments are not valid";
     194            2 :         return ERROR_FAIL;
     195              :     }
     196            4 :     if (!mOpenCDMSession->initialize(isLDL))
     197              :     {
     198            1 :         kLog << error << "Failed to create session";
     199            1 :         return ERROR_FAIL;
     200              :     }
     201            3 :     std::vector<uint8_t> challengeVec;
     202            3 :     if (!mOpenCDMSession->getChallengeData(challengeVec))
     203              :     {
     204            1 :         kLog << error << "Failed to get challenge data - operation returned NOK status";
     205            1 :         return ERROR_FAIL;
     206              :     }
     207            2 :     *challengeSize = challengeVec.size();
     208            2 :     if (nullptr != challenge)
     209              :     {
     210            1 :         memcpy(challenge, challengeVec.data(), challengeVec.size());
     211              :     }
     212            2 :     return ERROR_NONE;
     213            3 : }
     214              : 
     215            1 : OpenCDMError opencdm_session_cancel_challenge_data(struct OpenCDMSession *mOpenCDMSession)
     216              : {
     217            1 :     kLog << debug << __func__;
     218              :     // MKS is destructed in opencdm_session_clean_decrypt_context
     219            1 :     return ERROR_NONE;
     220              : }
     221              : 
     222            4 : OpenCDMError opencdm_session_store_license_data(struct OpenCDMSession *openCDMSession, const uint8_t licenseData[],
     223              :                                                 uint32_t licenseDataSize, uint8_t *secureStopId)
     224              : {
     225            4 :     kLog << debug << __func__;
     226            4 :     if (!openCDMSession)
     227              :     {
     228            1 :         kLog << error << "Failed to store license data - session is NULL";
     229            1 :         return ERROR_INVALID_SESSION;
     230              :     }
     231            3 :     if (!licenseData || 0 == licenseDataSize)
     232              :     {
     233            1 :         kLog << error << "Failed to store license data - data is null or empty";
     234            1 :         return ERROR_FAIL;
     235              :     }
     236            2 :     std::vector<uint8_t> license(licenseData, licenseData + licenseDataSize);
     237              : 
     238            2 :     if (!openCDMSession->updateSession(license))
     239              :     {
     240            1 :         kLog << error << "Failed to store license data - op failed";
     241            1 :         return ERROR_FAIL;
     242              :     }
     243              : 
     244            1 :     return ERROR_NONE;
     245            2 : }
     246              : 
     247            4 : OpenCDMError opencdm_session_select_key_id(struct OpenCDMSession *mOpenCDMSession, uint8_t keyLength,
     248              :                                            const uint8_t keyId[])
     249              : {
     250            4 :     kLog << debug << __func__;
     251            4 :     if (!mOpenCDMSession || !keyId || 0 == keyLength)
     252              :     {
     253            2 :         kLog << error << "Failed to select key id - session or key is NULL";
     254            2 :         return ERROR_FAIL;
     255              :     }
     256            2 :     std::vector<uint8_t> keyIdVec(keyId, keyId + keyLength);
     257            2 :     if (!mOpenCDMSession->selectKeyId(keyIdVec))
     258              :     {
     259            1 :         kLog << error << "Failed to select key id - operation returned NOK status";
     260            1 :         return ERROR_FAIL;
     261              :     }
     262            1 :     return ERROR_NONE;
     263            2 : }
     264              : 
     265            1 : OpenCDMError opencdm_system_teardown(struct OpenCDMSystem *system)
     266              : {
     267            1 :     kLog << debug << __func__;
     268            1 :     return ERROR_NONE;
     269              : }
     270              : 
     271            3 : OpenCDMError opencdm_session_clean_decrypt_context(struct OpenCDMSession *mOpenCDMSession)
     272              : {
     273            3 :     kLog << debug << __func__;
     274            3 :     if (!mOpenCDMSession)
     275              :     {
     276            1 :         kLog << error << "Failed to clean decrypt context - arguments are not valid";
     277            1 :         return ERROR_FAIL;
     278              :     }
     279            2 :     if (!mOpenCDMSession->closeSession())
     280              :     {
     281            1 :         kLog << error << "Failed to close the session";
     282            1 :         return ERROR_FAIL;
     283              :     }
     284            1 :     return ERROR_NONE;
     285              : }
        

Generated by: LCOV version 2.0-1