d33f5ef59df30f471a8bf6d1683ad25ccb8345f8
[platform/framework/native/installer.git] / src / Manager / SignatureManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        SignatureManager.cpp
19  * @brief       This is the implementation file for %SignatureManager class.
20  */
21
22 #include <pkgmgr_parser.h>
23 #include <pkgmgr_installer.h>
24 #include <package-manager.h>
25 #include <pkgmgr-info.h>
26
27 #include <FBase_StringConverter.h>
28 #include <FBaseInternalTypes.h>
29
30 #include "SignatureManager.h"
31
32 #include <vcore/SignatureFinder.h>
33 #include <vcore/SignatureData.h>
34 #include <vcore/SignatureReader.h>
35 #include <vcore/SignatureValidator.h>
36 #include <vcore/WrtSignatureValidator.h>
37 #include <vcore/VCore.h>
38
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Base::Utility;
42
43 SignatureManager::SignatureManager(void)
44 :__pContext(null)
45 {
46 }
47
48 SignatureManager::~SignatureManager(void)
49 {
50 }
51
52 bool
53 SignatureManager::Construct(InstallationContext* pContext)
54 {
55         __pContext = pContext;
56
57         return true;
58 }
59
60 bool
61 SignatureManager::ValidateSignatures()
62 {
63         TryReturn(__pContext, false, "__pContext is null.");
64
65         AppLog("ValidateSignatures start >>");
66
67         bool res = false;
68         res = ValidationCore::VCoreInit(
69                         std::string("/usr/share/wrt-engine/fingerprint_list.xml"),
70                         std::string("/usr/share/wrt-engine/fingerprint_list.xsd"),
71                         std::string("/opt/dbspace/.cert_svc_vcore.db"));
72         TryReturn(res, false, "ValidationCore::VCoreInit() is failed.");
73         TryReturn(__pContext->__rootPath.IsEmpty() == false, false, "__pContext->__rootPath is empty.");
74         AppLog("ValidationCore::VCoreInit() is done");
75
76         std::unique_ptr<char[]> pRootPath(_StringConverter::CopyToCharArrayN(__pContext->__rootPath));
77         TryReturn(pRootPath, false, "__pRootPath is null.");
78
79         std::string rootPath = pRootPath.get();
80         rootPath += "/";
81         AppLog("rootPath=[%s]", rootPath.c_str());
82
83         ValidationCore::SignatureFinder::Result findRes = ValidationCore::SignatureFinder::NO_ERROR;
84         ValidationCore::SignatureFinder signatureFinder(rootPath);
85         ValidationCore::SignatureFileInfoSet signatureFiles;
86
87         findRes = signatureFinder.find(signatureFiles);
88         TryReturn(findRes == ValidationCore::SignatureFinder::NO_ERROR , false, "signatureFinder.find() is failed, findRes=[%d]", (int)findRes);
89         AppLog("signatureFinder.find() is done");
90
91         ValidationCore::SignatureFileInfoSet::reverse_iterator iter = signatureFiles.rbegin();
92         for (; iter != signatureFiles.rend(); ++iter)
93         {
94                 int sigFileNumber = iter->getFileNumber();
95                 AppLog("SignatureFiles: file=[%s]", iter->getFileName().c_str());
96                 AppLog("SignatureFiles: number=[%d]", sigFileNumber);
97
98                 if (sigFileNumber > SIGNATURE_FILE_NUMBER_DISTRIBUTOR2)
99                 {
100                         AppLog("SignatureFiles: skip!");
101                         continue;
102                 }
103
104                 ValidationCore::SignatureData data(rootPath + iter->getFileName(), iter->getFileNumber());
105
106                 try {
107                         ValidationCore::SignatureReader xml;
108                         xml.initialize(data, "/usr/share/wrt-engine/schema.xsd");
109                         xml.read(data);
110                         AppLog("ValidationCore::SignatureReader() is done");
111
112                         ValidationCore::CertificateList certList = data.getCertList();
113                         ValidationCore::CertificateList::iterator it = certList.begin();
114                         ValidationCore::CertificateList::iterator it_end = certList.end();
115                         for (; it != it_end; it++)
116                         {
117                                 std::string value = (*it)->getBase64();
118
119                                 if (data.isAuthorSignature() == true)
120                                 {
121                                         __pContext->__pAuthorCertList->Add(new String(value.c_str()));
122                                         AppLog("Author cert value=[%s]", value.c_str());
123                                 }
124                                 else
125                                 {
126                                         if (sigFileNumber == SIGNATURE_FILE_NUMBER_DISTRIBUTOR)
127                                         {
128                                                 __pContext->__pDistributorCertList->Add(new String(value.c_str()));
129                                                 AppLog("Default distributor cert value=[%s]", value.c_str());
130                                         }
131                                         else if (sigFileNumber == SIGNATURE_FILE_NUMBER_DISTRIBUTOR2)
132                                         {
133                                                 AppLog("Default distributor2 cert value=[%s]", value.c_str());
134                                         }
135                                 }
136                         }
137
138                         ValidationCore::SignatureValidator::Result valRes = ValidationCore::SignatureValidator::SIGNATURE_VALID;
139                         ValidationCore::SignatureValidator::AppType appType = ValidationCore::SignatureValidator::TIZEN;
140                         ValidationCore::SignatureValidator validator(appType, false, false, false);
141
142                         AppLog("validator.check() start >>");
143                         valRes = validator.check(data, rootPath);
144                         if (sigFileNumber == SIGNATURE_FILE_NUMBER_DISTRIBUTOR2)
145                         {
146                                 if (valRes == ValidationCore::SignatureValidator::SIGNATURE_VERIFIED)
147                                 {
148                                         AppLog("Signature validator.check success, file=[%s], number=[%d]", iter->getFileName().c_str(), iter->getFileNumber());
149                                 }
150                                 else
151                                 {
152                                         AppLog("Signature validator.check failed, but it's ok, file=[%s], number=[%d]", iter->getFileName().c_str(), iter->getFileNumber());
153                                         __pContext->__pDistributorCertList2->RemoveAll();
154                                 }
155                         }
156                         else
157                         {
158                                 TryReturn(valRes == ValidationCore::SignatureValidator::SIGNATURE_VERIFIED, false, "validator.check() is failed, valRes=[%d]", (int)valRes);
159                                 AppLog("Signature validator.check success, file=[%s], number=[%d]", iter->getFileName().c_str(), iter->getFileNumber());
160                         }
161
162                         ValidationCore::CertificatePtr pRootCert = data.getRootCaCertificatePtr();
163                         TryReturn(pRootCert, false, "__pRootPath is null.");
164                         std::string value = pRootCert.Get()->getBase64();
165                         if (data.isAuthorSignature() == true)
166                         {
167                                 __pContext->__pAuthorCertList->Add(new String(value.c_str()));
168                                 AppLog("Author root cert value=[%s]", value.c_str());
169                         }
170                         else
171                         {
172                                 if (sigFileNumber == SIGNATURE_FILE_NUMBER_DISTRIBUTOR)
173                                 {
174                                         __pContext->__pDistributorCertList->Add(new String(value.c_str()));
175                                         AppLog("Default root distributor cert value=[%s]", value.c_str());
176
177                                         ValidationCore::CertStoreId::Type certStoreIdType = data.getVisibilityLevel();
178                                         AppLog("CertStoreIdType = [%d]", (int)certStoreIdType);
179                                         __pContext->__rootCertType = (RootCertificateType)certStoreIdType;
180                                 }
181                                 else if ((sigFileNumber == SIGNATURE_FILE_NUMBER_DISTRIBUTOR2) && (valRes == ValidationCore::SignatureValidator::SIGNATURE_VERIFIED))
182                                 {
183                                         __pContext->__pDistributorCertList2->Add(new String(value.c_str()));
184                                         AppLog("Default root distributor2 cert value=[%s]", value.c_str());
185                                 }
186                         }
187                 }
188                 catch (ValidationCore::ParserSchemaException::Base)
189                 {
190                         if (sigFileNumber == SIGNATURE_FILE_NUMBER_DISTRIBUTOR2)
191                         {
192                                 AppLog("ValidationCore::ParserSchemaException::Base occurred, but it's ok for DISTRIBUTOR2.");
193                                 continue;
194                         }
195                         TryReturn(0, false, "ParserSchemaException::Base exception occurred.");
196                 }
197                 catch (DPL::Exception)
198                 {
199                         if (sigFileNumber == SIGNATURE_FILE_NUMBER_DISTRIBUTOR2)
200                         {
201                                 AppLog("DPL::Exception occurred, but it's ok for DISTRIBUTOR2.");
202                                 continue;
203                         }
204                         TryReturn(0, false, "DPL::Exception exception occurred.");
205                 }
206         }
207
208         AppLog("ValidateSignatures done successfully <<");
209
210         if (__pContext->__isUpdated == true)
211         {
212                 res = ValidateUpdate();
213                 TryReturn(res, false, "ValidateUpdate() is failed.");
214         }
215
216         return true;
217 }
218
219 bool
220 SignatureManager::ValidateUpdate()
221 {
222         TryReturn(__pContext, false, "__pContext is null.");
223         TryReturn(__pContext->__isUpdated, false, "It's not update.");
224
225         if (InstallerUtil::IsAuthorSignatureVerificationEnabled() == false)
226         {
227                 AppLog("ValidateUpdate() skip.");
228                 return true;
229         }
230
231         std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(__pContext->__packageId));
232         TryReturn(pPackageId, false, "pPackageId is null.");
233
234         result r = E_SUCCESS;
235         String oldCertificate;
236         String* pNewCertificate = null;
237         const char* pValue = null;
238         pkgmgr_certinfo_h handle = null;
239
240         int res = pkgmgr_pkginfo_create_certinfo(&handle);
241         if (res == PMINFO_R_OK)
242         {
243                 res = pkgmgr_pkginfo_load_certinfo(pPackageId.get(), handle);
244                 if (res == PMINFO_R_OK)
245                 {
246                         pkgmgr_pkginfo_get_cert_value(handle, PM_AUTHOR_SIGNER_CERT, &pValue);
247                         oldCertificate = pValue;
248                 }
249
250                 pkgmgr_pkginfo_destroy_certinfo(handle);
251         }
252
253         if (oldCertificate.IsEmpty() == true)
254         {
255                 AppLog("oldCert is empty.");
256                 return true;
257         }
258         else
259         {
260                 r = __pContext->__pAuthorCertList->GetAt(0, pNewCertificate);
261                 TryReturn(r == E_SUCCESS, false, "GetAt() failed.");
262
263                 AppLog("------------------------------------------");
264                 AppLog("oldCert = [%ls]", oldCertificate.GetPointer());
265                 AppLog("newCert = [%ls]", pNewCertificate->GetPointer());
266                 AppLog("------------------------------------------");
267
268                 if (oldCertificate.Equals(*pNewCertificate, true) == false)
269                 {
270                         AppLog("oldCert, newCert is different.");
271                         return false;
272                 }
273         }
274
275         AppLog("oldCert, newCert is the same.");
276         return true;
277 }
278
279 bool
280 SignatureManager::ValidatePartialReferences()
281 {
282         AppLog("ValidatePartialReferences start >>");
283
284         bool res = true;
285         std::unique_ptr<char[]> pSignaturePath(_StringConverter::CopyToCharArrayN(__pContext->GetSignatureXmlPath()));
286         TryReturn(pSignaturePath, false, "pSignaturePath is null.");
287
288         std::unique_ptr<char[]> pAuthorSignaturePath(_StringConverter::CopyToCharArrayN(__pContext->GetAuthorSignatureXmlPath()));
289         TryReturn(pAuthorSignaturePath, false, "pAuthorSignaturePath is null.");
290
291         std::unique_ptr<SignatureHandler> pDistributorSignature(new (std::nothrow) SignatureHandler());
292         TryReturn(pDistributorSignature, false, "pDistributorSignature is null.");
293
294         res = pDistributorSignature->Construct(__pContext);
295         TryReturn(res == true, false, "pDistributorSignature->Construct() is failed.");
296
297         res = pDistributorSignature->Parse(pSignaturePath.get());
298         TryReturn(res == true, false, "pDistributorSignature->Parse() is failed.");
299
300         HashMap* pDistributorRefMap = pDistributorSignature->GetReferenceMap();
301         TryReturn(pDistributorRefMap, false, "pDistributorRefMap is null.");
302
303         std::unique_ptr<SignatureHandler> pAuthorSignature(new (std::nothrow) SignatureHandler());
304         TryReturn(pAuthorSignature, false, "pAuthorSignature is null.");
305
306         res = pAuthorSignature->Construct(__pContext);
307         TryReturn(res == true, false, "pAuthorSignature.Construct() is failed.");
308
309         res = pAuthorSignature->Parse(pAuthorSignaturePath.get());
310         TryReturn(res == true, false, "pAuthorSignature->Parse() is failed.");
311
312         HashMap* pAuthorRefMap = pAuthorSignature->GetReferenceMap();
313         TryReturn(pAuthorRefMap, false, "pAuthorRefMap is null.");
314
315         res = CompareReferences(pDistributorRefMap, pAuthorRefMap);
316         TryReturn(res == true, false, "CompareReferences() is failed.");
317
318         return true;
319 }
320
321 bool
322 SignatureManager::RegisterCertInfo() const
323 {
324         TryReturn(__pContext, false, "__pContext is null");
325
326         if (__pContext->__isHybridService == true)
327         {
328                 AppLog("Skip - HybridService");
329                 return true;
330         }
331
332         AppLog("START");
333
334         int error = 0;
335         bool res = false;
336         pkgmgr_instcertinfo_h handle = null;
337
338         std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(__pContext->__packageId));
339         TryReturn(pPackageId, false, "pPackageId is null");
340
341         error = pkgmgr_installer_create_certinfo_set_handle(&handle);
342         TryReturn(error == 0, false, "pkgmgr_installer_create_certinfo_set_handle() failed, error = [%d].", error);
343
344         if (__pContext->__pAuthorCertList)
345         {
346                 AppLog("[AuthorCert]");
347                 res = SetAuthorCertValue(handle, __pContext->__pAuthorCertList);
348                 TryCatch(res == true, , "SetAuthorCertHashValue() is failed.");
349         }
350
351         if (__pContext->__pDistributorCertList)
352         {
353                 AppLog("[DistributorCert]");
354                 res = SetDistributorCertValue(handle, __pContext->__pDistributorCertList, 1);
355                 TryCatch(res == true, , "SetDistributorCertValue() is failed.");
356         }
357
358         if (__pContext->__pDistributorCertList2)
359         {
360                 AppLog("[DistributorCert2]");
361                 res = SetDistributorCertValue(handle, __pContext->__pDistributorCertList2, 2);
362                 TryCatch(res == true, , "SetDistributorCertValue() is failed.");
363         }
364
365         error = pkgmgr_installer_save_certinfo(pPackageId.get(), handle);
366         TryCatch(error == 0, res = false, "pkgmgr_installer_save_certinfo(%s) failed, error = [%d]", pPackageId.get(), error);
367
368         AppLog("RegisterCertInfo - END");
369         AppLog("------------------------------------------");
370
371         res = true;
372
373 CATCH:
374         if (handle)
375         {
376                 pkgmgr_installer_destroy_certinfo_set_handle(handle);
377         }
378
379         return res;
380 }
381
382 bool
383 SignatureManager::UnregisterCertInfo() const
384 {
385         TryReturn(__pContext, false, "__pContext is null");
386
387         if (__pContext->__isHybridService == true)
388         {
389                 AppLog("Skip - HybridService");
390                 return true;
391         }
392
393         AppLog("START");
394         int error = 0;
395         std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(__pContext->__packageId));
396         TryReturn(pPackageId, false, "pPackageId is null");
397
398         error = pkgmgr_installer_delete_certinfo(pPackageId.get());
399         TryReturn(error == 0, false, "pkgmgr_installer_delete_certinfo(%s) failed, error = [%d]", pPackageId.get(), error);
400
401         AppLog("UnregisterCertInfo - END");
402         AppLog("------------------------------------------");
403
404         return true;
405 }
406
407 int
408 SignatureManager::GetApiVisibility(RootCertificateType certType)
409 {
410         int apiVisibility = _API_VISIBILITY_NONE;
411
412         if (certType == ROOT_CERTIFICATE_PUBLIC)
413         {
414                 apiVisibility = _API_VISIBILITY_PUBLIC;
415         }
416         else if (certType == ROOT_CERTIFICATE_PARTNER)
417         {
418                 apiVisibility = _API_VISIBILITY_PARTNER;
419         }
420         else if (certType == ROOT_CERTIFICATE_PARTNER_OPERATOR)
421         {
422                 apiVisibility = _API_VISIBILITY_PARTNER_OPERATOR;
423         }
424         else if (certType == ROOT_CERTIFICATE_PARTNER_MANUFACTURER)
425         {
426                 apiVisibility = _API_VISIBILITY_PARTNER_MANUFACTURER;
427         }
428         else if (certType == ROOT_CERTIFICATE_CERT_SVC_PUBLIC)
429         {
430                 apiVisibility = _API_VISIBILITY_PUBLIC;
431         }
432         else if (certType == ROOT_CERTIFICATE_CERT_SVC_PARTNER)
433         {
434                 apiVisibility = _API_VISIBILITY_PARTNER;
435         }
436         else if (certType == ROOT_CERTIFICATE_CERT_SVC_PARTNER_OPERATOR)
437         {
438                 apiVisibility = _API_VISIBILITY_PARTNER_OPERATOR;
439         }
440         else if (certType == ROOT_CERTIFICATE_CERT_SVC_PARTNER_MANUFACTURER)
441         {
442                 apiVisibility = _API_VISIBILITY_PARTNER_MANUFACTURER;
443         }
444         else if (certType == ROOT_CERTIFICATE_CERT_SVC_PLATFORM)
445         {
446                 apiVisibility = _API_VISIBILITY_PARTNER_MANUFACTURER;
447         }
448
449         return apiVisibility;
450 }
451
452 int
453 SignatureManager::GetPrivilegeLevel(int apiVisibility)
454 {
455         if (apiVisibility == _API_VISIBILITY_PARTNER_MANUFACTURER || apiVisibility == _API_VISIBILITY_PARTNER_OPERATOR)
456         {
457                 return PRIVILEGE_LEVEL_PLATFORM;
458         }
459         else if (apiVisibility == _API_VISIBILITY_PARTNER)
460         {
461                 return PRIVILEGE_LEVEL_PARTNER;
462         }
463
464         return PRIVILEGE_LEVEL_PUBLIC;
465 }
466
467 bool
468 SignatureManager::SetAuthorCertValue(void* pHandle, IListT<String *>* pCertList) const
469 {
470         TryReturn(pHandle, false, "pHandle is null.");
471         TryReturn(pCertList, false, "pCertPath is null.");
472
473         int res = 0;
474         result r = E_SUCCESS;
475         int certType = 0;
476
477         for (int i = 0; i < pCertList->GetCount(); i++)
478         {
479                 String* pCert = null;
480                 r = pCertList->GetAt(i, pCert);
481                 TryReturn(!IsFailed(r), false, "pCertList->GetAt() is failed, [%d]", i);
482                 TryReturn(pCert, false, "pCertList->GetAt() is failed, [%d]", i);
483
484                 std::unique_ptr<char[]> pCertValue(_StringConverter::CopyToCharArrayN(*pCert));
485
486                 if (i == 0)
487                 {
488                         certType = PM_SET_AUTHOR_SIGNER_CERT;
489                 }
490                 else if (i == 1)
491                 {
492                         certType = PM_SET_AUTHOR_INTERMEDIATE_CERT;
493                 }
494                 else if (i == 2)
495                 {
496                         certType = PM_SET_AUTHOR_ROOT_CERT;
497                 }
498                 else
499                 {
500                         AppLog("Invalid certificate type[%d]", i);
501                         break;
502                 }
503
504                 AppLog("------------------------------------------");
505                 AppLog("Certificate type=[%d]", certType);
506                 AppLog("[%s]", pCertValue.get());
507
508                 res = pkgmgr_installer_set_cert_value(pHandle, (pkgmgr_instcert_type)certType, pCertValue.get());
509                 TryReturn(res == 0, false, "pkgmgr_installer_set_cert_value(%d) failed.[%d]", i, res);
510         }
511
512         return true;
513 }
514
515 bool
516 SignatureManager::SetDistributorCertValue(void* pHandle, IListT<String *>* pCertList, int sigFileNumber) const
517 {
518         TryReturn(pHandle, false, "pHandle is null.");
519         TryReturn(pCertList, false, "pCertPath is null.");
520         TryReturn((sigFileNumber == 1) || (sigFileNumber == 2), false, "sigFileNumber[%d] is invalid.", sigFileNumber);
521
522         int res = 0;
523         result r = E_SUCCESS;
524         int certType = 0;
525
526         for (int i = 0; i < pCertList->GetCount(); i++)
527         {
528                 String* pCert = null;
529                 r = pCertList->GetAt(i, pCert);
530                 TryReturn(!IsFailed(r), false, "pCertList->GetAt() is failed, [%d]", i);
531                 TryReturn(pCert, false, "pCertList->GetAt() is failed, [%d]", i);
532
533                 std::unique_ptr<char[]> pCertValue(_StringConverter::CopyToCharArrayN(*pCert));
534
535                 if (sigFileNumber == 1)
536                 {
537                         if (i == 0)
538                         {
539                                 certType = PM_SET_DISTRIBUTOR_SIGNER_CERT;
540                         }
541                         else if (i == 1)
542                         {
543                                 certType = PM_SET_DISTRIBUTOR_INTERMEDIATE_CERT;
544                         }
545                         else if (i == 2)
546                         {
547                                 certType = PM_SET_DISTRIBUTOR_ROOT_CERT;
548                         }
549                         else
550                         {
551                                 AppLog("Invalid certificate type[%d]", i);
552                                 break;
553                         }
554                 }
555                 else if (sigFileNumber == 2)
556                 {
557                         if (pCertList->GetCount() == 1)
558                         {
559                                 certType = PM_SET_DISTRIBUTOR2_ROOT_CERT;
560                         }
561                         else
562                         {
563                                 if (i == 0)
564                                 {
565                                         certType = PM_SET_DISTRIBUTOR2_SIGNER_CERT;
566                                 }
567                                 else if (i == 1)
568                                 {
569                                         certType = PM_SET_DISTRIBUTOR2_INTERMEDIATE_CERT;
570                                 }
571                                 else if (i == 2)
572                                 {
573                                         certType = PM_SET_DISTRIBUTOR2_ROOT_CERT;
574                                 }
575                                 else
576                                 {
577                                         AppLog("Invalid certificate type[%d]", i);
578                                         break;
579                                 }
580                         }
581                 }
582
583                 AppLog("------------------------------------------");
584                 AppLog("Certificate type=[%d]", certType);
585                 AppLog("[%s]", pCertValue.get());
586
587                 res = pkgmgr_installer_set_cert_value(pHandle, (pkgmgr_instcert_type)certType, pCertValue.get());
588                 TryReturn(res == 0, false, "pkgmgr_installer_set_cert_value(%d) failed.[%d]", i, res);
589         }
590
591         return true;
592 }
593
594 bool
595 SignatureManager::CompareReferences(HashMap* pDistributorRefMap, HashMap* pAuthorRefMap)
596 {
597         TryReturn(__pContext, false, "__pContext is null.");
598         bool res = false;
599
600         std::unique_ptr< IMapEnumerator > pEnum(pAuthorRefMap->GetMapEnumeratorN());
601         TryReturn(pEnum, false, "pEnum is null.");
602
603         while (pEnum->MoveNext() == E_SUCCESS)
604         {
605                 String* pAuthorKey = static_cast< String* > (pEnum->GetKey());
606                 TryReturn(pAuthorKey, false, "pAuthorKey is null.");
607
608                 String* pAuthorValue = static_cast< String* > (pEnum->GetValue());
609                 TryReturn(pAuthorValue, false, "pAuthorValue is failed.");
610
611                 String* pDistValue = static_cast< String* >(pDistributorRefMap->GetValue(*pAuthorKey));
612                 TryReturn(pDistValue, false, "pDistValue is null, failed to compare.");
613
614                 AppLog("pAuthorValue=[%ls]", pAuthorValue->GetPointer());
615                 AppLog("pDistValue=[%ls]", pDistValue->GetPointer());
616                 if (*pAuthorValue != *pDistValue)
617                 {
618                         TryReturn(0, false, "Digest value does not be matched.");
619                 }
620
621                 String filePath = __pContext->__rootPath + L"/" + *pAuthorKey;
622                 String fileDigest;
623
624                 AppLog("filePath=[%ls]", filePath.GetPointer());
625                 res = InstallerUtil::GetFileDigest(filePath, fileDigest);
626                 TryReturn(res == true, false, "GetFileDigest() is failed.");
627
628                 AppLog("fileDigest=[%ls]", fileDigest.GetPointer());
629                 if (*pAuthorValue != fileDigest)
630                 {
631                         TryReturn(0, false, "Digest value does not be matched.");
632                 }
633         }
634
635         return true;
636 }
637
638 bool
639 SignatureManager::PrintCertValue(const String& certValue) const
640 {
641         const int certLength = 30;
642
643         String startString;
644         String endString;
645         certValue.SubString(0, certLength, startString);
646         certValue.SubString(certValue.GetLength() - certLength, certLength, endString);
647         AppLog("cert value, start with [%ls]", startString.GetPointer());
648         AppLog("cert value, end with [%ls]", endString.GetPointer());
649
650         return true;
651 }