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));
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);
373 int DTappsHasValidLicense(const char *szCid)
375 int const_buf_enclen = 0;
376 int hash_buf_enclen = 0;
377 int const_buf_declen = 0;
378 int hash_buf_declen = 0;
380 unsigned char *pDevKey = NULL;
381 unsigned int DevKeyLen = 0;
382 unsigned char const_buffer_dec[512] = {0, };
383 unsigned char hash_buffer_dec[64] = {0, };
384 unsigned char md[64] = {0, };
385 unsigned int md_len = 0;
387 DTAPPS_RIGHTS_ROW row;
390 int check_valid = TADC_LICENSE_VALID;
391 DTAPPS_CONSTRAINTS st_constaints = {0, };
393 check = DTapps_RIGHTS_SELECT_ONE(szCid, &row);
396 DRM_TAPPS_EXCEPTION("There is no RO in the DB. cid = %s", szCid);
397 check_valid = TADC_LICENSE_NO_LICENSE;
401 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen)) {
402 DRM_TAPPS_EXCEPTION("Error in DTAppsGetDeviceKey pDevKey = %s, DevKeyLen = %d",
404 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
408 /* BASE64 Decode the constraints buffer extracted from the DB */
409 const_buf_enclen = TAPPS_STRLEN(row.constraint_buffer);
410 const_buf_declen = const_buf_enclen / 4 * 3;
412 if (const_buf_enclen <= 0) {
413 DRM_TAPPS_EXCEPTION("There is no constaints buffer in the DB. cid = %s", szCid);
414 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
418 DRM_TAPPS_FRQ_LOG("const_buf_enclen = %d, const_buf_declen = %d",
419 const_buf_enclen, const_buf_declen);
421 (void)DTappsB64Decode((unsigned char *)row.constraint_buffer, const_buf_enclen,
422 const_buffer_dec, const_buf_declen);
424 if (const_buf_declen > (const_buf_enclen / 4 * 3)) {
425 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! const_buffer_dec = %s, "
426 "const_buf_declen = %d, (const_buf_enclen/4*3) = %d",
427 const_buffer_dec, const_buf_declen,
428 (const_buf_enclen / 4 * 3));
429 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
433 /* BASE64 Decode the hash buffer extracted from the DB */
434 DTAPPS_MEMSET(hash_buffer_dec, 0x00, sizeof(hash_buffer_dec));
435 DTAPPS_MEMSET(md, 0x00, sizeof(md));
437 hash_buf_enclen = TAPPS_STRLEN(row.constraint_hash);
438 hash_buf_declen = hash_buf_enclen / 4 * 3;
440 if (hash_buf_enclen <= 0) {
441 DRM_TAPPS_EXCEPTION("There is no constaints_hash buffer in the DB. cid = %s",
443 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
447 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen,
450 (void)DTappsB64Decode((unsigned char *)row.constraint_hash, hash_buf_enclen,
451 hash_buffer_dec, hash_buf_declen);
453 if (hash_buf_declen > (hash_buf_enclen / 4 * 3)) {
454 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! hash_buffer_dec = %s, "
455 "hash_buf_declen = %d, (hash_buf_enclen/4*3) = %d",
456 hash_buffer_dec, hash_buf_declen,
457 (hash_buf_enclen / 4 * 3));
458 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
462 // Calculate the hash using HMAC from the BASE64Decoded Constraint Buffers
463 // and check with the BASE64Decoded Hash buffers
464 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, const_buffer_dec, const_buf_declen,
467 if (DTAPPS_MEMCMP(md, hash_buffer_dec, hash_buf_declen) == 0) {
468 DRM_TAPPS_LOG("HASH matching!!! md = %s, hash_buffer_dec = %s, "
469 "hash_buf_declen = %d",
470 md, hash_buffer_dec, hash_buf_declen);
472 DRM_TAPPS_EXCEPTION("HASH not matching!!! md = %s, hash_buffer_dec = %s, "
473 "hash_buf_declen = %d",
474 md, hash_buffer_dec, hash_buf_declen);
475 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
479 /* Validate the constraints buffer */
480 DTAPPS_MEMCPY(&st_constaints, const_buffer_dec, sizeof(DTAPPS_CONSTRAINTS));
482 check_valid = DTappsValidateConstraints(&st_constaints, DTAPPS_VERIFY);
484 if (check_valid != TADC_LICENSE_VALID) {
485 DRM_TAPPS_LOG("Invalid Constraints for constraints_buffer = %s "
487 const_buffer_dec, check_valid);
488 // TODO: Implementation of Auto Deletion feature to delete the rights
489 // from the DB if the rights are expired!!!
492 DRM_TAPPS_LOG("Rights are Valid!!! Found atleast one Valid Rights..... "
493 "return with Success!! check_valid = %d",
500 DTappsFreeDeviceKey(&pDevKey);
503 if (check_valid != TADC_LICENSE_VALID) {
504 DRM_TAPPS_EXCEPTION("Constraints not Valid!!!! check_valid = %d", check_valid);
505 DRM_TAPPS_EXCEPTION("DrmTdcHasValidLicense Failed!!!");
508 DRM_TAPPS_LOG("Constraints are Valid!! check_valid = %d", check_valid);
509 return TADC_LICENSE_VALID;
513 int DTappsGetROInfo(const char *pszXML, T_RO *t_RO, unsigned char *name)
517 CXMLElement *pRoot, *pElement;
518 CPointerArray paChilds;
521 unsigned char *pbBuffer = NULL;
522 int len_enc = 0, len_dec = 0;
524 const char *pRoHeader = "<?xml version=\"1.0\"?>\n<TizenLicense>";
527 if (pszXML == NULL || t_RO == NULL || name == NULL) {
528 DRM_TAPPS_EXCEPTION("Parameters NULL!!! pszXML = %p, t_RO = %p", pszXML, t_RO);
532 if (memcmp(pszXML, pRoHeader, strlen(pRoHeader))) {
533 DRM_TAPPS_EXCEPTION("TADC_IF_MemCmp. pRoHeader[%s] Error Code = %x", pRoHeader,
534 TADC_XMLPARSER_ERROR);
538 DTAPPS_MEMSET(t_RO, 0, sizeof(T_RO));
540 nResult = oXMLFile.LoadFromStream((LPCTSTR)pszXML);
543 DRM_TAPPS_EXCEPTION("oXMLFile.LoadFromStream is failed\n");
549 pRoot = oXMLFile.GetRoot();
552 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
558 pRoot = oXMLFile.GetRoot();
561 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
566 paChilds.RemoveAll();
567 nResult = pRoot->Find(&paChilds, _T("LicenseInfo"), _T("uid"), NULL);
570 DRM_TAPPS_EXCEPTION("pRoot->Find is failed\n");
575 if (paChilds.GetCount() != 1) {
576 DRM_TAPPS_EXCEPTION("paChilds.GetCount() is failed\n");
581 pElement = (CXMLElement *) paChilds.Get(0);
582 pszValue = pElement->GetValue();
584 if (pszValue == NULL) {
585 DRM_TAPPS_EXCEPTION("pElement->GetValue() is failed\n");
590 length = TAPPS_STRLEN(pszValue);
592 if (length <= 0 || length > DTAPPS_NAME_SIZE) {
593 DRM_TAPPS_EXCEPTION("TAPPS_STRLEN failed(%d) - %s\n", length, pszValue);
598 memcpy(name, pszValue, length + 1);
599 DRM_TAPPS_LOG("name = %s", name);
602 pRoot = oXMLFile.GetRoot();
605 DRM_TAPPS_EXCEPTION("oXMLFile.GetRoot is failed\n");
610 paChilds.RemoveAll();
611 nResult = pRoot->Find(&paChilds, _T("ContentInfo"), _T("cid"), NULL);
614 DRM_TAPPS_EXCEPTION("pRoot->Find is failed\n");
619 if (paChilds.GetCount() != 1) {
620 DRM_TAPPS_EXCEPTION("paChilds.GetCount() is failed\n");
625 pElement = (CXMLElement *)paChilds.Get(0);
626 pszValue = pElement->GetValue();
628 if (pszValue == NULL) {
629 DRM_TAPPS_EXCEPTION("pElement->GetValue() is failed\n");
634 length = TAPPS_STRLEN(pszValue);
636 if (length <= 0 || length > CID_SIZE) {
637 DRM_TAPPS_EXCEPTION("TAPPS_STRLEN is failed(%d) - %s\n", length, pszValue);
642 t_RO->t_Content.CID = (TADC_U8 *)DTAPPS_MALLOC(CID_SIZE + 1);
643 IF_TRUE_GOTO(t_RO->t_Content.CID == NULL, -2);
645 memset(t_RO->t_Content.CID, 0, CID_SIZE + 1);
646 memcpy(t_RO->t_Content.CID, pszValue, CID_SIZE + 1);
648 // Get KeyValue (CEK)
649 pRoot = oXMLFile.GetRoot();
650 IF_TRUE_GOTO(pRoot == NULL, ERROR_INVALID_DATA);
651 paChilds.RemoveAll();
652 nResult = pRoot->Find(&paChilds, _T("KeyInfo"), _T("CipherValue"), NULL);
654 IF_TRUE_GOTO(nResult != 0, ERROR_INVALID_DATA);
655 IF_TRUE_GOTO(paChilds.GetCount() != 1, ERROR_INVALID_DATA);
657 pElement = (CXMLElement *)paChilds.Get(0);
658 pszValue = pElement->GetValue();
659 IF_TRUE_GOTO(pszValue == NULL, -2);
661 len_enc = TAPPS_STRLEN(pszValue);
662 len_dec = len_enc / 4 * 3;
664 DRM_TAPPS_LOG("CEK raw = [%s], len_enc = [%d], len_dec = [%d]", pszValue,
668 pbBuffer = (unsigned char *)DTAPPS_MALLOC(len_dec + 1);
670 if (pbBuffer == NULL) {
671 DRM_TAPPS_EXCEPTION("Memory Allocation Error pbBuffer = %p", pbBuffer);
676 DTAPPS_MEMSET(pbBuffer, 0x00, len_dec + 1);
679 pbBuffer = Base64Decode(pszValue, &len_dec);
681 if (pbBuffer == NULL) {
682 DRM_TAPPS_EXCEPTION("Memory Allocation Error pbBuffer = %p", pbBuffer);
687 if (len_dec > (len_enc / 4 * 3)) {
688 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! pbBuffer=%s, len_dec=%d, "
690 pbBuffer, len_dec, (len_enc / 4 * 3));
695 if (len_dec != CEK_SIZE) {
696 DRM_TAPPS_EXCEPTION("BASE64 Decode error !!! CEK size=%d, len_dec=%d", CEK_SIZE,
702 DRM_TAPPS_LOG("Base64Decoded CEK pbBuffer=%s, len_dec=%d, (len_enc/4*3)=%d",
703 pbBuffer, len_dec, (len_enc / 4 * 3));
705 t_RO->t_Content.CEK = (TADC_U8 *)DTAPPS_MALLOC(CEK_SIZE + 1);
706 IF_TRUE_GOTO(t_RO->t_Content.CEK == NULL, -2);
707 DTAPPS_MEMSET(t_RO->t_Content.CEK, 0x00, CEK_SIZE + 1);
708 DTAPPS_MEMCPY(t_RO->t_Content.CEK, pbBuffer, CEK_SIZE);
709 DRM_TAPPS_SECURE_LOG("CEK t_RO->t_Content.CEK = %s", t_RO->t_Content.CEK);
712 pRoot = oXMLFile.GetRoot();
713 IF_TRUE_GOTO(pRoot == NULL, ERROR_INVALID_DATA);
715 paChilds.RemoveAll();
716 nResult = pRoot->Find(&paChilds, _T("DeviceInfo"), _T("DUID"), NULL);
718 IF_TRUE_GOTO(nResult != 0, ERROR_INVALID_DATA);
719 IF_TRUE_GOTO(paChilds.GetCount() != 1, ERROR_INVALID_DATA);
721 pElement = (CXMLElement *)paChilds.Get(0);
722 pszValue = pElement->GetValue();
723 IF_TRUE_GOTO(pszValue == NULL, -1);
724 length = TADC_IF_StrLen((char *)pszValue);
731 t_RO->PerFlag |= DUID_RULE;
732 t_RO->t_Permission.t_Individual.BindingType |= DUID_RULE;
733 t_RO->t_Permission.t_Individual.DUID = (TADC_U8 *)TADC_IF_Malloc(length + 1);
735 if (t_RO->t_Permission.t_Individual.DUID == NULL) {
736 DRM_TAPPS_EXCEPTION("TADC_IF_MemCmp Error Code = %x", TADC_MEMAlOC_ERROR);
741 TADC_IF_MemSet(t_RO->t_Permission.t_Individual.DUID, 0, length + 1);
742 TADC_IF_MemCpy((CHAR *)t_RO->t_Permission.t_Individual.DUID, pszValue, length);
750 DTAPPS_FREE(pbBuffer);
754 DRM_TAPPS_EXCEPTION(" Error Code = %x", TADC_XMLPARSER_ERROR);
758 DRM_TAPPS_EXCEPTION(" Error Code = %x", TADC_MEMAlOC_ERROR);
764 BOOL DTappsGetCEK(const char *szCid, T_RO *t_RO)
766 int db_buf_enclen = 0;
767 int hash_buf_enclen = 0;
768 int db_buf_declen = 0;
769 int hash_buf_declen = 0;
770 DTAPPS_RIGHTS_ROW row;
773 unsigned char const_buffer_dec[512] = {0, };
774 unsigned char encr_cek[128] = {0, };
776 unsigned char hash_buffer[64] = {0, };
777 unsigned char md[64] = {0, };
778 unsigned int md_len = 0;
780 unsigned char *pDevKey = NULL;
781 unsigned int DevKeyLen = 0;
783 int check_valid = TADC_LICENSE_VALID;
784 DTAPPS_CONSTRAINTS st_constaints = {0, };
788 memset(&key, 0x00, sizeof(key));
790 if (NULL == szCid || NULL == t_RO) {
791 DRM_TAPPS_EXCEPTION("Null Parameters!! szCid = %p, t_RO = %p", szCid, t_RO);
795 check = DTapps_RIGHTS_SELECT_ONE(szCid, &row);
798 DRM_TAPPS_EXCEPTION("There is no RO in the DB. cid=%s", szCid);
799 check_valid = TADC_LICENSE_NO_LICENSE;
803 if (0 == DTappsGetDeviceKey(&pDevKey, &DevKeyLen)) {
804 DRM_TAPPS_EXCEPTION("error in DTappsGetDeviceKey pDevKey = %s, DevKeyLen = %d",
806 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
810 DRM_TAPPS_LOG("DTappsGetDeviceKey pDevKey = %s, DevKeyLen = %d", pDevKey,
813 check_valid = TADC_LICENSE_VALID;
815 /* BASE64 Decode the constraints buffer extracted from the DB */
816 db_buf_enclen = TAPPS_STRLEN(row.constraint_buffer);
817 db_buf_declen = db_buf_enclen / 4 * 3;
819 if (db_buf_enclen <= 0) {
820 DRM_TAPPS_EXCEPTION("There is no constaints buffer in the DB. cid = %s", szCid);
821 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
825 DRM_TAPPS_FRQ_LOG("db_buf_enclen = %d, db_buf_declen = %d", db_buf_enclen,
828 (void)DTappsB64Decode((unsigned char *)row.constraint_buffer, db_buf_enclen,
829 const_buffer_dec, db_buf_declen);
831 if (db_buf_declen > (db_buf_enclen / 4 * 3)) {
832 DRM_TAPPS_EXCEPTION("BASE64 Decode error! const_buffer_dec=%s, "
833 "db_buf_declen=%d, (db_buf_enclen/4*3)=%d",
834 const_buffer_dec, db_buf_declen, (db_buf_enclen / 4 * 3));
835 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
839 /* BASE64 Decode the hash buffer extracted from the DB */
840 DTAPPS_MEMSET(hash_buffer, 0x00, sizeof(hash_buffer));
841 DTAPPS_MEMSET(md, 0x00, sizeof(md));
843 hash_buf_enclen = TAPPS_STRLEN(row.constraint_hash);
844 hash_buf_declen = hash_buf_enclen / 4 * 3;
846 if (hash_buf_enclen <= 0) {
847 DRM_TAPPS_EXCEPTION("There is no hash buffer in the DB. cid = %s", szCid);
848 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
852 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen,
855 (void)DTappsB64Decode((unsigned char *)row.constraint_hash, hash_buf_enclen,
856 hash_buffer, hash_buf_declen);
858 if (hash_buf_declen > (hash_buf_enclen / 4 * 3)) {
859 DRM_TAPPS_EXCEPTION("BASE64 Decode error! hash_buffer_dec=%s, "
860 "hash_buf_declen=%d, (hash_buf_enclen/4*3)=%d",
861 hash_buffer, hash_buf_declen, (hash_buf_enclen / 4 * 3));
862 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
866 // Calculate the hash using HMAC from the BASE64Decoded Constraint Buffers
867 // and check with the BASE64Decoded Hash buffers
868 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, const_buffer_dec, db_buf_declen, md,
871 if (DTAPPS_MEMCMP(md, hash_buffer, hash_buf_declen) == 0) {
872 DRM_TAPPS_LOG("HASH for constraint buffer matching! md=%s, "
873 "hash_buffer_dec=%s, hash_buf_declen=%d",
874 md, hash_buffer, hash_buf_declen);
876 DRM_TAPPS_EXCEPTION("HASH for constraint buffer not matching! md=%s, "
877 "hash_buffer_dec=%s, hash_buf_declen=%d",
878 md, hash_buffer, hash_buf_declen);
879 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
883 /* Validate the constraints buffer */
884 DTAPPS_MEMCPY(&st_constaints, const_buffer_dec, sizeof(DTAPPS_CONSTRAINTS));
886 check_valid = DTappsValidateConstraints(&st_constaints, DTAPPS_VERIFY);
888 if (check_valid != TADC_LICENSE_VALID) {
889 DRM_TAPPS_LOG("Invalid Constraints for constraints_buffer=%s, check_valid=%d",
890 const_buffer_dec, check_valid);
891 // TODO: Implementation of Auto Deletion feature to delete the rights
892 // from the DB if the rights are expired!!!
895 DRM_TAPPS_LOG("Rights are Valid! check_valid = %d", check_valid);
897 // Constraints valid - Extract CEK and fill the t_RO structure with CEK, DUID
898 // BASE64 Decode the CEK buffer extracted from the DB
899 db_buf_enclen = TAPPS_STRLEN(row.cek);
900 db_buf_declen = db_buf_enclen / 4 * 3;
902 if (db_buf_enclen <= 0) {
903 DRM_TAPPS_EXCEPTION("There is no CEK in the DB. cid = %s", szCid);
904 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
908 DRM_TAPPS_FRQ_LOG("db_buf_enclen = %d, db_buf_declen = %d", db_buf_enclen,
913 (void)DTappsB64Decode((unsigned char *)row.cek, db_buf_enclen, encr_cek,
915 db_buf_declen = cek_declen;
917 if (cek_declen > (db_buf_enclen / 4 * 3)) {
918 DRM_TAPPS_EXCEPTION("BASE64 Decode error! encr_cek=%s, cek_declen=%d, "
919 "(db_buf_enclen/4*3)=%d",
920 encr_cek, cek_declen, (db_buf_enclen / 4 * 3));
921 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
925 DRM_TAPPS_LOG("BASE64 encr_cek=%s, cek_declen=%d, db_buf_declen=%d, "
926 "(db_buf_enclen/4*3)=%d",
927 encr_cek, cek_declen, db_buf_declen, (db_buf_enclen / 4 * 3));
929 /* BASE64 Decode the hash buffer extracted from the DB */
930 DTAPPS_MEMSET(hash_buffer, 0x00, sizeof(hash_buffer));
931 DTAPPS_MEMSET(md, 0x00, sizeof(md));
933 hash_buf_enclen = TAPPS_STRLEN(row.cek_hash);
934 hash_buf_declen = hash_buf_enclen / 4 * 3;
936 if (hash_buf_enclen <= 0) {
937 DRM_TAPPS_EXCEPTION("There is no CEK_hash buffer in the DB. cid = %s",
939 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
943 DRM_TAPPS_FRQ_LOG("hash_buf_enclen = %d, hash_buf_declen = %d", hash_buf_enclen,
946 (void)DTappsB64Decode((unsigned char *)row.cek_hash, hash_buf_enclen,
947 hash_buffer, hash_buf_declen);
949 if (hash_buf_declen > (hash_buf_enclen / 4 * 3)) {
950 DRM_TAPPS_EXCEPTION("BASE64 Decode error! hash_buffer_dec=%s, "
951 "hash_buf_declen=%d, (hash_buf_enclen/4*3)=%d",
952 hash_buffer, hash_buf_declen,
953 (hash_buf_enclen / 4 * 3));
954 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
958 // Calculate the hash using HMAC from the BASE64Decoded Encrypted CEK Buffer
959 // and check with the BASE64Decoded Hash buffer
960 DTappsCalHMACSHA1(pDevKey, (int)DevKeyLen, encr_cek, db_buf_declen, md,
963 if (DTAPPS_MEMCMP(md, hash_buffer, hash_buf_declen) == 0) {
964 DRM_TAPPS_LOG("HASH for Encrypted CEK buffer matching! md=%s, "
965 "hash_buffer_dec=%s, hash_buf_declen=%d",
966 md, hash_buffer, hash_buf_declen);
968 DRM_TAPPS_EXCEPTION("HASH for Encrypted CEK buffer not matching! "
969 "md=%s, hash_buffer_dec=%s, hash_buf_declen=%d",
970 md, hash_buffer, hash_buf_declen);
971 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
975 /* Allocate memory for CEK */
976 t_RO->t_Content.CEK = (unsigned char *)DTAPPS_MALLOC(CEK_SIZE + 1);
978 if (NULL == t_RO->t_Content.CEK) {
979 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! t_RO->t_Content.CEK = %p",
980 t_RO->t_Content.CEK);
981 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
985 DTAPPS_MEMSET(t_RO->t_Content.CEK, 0x00, CEK_SIZE + 1);
987 /* Decrypt CEK and update t_RO structure */
988 if (DTAPPS_AES_SET_DECR_KEY(pDevKey, 128, &key)) {
989 DRM_TAPPS_EXCEPTION("AES_set_decrypt_key failed!!");
990 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
994 (void)DTAPPS_AES_UNWRAP_KEY(&key, NULL, t_RO->t_Content.CEK, encr_cek,
996 DRM_TAPPS_LOG("DTAPPS_AES_UNWRAP_KEY success!!");
998 /* Store DUID in t_RO */
999 if (st_constaints.DUID[0] != '\0') {
1000 t_RO -> t_Permission.t_Individual.DUID = (unsigned char *)DTAPPS_MALLOC(
1003 if (NULL == t_RO -> t_Permission.t_Individual.DUID) {
1004 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! "
1005 "t_RO->t_Permission.t_Individual.DUID = %p",
1006 t_RO -> t_Permission.t_Individual.DUID);
1007 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
1011 DTAPPS_MEMSET(t_RO -> t_Permission.t_Individual.DUID, 0x00, DUID_SIZE + 1);
1012 t_RO->PerFlag |= DUID_RULE;
1013 t_RO->t_Permission.t_Individual.BindingType |= DUID_RULE;
1014 DTAPPS_MEMCPY(t_RO -> t_Permission.t_Individual.DUID, st_constaints.DUID,
1022 DTappsFreeDeviceKey(&pDevKey);
1025 if (check_valid != TADC_LICENSE_VALID) {
1026 DRM_TAPPS_EXCEPTION("DTappsGetCEK FAILED!!!, check_valid = %d", check_valid);
1029 /* All fine... Allocate memory for CID and fill the value */
1030 if ((t_RO != NULL) && (szCid != NULL)) {
1031 t_RO -> t_Content.CID = (unsigned char *) DTAPPS_MALLOC(CID_SIZE + 1);
1033 if (NULL == t_RO -> t_Content.CID) {
1034 DRM_TAPPS_EXCEPTION("Memory Allocation Error!! "
1035 "t_RO->t_Content.CID = %p",
1036 t_RO -> t_Content.CID);
1037 check_valid = TADC_LICENSE_UNKNOWN_ERROR;
1041 DTAPPS_MEMSET(t_RO -> t_Content.CID, 0x00, CID_SIZE + 1);
1042 DTAPPS_MEMCPY(t_RO -> t_Content.CID, szCid, CID_SIZE);
1043 DRM_TAPPS_LOG("DTappsGetCEK SUCCESS!!!, check_valid = %d", check_valid);
1050 BOOL DTapps_RIGHTS_INSTALL(const char *name,
1052 #ifdef DTAPPS_STORE_CEK_IN_DB
1054 const char *cek_hash,
1056 const char *constraint_buffer,
1057 const char *constraint_hash,
1062 const char *query = NULL;
1063 sqlite3_stmt *pstmt = NULL;
1064 unsigned int dIdx = 0;
1065 BOOL ret_value = FALSE;
1067 DRM_TAPPS_LOG("Open DB......");
1068 ret_value = DTappsDBOpen(pDb, __func__);
1070 if (ret_value != TRUE) {
1071 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
1075 if (isUpdate == FALSE) {
1076 query = "INSERT INTO dtapps2rights (name, time_t, "
1077 #ifdef DTAPPS_STORE_CEK_IN_DB
1080 " constraint_buffer, constraint_hash, cid) "
1082 #ifdef DTAPPS_STORE_CEK_IN_DB
1087 query = "UPDATE dtapps2rights SET name=?, time_t=?,"
1088 #ifdef DTAPPS_STORE_CEK_IN_DB
1089 " cek=?, cek_hash=?, "
1091 " constraint_buffer=?, constraint_hash=? "
1095 DRM_TAPPS_LOG("Prepare Statement........");
1096 pstmt = (sqlite3_stmt *) DTappsStmtPrepare(pDb, query);
1098 if (pstmt == NULL) {
1099 DRM_TAPPS_EXCEPTION("Prepare Statement failed. query=%s", query);
1103 DRM_TAPPS_LOG("Binding Parameters........");
1104 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1105 (void *)name, strlen(name));
1107 if (ret_value != TRUE) {
1108 DRM_TAPPS_EXCEPTION("Binding Parameter(name=%s) failed. ret_value = %d", name,
1113 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1114 (void *)time, strlen(time));
1116 if (ret_value != TRUE) {
1117 DRM_TAPPS_EXCEPTION("Binding Parameter(time=%s) failed. ret_value = %d", time,
1122 #ifdef DTAPPS_STORE_CEK_IN_DB
1123 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1124 (void *)cek, strlen(cek));
1126 if (ret_value != TRUE) {
1127 DRM_TAPPS_EXCEPTION("Binding Parameter(cek=%s) failed. ret_value = %d", cek,
1132 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1133 (void *)cek_hash, strlen(cek_hash));
1135 if (ret_value != TRUE) {
1136 DRM_TAPPS_EXCEPTION("Binding Parameter(cek_hash=%s) failed. ret_value = %d",
1137 cek_hash, ret_value);
1143 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1144 (void *)constraint_buffer, strlen(constraint_buffer));
1146 if (ret_value != TRUE) {
1147 DRM_TAPPS_EXCEPTION("Binding Parameter(constraint_buffer=%s) failed. "
1149 constraint_buffer, ret_value);
1153 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1154 (void *)constraint_hash, strlen(constraint_hash));
1156 if (ret_value != TRUE) {
1157 DRM_TAPPS_EXCEPTION("Binding Parameter(constraint_hash=%s) failed. "
1159 constraint_hash, ret_value);
1163 ret_value = DTappsStmtBindParam(pstmt, dIdx++, TAPPSDB_TYPE_VARCHAR,
1164 (void *)cid, strlen(cid));
1166 if (ret_value != TRUE) {
1167 DRM_TAPPS_EXCEPTION("Binding Parameter(cid=%s) failed. ret_value = %d", cid,
1172 DRM_TAPPS_LOG("Begin Transaction........");
1173 ret_value = DTappsDBBeginImmedTrans(__func__);
1175 if (ret_value != TRUE) {
1176 DRM_TAPPS_EXCEPTION("DB Begin Transaction ret_value = %d", ret_value);
1180 DRM_TAPPS_LOG("Execute SQL to Insert Contents into Table........");
1181 ret_value = DTappsStmtExecute(pstmt);
1183 if (ret_value != TRUE) {
1184 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! ret_value = %d", ret_value);
1188 DRM_TAPPS_LOG("Commit DB........");
1189 ret_value = DTappsDBCommit(__func__);
1191 if (ret_value != TRUE) {
1192 DRM_TAPPS_EXCEPTION("Commit DB Failed!! ret_value = %d", ret_value);
1196 DRM_TAPPS_LOG("Release Statement........");
1197 ret_value = DTappsStmtRelease(pstmt);
1199 if (ret_value != TRUE) {
1200 DRM_TAPPS_EXCEPTION("Release Statement Failed!! ret_value = %d", ret_value);
1205 DRM_TAPPS_LOG("Close DB........");
1206 ret_value = DTappsDBClose(__func__);
1208 if (ret_value != TRUE) {
1209 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
1213 DRM_TAPPS_LOG("Install DB Operartion Successful!!!");
1219 DTappsStmtRelease(pstmt);
1221 ret_value = DTappsDBRollback(__func__);
1223 if (ret_value != TRUE) {
1224 DRM_TAPPS_EXCEPTION("Rollback DB Failed!! ret_value = %d", ret_value);
1227 ret_value = DTappsDBClose(__func__);
1229 if (ret_value != TRUE) {
1230 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
1236 BOOL DTapps_RIGHTS_SELECT_ONE(const char *cid, DTAPPS_RIGHTS_ROW *row)
1239 const char *query = NULL;
1240 sqlite3_stmt *pstmt = NULL;
1241 unsigned int dIdx = 0;
1242 BOOL ret_value = FALSE;
1244 DTAPPS_RIGHTS_ROW *result = row;
1246 char *name, *time, *constraint_buffer, *constraint_hash;
1247 #ifdef DTAPPS_STORE_CEK_IN_DB
1248 char *cek, *cek_hash;
1251 DRM_TAPPS_LOG("Open DB......");
1252 ret_value = DTappsDBOpen(pDb, __func__);
1254 if (ret_value != TRUE) {
1255 DRM_TAPPS_EXCEPTION("DB Open Failed!! ret_value = %d", ret_value);
1259 query = "SELECT r_id, name, time_t, "
1260 #ifdef DTAPPS_STORE_CEK_IN_DB
1263 " constraint_buffer, constraint_hash "
1264 " FROM dtapps2rights"
1265 " WHERE cid=? ORDER BY r_id desc limit 1;";
1268 DRM_TAPPS_LOG("Begin Transaction........");
1269 ret_value = DTappsDBBeginImmedTrans(__func__);
1271 if (ret_value != TRUE) {
1272 DRM_TAPPS_EXCEPTION("DB Begin Transaction Failed!! ret_value = %d", ret_value);
1276 DRM_TAPPS_LOG("Prepare Statement........");
1277 db_ret = sqlite3_prepare((sqlite3 *)pDb, query, -1, &pstmt, NULL);
1279 if (pstmt == NULL) {
1280 DRM_TAPPS_EXCEPTION("Prepare Statement failed. query=%s, error=%s", query,
1281 sqlite3_errmsg((sqlite3 *)pDb));
1285 DRM_TAPPS_LOG("Binding Parameters........");
1286 db_ret = sqlite3_bind_text(pstmt, ++dIdx, cid, strlen(cid), SQLITE_TRANSIENT);
1288 if (db_ret != SQLITE_OK) {
1289 DRM_TAPPS_EXCEPTION("Binding Parameter(cid=%s) failed. "
1290 "ret_value = %d, query=%s",
1291 cid, db_ret, query);
1295 DRM_TAPPS_LOG("Execute SQL to Select Contents from Table........");
1296 db_ret = sqlite3_step(pstmt);
1298 if (db_ret == SQLITE_OK || db_ret == SQLITE_DONE) {
1299 DRM_TAPPS_FRQ_LOG("Executed SQL Select Query. But no row was returned");
1301 } else if (db_ret != SQLITE_ROW) {
1302 DRM_TAPPS_EXCEPTION("Execute SQL Query Failed!! "
1303 "ret_value = %d, query=%s, error=%s",
1304 db_ret, query, sqlite3_errmsg((sqlite3 *)pDb));
1308 memset(result, 0, sizeof(DTAPPS_RIGHTS_ROW));
1311 result->r_id = sqlite3_column_int(pstmt, dIdx++);
1312 DRM_TAPPS_LOG("....SEELECTED : r_id = %d", result->r_id);
1314 name = (char *) sqlite3_column_text(pstmt, dIdx++);
1317 memcpy(result->name, name, strlen(name));
1319 DRM_TAPPS_LOG("....SEELECTED : name = %s", result->name);
1321 time = (char *) sqlite3_column_text(pstmt, dIdx++);
1324 memcpy(result->time, time, strlen(time));
1326 DRM_TAPPS_LOG("....SEELECTED : time = %s", result->time);
1328 #ifdef DTAPPS_STORE_CEK_IN_DB
1329 cek = (char *) sqlite3_column_text(pstmt, dIdx++);
1332 memcpy(result->cek, cek, strlen(cek));
1334 DRM_TAPPS_LOG("....SEELECTED : cek = %s", result->cek);
1336 cek_hash = (char *) sqlite3_column_text(pstmt, dIdx++);
1338 if (cek_hash != NULL)
1339 memcpy(result->cek_hash, cek_hash, strlen(cek_hash));
1341 DRM_TAPPS_LOG("....SEELECTED : cek_hash = %s", result->cek_hash);
1344 constraint_buffer = (char *) sqlite3_column_text(pstmt, dIdx++);
1346 if (constraint_buffer != NULL)
1347 memcpy(result->constraint_buffer, constraint_buffer, strlen(constraint_buffer));
1349 DRM_TAPPS_LOG("....SEELECTED : constraint_buffer = %s",
1350 result->constraint_buffer);
1352 constraint_hash = (char *) sqlite3_column_text(pstmt, dIdx++);
1354 if (constraint_hash != NULL)
1355 memcpy(result->constraint_hash, constraint_hash, strlen(constraint_hash));
1357 DRM_TAPPS_LOG("....SEELECTED : constraint_hash = %s", result->constraint_hash);
1359 memcpy(result->cid, cid, strlen(cid));
1360 DRM_TAPPS_LOG("....SEELECTED : cid = %s", result->cid);
1362 DRM_TAPPS_LOG("Release Statement........");
1363 ret_value = DTappsStmtRelease(pstmt);
1365 if (ret_value != TRUE) {
1366 DRM_TAPPS_EXCEPTION("Release Statement Failed!! ret_value = %d", ret_value);
1371 DRM_TAPPS_LOG("Close DB........");
1372 ret_value = DTappsDBClose(__func__);
1374 if (ret_value != TRUE) {
1375 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);
1379 DRM_TAPPS_LOG("Select a DB row Operartion Successful!!!");
1385 DTappsStmtRelease(pstmt);
1387 ret_value = DTappsDBClose(__func__);
1389 if (ret_value != TRUE) {
1390 DRM_TAPPS_EXCEPTION("Close DB Failed!! ret_value = %d", ret_value);