LCOV - code coverage report
Current view: top level - source - open_cdm_ext.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 146 146
Test Date: 2026-03-31 11:25:48 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            7 : OpenCDMError opencdm_session_get_challenge_data(struct OpenCDMSession *mOpenCDMSession, uint8_t *challenge,
     188              :                                                 uint32_t *challengeSize, uint32_t isLDL)
     189              : {
     190            7 :     kLog << debug << __func__;
     191            7 :     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              : 
     197            5 :     if (0 == *challengeSize && nullptr == challenge)
     198              :     {
     199            3 :         if (!mOpenCDMSession->getChallengeDataSize(*challengeSize, isLDL != 0))
     200              :         {
     201            1 :             kLog << error << "Failed to get challenge data size - operation returned NOK status";
     202            1 :             return ERROR_FAIL;
     203              :         }
     204              :     }
     205            2 :     else if (nullptr != challenge)
     206              :     {
     207            2 :         std::vector<uint8_t> challengeVec;
     208            2 :         if (!mOpenCDMSession->getChallengeData(challengeVec, isLDL != 0))
     209              :         {
     210            1 :             kLog << error << "Failed to get challenge data - operation returned NOK status";
     211            1 :             return ERROR_FAIL;
     212              :         }
     213            1 :         *challengeSize = static_cast<uint32_t>(challengeVec.size());
     214            1 :         memcpy(challenge, challengeVec.data(), challengeVec.size());
     215            2 :     }
     216            3 :     return ERROR_NONE;
     217              : }
     218              : 
     219            1 : OpenCDMError opencdm_session_cancel_challenge_data(struct OpenCDMSession *mOpenCDMSession)
     220              : {
     221            1 :     kLog << debug << __func__;
     222              :     // MKS is destructed in opencdm_session_clean_decrypt_context
     223            1 :     return ERROR_NONE;
     224              : }
     225              : 
     226            4 : OpenCDMError opencdm_session_store_license_data(struct OpenCDMSession *openCDMSession, const uint8_t licenseData[],
     227              :                                                 uint32_t licenseDataSize, uint8_t *secureStopId)
     228              : {
     229            4 :     kLog << debug << __func__;
     230            4 :     if (!openCDMSession)
     231              :     {
     232            1 :         kLog << error << "Failed to store license data - session is NULL";
     233            1 :         return ERROR_INVALID_SESSION;
     234              :     }
     235            3 :     if (!licenseData || 0 == licenseDataSize)
     236              :     {
     237            1 :         kLog << error << "Failed to store license data - data is null or empty";
     238            1 :         return ERROR_FAIL;
     239              :     }
     240            2 :     std::vector<uint8_t> license(licenseData, licenseData + licenseDataSize);
     241              : 
     242            2 :     if (!openCDMSession->updateSession(license))
     243              :     {
     244            1 :         kLog << error << "Failed to store license data - op failed";
     245            1 :         return ERROR_FAIL;
     246              :     }
     247              : 
     248            1 :     return ERROR_NONE;
     249            2 : }
     250              : 
     251            4 : OpenCDMError opencdm_session_select_key_id(struct OpenCDMSession *mOpenCDMSession, uint8_t keyLength,
     252              :                                            const uint8_t keyId[])
     253              : {
     254            4 :     kLog << debug << __func__;
     255            4 :     if (!mOpenCDMSession || !keyId || 0 == keyLength)
     256              :     {
     257            2 :         kLog << error << "Failed to select key id - session or key is NULL";
     258            2 :         return ERROR_FAIL;
     259              :     }
     260            2 :     std::vector<uint8_t> keyIdVec(keyId, keyId + keyLength);
     261            2 :     if (!mOpenCDMSession->selectKeyId(keyIdVec))
     262              :     {
     263            1 :         kLog << error << "Failed to select key id - operation returned NOK status";
     264            1 :         return ERROR_FAIL;
     265              :     }
     266            1 :     return ERROR_NONE;
     267            2 : }
     268              : 
     269            1 : OpenCDMError opencdm_system_teardown(struct OpenCDMSystem *system)
     270              : {
     271            1 :     kLog << debug << __func__;
     272            1 :     return ERROR_NONE;
     273              : }
     274              : 
     275            3 : OpenCDMError opencdm_session_clean_decrypt_context(struct OpenCDMSession *mOpenCDMSession)
     276              : {
     277            3 :     kLog << debug << __func__;
     278            3 :     if (!mOpenCDMSession)
     279              :     {
     280            1 :         kLog << error << "Failed to clean decrypt context - arguments are not valid";
     281            1 :         return ERROR_FAIL;
     282              :     }
     283            2 :     if (!mOpenCDMSession->closeSession())
     284              :     {
     285            1 :         kLog << error << "Failed to close the session";
     286            1 :         return ERROR_FAIL;
     287              :     }
     288            1 :     return ERROR_NONE;
     289              : }
        

Generated by: LCOV version 2.0-1