diff options
-rwxr-xr-x | inc/InstallerDefs.h | 2 | ||||
-rwxr-xr-x | src/Context/InstallationContext.cpp | 33 | ||||
-rwxr-xr-x | src/Context/InstallationContext.h | 11 | ||||
-rwxr-xr-x | src/Installer/Installer.cpp | 3 | ||||
-rwxr-xr-x | src/Manager/ConfigurationManager.cpp | 138 | ||||
-rwxr-xr-x | src/Manager/ConfigurationManager.h | 5 | ||||
-rwxr-xr-x | src/Manager/SignatureManager.cpp | 6 |
7 files changed, 196 insertions, 2 deletions
diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h index 49bd167..5c7002e 100755 --- a/inc/InstallerDefs.h +++ b/inc/InstallerDefs.h @@ -75,7 +75,7 @@ #define DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP L"/opt/storage/sdcard/apps/__@@osp_tmp@@__" #define OSP_INSTALLER "osp-installer" -#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/18(10)" +#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/22" enum InstallationSetStep { diff --git a/src/Context/InstallationContext.cpp b/src/Context/InstallationContext.cpp index 8d0a40b..d0ab876 100755 --- a/src/Context/InstallationContext.cpp +++ b/src/Context/InstallationContext.cpp @@ -34,6 +34,7 @@ using namespace Osp::Base; using namespace Osp::Base::Collection; using namespace Osp::Io; +using namespace Osp::Security::Cert; using namespace Osp::App; InstallationContext::InstallationContext(void) @@ -51,6 +52,8 @@ InstallationContext::InstallationContext(void) ,__storage(INSTALLATION_STORAGE_INTERNAL) ,__pPrivilegeList(null) ,__pLiveBoxList(null) +,__pAuthorCertPath(null) +,__pDistributorCertPath(null) ,__rootCertType(ROOT_CERTIFICATE_NONE) ,__packageNameType(INSTALLER_PREFIX_TYPE_NONE) ,__pPackageInfoImpl(null) @@ -65,6 +68,12 @@ InstallationContext::~InstallationContext(void) delete __pDrmLicense; __pDrmLicense = null; + delete __pAuthorCertPath; + __pAuthorCertPath = null; + + delete __pDistributorCertPath; + __pDistributorCertPath = null; + if (__pPrivilegeList) { __pPrivilegeList->RemoveAll(); @@ -415,6 +424,30 @@ InstallationContext::SetLiveBoxList(ArrayList* pLiveBoxList) __pLiveBoxList = pLiveBoxList; } +X509CertificatePath* +InstallationContext::GetAuthorCertPath(void) const +{ + return __pAuthorCertPath; +} + +void +InstallationContext::SetAuthorCertPath(X509CertificatePath* pAuthorCertPath) +{ + __pAuthorCertPath = pAuthorCertPath; +} + +X509CertificatePath* +InstallationContext::GetDistributorCertPath(void) const +{ + return __pDistributorCertPath; +} + +void +InstallationContext::SetDistributorCertPath(X509CertificatePath* pDistributorCertPath) +{ + __pDistributorCertPath = pDistributorCertPath; +} + RootCertificateType InstallationContext::GetRootCertType(void) const { diff --git a/src/Context/InstallationContext.h b/src/Context/InstallationContext.h index 3103587..b8c7d60 100755 --- a/src/Context/InstallationContext.h +++ b/src/Context/InstallationContext.h @@ -24,6 +24,7 @@ #define _INSTALLATION_CONTEXT_H_ #include <FAppPackageInfo.h> +#include <FSecCertX509CertificatePath.h> #include "InstallerDefs.h" #include "IInstallationStep.h" @@ -113,7 +114,13 @@ public: void SetPrivilegeList(Osp::Base::Collection::ArrayList* privilegeList); Osp::Base::Collection::ArrayList* GetLiveBoxList(void) const; - void SetLiveBoxList(Osp::Base::Collection::ArrayList* privilegeList); + void SetLiveBoxList(Osp::Base::Collection::ArrayList* pLiveBoxList); + + Osp::Security::Cert::X509CertificatePath* GetAuthorCertPath(void) const; + void SetAuthorCertPath(Osp::Security::Cert::X509CertificatePath* pAuthorCertPath); + + Osp::Security::Cert::X509CertificatePath* GetDistributorCertPath(void) const; + void SetDistributorCertPath(Osp::Security::Cert::X509CertificatePath* pDistributorCertPath); RootCertificateType GetRootCertType(void) const; void SetRootCertType(RootCertificateType certType); @@ -153,6 +160,8 @@ private: Osp::Base::Collection::ArrayList* __pPrivilegeList; Osp::Base::Collection::ArrayList* __pLiveBoxList; + Osp::Security::Cert::X509CertificatePath* __pAuthorCertPath; + Osp::Security::Cert::X509CertificatePath* __pDistributorCertPath; RootCertificateType __rootCertType; int __packageNameType; diff --git a/src/Installer/Installer.cpp b/src/Installer/Installer.cpp index a65eb60..89c328c 100755 --- a/src/Installer/Installer.cpp +++ b/src/Installer/Installer.cpp @@ -124,10 +124,13 @@ Installer::OnEnd(void) PermissionManager::SetFile(pContext); configurationManager.CreateFile(pContext); + configurationManager.UnregisterCertInfo(pContext); + configurationManager.RegisterCertInfo(pContext); } else if (operation == INSTALLER_OPERATION_UNINSTALL) { configurationManager.RemoveFile(pContext); + configurationManager.UnregisterCertInfo(pContext); } AppLogTag(OSP_INSTALLER, "END"); diff --git a/src/Manager/ConfigurationManager.cpp b/src/Manager/ConfigurationManager.cpp index 65dbccb..363345e 100755 --- a/src/Manager/ConfigurationManager.cpp +++ b/src/Manager/ConfigurationManager.cpp @@ -24,10 +24,13 @@ #include <unistd.h> #include <pkgmgr_parser.h> +#include <pkgmgr_installer.h> #include <FBaseUtilStringUtil.h> #include <FIoFile.h> #include <FIoDirectory.h> +#include <FSecCryptoSha1Hash.h> +#include <FSecCertX509CertificatePath.h> #include <FApp_Aul.h> #include <FApp_PackageInfoImpl.h> #include <FApp_PackageManagerImpl.h> @@ -40,6 +43,8 @@ using namespace Osp::Base; using namespace Osp::Base::Collection; using namespace Osp::Base::Utility; +using namespace Osp::Security::Cert; +using namespace Osp::Security::Crypto; using namespace Osp::App; using namespace Osp::Io; @@ -341,6 +346,139 @@ CATCH: } bool +ConfigurationManager::RegisterCertInfo(InstallationContext* pContext) const +{ + AppLogTag(OSP_INSTALLER, "RegisterCertInfo - START"); + + int res = 0; + bool result = true; + pkgmgr_instcertinfo_h handle = null; + String appId = pContext->GetAppId(); + X509CertificatePath* pAuthorCertPath = pContext->GetAuthorCertPath(); + X509CertificatePath* pDistributorCertPath = pContext->GetDistributorCertPath(); + + char* pAppId = _StringConverter::CopyToCharArrayN(appId); + TryCatch(pAppId, result = false, "[osp-installer] pAppId is null"); + + res = pkgmgr_installer_create_certinfo_set_handle(&handle); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_create_certinfo_set_handle() failed.[%d]", res); + + if (pAuthorCertPath) + { + AppLogTag(OSP_INSTALLER, "pAuthorCertPath is processing."); + result = SetCertHashValue(handle, pAuthorCertPath, PM_SET_AUTHOR_SIGNER_CERT); + TryCatch(result == true, , "[osp-installer] RegisterCertHashValue() failed. [pAuthorCertPath]"); + } + + if (pDistributorCertPath) + { + AppLogTag(OSP_INSTALLER, "pDistributorCertPath is processing."); + result = SetCertHashValue(handle, pDistributorCertPath, PM_SET_DISTRIBUTOR_SIGNER_CERT); + TryCatch(result == true, , "[osp-installer] RegisterCertHashValue() failed. [pDistributorCertPath]"); + } + + res = pkgmgr_installer_save_certinfo(pAppId, handle); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_save_certinfo(%s) failed.[%d]", pAppId, res); + + AppLogTag(OSP_INSTALLER, "RegisterCertInfo - END"); + +CATCH: + if (handle) + { + pkgmgr_installer_destroy_certinfo_set_handle(handle); + } + + delete[] pAppId; + return result; +} + +bool +ConfigurationManager::SetCertHashValue(void* pHandle, X509CertificatePath* pCertPath, int certType) const +{ + TryReturn(pCertPath, false, "[osp-installer] pCertPath is null."); + + int res = 0; + bool result = true; + ICertificate* pCert = null; + char* pCertValue = null; + + for (int i = 0; i < pCertPath->GetLength(); i++) + { + pCert = pCertPath->GetCertificateN(i); + TryCatch(pCert, result = false, "[osp-installer] pCert is null.[%i]", i); + + pCertValue = GetCertValueN(pCert); + TryCatch(pCertValue, result = false, "[osp-installer] pCertValue is null.[%i]", i); + + AppLogTag(OSP_INSTALLER, "[%d] - pCertValue[%s] certType[%d]", i, pCertValue, certType); + + res = pkgmgr_installer_set_cert_value(pHandle, (pkgmgr_instcert_type)certType, pCertValue); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_set_cert_value(%d) failed.[%d]", i, res); + + delete pCert; + pCert = null; + delete[] pCertValue; + pCertValue = null; + + certType--; + } + +CATCH: + delete pCert; + delete[] pCertValue; + + return result; +} + +char* +ConfigurationManager::GetCertValueN(ICertificate* pCert) const +{ + bool result = true; + Sha1Hash hash; + ByteBuffer* pEncodedData = null; + ByteBuffer* pHashValue = null; + String base64Value; + char* pEncodedValue = null; + + pEncodedData = pCert->GetEncodedDataN(); + TryCatch(pEncodedData, result = false, "[osp-installer] pEncodedData is null."); + + pHashValue = hash.GetHashN(*pEncodedData); + TryCatch(pHashValue, result = false, "[osp-installer] pHashValue is null"); + + StringUtil::EncodeToBase64String(*pHashValue, base64Value); + pEncodedValue = _StringConverter::CopyToCharArrayN(base64Value); + TryCatch(pEncodedValue, result = false, "[osp-installer] pEncodedValue is null"); + +CATCH: + delete pEncodedData; + delete pHashValue; + + return pEncodedValue; +} + +bool +ConfigurationManager::UnregisterCertInfo(InstallationContext* pContext) const +{ + AppLogTag(OSP_INSTALLER, "UnregisterCertInfo - START"); + int res = 0; + bool result = true; + String appId = pContext->GetAppId(); + + char* pAppId = _StringConverter::CopyToCharArrayN(appId); + TryCatch(pAppId, result = false, "[osp-installer] pAppId is null"); + + res = pkgmgr_installer_delete_certinfo(pAppId); + TryCatch(res == 0, result = false, "[osp-installer] pkgmgr_installer_delete_certinfo(%s) failed.[%d]", pAppId, res); + + AppLogTag(OSP_INSTALLER, "UnregisterCertInfo - END"); + +CATCH: + delete[] pAppId; + return result; +} + +bool ConfigurationManager::CreateSystemXmlFile(InstallationContext* pContext) { AppLogTag(OSP_INSTALLER, "SystemXmlFile - START"); diff --git a/src/Manager/ConfigurationManager.h b/src/Manager/ConfigurationManager.h index c3ce578..e68f8ed 100755 --- a/src/Manager/ConfigurationManager.h +++ b/src/Manager/ConfigurationManager.h @@ -45,12 +45,17 @@ public: bool CreateFile(InstallationContext* pContext); bool RemoveFile(InstallationContext* pContext); + bool RegisterCertInfo(InstallationContext* pContext) const; + bool UnregisterCertInfo(InstallationContext* pContext) const; + private: bool CreateSystemXmlFile(InstallationContext* pContext); bool CreateHybridServiceDesktopFile(InstallationContext* pContext); bool CreateInfoFile(const Osp::Base::String& filePath, const Osp::Base::String* pContext); bool CreateImeSymlink(const Osp::Base::String& binaryPath, const Osp::Base::String& packageName); bool FindPrivilege(InstallationContext* pContext, const Osp::Base::String& privilege) const; + bool SetCertHashValue(void* pHandle, Osp::Security::Cert::X509CertificatePath* pCertPath, int certType) const; + char* GetCertValueN(Osp::Security::Cert::ICertificate* pCert) const; }; // ConfigurationManager diff --git a/src/Manager/SignatureManager.cpp b/src/Manager/SignatureManager.cpp index 16d4664..14443e3 100755 --- a/src/Manager/SignatureManager.cpp +++ b/src/Manager/SignatureManager.cpp @@ -147,6 +147,9 @@ SignatureManager::VerifyChain(RootCertificateType certType) ret = Validate(__pAuthorCertPath); AppLogTag(OSP_INSTALLER, "__pAuthorCertPath Validate [END]"); TryCatch(ret == true, ret = false, "[osp-installer] Validate(AuthorCert) is failed."); + + __pContext->SetAuthorCertPath(__pAuthorCertPath); + __pAuthorCertPath = null; } } else @@ -157,6 +160,9 @@ SignatureManager::VerifyChain(RootCertificateType certType) ret = Validate(__pDistributorCertPath); AppLogTag(OSP_INSTALLER, "__pDistributorCertPath Validate [END]"); TryCatch(ret == true, ret = false, "[osp-installer] Validate(DistributorCert) is failed."); + + __pContext->SetDistributorCertPath(__pDistributorCertPath); + __pDistributorCertPath = null; } } |