2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file DTapps2Rights.cpp
19 * @brief This file includes functions relating to Rights.
24 #include "TADC_Core.h"
26 #include "drm-tizen-error.h"
28 #include "TADC_Util.h"
30 #include "DTapps2Rights.h"
31 #include "DTapps2SqliteDB.h"
32 #include "DTapps2HMAC.h"
33 #include "DTapps2Base64.h"
34 #include "DTapps2Time.h"
36 /* Validation and Installation of the Constraints Structure */
37 int DTappsValidateConstraints(DTAPPS_CONSTRAINTS* st_const, DTAPPS_OPERATION opr)
39 int ret = TADC_LICENSE_VALID;
40 char DUID[DTAPPS_DUID_SIZE] = {0, };
41 unsigned char zeroduid[DTAPPS_DUID_SIZE] = {0, };
42 int retDeviceInfo = 0;
46 DRM_TAPPS_EXCEPTION("Invalid Paramter st_const = %p", st_const);
47 ret = TADC_PARAMETER_ERROR;
52 if (DTAPPS_MEMCMP(st_const->DUID, zeroduid, DTAPPS_DUID_SIZE))
54 DRM_TAPPS_LOG("st_const->DUID = %s", st_const->DUID);
55 if(opr == DTAPPS_VERIFY || opr == DTAPPS_INSTALL)
57 retDeviceInfo = TADC_IF_GetDUID(DUID);
58 if (retDeviceInfo < 0)
60 DRM_TAPPS_EXCEPTION("Retrieve for DUID Failed!!! DUID = %s, duid_len = %d", DUID, strlen(DUID));
61 return TADC_LICENSE_UNKNOWN_ERROR;
63 if (!(DTAPPS_MEMCMP(st_const->DUID, DUID, DTAPPS_DUID_SIZE)))
65 DRM_TAPPS_LOG("DUID match!! st_const->DUID = %s, DUID = %s", st_const->DUID, DUID);
66 ret = TADC_LICENSE_VALID;
70 DRM_TAPPS_EXCEPTION("DUID don't match!!! st_const->DUID = %s, DUID = %s", st_const->DUID, DUID);
71 ret = TADC_LICENSE_DUID_MISMATCH;
76 DRM_TAPPS_LOG("ret = %d", ret);
80 DRM_TAPPS_EXCEPTION("Validate Constraints failed!!!, ret = %d", ret);
84 int DTappsInstallLicense(const char* declicbuffer)
86 unsigned char* db_buffer_org = NULL;
87 unsigned char db_buffer_enc[512] = {0, };
88 int len_enc = 0, check_ret = 0;
89 unsigned char *pDevKey = NULL;
90 unsigned int DevKeyLen = 0;
91 unsigned char hash[32] = {0, };
92 unsigned char hash_enc[64] = {0, };
93 unsigned int hash_len = 0;
94 int check = TADC_LICENSE_VALID;
97 int ret = TADC_SUCCESS;
99 unsigned char name[DTAPPS_NAME_SIZE] = {0, };
100 unsigned char nullCek[CEK_SIZE] = {0, };
104 char time_buffer[21] = {0, };
107 memset(&t_RO, 0x00, sizeof(t_RO));
109 DTAPPS_RIGHTS_ROW row;
111 #ifdef DTAPPS_STORE_CEK_IN_DB
114 memset(&key, 0x00, sizeof(key));
116 unsigned char *encr_cek = NULL;
117 unsigned int keylen = 0;
118 unsigned int encr_cek_len = 0;
119 unsigned char b64_encr_cek[128] = {0, };
120 unsigned char encr_cek_hash[32] = {0, };
121 unsigned char b64_encr_cek_hash[64] = {0, };
122 unsigned int encr_cek_hash_len = 0;
125 // Copy necessary fields into structure to be stored in DB
126 DTAPPS_CONSTRAINTS st_constraints = {0, };
128 // First Parse the decrypted Licence buffer in order to fill the t_RO buffer and use it to store in DB
129 check_ret = DTappsGetROInfo(declicbuffer, &t_RO, name);
132 DRM_TAPPS_EXCEPTION("DTappsGetROInfo Error Code = %x, check_ret = %d", TADC_LICENSEXMLPARSING_ERROR,check_ret);
133 ret = TADC_LICENSEXMLPARSING_ERROR;
138 if (t_RO.t_Permission.t_Individual.DUID != NULL)
140 DTAPPS_MEMCPY(st_constraints.DUID, t_RO.t_Permission.t_Individual.DUID, TAPPS_STRLEN((const char*)t_RO.t_Permission.t_Individual.DUID));
142 DRM_TAPPS_LOG("st_constraints.DUID = %s", st_constraints.DUID);
144 /* Validation of constraints */
145 check = DTappsValidateConstraints(&st_constraints, DTAPPS_INSTALL);
146 if (check != TADC_LICENSE_VALID)
148 DRM_TAPPS_LOG("Constraints obtained are NOT VALID!!!, check = %d",check);
149 ret = TADC_LICENSE_INVALID_ERROR;
153 /* Create the contraints buffer to be put in DB */
154 db_buffer_org = (unsigned char*)DTAPPS_MALLOC(sizeof(DTAPPS_CONSTRAINTS));
155 if (db_buffer_org == NULL)
157 DRM_TAPPS_EXCEPTION("Memory Allocation error , db_buffer_org = %p", db_buffer_org);
158 ret = TADC_MEMAlOC_ERROR;
162 DTAPPS_MEMSET(db_buffer_org, 0x00, sizeof(DTAPPS_CONSTRAINTS));
163 DTAPPS_MEMCPY(db_buffer_org, &st_constraints, sizeof(DTAPPS_CONSTRAINTS));
165 /* Calculate the hash - HMAC for the constraints buffer */
166 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen))
168 DRM_TAPPS_EXCEPTION("Error in DTAppsGetDeviceKey!!!, pDevKey = %p, DevKeyLen = %d", pDevKey, DevKeyLen);
169 ret = TADC_GET_DEVICEKEY_ERROR;
173 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, db_buffer_org, sizeof(DTAPPS_CONSTRAINTS), hash, &hash_len);
175 /* Encode the buffer and hash using Base64 and then store it into the DB */
176 /* Base64 Encode the constraints buffer */
177 len_enc = (sizeof(DTAPPS_CONSTRAINTS) + 2) / 3 * 4;
179 isOk = DTappsB64Encode(db_buffer_org, sizeof(DTAPPS_CONSTRAINTS), db_buffer_enc, len_enc);
182 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
183 ret = TADC_GET_BASE64ENCODE_ERROR;
187 /* Base64 Encode the hash buffer */
188 len_enc = (hash_len + 2) / 3 * 4;
190 isOk = DTappsB64Encode(hash, hash_len, hash_enc, len_enc);
193 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
194 ret = TADC_GET_BASE64ENCODE_ERROR;
198 DRM_TAPPS_LOG("CEK installation started!!");
199 if (DTAPPS_MEMCMP((void*)t_RO.t_Content.CEK, (void*)nullCek, CEK_SIZE) != 0)
201 #ifdef DTAPPS_STORE_CEK_IN_DB
202 /* Store the CEK in DB */
203 /* First encrypt the CEK , calculate the HASH and then convert both into BASE64 Encoded form */
204 //ceklen = (unsigned int)TAPPS_STRLEN((const char*) t_RO.t_Content.CEK);
205 /* keylen => Should be a multiple of 8 */
207 encr_cek_len = keylen + 8;
209 if ((check_ret = DTAPPS_AES_SET_ENCR_KEY(pDevKey, 128, &key)) != 0)
211 DRM_TAPPS_EXCEPTION("DTAPPS_AES_SET_ENC_KEY failed!!, check_ret = %d", check_ret);
212 ret = TADC_SET_AES_ENCRYPTKEY_ERROR;
216 encr_cek = (unsigned char*)DTAPPS_MALLOC(encr_cek_len);
217 if (NULL == encr_cek)
219 DRM_TAPPS_EXCEPTION("Memory Allocation Error!!, encr_cek = %p", encr_cek);
220 ret = TADC_MEMAlOC_ERROR;
224 check_ret = DTAPPS_AES_WRAP_KEY(&key, NULL, encr_cek, t_RO.t_Content.CEK, keylen);
227 DRM_TAPPS_EXCEPTION("DTAPPS_AES_WRAP_KEY failed!!, check_ret = %d", check_ret);
228 ret = TADC_SET_AES_WRAPKEY_ERROR;
231 DRM_TAPPS_LOG("encr_cek = %s", encr_cek);
233 /* Calculate the HASH for Encrypted CEK */
234 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, encr_cek, encr_cek_len, encr_cek_hash, &encr_cek_hash_len);
235 DRM_TAPPS_LOG("encr_cek_hash = %s", encr_cek_hash);
237 /* Base64 Encode the Encrypted CEK */
238 len_enc = (encr_cek_len + 2) / 3 * 4;
239 isOk = DTappsB64Encode(encr_cek, encr_cek_len, b64_encr_cek, len_enc);
242 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
243 ret = TADC_GET_BASE64ENCODE_ERROR;
247 /* Base64 Encode the Hash of Encrypted CEK */
248 len_enc = (encr_cek_hash_len + 2) / 3 * 4;
249 isOk = DTappsB64Encode(encr_cek_hash, encr_cek_hash_len, b64_encr_cek_hash, len_enc);
252 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
253 ret = TADC_GET_BASE64ENCODE_ERROR;
257 DRM_TAPPS_LOG("b64_encr_cek = %s, b64_encr_cek_hash = %s", b64_encr_cek, b64_encr_cek_hash);
259 DRM_TAPPS_LOG("CEK in Secure Storage to be implemented!!!");
264 DRM_TAPPS_EXCEPTION("t_RO.t_Content.CEK is null!!");
267 /* Calculate the Time of storage */
268 now = DTAPPS_TIME(NULL);
270 DTAPPS_GMTIME_THREAD_SAFE(&now, &time_gmt);
272 /* Format the time to be stored in the DB buffer - DATETIME format */
273 len = DTAPPS_SNPRINTF(
276 "%04d-%02d-%02dT%02d:%02d:%02dZ",
277 time_gmt.tm_year + 1900,
284 if ((len == -1) || (len >= (int)sizeof(time_buffer)))
286 DRM_TAPPS_EXCEPTION("snprintf failed , len = %d, sizeof(time_buffer) = %d",len,sizeof(time_buffer));
287 ret = TADC_MEMAlOC_ERROR;
290 DRM_TAPPS_LOG("time_buffer = %s", time_buffer);
291 DRM_TAPPS_LOG("Constraint_buffer = %s, Constraint_Hash = %s", db_buffer_enc, hash_enc);
293 // 2013/04/25 added for db update
294 isOk = DTapps_RIGHTS_SELECT_ONE((char*) t_RO.t_Content.CID, &row);
296 // if there is no rights in the db, insert into rights to db
299 DRM_TAPPS_LOG("Insert into dtapps2rights started....");
300 isOk = DTapps_RIGHTS_INSTALL((char*) name, time_buffer,
301 #ifdef DTAPPS_STORE_CEK_IN_DB
302 (char*) b64_encr_cek, (char*) b64_encr_cek_hash,
304 (char*) db_buffer_enc, (char*) hash_enc, (char*) t_RO.t_Content.CID,
308 DRM_TAPPS_EXCEPTION("DB Installation failure!!!! ret = %d", isOk);
309 ret = TADC_DB_INSTALL_ERROR;
312 DRM_TAPPS_LOG("DrmTdcInstallLicense Success!!!!!! ret = %d", ret);
314 // if there is same cid rights exist, update right to db
317 DRM_TAPPS_LOG("Update dtapps2rights started....");
318 isOk = DTapps_RIGHTS_INSTALL((char*) name, time_buffer,
319 #ifdef DTAPPS_STORE_CEK_IN_DB
320 (char*) b64_encr_cek, (char*) b64_encr_cek_hash,
322 (char*) db_buffer_enc, (char*) hash_enc, (char*) t_RO.t_Content.CID,
326 DRM_TAPPS_EXCEPTION("DB Update failure!!!! ret = %d", isOk);
327 ret = TADC_DB_INSTALL_ERROR;
330 DRM_TAPPS_LOG("DrmTdcInstallLicense Success!!!!!! ret = %d", ret);
333 // Test Code for get the plaintext ro
335 std::string tmpPath((char *)(t_RO.t_Content.CID));
338 FILE *fd = fopen(tmpPath.c_str(), "w+b");
343 fwrite(declicbuffer, 1, strlen(declicbuffer), fd);
345 DRM_TAPPS_LOG("Save decrypted RO success!, path = %s", tmpPath.c_str());
350 TADC_MEMFree_RO(&t_RO);
354 DTAPPS_FREE((unsigned char*)db_buffer_org);
358 DTAPPS_FREE(encr_cek);
364 int DTappsHasValidLicense(const char* szCid)
366 int const_buf_enclen = 0, hash_buf_enclen = 0, const_buf_declen = 0, hash_buf_declen = 0;
368 unsigned char *pDevKey = NULL;
369 unsigned int DevKeyLen = 0;
370 unsigned char const_buffer_dec[512] = {0, };
371 unsigned char hash_buffer_dec[64] = {0, };
372 unsigned char md[64] = {0, };
373 unsigned int md_len = 0;
375 DTAPPS_RIGHTS_ROW row;
378 int check_valid = TADC_LICENSE_VALID;
379 DTAPPS_CONSTRAINTS st_constaints = {0, };
381 check = DTapps_RIGHTS_SELECT_ONE(szCid, &row);
384 DRM_TAPPS_EXCEPTION("There is no RO in the DB. cid = %s", szCid);
385 check_valid = TADC_LICENSE_NO_LICENSE;
389 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen))
391 DRM_TAPPS_EXCEPTION("Error in DTAppsGetDeviceKey pDevKey = %s, DevKeyLen = %d", pDevKey, DevKeyLen);
392 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
396 /* BASE64 Decode the constraints buffer extracted from the DB */
397 const_buf_enclen = TAPPS_STRLEN(row.constraint_buffer);
398 const_buf_declen = const_buf_enclen / 4 * 3;
399 if (const_buf_enclen <= 0)
401 DRM_TAPPS_EXCEPTION("There is no constaints buffer in the DB. cid = %s", szCid);
402 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
405 DRM_TAPPS_FRQ_LOG("const_buf_enclen = %d, const_buf_declen = %d", const_buf_enclen, const_buf_declen);
407 (void)DTappsB64Decode((unsigned char*)row.constraint_buffer, const_buf_enclen, const_buffer_dec, const_buf_declen);
408 if (const_buf_declen > (const_buf_enclen / 4 * 3))
410 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! const_buffer_dec = %s, const_buf_declen = %d, (const_buf_enclen/4*3) = %d", const_buffer_dec, const_buf_declen, (const_buf_enclen / 4 * 3));
411 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
415 /* BASE64 Decode the hash buffer extracted from the DB */
416 DTAPPS_MEMSET(hash_buffer_dec, 0x00, sizeof(hash_buffer_dec));
417 DTAPPS_MEMSET(md, 0x00, sizeof(md));
419 hash_buf_enclen = TAPPS_STRLEN(row.constraint_hash);
420 hash_buf_declen = hash_buf_enclen / 4 * 3;
421 if (hash_buf_enclen <= 0)
423 DRM_TAPPS_EXCEPTION("There is no constaints_hash buffer in the DB. cid = %s", szCid);
424 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
427 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen, hash_buf_declen);
429 (void)DTappsB64Decode((unsigned char*)row.constraint_hash, hash_buf_enclen, hash_buffer_dec, hash_buf_declen);
430 if (hash_buf_declen > (hash_buf_enclen / 4 * 3))
432 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! hash_buffer_dec = %s, hash_buf_declen = %d, (hash_buf_enclen/4*3) = %d", hash_buffer_dec, hash_buf_declen, (hash_buf_enclen / 4 * 3));
433 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
437 /* Calculate the hash using HMAC from the BASE64Decoded Constraint Buffers and check with the BASE64Decoded Hash buffers */
438 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, const_buffer_dec, const_buf_declen, md, &md_len);
439 if (DTAPPS_MEMCMP(md, hash_buffer_dec, hash_buf_declen) == 0)
441 DRM_TAPPS_LOG("HASH matching!!! md = %s, hash_buffer_dec = %s, hash_buf_declen = %d", md, hash_buffer_dec, hash_buf_declen);
445 DRM_TAPPS_EXCEPTION("HASH not matching!!! md = %s, hash_buffer_dec = %s, hash_buf_declen = %d", md, hash_buffer_dec, hash_buf_declen);
446 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
450 /* Validate the constraints buffer */
451 DTAPPS_MEMCPY(&st_constaints, const_buffer_dec, sizeof(DTAPPS_CONSTRAINTS));
453 check_valid = DTappsValidateConstraints(&st_constaints, DTAPPS_VERIFY);
454 if (check_valid != TADC_LICENSE_VALID)
456 DRM_TAPPS_LOG("Invalid Constraints for constraints_buffer = %s check_valid = %d", const_buffer_dec, check_valid);
457 /* TODO: Implementation of Auto Deletion feature to delete the rights from the DB if the rights are expired!!!*/
462 DRM_TAPPS_LOG("Rights are Valid!!! Found atleast one Valid Rights..... return with Success!! check_valid = %d", check_valid);
468 DTappsFreeDeviceKey(&pDevKey);
470 if (check_valid != TADC_LICENSE_VALID)
472 DRM_TAPPS_EXCEPTION("Constraints not Valid!!!! check_valid = %d", check_valid);
473 DRM_TAPPS_EXCEPTION("DrmTdcHasValidLicense Failed!!!");
478 DRM_TAPPS_LOG("Constraints are Valid!! check_valid = %d", check_valid);
479 return TADC_LICENSE_VALID;
483 int DTappsGetROInfo(const char* pszXML, T_RO *t_RO, unsigned char* name)
487 CXMLElement* pRoot, *pElement;
488 CPointerArray paChilds;
491 unsigned char *pbBuffer = NULL;
492 int len_enc = 0, len_dec = 0;
494 const char *pRoHeader = "<?xml version=\"1.0\"?>\n<TizenLicense>";
497 if (pszXML == NULL || t_RO == NULL || name == NULL)
499 DRM_TAPPS_EXCEPTION("Parameters NULL!!! pszXML = %p, t_RO = %p", pszXML, t_RO);
503 if (memcmp(pszXML, pRoHeader, strlen(pRoHeader))) {
504 DRM_TAPPS_EXCEPTION("TADC_IF_MemCmp. pRoHeader[%s] Error Code = %x", pRoHeader, TADC_XMLPARSER_ERROR);
508 DTAPPS_MEMSET(t_RO, 0, sizeof(T_RO));
510 nResult = oXMLFile.LoadFromStream((LPCTSTR)pszXML);
513 DRM_TAPPS_EXCEPTION("oXMLFile.LoadFromStream is failed\n");
519 pRoot = oXMLFile.GetRoot();
522 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
528 pRoot = oXMLFile.GetRoot();
531 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
536 paChilds.RemoveAll();
537 nResult = pRoot->Find(&paChilds, _T("LicenseInfo"), _T("uid"), NULL);
540 DRM_TAPPS_EXCEPTION("pRoot->Find is failed\n");
545 if (paChilds.GetCount() != 1)
547 DRM_TAPPS_EXCEPTION("paChilds.GetCount() is failed\n");
552 pElement = (CXMLElement*) paChilds.Get(0);
553 pszValue = pElement->GetValue();
554 if (pszValue == NULL)
556 DRM_TAPPS_EXCEPTION("pElement->GetValue() is failed\n");
561 length = TAPPS_STRLEN(pszValue);
562 if (length <= 0 || length > DTAPPS_NAME_SIZE)
564 DRM_TAPPS_EXCEPTION("TAPPS_STRLEN failed(%d) - %s\n", length, pszValue);
569 memcpy(name, pszValue, length + 1);
570 DRM_TAPPS_LOG("name = %s", name);
573 pRoot = oXMLFile.GetRoot();
576 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
581 paChilds.RemoveAll();
582 nResult = pRoot->Find(&paChilds, _T("ContentInfo"), _T("cid"), NULL);
585 DRM_TAPPS_EXCEPTION("pRoot->Find is failed\n");
589 if (paChilds.GetCount() != 1)
591 DRM_TAPPS_EXCEPTION("paChilds.GetCount() is failed\n");
596 pElement = (CXMLElement*)paChilds.Get(0);
597 pszValue = pElement->GetValue();
598 if (pszValue == NULL)
600 DRM_TAPPS_EXCEPTION("pElement->GetValue() is failed\n");
605 length = TAPPS_STRLEN(pszValue);
606 if (length <= 0 || length > CID_SIZE)
608 DRM_TAPPS_EXCEPTION("TAPPS_STRLEN is failed(%d) - %s\n", length, pszValue);
613 t_RO->t_Content.CID = (TADC_U8*)DTAPPS_MALLOC(CID_SIZE + 1);
614 IF_TRUE_GOTO(t_RO->t_Content.CID == NULL, -2);
616 memset(t_RO->t_Content.CID, 0, CID_SIZE + 1);
617 memcpy(t_RO->t_Content.CID, pszValue, CID_SIZE + 1);
619 // Get KeyValue (CEK)
620 pRoot = oXMLFile.GetRoot();
621 IF_TRUE_GOTO(pRoot == NULL, ERROR_INVALID_DATA);
622 paChilds.RemoveAll();
623 nResult = pRoot->Find(&paChilds, _T("KeyInfo"), _T("CipherValue"), NULL);
625 IF_TRUE_GOTO( nResult != 0, ERROR_INVALID_DATA );
626 IF_TRUE_GOTO( paChilds.GetCount() != 1, ERROR_INVALID_DATA );
628 pElement = (CXMLElement*)paChilds.Get(0);
629 pszValue = pElement->GetValue();
630 IF_TRUE_GOTO(pszValue == NULL, -2);
632 len_enc = TAPPS_STRLEN(pszValue);
633 len_dec = len_enc / 4 * 3;
635 DRM_TAPPS_LOG("CEK raw = [%s], len_enc = [%d], len_dec = [%d]", pszValue, len_enc, len_dec);
638 pbBuffer = (unsigned char*)DTAPPS_MALLOC(len_dec + 1);
639 if (pbBuffer == NULL)
641 DRM_TAPPS_EXCEPTION("Memory Allocation Error pbBuffer = %p", pbBuffer);
646 DTAPPS_MEMSET(pbBuffer, 0x00, len_dec + 1);
649 pbBuffer = Base64Decode(pszValue, &len_dec);
650 if (pbBuffer == NULL)
652 DRM_TAPPS_EXCEPTION("Memory Allocation Error pbBuffer = %p", pbBuffer);
657 if (len_dec > (len_enc / 4 * 3))
659 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! pbBuffer=%s, len_dec=%d, (len_enc/4*3)=%d", pbBuffer, len_dec, (len_enc / 4 * 3));
663 if (len_dec != CEK_SIZE)
665 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! CEK size=%d, len_dec=%d", CEK_SIZE, len_dec);
670 DRM_TAPPS_LOG("Base64Decoded CEK pbBuffer=%s, len_dec=%d, (len_enc/4*3)=%d", pbBuffer, len_dec, (len_enc / 4 * 3));
672 t_RO->t_Content.CEK = (TADC_U8*)DTAPPS_MALLOC(CEK_SIZE + 1);
673 IF_TRUE_GOTO(t_RO->t_Content.CEK == NULL, -2);
674 DTAPPS_MEMSET(t_RO->t_Content.CEK, 0x00, CEK_SIZE + 1);
675 DTAPPS_MEMCPY(t_RO->t_Content.CEK, pbBuffer, CEK_SIZE);
676 DRM_TAPPS_SECURE_LOG("CEK t_RO->t_Content.CEK = %s", t_RO->t_Content.CEK);
679 pRoot = oXMLFile.GetRoot();
680 IF_TRUE_GOTO( pRoot == NULL, ERROR_INVALID_DATA );
682 paChilds.RemoveAll();
683 nResult = pRoot->Find(&paChilds, _T("DeviceInfo"), _T("DUID"), NULL);
685 IF_TRUE_GOTO(nResult != 0, ERROR_INVALID_DATA);
686 IF_TRUE_GOTO(paChilds.GetCount() != 1, ERROR_INVALID_DATA);
688 pElement = (CXMLElement*)paChilds.Get(0);
689 pszValue = pElement->GetValue();
690 IF_TRUE_GOTO(pszValue == NULL, -1);
691 length = TADC_IF_StrLen((char*)pszValue);
698 t_RO->PerFlag |= DUID_RULE;
699 t_RO->t_Permission.t_Individual.BindingType |= DUID_RULE;
700 t_RO->t_Permission.t_Individual.DUID = (TADC_U8*)TADC_IF_Malloc(length + 1);
702 if (t_RO->t_Permission.t_Individual.DUID == NULL)
704 DRM_TAPPS_EXCEPTION("TADC_IF_MemCmp Error Code = %x", TADC_MEMAlOC_ERROR);
709 TADC_IF_MemSet(t_RO->t_Permission.t_Individual.DUID, 0, length + 1);
710 TADC_IF_MemCpy((CHAR*)t_RO->t_Permission.t_Individual.DUID, pszValue, length);
719 DTAPPS_FREE(pbBuffer);
724 DRM_TAPPS_EXCEPTION(" Error Code = %x", TADC_XMLPARSER_ERROR);
729 DRM_TAPPS_EXCEPTION(" Error Code = %x", TADC_MEMAlOC_ERROR);
735 BOOL DTappsGetCEK(const char* szCid, T_RO* t_RO)
737 int db_buf_enclen = 0, hash_buf_enclen = 0, db_buf_declen = 0, hash_buf_declen = 0;
738 DTAPPS_RIGHTS_ROW row;
741 unsigned char const_buffer_dec[512] = {0, };
742 unsigned char encr_cek[128] = {0, };
744 unsigned char hash_buffer[64] = {0, };
745 unsigned char md[64] = {0, };
746 unsigned int md_len = 0;
748 unsigned char *pDevKey = NULL;
749 unsigned int DevKeyLen = 0;
751 int check_valid = TADC_LICENSE_VALID;
752 DTAPPS_CONSTRAINTS st_constaints = {0, };
756 memset(&key, 0x00, sizeof(key));
758 if (NULL == szCid || NULL == t_RO)
760 DRM_TAPPS_EXCEPTION("Null Parameters!! szCid = %p, t_RO = %p", szCid, t_RO);
764 check = DTapps_RIGHTS_SELECT_ONE(szCid, &row);
767 DRM_TAPPS_EXCEPTION("There is no RO in the DB. cid=%s", szCid);
768 check_valid = TADC_LICENSE_NO_LICENSE;
772 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen))
774 DRM_TAPPS_EXCEPTION("error in DTappsGetDeviceKey pDevKey = %s, DevKeyLen = %d", pDevKey, DevKeyLen);
775 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
778 DRM_TAPPS_LOG("DTappsGetDeviceKey pDevKey = %s, DevKeyLen = %d", pDevKey, DevKeyLen);
780 check_valid = TADC_LICENSE_VALID;
782 /* BASE64 Decode the constraints buffer extracted from the DB */
783 db_buf_enclen = TAPPS_STRLEN(row.constraint_buffer);
784 db_buf_declen = db_buf_enclen / 4 * 3;
785 if (db_buf_enclen <= 0)
787 DRM_TAPPS_EXCEPTION("There is no constaints buffer in the DB. cid = %s", szCid);
788 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
792 DRM_TAPPS_FRQ_LOG("db_buf_enclen = %d, db_buf_declen = %d", db_buf_enclen, db_buf_declen);
794 (void)DTappsB64Decode((unsigned char*)row.constraint_buffer, db_buf_enclen, const_buffer_dec, db_buf_declen);
795 if (db_buf_declen > (db_buf_enclen / 4 * 3))
797 DRM_TAPPS_EXCEPTION("BASE64 Decode error! const_buffer_dec=%s, db_buf_declen=%d, (db_buf_enclen/4*3)=%d", const_buffer_dec, db_buf_declen, (db_buf_enclen / 4 * 3));
798 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
802 /* BASE64 Decode the hash buffer extracted from the DB */
803 DTAPPS_MEMSET(hash_buffer, 0x00, sizeof(hash_buffer));
804 DTAPPS_MEMSET(md, 0x00, sizeof(md));
806 hash_buf_enclen = TAPPS_STRLEN(row.constraint_hash);
807 hash_buf_declen = hash_buf_enclen / 4 * 3;
808 if (hash_buf_enclen <= 0)
810 DRM_TAPPS_EXCEPTION("There is no hash buffer in the DB. cid = %s", szCid);
811 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
814 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen, hash_buf_declen);
816 (void)DTappsB64Decode((unsigned char*)row.constraint_hash, hash_buf_enclen, hash_buffer, hash_buf_declen);
817 if (hash_buf_declen > (hash_buf_enclen / 4 * 3))
819 DRM_TAPPS_EXCEPTION("BASE64 Decode error! hash_buffer_dec=%s, hash_buf_declen=%d, (hash_buf_enclen/4*3)=%d", hash_buffer, hash_buf_declen, (hash_buf_enclen / 4 * 3));
820 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
824 /* Calculate the hash using HMAC from the BASE64Decoded Constraint Buffers and check with the BASE64Decoded Hash buffers */
825 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, const_buffer_dec, db_buf_declen, md, &md_len);
826 if (DTAPPS_MEMCMP(md, hash_buffer, hash_buf_declen) == 0)
828 DRM_TAPPS_LOG("HASH for constraint buffer matching! md=%s, hash_buffer_dec=%s, hash_buf_declen=%d", md, hash_buffer, hash_buf_declen);
832 DRM_TAPPS_EXCEPTION("HASH for constraint buffer not matching! md=%s, hash_buffer_dec=%s, hash_buf_declen=%d", md, hash_buffer, hash_buf_declen);
833 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
837 /* Validate the constraints buffer */
838 DTAPPS_MEMCPY(&st_constaints, const_buffer_dec, sizeof(DTAPPS_CONSTRAINTS));
840 check_valid = DTappsValidateConstraints(&st_constaints, DTAPPS_VERIFY);
841 if (check_valid != TADC_LICENSE_VALID)
843 DRM_TAPPS_LOG("Invalid Constraints for constraints_buffer=%s, check_valid=%d", const_buffer_dec, check_valid);
844 /* TODO: Implementation of Auto Deletion feature to delete the rights from the DB if the rights are expired!!!*/
849 DRM_TAPPS_LOG("Rights are Valid! check_valid = %d", check_valid);
851 /* Constraints valid - Extract CEK and fill the t_RO structure with CEK, DUID */
852 /* BASE64 Decode the CEK buffer extracted from the DB */
853 db_buf_enclen = TAPPS_STRLEN(row.cek);
854 db_buf_declen = db_buf_enclen / 4 * 3;
855 if (db_buf_enclen <= 0)
857 DRM_TAPPS_EXCEPTION("There is no CEK in the DB. cid = %s", szCid);
858 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
861 DRM_TAPPS_FRQ_LOG("db_buf_enclen = %d, db_buf_declen = %d", db_buf_enclen, db_buf_declen);
865 (void)DTappsB64Decode((unsigned char*)row.cek, db_buf_enclen, encr_cek, cek_declen);
866 db_buf_declen = cek_declen;
868 if (cek_declen > (db_buf_enclen / 4 * 3))
870 DRM_TAPPS_EXCEPTION("BASE64 Decode error! encr_cek=%s, cek_declen=%d, (db_buf_enclen/4*3)=%d", encr_cek, cek_declen, (db_buf_enclen / 4 * 3));
871 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
874 DRM_TAPPS_LOG("BASE64 encr_cek=%s, cek_declen=%d, db_buf_declen=%d, (db_buf_enclen/4*3)=%d", encr_cek, cek_declen, db_buf_declen, (db_buf_enclen / 4 * 3));
876 /* BASE64 Decode the hash buffer extracted from the DB */
877 DTAPPS_MEMSET(hash_buffer, 0x00, sizeof(hash_buffer));
878 DTAPPS_MEMSET(md, 0x00, sizeof(md));
880 hash_buf_enclen = TAPPS_STRLEN(row.cek_hash);
881 hash_buf_declen = hash_buf_enclen / 4 * 3;
882 if (db_buf_enclen <= 0)
884 DRM_TAPPS_EXCEPTION("There is no CEK_hash buffer in the DB. cid = %s", szCid);
885 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
888 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen, hash_buf_declen);
890 (void)DTappsB64Decode((unsigned char*)row.cek_hash, hash_buf_enclen, hash_buffer, hash_buf_declen);
891 if (hash_buf_declen > (hash_buf_enclen / 4 * 3))
893 DRM_TAPPS_EXCEPTION("BASE64 Decode error! hash_buffer_dec=%s, hash_buf_declen=%d, (hash_buf_enclen/4*3)=%d", hash_buffer, hash_buf_declen, (hash_buf_enclen/4*3));
894 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
898 /* Calculate the hash using HMAC from the BASE64Decoded Encrypted CEK Buffer and check with the BASE64Decoded Hash buffer */
899 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, encr_cek, db_buf_declen, md, &md_len);
900 if (DTAPPS_MEMCMP(md, hash_buffer, hash_buf_declen) == 0)
902 DRM_TAPPS_LOG("HASH for Encrypted CEK buffer matching! md=%s, hash_buffer_dec=%s, hash_buf_declen=%d", md, hash_buffer, hash_buf_declen);
906 DRM_TAPPS_EXCEPTION("HASH for Encrypted CEK buffer not matching! md=%s, hash_buffer_dec=%s, hash_buf_declen=%d", md, hash_buffer, hash_buf_declen);
907 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
911 /* Allocate memory for CEK */
912 t_RO->t_Content.CEK = (unsigned char*)DTAPPS_MALLOC(CEK_SIZE + 1);
913 if (NULL == t_RO->t_Content.CEK)
915 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! t_RO->t_Content.CEK = %p", t_RO->t_Content.CEK);
916 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
920 DTAPPS_MEMSET(t_RO->t_Content.CEK, 0x00, CEK_SIZE + 1);
921 /* Decrypt CEK and update t_RO structure */
922 if (DTAPPS_AES_SET_DECR_KEY(pDevKey, 128, &key))
924 DRM_TAPPS_EXCEPTION("AES_set_decrypt_key failed!!");
925 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
929 (void)DTAPPS_AES_UNWRAP_KEY(&key, NULL, t_RO->t_Content.CEK, encr_cek, cek_declen);
930 DRM_TAPPS_LOG("DTAPPS_AES_UNWRAP_KEY success!!");
932 /* Store DUID in t_RO */
933 if (st_constaints.DUID[0] != '\0')
935 t_RO -> t_Permission.t_Individual.DUID = (unsigned char*)DTAPPS_MALLOC(DUID_SIZE + 1);
936 if (NULL == t_RO -> t_Permission.t_Individual.DUID)
938 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! t_RO->t_Permission.t_Individual.DUID = %p", t_RO -> t_Permission.t_Individual.DUID);
939 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
942 DTAPPS_MEMSET(t_RO -> t_Permission.t_Individual.DUID, 0x00, DUID_SIZE + 1);
943 t_RO->PerFlag |= DUID_RULE;
944 t_RO->t_Permission.t_Individual.BindingType |= DUID_RULE;
945 DTAPPS_MEMCPY(t_RO -> t_Permission.t_Individual.DUID, st_constaints.DUID, DUID_SIZE);
952 DTappsFreeDeviceKey(&pDevKey);
955 if (check_valid != TADC_LICENSE_VALID)
957 DRM_TAPPS_EXCEPTION("DTappsGetCEK FAILED!!!, check_valid = %d", check_valid);
962 /* All fine... Allocate memory for CID and fill the value */
963 if ((t_RO != NULL) && (szCid != NULL))
965 t_RO -> t_Content.CID = (unsigned char*) DTAPPS_MALLOC(CID_SIZE + 1);
966 if (NULL == t_RO -> t_Content.CID)
968 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! t_RO->t_Content.CID = %p", t_RO -> t_Content.CID);
969 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
972 DTAPPS_MEMSET(t_RO -> t_Content.CID, 0x00, CID_SIZE + 1);
973 DTAPPS_MEMCPY(t_RO -> t_Content.CID, szCid, CID_SIZE);
974 DRM_TAPPS_LOG("DTappsGetCEK SUCCESS!!!, check_valid = %d", check_valid);
981 BOOL DTapps_RIGHTS_INSTALL(const char* name,
983 #ifdef DTAPPS_STORE_CEK_IN_DB
985 const char* cek_hash,
987 const char* constraint_buffer,
988 const char* constraint_hash,
993 const char* query = NULL;
994 sqlite3_stmt* pstmt = NULL;
995 unsigned int dIdx = 0;
996 BOOL ret_value = FALSE;
998 DRM_TAPPS_LOG("Open DB......");
999 ret_value = DTappsDBOpen(pDb,__func__);
1000 if(ret_value != TRUE)
1002 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d",ret_value);
1006 if(isUpdate == FALSE)
1008 query = "INSERT INTO dtapps2rights (name, time_t, "
1009 #ifdef DTAPPS_STORE_CEK_IN_DB
1012 " constraint_buffer, constraint_hash, cid) "
1014 #ifdef DTAPPS_STORE_CEK_IN_DB
1021 query = "UPDATE dtapps2rights SET name=?, time_t=?,"
1022 #ifdef DTAPPS_STORE_CEK_IN_DB
1023 " cek=?, cek_hash=?, "
1025 " constraint_buffer=?, constraint_hash=? "
1029 DRM_TAPPS_LOG("Prepare Statement........");
1030 pstmt = (sqlite3_stmt*) DTappsStmtPrepare(pDb, query);
1033 DRM_TAPPS_EXCEPTION("Prepare Statement failed. query=%s", query);
1037 DRM_TAPPS_LOG("Binding Parameters........");
1038 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR, (void *)name, strlen(name));
1039 if(ret_value != TRUE)
1041 DRM_TAPPS_EXCEPTION("Binding Parameter(name=%s) failed. ret_value = %d", name, ret_value);
1045 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR, (void *)time, strlen(time));
1046 if(ret_value != TRUE)
1048 DRM_TAPPS_EXCEPTION("Binding Parameter(time=%s) failed. ret_value = %d", time, ret_value);
1052 #ifdef DTAPPS_STORE_CEK_IN_DB
1053 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR, (void *)cek, strlen(cek));
1054 if(ret_value != TRUE)
1056 DRM_TAPPS_EXCEPTION("Binding Parameter(cek=%s) failed. ret_value = %d", cek, ret_value);
1060 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR, (void *)cek_hash, strlen(cek_hash));
1061 if(ret_value != TRUE)
1063 DRM_TAPPS_EXCEPTION("Binding Parameter(cek_hash=%s) failed. ret_value = %d", cek_hash, ret_value);
1068 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR, (void *)constraint_buffer, strlen(constraint_buffer));
1069 if(ret_value != TRUE)
1071 DRM_TAPPS_EXCEPTION("Binding Parameter(constraint_buffer=%s) failed. ret_value = %d", constraint_buffer, ret_value);
1075 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR, (void *)constraint_hash, strlen(constraint_hash));
1076 if(ret_value != TRUE)
1078 DRM_TAPPS_EXCEPTION("Binding Parameter(constraint_hash=%s) failed. ret_value = %d", constraint_hash, ret_value);
1082 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR, (void *)cid, strlen(cid));
1083 if(ret_value != TRUE)
1085 DRM_TAPPS_EXCEPTION("Binding Parameter(cid=%s) failed. ret_value = %d", cid, ret_value);
1089 DRM_TAPPS_LOG("Begin Transaction........");
1090 ret_value = DTappsDBBeginImmedTrans(__func__);
1091 if(ret_value != TRUE)
1093 DRM_TAPPS_EXCEPTION("DB Begin Transaction ret_value = %d",ret_value);
1097 DRM_TAPPS_LOG("Execute SQL to Insert Contents into Table........");
1098 ret_value = DTappsStmtExecute(pstmt);
1099 if(ret_value != TRUE)
1101 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! ret_value = %d",ret_value);
1105 DRM_TAPPS_LOG("Commit DB........");
1106 ret_value = DTappsDBCommit(__func__);
1107 if(ret_value != TRUE)
1109 DRM_TAPPS_EXCEPTION("Commit DB Failed!! ret_value = %d",ret_value);
1113 DRM_TAPPS_LOG("Release Statement........");
1114 ret_value = DTappsStmtRelease(pstmt);
1115 if(ret_value != TRUE)
1117 DRM_TAPPS_EXCEPTION("Release Statement Failed!! ret_value = %d",ret_value);
1122 DRM_TAPPS_LOG("Close DB........");
1123 ret_value = DTappsDBClose(__func__);
1124 if(ret_value != TRUE)
1126 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d",ret_value);
1130 DRM_TAPPS_LOG("Install DB Operartion Successful!!!");
1135 DTappsStmtRelease(pstmt);
1137 ret_value = DTappsDBRollback (__func__);
1138 if(ret_value != TRUE)
1140 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d",ret_value);
1143 ret_value = DTappsDBClose(__func__);
1144 if(ret_value != TRUE)
1146 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d",ret_value);
1152 BOOL DTapps_RIGHTS_SELECT_ONE(const char* cid, DTAPPS_RIGHTS_ROW* row)
1155 const char* query = NULL;
1156 sqlite3_stmt* pstmt = NULL;
1157 unsigned int dIdx = 0;
1158 BOOL ret_value = FALSE;
1160 DTAPPS_RIGHTS_ROW* result = row;
1162 char *name, *time, *constraint_buffer, *constraint_hash;
1163 #ifdef DTAPPS_STORE_CEK_IN_DB
1164 char *cek, *cek_hash;
1167 DRM_TAPPS_LOG("Open DB......");
1168 ret_value = DTappsDBOpen(pDb,__func__);
1169 if(ret_value != TRUE)
1171 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d",ret_value);
1175 query = "SELECT r_id, name, time_t, "
1176 #ifdef DTAPPS_STORE_CEK_IN_DB
1179 " constraint_buffer, constraint_hash "
1180 " FROM dtapps2rights"
1181 " WHERE cid=? ORDER BY r_id desc limit 1;";
1184 DRM_TAPPS_LOG("Begin Transaction........");
1185 ret_value = DTappsDBBeginImmedTrans(__func__);
1186 if(ret_value != TRUE)
1188 DRM_TAPPS_EXCEPTION("DB Begin Transaction Failed!! ret_value = %d",ret_value);
1192 DRM_TAPPS_LOG("Prepare Statement........");
1193 db_ret = sqlite3_prepare((sqlite3*)pDb, query, -1, &pstmt, NULL);
1196 DRM_TAPPS_EXCEPTION("Prepare Statement failed. query=%s, error=%s", query, sqlite3_errmsg((sqlite3*)pDb));
1200 DRM_TAPPS_LOG("Binding Parameters........");
1201 db_ret = sqlite3_bind_text(pstmt, ++dIdx, cid, strlen(cid), SQLITE_TRANSIENT);
1202 if(db_ret != SQLITE_OK)
1204 DRM_TAPPS_EXCEPTION("Binding Parameter(cid=%s) failed. ret_value = %d, query=%s", cid, db_ret, query);
1208 DRM_TAPPS_LOG("Execute SQL to Select Contents from Table........");
1209 db_ret = sqlite3_step(pstmt);
1210 if(db_ret == SQLITE_OK || db_ret == SQLITE_DONE)
1212 DRM_TAPPS_FRQ_LOG("Executed SQL Select Query. But no row was returned");
1215 else if(db_ret != SQLITE_ROW)
1217 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! ret_value = %d, query=%s, error=%s",
1218 db_ret, query, sqlite3_errmsg((sqlite3*)pDb));
1222 memset(result, 0, sizeof(DTAPPS_RIGHTS_ROW));
1225 result->r_id = sqlite3_column_int(pstmt, dIdx++);
1226 DRM_TAPPS_LOG("....SEELECTED : r_id = %d", result->r_id);
1228 name = (char*) sqlite3_column_text(pstmt, dIdx++);
1230 memcpy(result->name, name, strlen(name));
1231 DRM_TAPPS_LOG("....SEELECTED : name = %s", result->name);
1233 time= (char*) sqlite3_column_text(pstmt, dIdx++);
1235 memcpy(result->time, time, strlen(time));
1236 DRM_TAPPS_LOG("....SEELECTED : time = %s", result->time);
1238 #ifdef DTAPPS_STORE_CEK_IN_DB
1239 cek= (char*) sqlite3_column_text(pstmt, dIdx++);
1241 memcpy(result->cek, cek, strlen(cek));
1242 DRM_TAPPS_LOG("....SEELECTED : cek = %s", result->cek);
1244 cek_hash= (char*) sqlite3_column_text(pstmt, dIdx++);
1245 if(cek_hash != NULL)
1246 memcpy(result->cek_hash, cek_hash, strlen(cek_hash));
1247 DRM_TAPPS_LOG("....SEELECTED : cek_hash = %s", result->cek_hash);
1250 constraint_buffer = (char*) sqlite3_column_text(pstmt, dIdx++);
1251 if(constraint_buffer != NULL)
1252 memcpy(result->constraint_buffer, constraint_buffer, strlen(constraint_buffer));
1253 DRM_TAPPS_LOG("....SEELECTED : constraint_buffer = %s", result->constraint_buffer);
1255 constraint_hash = (char*) sqlite3_column_text(pstmt, dIdx++);
1256 if(constraint_hash != NULL)
1257 memcpy(result->constraint_hash, constraint_hash, strlen(constraint_hash));
1258 DRM_TAPPS_LOG("....SEELECTED : constraint_hash = %s", result->constraint_hash);
1260 memcpy(result->cid, cid, strlen(cid));
1261 DRM_TAPPS_LOG("....SEELECTED : cid = %s", result->cid);
1263 DRM_TAPPS_LOG("Release Statement........");
1264 ret_value = DTappsStmtRelease(pstmt);
1265 if(ret_value != TRUE)
1267 DRM_TAPPS_EXCEPTION("Release Statement Failed!! ret_value = %d",ret_value);
1272 DRM_TAPPS_LOG("Close DB........");
1273 ret_value = DTappsDBClose(__func__);
1274 if(ret_value != TRUE)
1276 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d",ret_value);
1280 DRM_TAPPS_LOG("Select a DB row Operartion Successful!!!");
1285 DTappsStmtRelease(pstmt);
1287 ret_value = DTappsDBClose(__func__);
1288 if(ret_value != TRUE)
1290 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d",ret_value);