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.
16 * @file DTapps2Rights.cpp
22 #include "TADC_Core.h"
24 #include "drm-tizen-error.h"
26 #include "TADC_Util.h"
28 #include "DTapps2Rights.h"
29 #include "DTapps2SqliteDB.h"
30 #include "DTapps2HMAC.h"
31 #include "DTapps2Base64.h"
32 #include "DTapps2Time.h"
34 /* Validation and Installation of the Constraints Structure */
35 int DTappsValidateConstraints(DTAPPS_CONSTRAINTS *st_const,
38 int ret = TADC_LICENSE_VALID;
39 char DUID[DTAPPS_DUID_SIZE] = {0, };
40 unsigned char zeroduid[DTAPPS_DUID_SIZE] = {0, };
41 int retDeviceInfo = 0;
43 if (st_const == NULL) {
44 DRM_TAPPS_EXCEPTION("Invalid Paramter st_const = %p", st_const);
45 ret = TADC_PARAMETER_ERROR;
50 if (DTAPPS_MEMCMP(st_const->DUID, zeroduid, DTAPPS_DUID_SIZE)) {
51 DRM_TAPPS_LOG("st_const->DUID = %s", st_const->DUID);
53 if (opr == DTAPPS_VERIFY || opr == DTAPPS_INSTALL) {
54 retDeviceInfo = TADC_IF_GetDUID(DUID);
56 if (retDeviceInfo < 0) {
57 DRM_TAPPS_EXCEPTION("Retrieve for DUID Failed!!! DUID = %s, duid_len = %d",
59 return TADC_LICENSE_UNKNOWN_ERROR;
62 if (!(DTAPPS_MEMCMP(st_const->DUID, DUID, DTAPPS_DUID_SIZE))) {
63 DRM_TAPPS_LOG("DUID match!! st_const->DUID = %s, DUID = %s", st_const->DUID,
65 ret = TADC_LICENSE_VALID;
67 DRM_TAPPS_EXCEPTION("DUID don't match!!! st_const->DUID = %s, DUID = %s",
68 st_const->DUID, DUID);
69 ret = TADC_LICENSE_DUID_MISMATCH;
75 DRM_TAPPS_LOG("ret = %d", ret);
79 DRM_TAPPS_EXCEPTION("Validate Constraints failed!!!, ret = %d", ret);
83 int DTappsInstallLicense(const char *declicbuffer)
85 unsigned char *db_buffer_org = NULL;
86 unsigned char db_buffer_enc[512] = {0, };
87 int len_enc = 0, check_ret = 0;
88 unsigned char *pDevKey = NULL;
89 unsigned int DevKeyLen = 0;
90 unsigned char hash[32] = {0, };
91 unsigned char hash_enc[64] = {0, };
92 unsigned int hash_len = 0;
93 int check = TADC_LICENSE_VALID;
96 int ret = TADC_SUCCESS;
98 unsigned char name[DTAPPS_NAME_SIZE] = {0, };
99 unsigned char nullCek[CEK_SIZE] = {0, };
103 char time_buffer[21] = {0, };
106 memset(&t_RO, 0x00, sizeof(t_RO));
108 DTAPPS_RIGHTS_ROW row;
110 #ifdef DTAPPS_STORE_CEK_IN_DB
113 memset(&key, 0x00, sizeof(key));
115 unsigned char *encr_cek = NULL;
116 unsigned int keylen = 0;
117 unsigned int encr_cek_len = 0;
118 unsigned char b64_encr_cek[128] = {0, };
119 unsigned char encr_cek_hash[32] = {0, };
120 unsigned char b64_encr_cek_hash[64] = {0, };
121 unsigned int encr_cek_hash_len = 0;
124 // Copy necessary fields into structure to be stored in DB
125 DTAPPS_CONSTRAINTS st_constraints = {0, };
127 // First Parse the decrypted Licence buffer in order
128 // 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",
133 TADC_LICENSEXMLPARSING_ERROR, check_ret);
134 ret = TADC_LICENSEXMLPARSING_ERROR;
139 if (t_RO.t_Permission.t_Individual.DUID != NULL) {
140 DTAPPS_MEMCPY(st_constraints.DUID, t_RO.t_Permission.t_Individual.DUID,
141 TAPPS_STRLEN((const char *)t_RO.t_Permission.t_Individual.DUID) + 1);
144 DRM_TAPPS_LOG("st_constraints.DUID = %s", st_constraints.DUID);
146 /* Validation of constraints */
147 check = DTappsValidateConstraints(&st_constraints, DTAPPS_INSTALL);
149 if (check != TADC_LICENSE_VALID) {
150 DRM_TAPPS_LOG("Constraints obtained are NOT VALID!!!, check = %d", check);
151 ret = TADC_LICENSE_INVALID_ERROR;
155 /* Create the contraints buffer to be put in DB */
156 db_buffer_org = (unsigned char *)DTAPPS_MALLOC(sizeof(DTAPPS_CONSTRAINTS));
158 if (db_buffer_org == NULL) {
159 DRM_TAPPS_EXCEPTION("Memory Allocation error , db_buffer_org = %p",
161 ret = TADC_MEMAlOC_ERROR;
165 DTAPPS_MEMSET(db_buffer_org, 0x00, sizeof(DTAPPS_CONSTRAINTS));
166 DTAPPS_MEMCPY(db_buffer_org, &st_constraints, sizeof(DTAPPS_CONSTRAINTS));
168 // Calculate the hash - HMAC for the constraints buffer
169 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen)) {
170 DRM_TAPPS_EXCEPTION("Error in DTAppsGetDeviceKey!!!, "
171 "pDevKey = %p, DevKeyLen = %d",
173 ret = TADC_GET_DEVICEKEY_ERROR;
177 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, db_buffer_org,
178 sizeof(DTAPPS_CONSTRAINTS), hash, &hash_len);
180 // Encode the buffer and hash using Base64 and then store it into the DB
181 // Base64 Encode the constraints buffer
182 len_enc = (sizeof(DTAPPS_CONSTRAINTS) + 2) / 3 * 4;
184 isOk = DTappsB64Encode(db_buffer_org, sizeof(DTAPPS_CONSTRAINTS), db_buffer_enc,
188 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
189 ret = TADC_GET_BASE64ENCODE_ERROR;
193 // Base64 Encode the hash buffer
194 len_enc = (hash_len + 2) / 3 * 4;
196 isOk = DTappsB64Encode(hash, hash_len, hash_enc, len_enc);
199 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
200 ret = TADC_GET_BASE64ENCODE_ERROR;
204 DRM_TAPPS_LOG("CEK installation started!!");
206 if (DTAPPS_MEMCMP((void *)t_RO.t_Content.CEK, (void *)nullCek, CEK_SIZE) != 0) {
207 #ifdef DTAPPS_STORE_CEK_IN_DB
208 // Store the CEK in DB
209 // First encrypt the CEK , calculate the HASH and then convert both
210 // into BASE64 Encoded form
211 //ceklen = (unsigned int)TAPPS_STRLEN((const char*) t_RO.t_Content.CEK);
212 // keylen => Should be a multiple of 8
214 encr_cek_len = keylen + 8;
216 if ((check_ret = DTAPPS_AES_SET_ENCR_KEY(pDevKey, 128, &key)) != 0) {
217 DRM_TAPPS_EXCEPTION("DTAPPS_AES_SET_ENC_KEY failed!!, check_ret = %d",
219 ret = TADC_SET_AES_ENCRYPTKEY_ERROR;
223 encr_cek = (unsigned char *)DTAPPS_MALLOC(encr_cek_len);
225 if (NULL == encr_cek) {
226 DRM_TAPPS_EXCEPTION("Memory Allocation Error!!, encr_cek = %p", encr_cek);
227 ret = TADC_MEMAlOC_ERROR;
231 check_ret = DTAPPS_AES_WRAP_KEY(&key, NULL, encr_cek, t_RO.t_Content.CEK,
234 if (check_ret <= 0) {
235 DRM_TAPPS_EXCEPTION("DTAPPS_AES_WRAP_KEY failed!!, check_ret = %d",
237 ret = TADC_SET_AES_WRAPKEY_ERROR;
241 DRM_TAPPS_LOG("encr_cek = %s", encr_cek);
243 /* Calculate the HASH for Encrypted CEK */
244 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, encr_cek, encr_cek_len,
245 encr_cek_hash, &encr_cek_hash_len);
246 DRM_TAPPS_LOG("encr_cek_hash = %s", encr_cek_hash);
248 /* Base64 Encode the Encrypted CEK */
249 len_enc = (encr_cek_len + 2) / 3 * 4;
250 isOk = DTappsB64Encode(encr_cek, encr_cek_len, b64_encr_cek, len_enc);
253 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
254 ret = TADC_GET_BASE64ENCODE_ERROR;
258 /* Base64 Encode the Hash of Encrypted CEK */
259 len_enc = (encr_cek_hash_len + 2) / 3 * 4;
260 isOk = DTappsB64Encode(encr_cek_hash, encr_cek_hash_len, b64_encr_cek_hash,
264 DRM_TAPPS_EXCEPTION("BASE64 Encoding failure!!!! ret = %d", isOk);
265 ret = TADC_GET_BASE64ENCODE_ERROR;
269 DRM_TAPPS_LOG("b64_encr_cek = %s, b64_encr_cek_hash = %s", b64_encr_cek,
272 DRM_TAPPS_LOG("CEK in Secure Storage to be implemented!!!");
275 DRM_TAPPS_EXCEPTION("t_RO.t_Content.CEK is null!!");
278 /* Calculate the Time of storage */
279 now = DTAPPS_TIME(NULL);
281 DTAPPS_GMTIME_THREAD_SAFE(&now, &time_gmt);
283 /* Format the time to be stored in the DB buffer - DATETIME format */
284 len = DTAPPS_SNPRINTF(
287 "%04d-%02d-%02dT%02d:%02d:%02dZ",
288 time_gmt.tm_year + 1900,
295 if ((len == -1) || (len >= (int)sizeof(time_buffer))) {
296 DRM_TAPPS_EXCEPTION("snprintf failed , len = %d, sizeof(time_buffer) = %d", len,
297 sizeof(time_buffer));
298 ret = TADC_MEMAlOC_ERROR;
302 DRM_TAPPS_LOG("time_buffer = %s", time_buffer);
303 DRM_TAPPS_LOG("Constraint_buffer = %s, Constraint_Hash = %s", db_buffer_enc,
306 // 2013/04/25 added for db update
307 isOk = DTapps_RIGHTS_SELECT_ONE((char *) t_RO.t_Content.CID, &row);
309 // if there is no rights in the db, insert into rights to db
311 DRM_TAPPS_LOG("Insert into dtapps2rights started....");
312 isOk = DTapps_RIGHTS_INSTALL((char *) name, time_buffer,
313 #ifdef DTAPPS_STORE_CEK_IN_DB
314 (char *) b64_encr_cek, (char *) b64_encr_cek_hash,
316 (char *) db_buffer_enc, (char *) hash_enc,
317 (char *) t_RO.t_Content.CID, FALSE);
320 DRM_TAPPS_EXCEPTION("DB Installation failure!!!! ret = %d", isOk);
321 ret = TADC_DB_INSTALL_ERROR;
325 DRM_TAPPS_LOG("DrmTdcInstallLicense Success!!!!!! ret = %d", ret);
327 // if there is same cid rights exist, update right to db
328 DRM_TAPPS_LOG("Update dtapps2rights started....");
329 isOk = DTapps_RIGHTS_INSTALL((char *) name, time_buffer,
330 #ifdef DTAPPS_STORE_CEK_IN_DB
331 (char *) b64_encr_cek, (char *) b64_encr_cek_hash,
333 (char *) db_buffer_enc, (char *) hash_enc,
334 (char *) t_RO.t_Content.CID, TRUE);
337 DRM_TAPPS_EXCEPTION("DB Update failure!!!! ret = %d", isOk);
338 ret = TADC_DB_INSTALL_ERROR;
342 DRM_TAPPS_LOG("DrmTdcInstallLicense Success!!!!!! ret = %d", ret);
345 // Test Code for get the plaintext ro
347 std::string tmpPath((char *)(t_RO.t_Content.CID));
350 FILE *fd = fopen(tmpPath.c_str(), "w+b");
355 fwrite(declicbuffer, 1, strlen(declicbuffer), fd);
357 DRM_TAPPS_LOG("Save decrypted RO success!, path = %s", tmpPath.c_str());
362 TADC_MEMFree_RO(&t_RO);
365 DTAPPS_FREE((unsigned char *)db_buffer_org);
368 DTAPPS_FREE(encr_cek);
371 DTappsFreeDeviceKey(&pDevKey);
376 int DTappsHasValidLicense(const char *szCid)
378 int const_buf_enclen = 0;
379 int hash_buf_enclen = 0;
380 int const_buf_declen = 0;
381 int hash_buf_declen = 0;
383 unsigned char *pDevKey = NULL;
384 unsigned int DevKeyLen = 0;
385 unsigned char const_buffer_dec[512] = {0, };
386 unsigned char hash_buffer_dec[64] = {0, };
387 unsigned char md[64] = {0, };
388 unsigned int md_len = 0;
390 DTAPPS_RIGHTS_ROW row;
393 int check_valid = TADC_LICENSE_VALID;
394 DTAPPS_CONSTRAINTS st_constaints = {0, };
396 check = DTapps_RIGHTS_SELECT_ONE(szCid, &row);
399 DRM_TAPPS_EXCEPTION("There is no RO in the DB. cid = %s", szCid);
400 check_valid = TADC_LICENSE_NO_LICENSE;
404 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen)) {
405 DRM_TAPPS_EXCEPTION("Error in DTAppsGetDeviceKey pDevKey = %s, DevKeyLen = %d",
407 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
411 /* BASE64 Decode the constraints buffer extracted from the DB */
412 const_buf_enclen = TAPPS_STRLEN(row.constraint_buffer);
413 const_buf_declen = const_buf_enclen / 4 * 3;
415 if (const_buf_enclen <= 0) {
416 DRM_TAPPS_EXCEPTION("There is no constaints buffer in the DB. cid = %s", szCid);
417 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
421 DRM_TAPPS_FRQ_LOG("const_buf_enclen = %d, const_buf_declen = %d",
422 const_buf_enclen, const_buf_declen);
424 (void)DTappsB64Decode((unsigned char *)row.constraint_buffer, const_buf_enclen,
425 const_buffer_dec, const_buf_declen);
427 if (const_buf_declen > (const_buf_enclen / 4 * 3)) {
428 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! const_buffer_dec = %s, "
429 "const_buf_declen = %d, (const_buf_enclen/4*3) = %d",
430 const_buffer_dec, const_buf_declen,
431 (const_buf_enclen / 4 * 3));
432 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
436 /* BASE64 Decode the hash buffer extracted from the DB */
437 DTAPPS_MEMSET(hash_buffer_dec, 0x00, sizeof(hash_buffer_dec));
438 DTAPPS_MEMSET(md, 0x00, sizeof(md));
440 hash_buf_enclen = TAPPS_STRLEN(row.constraint_hash);
441 hash_buf_declen = hash_buf_enclen / 4 * 3;
443 if (hash_buf_enclen <= 0) {
444 DRM_TAPPS_EXCEPTION("There is no constaints_hash buffer in the DB. cid = %s",
446 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
450 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen,
453 (void)DTappsB64Decode((unsigned char *)row.constraint_hash, hash_buf_enclen,
454 hash_buffer_dec, hash_buf_declen);
456 if (hash_buf_declen > (hash_buf_enclen / 4 * 3)) {
457 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! hash_buffer_dec = %s, "
458 "hash_buf_declen = %d, (hash_buf_enclen/4*3) = %d",
459 hash_buffer_dec, hash_buf_declen,
460 (hash_buf_enclen / 4 * 3));
461 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
465 // Calculate the hash using HMAC from the BASE64Decoded Constraint Buffers
466 // and check with the BASE64Decoded Hash buffers
467 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, const_buffer_dec, const_buf_declen,
470 if (DTAPPS_MEMCMP(md, hash_buffer_dec, hash_buf_declen) == 0) {
471 DRM_TAPPS_LOG("HASH matching!!! md = %s, hash_buffer_dec = %s, "
472 "hash_buf_declen = %d",
473 md, hash_buffer_dec, hash_buf_declen);
475 DRM_TAPPS_EXCEPTION("HASH not matching!!! md = %s, hash_buffer_dec = %s, "
476 "hash_buf_declen = %d",
477 md, hash_buffer_dec, hash_buf_declen);
478 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
482 /* Validate the constraints buffer */
483 DTAPPS_MEMCPY(&st_constaints, const_buffer_dec, sizeof(DTAPPS_CONSTRAINTS));
485 check_valid = DTappsValidateConstraints(&st_constaints, DTAPPS_VERIFY);
487 if (check_valid != TADC_LICENSE_VALID) {
488 DRM_TAPPS_LOG("Invalid Constraints for constraints_buffer = %s "
490 const_buffer_dec, check_valid);
491 // TODO: Implementation of Auto Deletion feature to delete the rights
492 // from the DB if the rights are expired!!!
495 DRM_TAPPS_LOG("Rights are Valid!!! Found atleast one Valid Rights..... "
496 "return with Success!! check_valid = %d",
503 DTappsFreeDeviceKey(&pDevKey);
506 if (check_valid != TADC_LICENSE_VALID) {
507 DRM_TAPPS_EXCEPTION("Constraints not Valid!!!! check_valid = %d", check_valid);
508 DRM_TAPPS_EXCEPTION("DrmTdcHasValidLicense Failed!!!");
511 DRM_TAPPS_LOG("Constraints are Valid!! check_valid = %d", check_valid);
512 return TADC_LICENSE_VALID;
516 int DTappsGetROInfo(const char *pszXML, T_RO *t_RO, unsigned char *name)
520 CXMLElement *pRoot, *pElement;
521 CPointerArray paChilds;
524 unsigned char *pbBuffer = NULL;
525 int len_enc = 0, len_dec = 0;
527 const char *pRoHeader = "<?xml version=\"1.0\"?>\n<TizenLicense>";
530 if (pszXML == NULL || t_RO == NULL || name == NULL) {
531 DRM_TAPPS_EXCEPTION("Parameters NULL!!! pszXML = %p, t_RO = %p", pszXML, t_RO);
535 if (memcmp(pszXML, pRoHeader, strlen(pRoHeader))) {
536 DRM_TAPPS_EXCEPTION("TADC_IF_MemCmp. pRoHeader[%s] Error Code = %x", pRoHeader,
537 TADC_XMLPARSER_ERROR);
541 DTAPPS_MEMSET(t_RO, 0, sizeof(T_RO));
543 nResult = oXMLFile.LoadFromStream((LPCTSTR)pszXML);
546 DRM_TAPPS_EXCEPTION("oXMLFile.LoadFromStream is failed\n");
552 pRoot = oXMLFile.GetRoot();
555 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
561 pRoot = oXMLFile.GetRoot();
564 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
569 paChilds.RemoveAll();
570 nResult = pRoot->Find(&paChilds, _T("LicenseInfo"), _T("uid"), NULL);
573 DRM_TAPPS_EXCEPTION("pRoot->Find is failed\n");
578 if (paChilds.GetCount() != 1) {
579 DRM_TAPPS_EXCEPTION("paChilds.GetCount() is failed\n");
584 pElement = (CXMLElement *) paChilds.Get(0);
585 pszValue = pElement->GetValue();
587 if (pszValue == NULL) {
588 DRM_TAPPS_EXCEPTION("pElement->GetValue() is failed\n");
593 length = TAPPS_STRLEN(pszValue);
595 if (length <= 0 || length > DTAPPS_NAME_SIZE) {
596 DRM_TAPPS_EXCEPTION("TAPPS_STRLEN failed(%d) - %s\n", length, pszValue);
601 memcpy(name, pszValue, length + 1);
602 DRM_TAPPS_LOG("name = %s", name);
605 pRoot = oXMLFile.GetRoot();
608 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
613 paChilds.RemoveAll();
614 nResult = pRoot->Find(&paChilds, _T("ContentInfo"), _T("cid"), NULL);
617 DRM_TAPPS_EXCEPTION("pRoot->Find is failed\n");
622 if (paChilds.GetCount() != 1) {
623 DRM_TAPPS_EXCEPTION("paChilds.GetCount() is failed\n");
628 pElement = (CXMLElement *)paChilds.Get(0);
629 pszValue = pElement->GetValue();
631 if (pszValue == NULL) {
632 DRM_TAPPS_EXCEPTION("pElement->GetValue() is failed\n");
637 length = TAPPS_STRLEN(pszValue);
639 if (length <= 0 || length > CID_SIZE) {
640 DRM_TAPPS_EXCEPTION("TAPPS_STRLEN is failed(%d) - %s\n", length, pszValue);
645 t_RO->t_Content.CID = (TADC_U8 *)DTAPPS_MALLOC(CID_SIZE + 1);
646 IF_TRUE_GOTO(t_RO->t_Content.CID == NULL, -2);
648 memset(t_RO->t_Content.CID, 0, CID_SIZE + 1);
649 memcpy(t_RO->t_Content.CID, pszValue, CID_SIZE + 1);
651 // Get KeyValue (CEK)
652 pRoot = oXMLFile.GetRoot();
653 IF_TRUE_GOTO(pRoot == NULL, ERROR_INVALID_DATA);
654 paChilds.RemoveAll();
655 nResult = pRoot->Find(&paChilds, _T("KeyInfo"), _T("CipherValue"), NULL);
657 IF_TRUE_GOTO(nResult != 0, ERROR_INVALID_DATA);
658 IF_TRUE_GOTO(paChilds.GetCount() != 1, ERROR_INVALID_DATA);
660 pElement = (CXMLElement *)paChilds.Get(0);
661 pszValue = pElement->GetValue();
662 IF_TRUE_GOTO(pszValue == NULL, -2);
664 len_enc = TAPPS_STRLEN(pszValue);
665 len_dec = len_enc / 4 * 3;
667 DRM_TAPPS_LOG("CEK raw = [%s], len_enc = [%d], len_dec = [%d]", pszValue,
671 pbBuffer = (unsigned char *)DTAPPS_MALLOC(len_dec + 1);
673 if (pbBuffer == NULL) {
674 DRM_TAPPS_EXCEPTION("Memory Allocation Error pbBuffer = %p", pbBuffer);
679 DTAPPS_MEMSET(pbBuffer, 0x00, len_dec + 1);
682 pbBuffer = Base64Decode(pszValue, &len_dec);
684 if (pbBuffer == NULL) {
685 DRM_TAPPS_EXCEPTION("Memory Allocation Error pbBuffer = %p", pbBuffer);
690 if (len_dec > (len_enc / 4 * 3)) {
691 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! pbBuffer=%s, len_dec=%d, "
693 pbBuffer, len_dec, (len_enc / 4 * 3));
698 if (len_dec != CEK_SIZE) {
699 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! CEK size=%d, len_dec=%d", CEK_SIZE,
705 DRM_TAPPS_LOG("Base64Decoded CEK pbBuffer=%s, len_dec=%d, (len_enc/4*3)=%d",
706 pbBuffer, len_dec, (len_enc / 4 * 3));
708 t_RO->t_Content.CEK = (TADC_U8 *)DTAPPS_MALLOC(CEK_SIZE + 1);
709 IF_TRUE_GOTO(t_RO->t_Content.CEK == NULL, -2);
710 DTAPPS_MEMSET(t_RO->t_Content.CEK, 0x00, CEK_SIZE + 1);
711 DTAPPS_MEMCPY(t_RO->t_Content.CEK, pbBuffer, CEK_SIZE);
712 DRM_TAPPS_SECURE_LOG("CEK t_RO->t_Content.CEK = %s", t_RO->t_Content.CEK);
715 pRoot = oXMLFile.GetRoot();
716 IF_TRUE_GOTO(pRoot == NULL, ERROR_INVALID_DATA);
718 paChilds.RemoveAll();
719 nResult = pRoot->Find(&paChilds, _T("DeviceInfo"), _T("DUID"), NULL);
721 IF_TRUE_GOTO(nResult != 0, ERROR_INVALID_DATA);
722 IF_TRUE_GOTO(paChilds.GetCount() != 1, ERROR_INVALID_DATA);
724 pElement = (CXMLElement *)paChilds.Get(0);
725 pszValue = pElement->GetValue();
726 IF_TRUE_GOTO(pszValue == NULL, -1);
727 length = TADC_IF_StrLen((char *)pszValue);
734 t_RO->PerFlag |= DUID_RULE;
735 t_RO->t_Permission.t_Individual.BindingType |= DUID_RULE;
736 t_RO->t_Permission.t_Individual.DUID = (TADC_U8 *)TADC_IF_Malloc(length + 1);
738 if (t_RO->t_Permission.t_Individual.DUID == NULL) {
739 DRM_TAPPS_EXCEPTION("TADC_IF_MemCmp Error Code = %x", TADC_MEMAlOC_ERROR);
744 TADC_IF_MemSet(t_RO->t_Permission.t_Individual.DUID, 0, length + 1);
745 TADC_IF_MemCpy((CHAR *)t_RO->t_Permission.t_Individual.DUID, pszValue, length + 1);
753 DTAPPS_FREE(pbBuffer);
757 DRM_TAPPS_EXCEPTION(" Error Code = %x", TADC_XMLPARSER_ERROR);
761 DRM_TAPPS_EXCEPTION(" Error Code = %x", TADC_MEMAlOC_ERROR);
767 BOOL DTappsGetCEK(const char *szCid, T_RO *t_RO)
769 int db_buf_enclen = 0;
770 int hash_buf_enclen = 0;
771 int db_buf_declen = 0;
772 int hash_buf_declen = 0;
773 DTAPPS_RIGHTS_ROW row;
776 unsigned char const_buffer_dec[512] = {0, };
777 unsigned char encr_cek[128] = {0, };
779 unsigned char hash_buffer[64] = {0, };
780 unsigned char md[64] = {0, };
781 unsigned int md_len = 0;
783 unsigned char *pDevKey = NULL;
784 unsigned int DevKeyLen = 0;
786 int check_valid = TADC_LICENSE_VALID;
787 DTAPPS_CONSTRAINTS st_constaints = {0, };
791 memset(&key, 0x00, sizeof(key));
793 if (NULL == szCid || NULL == t_RO) {
794 DRM_TAPPS_EXCEPTION("Null Parameters!! szCid = %p, t_RO = %p", szCid, t_RO);
798 check = DTapps_RIGHTS_SELECT_ONE(szCid, &row);
801 DRM_TAPPS_EXCEPTION("There is no RO in the DB. cid=%s", szCid);
802 check_valid = TADC_LICENSE_NO_LICENSE;
806 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen)) {
807 DRM_TAPPS_EXCEPTION("error in DTappsGetDeviceKey pDevKey = %s, DevKeyLen = %d",
809 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
813 DRM_TAPPS_LOG("DTappsGetDeviceKey pDevKey = %s, DevKeyLen = %d", pDevKey,
816 check_valid = TADC_LICENSE_VALID;
818 /* BASE64 Decode the constraints buffer extracted from the DB */
819 db_buf_enclen = TAPPS_STRLEN(row.constraint_buffer);
820 db_buf_declen = db_buf_enclen / 4 * 3;
822 if (db_buf_enclen <= 0) {
823 DRM_TAPPS_EXCEPTION("There is no constaints buffer in the DB. cid = %s", szCid);
824 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
828 DRM_TAPPS_FRQ_LOG("db_buf_enclen = %d, db_buf_declen = %d", db_buf_enclen,
831 (void)DTappsB64Decode((unsigned char *)row.constraint_buffer, db_buf_enclen,
832 const_buffer_dec, db_buf_declen);
834 if (db_buf_declen > (db_buf_enclen / 4 * 3)) {
835 DRM_TAPPS_EXCEPTION("BASE64 Decode error! const_buffer_dec=%s, "
836 "db_buf_declen=%d, (db_buf_enclen/4*3)=%d",
837 const_buffer_dec, db_buf_declen, (db_buf_enclen / 4 * 3));
838 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
842 /* BASE64 Decode the hash buffer extracted from the DB */
843 DTAPPS_MEMSET(hash_buffer, 0x00, sizeof(hash_buffer));
844 DTAPPS_MEMSET(md, 0x00, sizeof(md));
846 hash_buf_enclen = TAPPS_STRLEN(row.constraint_hash);
847 hash_buf_declen = hash_buf_enclen / 4 * 3;
849 if (hash_buf_enclen <= 0) {
850 DRM_TAPPS_EXCEPTION("There is no hash buffer in the DB. cid = %s", szCid);
851 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
855 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen,
858 (void)DTappsB64Decode((unsigned char *)row.constraint_hash, hash_buf_enclen,
859 hash_buffer, hash_buf_declen);
861 if (hash_buf_declen > (hash_buf_enclen / 4 * 3)) {
862 DRM_TAPPS_EXCEPTION("BASE64 Decode error! hash_buffer_dec=%s, "
863 "hash_buf_declen=%d, (hash_buf_enclen/4*3)=%d",
864 hash_buffer, hash_buf_declen, (hash_buf_enclen / 4 * 3));
865 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
869 // Calculate the hash using HMAC from the BASE64Decoded Constraint Buffers
870 // and check with the BASE64Decoded Hash buffers
871 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, const_buffer_dec, db_buf_declen, md,
874 if (DTAPPS_MEMCMP(md, hash_buffer, hash_buf_declen) == 0) {
875 DRM_TAPPS_LOG("HASH for constraint buffer matching! md=%s, "
876 "hash_buffer_dec=%s, hash_buf_declen=%d",
877 md, hash_buffer, hash_buf_declen);
879 DRM_TAPPS_EXCEPTION("HASH for constraint buffer not matching! md=%s, "
880 "hash_buffer_dec=%s, hash_buf_declen=%d",
881 md, hash_buffer, hash_buf_declen);
882 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
886 /* Validate the constraints buffer */
887 DTAPPS_MEMCPY(&st_constaints, const_buffer_dec, sizeof(DTAPPS_CONSTRAINTS));
889 check_valid = DTappsValidateConstraints(&st_constaints, DTAPPS_VERIFY);
891 if (check_valid != TADC_LICENSE_VALID) {
892 DRM_TAPPS_LOG("Invalid Constraints for constraints_buffer=%s, check_valid=%d",
893 const_buffer_dec, check_valid);
894 // TODO: Implementation of Auto Deletion feature to delete the rights
895 // from the DB if the rights are expired!!!
898 DRM_TAPPS_LOG("Rights are Valid! check_valid = %d", check_valid);
900 // Constraints valid - Extract CEK and fill the t_RO structure with CEK, DUID
901 // BASE64 Decode the CEK buffer extracted from the DB
902 db_buf_enclen = TAPPS_STRLEN(row.cek);
903 db_buf_declen = db_buf_enclen / 4 * 3;
905 if (db_buf_enclen <= 0) {
906 DRM_TAPPS_EXCEPTION("There is no CEK in the DB. cid = %s", szCid);
907 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
911 DRM_TAPPS_FRQ_LOG("db_buf_enclen = %d, db_buf_declen = %d", db_buf_enclen,
916 (void)DTappsB64Decode((unsigned char *)row.cek, db_buf_enclen, encr_cek,
918 db_buf_declen = cek_declen;
920 if (cek_declen > (db_buf_enclen / 4 * 3)) {
921 DRM_TAPPS_EXCEPTION("BASE64 Decode error! encr_cek=%s, cek_declen=%d, "
922 "(db_buf_enclen/4*3)=%d",
923 encr_cek, cek_declen, (db_buf_enclen / 4 * 3));
924 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
928 DRM_TAPPS_LOG("BASE64 encr_cek=%s, cek_declen=%d, db_buf_declen=%d, "
929 "(db_buf_enclen/4*3)=%d",
930 encr_cek, cek_declen, db_buf_declen, (db_buf_enclen / 4 * 3));
932 /* BASE64 Decode the hash buffer extracted from the DB */
933 DTAPPS_MEMSET(hash_buffer, 0x00, sizeof(hash_buffer));
934 DTAPPS_MEMSET(md, 0x00, sizeof(md));
936 hash_buf_enclen = TAPPS_STRLEN(row.cek_hash);
937 hash_buf_declen = hash_buf_enclen / 4 * 3;
939 if (hash_buf_enclen <= 0) {
940 DRM_TAPPS_EXCEPTION("There is no CEK_hash buffer in the DB. cid = %s",
942 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
946 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen,
949 (void)DTappsB64Decode((unsigned char *)row.cek_hash, hash_buf_enclen,
950 hash_buffer, hash_buf_declen);
952 if (hash_buf_declen > (hash_buf_enclen / 4 * 3)) {
953 DRM_TAPPS_EXCEPTION("BASE64 Decode error! hash_buffer_dec=%s, "
954 "hash_buf_declen=%d, (hash_buf_enclen/4*3)=%d",
955 hash_buffer, hash_buf_declen,
956 (hash_buf_enclen / 4 * 3));
957 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
961 // Calculate the hash using HMAC from the BASE64Decoded Encrypted CEK Buffer
962 // and check with the BASE64Decoded Hash buffer
963 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, encr_cek, db_buf_declen, md,
966 if (DTAPPS_MEMCMP(md, hash_buffer, hash_buf_declen) == 0) {
967 DRM_TAPPS_LOG("HASH for Encrypted CEK buffer matching! md=%s, "
968 "hash_buffer_dec=%s, hash_buf_declen=%d",
969 md, hash_buffer, hash_buf_declen);
971 DRM_TAPPS_EXCEPTION("HASH for Encrypted CEK buffer not matching! "
972 "md=%s, hash_buffer_dec=%s, hash_buf_declen=%d",
973 md, hash_buffer, hash_buf_declen);
974 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
978 /* Allocate memory for CEK */
979 t_RO->t_Content.CEK = (unsigned char *)DTAPPS_MALLOC(CEK_SIZE + 1);
981 if (NULL == t_RO->t_Content.CEK) {
982 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! t_RO->t_Content.CEK = %p",
983 t_RO->t_Content.CEK);
984 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
988 DTAPPS_MEMSET(t_RO->t_Content.CEK, 0x00, CEK_SIZE + 1);
990 /* Decrypt CEK and update t_RO structure */
991 if (DTAPPS_AES_SET_DECR_KEY(pDevKey, 128, &key)) {
992 DRM_TAPPS_EXCEPTION("AES_set_decrypt_key failed!!");
993 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
997 (void)DTAPPS_AES_UNWRAP_KEY(&key, NULL, t_RO->t_Content.CEK, encr_cek,
999 DRM_TAPPS_LOG("DTAPPS_AES_UNWRAP_KEY success!!");
1001 /* Store DUID in t_RO */
1002 if (st_constaints.DUID[0] != '\0') {
1003 t_RO -> t_Permission.t_Individual.DUID = (unsigned char *)DTAPPS_MALLOC(
1006 if (NULL == t_RO -> t_Permission.t_Individual.DUID) {
1007 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! "
1008 "t_RO->t_Permission.t_Individual.DUID = %p",
1009 t_RO -> t_Permission.t_Individual.DUID);
1010 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
1014 DTAPPS_MEMSET(t_RO -> t_Permission.t_Individual.DUID, 0x00, DUID_SIZE + 1);
1015 t_RO->PerFlag |= DUID_RULE;
1016 t_RO->t_Permission.t_Individual.BindingType |= DUID_RULE;
1017 DTAPPS_MEMCPY(t_RO -> t_Permission.t_Individual.DUID, st_constaints.DUID,
1025 DTappsFreeDeviceKey(&pDevKey);
1028 if (check_valid != TADC_LICENSE_VALID) {
1029 DRM_TAPPS_EXCEPTION("DTappsGetCEK FAILED!!!, check_valid = %d", check_valid);
1032 /* All fine... Allocate memory for CID and fill the value */
1033 if ((t_RO != NULL) && (szCid != NULL)) {
1034 t_RO -> t_Content.CID = (unsigned char *) DTAPPS_MALLOC(CID_SIZE + 1);
1036 if (NULL == t_RO -> t_Content.CID) {
1037 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! "
1038 "t_RO->t_Content.CID = %p",
1039 t_RO -> t_Content.CID);
1040 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
1044 DTAPPS_MEMSET(t_RO -> t_Content.CID, 0x00, CID_SIZE + 1);
1045 DTAPPS_MEMCPY(t_RO -> t_Content.CID, szCid, CID_SIZE);
1046 DRM_TAPPS_LOG("DTappsGetCEK SUCCESS!!!, check_valid = %d", check_valid);
1053 BOOL DTapps_RIGHTS_INSTALL(const char *name,
1055 #ifdef DTAPPS_STORE_CEK_IN_DB
1057 const char *cek_hash,
1059 const char *constraint_buffer,
1060 const char *constraint_hash,
1065 const char *query = NULL;
1066 sqlite3_stmt *pstmt = NULL;
1067 unsigned int dIdx = 0;
1068 BOOL ret_value = FALSE;
1070 DRM_TAPPS_LOG("Open DB......");
1071 ret_value = DTappsDBOpen(pDb, __func__);
1073 if (ret_value != TRUE) {
1074 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
1078 if (isUpdate == FALSE) {
1079 query = "INSERT INTO dtapps2rights (name, time_t, "
1080 #ifdef DTAPPS_STORE_CEK_IN_DB
1083 " constraint_buffer, constraint_hash, cid) "
1085 #ifdef DTAPPS_STORE_CEK_IN_DB
1090 query = "UPDATE dtapps2rights SET name=?, time_t=?,"
1091 #ifdef DTAPPS_STORE_CEK_IN_DB
1092 " cek=?, cek_hash=?, "
1094 " constraint_buffer=?, constraint_hash=? "
1098 DRM_TAPPS_LOG("Prepare Statement........");
1099 pstmt = (sqlite3_stmt *) DTappsStmtPrepare(pDb, query);
1101 if (pstmt == NULL) {
1102 DRM_TAPPS_EXCEPTION("Prepare Statement failed. query=%s", query);
1106 DRM_TAPPS_LOG("Binding Parameters........");
1107 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1108 (void *)name, strlen(name));
1110 if (ret_value != TRUE) {
1111 DRM_TAPPS_EXCEPTION("Binding Parameter(name=%s) failed. ret_value = %d", name,
1116 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1117 (void *)time, strlen(time));
1119 if (ret_value != TRUE) {
1120 DRM_TAPPS_EXCEPTION("Binding Parameter(time=%s) failed. ret_value = %d", time,
1125 #ifdef DTAPPS_STORE_CEK_IN_DB
1126 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1127 (void *)cek, strlen(cek));
1129 if (ret_value != TRUE) {
1130 DRM_TAPPS_EXCEPTION("Binding Parameter(cek=%s) failed. ret_value = %d", cek,
1135 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1136 (void *)cek_hash, strlen(cek_hash));
1138 if (ret_value != TRUE) {
1139 DRM_TAPPS_EXCEPTION("Binding Parameter(cek_hash=%s) failed. ret_value = %d",
1140 cek_hash, ret_value);
1146 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1147 (void *)constraint_buffer, strlen(constraint_buffer));
1149 if (ret_value != TRUE) {
1150 DRM_TAPPS_EXCEPTION("Binding Parameter(constraint_buffer=%s) failed. "
1152 constraint_buffer, ret_value);
1156 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1157 (void *)constraint_hash, strlen(constraint_hash));
1159 if (ret_value != TRUE) {
1160 DRM_TAPPS_EXCEPTION("Binding Parameter(constraint_hash=%s) failed. "
1162 constraint_hash, ret_value);
1166 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1167 (void *)cid, strlen(cid));
1169 if (ret_value != TRUE) {
1170 DRM_TAPPS_EXCEPTION("Binding Parameter(cid=%s) failed. ret_value = %d", cid,
1175 DRM_TAPPS_LOG("Begin Transaction........");
1176 ret_value = DTappsDBBeginImmedTrans(__func__);
1178 if (ret_value != TRUE) {
1179 DRM_TAPPS_EXCEPTION("DB Begin Transaction ret_value = %d", ret_value);
1183 DRM_TAPPS_LOG("Execute SQL to Insert Contents into Table........");
1184 ret_value = DTappsStmtExecute(pstmt);
1186 if (ret_value != TRUE) {
1187 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! ret_value = %d", ret_value);
1191 DRM_TAPPS_LOG("Commit DB........");
1192 ret_value = DTappsDBCommit(__func__);
1194 if (ret_value != TRUE) {
1195 DRM_TAPPS_EXCEPTION("Commit DB Failed!! ret_value = %d", ret_value);
1199 DRM_TAPPS_LOG("Release Statement........");
1200 ret_value = DTappsStmtRelease(pstmt);
1202 if (ret_value != TRUE) {
1203 DRM_TAPPS_EXCEPTION("Release Statement Failed!! ret_value = %d", ret_value);
1208 DRM_TAPPS_LOG("Close DB........");
1209 ret_value = DTappsDBClose(__func__);
1211 if (ret_value != TRUE) {
1212 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
1216 DRM_TAPPS_LOG("Install DB Operartion Successful!!!");
1222 DTappsStmtRelease(pstmt);
1224 ret_value = DTappsDBRollback(__func__);
1226 if (ret_value != TRUE) {
1227 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d", ret_value);
1230 ret_value = DTappsDBClose(__func__);
1232 if (ret_value != TRUE) {
1233 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
1239 BOOL DTapps_RIGHTS_SELECT_ONE(const char *cid, DTAPPS_RIGHTS_ROW *row)
1242 const char *query = NULL;
1243 sqlite3_stmt *pstmt = NULL;
1244 unsigned int dIdx = 0;
1245 BOOL ret_value = FALSE;
1247 DTAPPS_RIGHTS_ROW *result = row;
1249 char *name, *time, *constraint_buffer, *constraint_hash;
1250 #ifdef DTAPPS_STORE_CEK_IN_DB
1251 char *cek, *cek_hash;
1254 DRM_TAPPS_LOG("Open DB......");
1255 ret_value = DTappsDBOpen(pDb, __func__);
1257 if (ret_value != TRUE) {
1258 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
1262 query = "SELECT r_id, name, time_t, "
1263 #ifdef DTAPPS_STORE_CEK_IN_DB
1266 " constraint_buffer, constraint_hash "
1267 " FROM dtapps2rights"
1268 " WHERE cid=? ORDER BY r_id desc limit 1;";
1271 DRM_TAPPS_LOG("Begin Transaction........");
1272 ret_value = DTappsDBBeginImmedTrans(__func__);
1274 if (ret_value != TRUE) {
1275 DRM_TAPPS_EXCEPTION("DB Begin Transaction Failed!! ret_value = %d", ret_value);
1279 DRM_TAPPS_LOG("Prepare Statement........");
1280 db_ret = sqlite3_prepare((sqlite3 *)pDb, query, -1, &pstmt, NULL);
1282 if (pstmt == NULL) {
1283 DRM_TAPPS_EXCEPTION("Prepare Statement failed. query=%s, error=%s", query,
1284 sqlite3_errmsg((sqlite3 *)pDb));
1288 DRM_TAPPS_LOG("Binding Parameters........");
1289 db_ret = sqlite3_bind_text(pstmt, ++dIdx, cid, strlen(cid), SQLITE_TRANSIENT);
1291 if (db_ret != SQLITE_OK) {
1292 DRM_TAPPS_EXCEPTION("Binding Parameter(cid=%s) failed. "
1293 "ret_value = %d, query=%s",
1294 cid, db_ret, query);
1298 DRM_TAPPS_LOG("Execute SQL to Select Contents from Table........");
1299 db_ret = sqlite3_step(pstmt);
1301 if (db_ret == SQLITE_OK || db_ret == SQLITE_DONE) {
1302 DRM_TAPPS_FRQ_LOG("Executed SQL Select Query. But no row was returned");
1304 } else if (db_ret != SQLITE_ROW) {
1305 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! "
1306 "ret_value = %d, query=%s, error=%s",
1307 db_ret, query, sqlite3_errmsg((sqlite3 *)pDb));
1311 memset(result, 0, sizeof(DTAPPS_RIGHTS_ROW));
1314 result->r_id = sqlite3_column_int(pstmt, dIdx++);
1315 DRM_TAPPS_LOG("....SEELECTED : r_id = %d", result->r_id);
1317 name = (char *) sqlite3_column_text(pstmt, dIdx++);
1320 memcpy(result->name, name, strlen(name) + 1);
1322 DRM_TAPPS_LOG("....SEELECTED : name = %s", result->name);
1324 time = (char *) sqlite3_column_text(pstmt, dIdx++);
1327 memcpy(result->time, time, strlen(time) + 1);
1329 DRM_TAPPS_LOG("....SEELECTED : time = %s", result->time);
1331 #ifdef DTAPPS_STORE_CEK_IN_DB
1332 cek = (char *) sqlite3_column_text(pstmt, dIdx++);
1335 memcpy(result->cek, cek, strlen(cek) + 1);
1337 DRM_TAPPS_LOG("....SEELECTED : cek = %s", result->cek);
1339 cek_hash = (char *) sqlite3_column_text(pstmt, dIdx++);
1341 if (cek_hash != NULL)
1342 memcpy(result->cek_hash, cek_hash, strlen(cek_hash) + 1);
1344 DRM_TAPPS_LOG("....SEELECTED : cek_hash = %s", result->cek_hash);
1347 constraint_buffer = (char *) sqlite3_column_text(pstmt, dIdx++);
1349 if (constraint_buffer != NULL)
1350 memcpy(result->constraint_buffer, constraint_buffer, strlen(constraint_buffer) + 1);
1352 DRM_TAPPS_LOG("....SEELECTED : constraint_buffer = %s",
1353 result->constraint_buffer);
1355 constraint_hash = (char *) sqlite3_column_text(pstmt, dIdx++);
1357 if (constraint_hash != NULL)
1358 memcpy(result->constraint_hash, constraint_hash, strlen(constraint_hash) + 1);
1360 DRM_TAPPS_LOG("....SEELECTED : constraint_hash = %s", result->constraint_hash);
1362 memcpy(result->cid, cid, strlen(cid) + 1);
1363 DRM_TAPPS_LOG("....SEELECTED : cid = %s", result->cid);
1365 DRM_TAPPS_LOG("Release Statement........");
1366 ret_value = DTappsStmtRelease(pstmt);
1368 if (ret_value != TRUE) {
1369 DRM_TAPPS_EXCEPTION("Release Statement Failed!! ret_value = %d", ret_value);
1374 DRM_TAPPS_LOG("Close DB........");
1375 ret_value = DTappsDBClose(__func__);
1377 if (ret_value != TRUE) {
1378 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
1382 DRM_TAPPS_LOG("Select a DB row Operartion Successful!!!");
1388 DTappsStmtRelease(pstmt);
1390 ret_value = DTappsDBClose(__func__);
1392 if (ret_value != TRUE) {
1393 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);