diff options
author | jh0522.choi <jh0522.choi@samsung.com> | 2012-10-05 13:54:12 +0900 |
---|---|---|
committer | jh0522.choi <jh0522.choi@samsung.com> | 2012-10-05 13:54:12 +0900 |
commit | c6fdf2fe68fbab516825cb00afd34c86262e9fbd (patch) | |
tree | b2662be0980746c19f0ddf8b7d7acb55eef74f29 /src/Manager | |
parent | f064727a492edc71d743c53bb9b906ea8d3f379f (diff) | |
download | installer-c6fdf2fe68fbab516825cb00afd34c86262e9fbd.tar.gz installer-c6fdf2fe68fbab516825cb00afd34c86262e9fbd.tar.bz2 installer-c6fdf2fe68fbab516825cb00afd34c86262e9fbd.zip |
Seperate the osp-installer
Diffstat (limited to 'src/Manager')
-rwxr-xr-x | src/Manager/ConfigurationManager.cpp | 347 | ||||
-rwxr-xr-x | src/Manager/ConfigurationManager.h | 55 | ||||
-rwxr-xr-x | src/Manager/InstallerManager.cpp | 818 | ||||
-rwxr-xr-x | src/Manager/InstallerManager.h | 86 | ||||
-rwxr-xr-x | src/Manager/PermissionManager.cpp | 504 | ||||
-rw-r--r-- | src/Manager/PermissionManager.h | 56 | ||||
-rwxr-xr-x | src/Manager/SignatureManager.cpp | 314 | ||||
-rwxr-xr-x | src/Manager/SignatureManager.h | 69 |
8 files changed, 2249 insertions, 0 deletions
diff --git a/src/Manager/ConfigurationManager.cpp b/src/Manager/ConfigurationManager.cpp new file mode 100755 index 0000000..4a21f1b --- /dev/null +++ b/src/Manager/ConfigurationManager.cpp @@ -0,0 +1,347 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ConfigurationManager.cpp + * @brief This is the implementation file for %ConfigurationManager class. + */ + +#include <stdio.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <pkgmgr_parser.h> + +#include <FBaseUtilStringUtil.h> +#include <FIoFile.h> +#include <FApp_PackageInfoImpl.h> +#include <FApp_PackageManagerImpl.h> +#include <FBase_StringConverter.h> + +#include "ConfigurationManager.h" +#include "ManifestGenerator.h" +#include "InstallerUtil.h" + +using namespace Osp::Base; +using namespace Osp::Base::Collection; +using namespace Osp::Base::Utility; +using namespace Osp::App; +using namespace Osp::Io; + +ConfigurationManager::ConfigurationManager(void) +{ +} + +ConfigurationManager::~ConfigurationManager(void) +{ +} + +bool +ConfigurationManager::CreateFile(InstallationContext* pContext) +{ + bool res = false; + const char* pBinaryPath = null; + String xmlPath; + char* pXmlPath = null; + int err = 0; + + _PackageInfoImpl *pPackageInfoImpl = null; + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null."); + + String rootPath; + rootPath = pPackageInfoImpl->GetAppRootPath(); + + String apiVersion; + apiVersion = pPackageInfoImpl->GetAppApiVersion(); + String versionInfoFile; + versionInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), VERSION_INFO_FILE); + CreateInfoFile(versionInfoFile, &apiVersion); + + String webServicePrivilege("WEB_SERVICE"); + if (FindPrivilege(pContext, webServicePrivilege) == true) + { + AppLogTag(OSP_INSTALLER, "WEB_SERVICE privilege is detected. rootPath=[%ls]", rootPath.GetPointer()); + + String webServiceInfoFile; + webServiceInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), WEBSERVICE_INFO_FILE); + CreateInfoFile(webServiceInfoFile, null); + } + + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + pAppList = pPackageInfoImpl->GetAppInfoList(); + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + result r = E_SUCCESS; + + String appName; + appName = pAppInfoImpl->GetName(); + + String appType; + appType = pAppInfoImpl->GetType(); + + String packageName; + packageName = pAppInfoImpl->GetPackageName(); + + String binaryPath; + binaryPath.Format(1024, L"%ls%ls/%ls", rootPath.GetPointer(), DIR_BIN, appName.GetPointer()); + + pBinaryPath = _StringConverter::CopyToCharArrayN(binaryPath); + TryCatch(pBinaryPath, res = false, "[osp-installer] pBinaryPath is null"); + + if (File::IsFileExist(binaryPath) == true) + { + InstallerUtil::Remove(binaryPath); + } + + if (appType == L"UiApp") + { + //err = symlink(UIAPP_LOADER_PATH, pBinaryPath); + + r = File::Copy(UIAPP_LOADER_PATH, pBinaryPath, false); + TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed, filePath=[%s]", pBinaryPath); + + ArrayList* pFeatureList = pAppInfoImpl->GetAppFeatureList(); + TryCatch(pFeatureList, res = false, "[osp-installer] pFeatureList is null"); + + String coordinateSystem; + String baseScreenSize; + String logicalCoordinate; + + for (int j = 0; j < pFeatureList->GetCount(); j++) + { + _AppFeatureInfoImpl* pAppFeature = dynamic_cast<_AppFeatureInfoImpl*>(pFeatureList->GetAt(j)); + + if (pAppFeature != null) + { + if (pAppFeature->GetName() == L"CoordinateSystem") + { + coordinateSystem = pAppFeature->GetValue(); + } + + if (pAppFeature->GetName() == L"BaseScreenSize") + { + baseScreenSize = pAppFeature->GetValue(); + } + + if (pAppFeature->GetName() == L"LogicalCoordinate") + { + logicalCoordinate = pAppFeature->GetValue(); + } + } + } + + String uiScalability; + uiScalability.Format(1024, UISCALABILITY_INFO, coordinateSystem.GetPointer(), baseScreenSize.GetPointer(), logicalCoordinate.GetPointer()); + + String uiScalabilityInfoFile; + uiScalabilityInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), UISCALABILITY_INFO_FILE); + + CreateInfoFile(uiScalabilityInfoFile, &uiScalability); + } + else if (appType == L"ServiceApp") + { + if (pContext->IsPreloaded() == false) + { + //err = symlink(SERVICEAPP_LOADER_PATH, pBinaryPath); + r = File::Copy(SERVICEAPP_LOADER_PATH, pBinaryPath, false); + TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed, filePath=[%s]", pBinaryPath); + } + else + { + //err = symlink(SYSTEMAPP_LOADER_PATH, pBinaryPath); + r = File::Copy(SYSTEMAPP_LOADER_PATH, pBinaryPath, false); + TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed, filePath=[%s]", pBinaryPath); + } + } + + int res = -1; + res = chmod(pBinaryPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", pBinaryPath, res); + } + else + { + AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", pBinaryPath, res); + } + + delete[] pBinaryPath; + pBinaryPath = null; + } + } + + //if (pContext->IsPreloaded() == true) + //{ + // xmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, pContext->GetAppId().GetPointer()); + //} + //else + //{ + xmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, pContext->GetAppId().GetPointer()); + //} + + pXmlPath = _StringConverter::CopyToCharArrayN(xmlPath); + TryCatch(pXmlPath != null, res = false, "[osp-installer] pXmlPath is null"); + + pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath, null); + + CreateSystemXmlFile(pContext); + + AppLogTag(OSP_INSTALLER, "START(sync)"); + sync(); + AppLogTag(OSP_INSTALLER, "END(sync)"); + + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() START"); + if (pkgmgr_parser_parse_manifest_for_installation(pXmlPath, null) != 0) + { + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() is failed.[%s]", pXmlPath); + } + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() END"); + + res = true; + +CATCH: + delete[] pBinaryPath; + delete[] pXmlPath; + + return res; +} + +bool +ConfigurationManager::RemoveFile(InstallationContext* pContext) +{ + String xmlPath; + char* pXmlPath = null; + _PackageInfoImpl *pPackageInfoImpl = null; + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + + //if (pContext->IsPreloaded() == true) + //{ + // xmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, pContext->GetAppId().GetPointer()); + //} + //else + //{ + xmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, pContext->GetAppId().GetPointer()); + //} + + pXmlPath = _StringConverter::CopyToCharArrayN(xmlPath); + TryCatch(pXmlPath != null, , "[osp-installer] pXmlPath is null"); + + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_uninstallation() START"); + if (pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath, null) != 0) + { + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_uninstallation() is failed.[%s]", pXmlPath); + } + AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_uninstallation() END"); + + if (File::IsFileExist(xmlPath) == true) + { + AppLogTag(OSP_INSTALLER, "removing xml filePath=[%ls]", xmlPath.GetPointer()); + + InstallerUtil::Remove(xmlPath); + } + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryCatch(pPackageInfoImpl, , "[osp-installer] pPackageInfoImpl is null."); + + pAppList = pPackageInfoImpl->GetAppInfoList(); + + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + String packageName = pAppInfoImpl->GetPackageName(); + String destPath; + char dest[772] = {0}; + + destPath.Format(1024, L"%ls/%ls", SLP_APP_PATH, packageName.GetPointer()); + sprintf(dest, "%ls", destPath.GetPointer()); + unlink(dest); + } + } + +CATCH: + delete[] pXmlPath; + + return true; +} + +bool +ConfigurationManager::CreateSystemXmlFile(InstallationContext* pContext) +{ + AppLogTag(OSP_INSTALLER, "SystemXmlFile - START"); + bool ret = false; + + ManifestGenerator manifestGenerator; + manifestGenerator.Construct(pContext); + ret = manifestGenerator.Write(); + + if (ret == false) + { + fprintf(stderr, "manifestGenerator.Write() is failed.\n"); + AppLogTag(OSP_INSTALLER, "manifestGenerator.Write() is failed."); + } + AppLogTag(OSP_INSTALLER, "SystemXmlFile - END"); + + return ret; +} + +bool +ConfigurationManager::CreateInfoFile(const String& filePath, const String* pContext) +{ + result r = E_SUCCESS; + File file; + + r = file.Construct(filePath, "w"); + TryReturn(!IsFailed(r), false, "[osp-installer] file.Construct() failed, filePath=[%ls]", filePath.GetPointer()); + + if (pContext) + { + r = file.Write(*pContext); + TryReturn(!IsFailed(r), false, "[osp-installer] file.Write() failed, filePath=[%ls]", filePath.GetPointer()); + AppLogTag(OSP_INSTALLER, "Context = [%ls]", pContext->GetPointer()); + } + + AppLogTag(OSP_INSTALLER, "filePath = [%ls]", filePath.GetPointer()); + + return true; +} + +bool +ConfigurationManager::FindPrivilege(InstallationContext* pContext, const String& privilege) const +{ + TryReturn(pContext, false, "[osp-installer] pContext is null."); + + bool ret = false; + const ArrayList* pPrivilegeList = pContext->GetPrivilegeList(); + + if (pPrivilegeList) + { + if (pPrivilegeList->Contains(privilege) == true) + { + AppLogTag(OSP_INSTALLER, "Privilege = [%ls]", privilege.GetPointer()); + ret = true; + } + } + + return ret; +} diff --git a/src/Manager/ConfigurationManager.h b/src/Manager/ConfigurationManager.h new file mode 100755 index 0000000..31b8995 --- /dev/null +++ b/src/Manager/ConfigurationManager.h @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file ConfigurationManager.h + * @brief This is the header file for the %ConfigurationManager class. + * + * This header file contains the declarations of the %ConfigurationManager class. + */ +#ifndef _CONFIGURATION_MANAGER_H_ +#define _CONFIGURATION_MANAGER_H_ + +#include <FApp_AppInfoImpl.h> + +#include "InstallationContext.h" + + +/** + * @class ConfigurationManager + * @brief This class represents the class of ConfigurationManager. + * @since 1.0 + * + * This class represents the class of ConfigurationManager. + * + */ +class ConfigurationManager +{ +public: + ConfigurationManager(void); + virtual ~ConfigurationManager(void); + + bool CreateFile(InstallationContext* pContext); + bool RemoveFile(InstallationContext* pContext); + +private: + bool CreateSystemXmlFile(InstallationContext* pContext); + bool CreateInfoFile(const Osp::Base::String& filePath, const Osp::Base::String* pContext); + bool FindPrivilege(InstallationContext* pContext, const Osp::Base::String& privilege) const; + +}; // ConfigurationManager + +#endif // _CONFIGURATION_MANAGER_H_ diff --git a/src/Manager/InstallerManager.cpp b/src/Manager/InstallerManager.cpp new file mode 100755 index 0000000..fefc02d --- /dev/null +++ b/src/Manager/InstallerManager.cpp @@ -0,0 +1,818 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerManager.cpp + * @brief This is the implementation file for %InstallerManager class. + */ + +#include <unistd.h> + +#include <FIoFile.h> +#include <FIoDirectory.h> +#include <FBase_StringConverter.h> +#include <FApp_PackageInfoImpl.h> + +#include "InstallerManager.h" +#include "GuestInstaller.h" +#include "IDEInstaller.h" +#include "PreloadedInstaller.h" +#include "RestorationInstaller.h" +#include "InstallerUtil.h" + +using namespace Osp::Base; +using namespace Osp::Base::Utility; +using namespace Osp::Base::Collection; +using namespace Osp::Io; +using namespace Osp::App; + +const int BUFSIZE = 512; +InstallerManager* InstallerManager::__pInstallerManager = null; + +InstallerManager::InstallerManager(void) +: __pContext(null) +, __pInstaller(null) +{ +} + +InstallerManager::~InstallerManager(void) +{ + delete __pContext; + __pContext = null; + + delete __pInstaller; + __pInstaller = null; +} + +InstallerManager* +InstallerManager::GetInstance() +{ + if (__pInstallerManager == null) + { + AppLogTag(OSP_INSTALLER, "InstallerManager::GetInstance Create new instance."); + __pInstallerManager = new InstallerManager(); + TryReturn(__pInstallerManager, null, "[osp-installer] __pInstallerManager is null"); + } + + return __pInstallerManager; +} + +InstallerError +InstallerManager::Construct(const String& path, InstallerType installerType, InstallerOperation operation, RequesterType requesterType) +{ + InstallerError error = INSTALLER_ERROR_NONE; + + __pContext = new InstallationContext(); + TryReturn(__pContext, INSTALLER_ERROR_MEMORY, "[osp-installer] __pContext is null."); + + error = __pContext->Construct(); + TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pContext->Construct() failed."); + + __pContext->SetInstallerOperation(operation); + + if (requesterType == REQUESTER_TYPE_PRELOADED) + { + __pContext->SetPreloaded(true); + } + + __pInstaller = CreateInstaller(installerType); + TryReturn(__pInstaller, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller is null."); + + if (installerType == INSTALLER_TYPE_DIRECTORY) + { + _PackageInfoImpl *pPackageInfoImpl = null; + + pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + pPackageInfoImpl->SetAppRootPath(path); + + AppLogTag(OSP_INSTALLER, "path = [%ls]", path.GetPointer()); + } + + if (operation == INSTALLER_OPERATION_INSTALL) + { + __pContext->SetInputPath(path); + __pContext->SetPackagePath(path); + __pContext->SetInstallDir(path); + + FileAttributes attribute; + result r = File::GetAttributes(path, attribute); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] path is invalid. path=[%ls]", path.GetPointer()); + + // org.tizen.* + if (path.Contains(PACKAGE_NAME_PREFIX_ORG) == true) + { + __pContext->SetPackageNameType(INSTALLER_PREFIX_TYPE_ORG); + } + } + else if (operation == INSTALLER_OPERATION_UNINSTALL) + { + AppLogTag(OSP_INSTALLER, "operation is INSTALLER_OPERATION_UNINSTALL"); + __pContext->SetCurrentInstallationStep(INSTALLER_STEP_INIT_UNINSTALL); + __pContext->SetAppId(path); + } + + error = __pInstaller->Construct(__pContext); + TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller->Construct() failed"); + + AppLogTag(OSP_INSTALLER, "Construct() is success"); + + return error; +} + +void +InstallerManager::Release(void) +{ + delete __pInstallerManager; + __pInstallerManager = null; +} + +Installer* +InstallerManager::CreateInstaller(InstallerType installerType) +{ + Installer* pInstaller = null; + + switch (installerType) + { + case INSTALLER_TYPE_INSTALLER: + AppLogTag(OSP_INSTALLER, "INSTALLER_TYPE_INSTALLER"); + pInstaller = new Installer(); + break; + + case INSTALLER_TYPE_PACKAGE: + AppLogTag(OSP_INSTALLER, "INSTALLER_TYPE_PACKAGE"); + pInstaller = new PackageInstaller(); + break; + + case INSTALLER_TYPE_DIRECTORY: + AppLogTag(OSP_INSTALLER, "INSTALLER_TYPE_DIRECTORY"); + pInstaller = new DirectoryInstaller(); + break; + + case INSTALLER_TYPE_GUEST: + AppLogTag(OSP_INSTALLER, "INSTALLER_TYPE_GUEST"); + pInstaller = new GuestInstaller(); + break; + + case INSTALLER_TYPE_PRELOADED: + AppLogTag(OSP_INSTALLER, "INSTALLER_TYPE_PRELOADED"); + pInstaller = new PreloadedInstaller(); + break; + + case INSTALLER_TYPE_IDE: + AppLogTag(OSP_INSTALLER, "INSTALLER_TYPE_IDE"); + pInstaller = new IDEInstaller(); + break; + + case INSTALLER_TYPE_RESTORATION: + AppLogTag(OSP_INSTALLER, "INSTALLER_TYPE_RESTORATION"); + pInstaller = new RestorationInstaller(); + break; + + default: + AppLogExceptionTag(OSP_INSTALLER, "Installer is not found."); + break; + } + + return pInstaller; +} + +InstallationStep +InstallerManager::GetNext(void) +{ + InstallationStep step = __pContext->GetCurrentInstallationStep(); + return __pInstaller->GetNext(step); +} + +InstallerError +InstallerManager::Init(void) +{ + return __pInstaller->OnInit(); +} + +InstallerError +InstallerManager::Error(void) +{ + return __pInstaller->OnError(); +} + +InstallerError +InstallerManager::Register(void) +{ + return __pInstaller->OnRegister(); +} + +InstallerError +InstallerManager::End(void) +{ + return __pInstaller->OnEnd(); +} + +InstallerError +InstallerManager::Rollback(void) +{ + return __pInstaller->OnRollback(); +} + +InstallerError +InstallerManager::UserCancel(void) +{ + return __pInstaller->OnUserCancel(); +} + +InstallerError +InstallerManager::Activate(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + IInstallationStep* pStep = null; + InstallationStep currentStep; + + while (__pContext->GetState() == INSTALLER_STATE_RUNNING) + { + currentStep = GetNext(); + __pContext->ChangeStep(currentStep); + + pStep = __pContext->GetStep(); + if (pStep) + { + error = pStep->Run(__pContext); + + if (error != INSTALLER_ERROR_NONE) + { + __pContext->SetError(error); + fprintf(stderr, "Activate:: Error = [%d]\n", error); + Error(); + return error; + } + } + + if (currentStep == INSTALLER_STEP_INIT) + { + error = Init(); + TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred."); + } + else if (currentStep == INSTALLER_STEP_END) + { + error = Register(); + TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred."); + + error = End(); + TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred."); + } + + if (__pContext->IsContinue() == false) + { + break; + } + + if (__pContext->GetCurrentInstallationStep() >= INSTALLER_STEP_MAX) + { + break; + } + } + + return error; +} + +InstallerError +InstallerManager::Progress(void) +{ + return INSTALLER_ERROR_NONE; +} + +InstallationContext* +InstallerManager::GetContext(void) +{ + return __pContext; +} + +int +InstallerManager::Request(const String& path, InstallerOperation operation, RequesterType requesterType, String& appid, int& errorType) +{ + InstallerType type = INSTALLER_TYPE_INSTALLER; + InstallationContext* pContext = null; + InstallerError error = INSTALLER_ERROR_NONE; + InstallerManager* pInstallManager = null; + //bool isRunning = false; + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "InstallerManager::Request"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "# operation = [%s]", (operation == INSTALLER_OPERATION_INSTALL) ? "Install":"Uninstall"); + AppLogTag(OSP_INSTALLER, "# path = [%ls]", path.GetPointer()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + if (operation == INSTALLER_OPERATION_INSTALL) + { + FileAttributes attr; + result r = File::GetAttributes(path, attr); + TryCatch(!IsFailed(r), error = INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] File::GetAttributes() failed"); + + if (attr.IsDirectory()) + { + type = INSTALLER_TYPE_DIRECTORY; + } + else + { + type = INSTALLER_TYPE_PACKAGE; + } + } + else if (operation == INSTALLER_OPERATION_UNINSTALL) + { + type = INSTALLER_TYPE_INSTALLER; + } + + pInstallManager = InstallerManager::GetInstance(); + TryCatch(pInstallManager, error = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pInstallManager is null."); + + error = pInstallManager->Construct(path, type, operation, requesterType); + TryCatch(error == INSTALLER_ERROR_NONE, , "[osp-installer] pInstallManager->Construct() failed."); + + error = pInstallManager->Activate(); + TryCatch(error == INSTALLER_ERROR_NONE, , "[osp-installer] pInstallManager->Activate() failed."); + + pContext = pInstallManager->GetContext(); + TryCatch(pContext, error = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pContext is null."); + + appid = pContext->GetAppId(); + +CATCH: + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); + } + + if (pInstallManager) + { + pInstallManager->Release(); + } + + if (error != INSTALLER_ERROR_NONE) + { + fprintf(stderr, " ErrorType [%d]\n", error); + } + + errorType = error; + return error; +} + +int +InstallerManager::RequestRecursiveDirectory(const Osp::Base::String& path, int& errorType) +{ + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + result r = E_SUCCESS; + int res = false; + String appid; + InstallerError error = INSTALLER_ERROR_NONE; + + pDir = new Directory; // Allocate %Directory instance + TryCatch(pDir, res = false, "[osp-installer] pDir is null"); + + r = pDir->Construct(path); + TryCatch(!IsFailed(r), res = false, "[osp-installer] pDir->Construct() failed, path=[%ls]", path.GetPointer()); + + pDirEnum = pDir->ReadN(); + TryCatch(pDirEnum, res = false, "[osp-installer] pDirEnum is null"); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String entryDir = path; + entryDir += L"/"; + entryDir += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + if (entry.IsDirectory() == false) + { + continue; + } + + const int entryLength = entryName.GetLength(); + if (entryLength == APPID_LENGTH) + { + // AppId + } + else if (entryLength == APP_DIR_LENGTH) + { + if (entryName.Contains(PACKAGE_NAME_PREFIX_ORG) == false) + { + fprintf(stderr, " - Not osp = [%ls]: prefix mismatch\n", entryDir.GetPointer()); + continue; + } + } + else + { + fprintf(stderr, " - Not osp = [%ls]: length(%d) mismatch\n", entryDir.GetPointer(), entryLength); + continue; + } + + String xmlFile; + xmlFile.Format(1024, L"%ls%ls", entryDir.GetPointer(), PACKAGE_XML_FILE); + + FileAttributes attr; + r = File::GetAttributes(xmlFile, attr); + if (IsFailed(r)) + { + fprintf(stderr, " - Not osp = [%ls]: No manifest.xml\n", entryDir.GetPointer()); + continue; + } + + fprintf(stderr, "---------------------------------------------------\n"); + AppLogTag(OSP_INSTALLER, "---------------------------------------------------"); + + fprintf(stderr, " # directory = [%ls]\n", entryDir.GetPointer()); + AppLogTag(OSP_INSTALLER, " # directory = [%ls]", entryDir.GetPointer()); + + Request(entryDir, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_PRELOADED, appid, errorType); + + fprintf(stderr, " # appid = [%ls], error = [%d]\n", appid.GetPointer(), errorType); + AppLogTag(OSP_INSTALLER, " # appid = [%ls], error = [%d]", appid.GetPointer(), errorType); + + if (errorType != 0) + { + fprintf(stderr, " # result = [installation][failure <------------------------]\n"); + AppLogTag(OSP_INSTALLER, " # result = [installation][failure <------------------------]"); + } + else + { + fprintf(stderr, " # result = [installation][success]\n"); + AppLogTag(OSP_INSTALLER, " # result = [installation][success]"); + } + + fprintf(stderr, "---------------------------------------------------\n"); + AppLogTag(OSP_INSTALLER, "---------------------------------------------------"); + } + + delete pDir; + pDir = null; + return error; + +CATCH: + delete pDir; + return error; +} + +int +InstallerManager::RequestByCommand(int argc, char **argv) +{ + int mode = 0; + char buf[BUFSIZE] = {0}; + String appId; + int errorType = -1; + int result = 0; + bool output = false; + + fprintf(stderr, "%s\n", OSP_INSTALLER_VERSION); + AppLogTag(OSP_INSTALLER, "%s", OSP_INSTALLER_VERSION); + + fprintf(stderr, " - argc = [%d]\n", argc); + AppLogTag(OSP_INSTALLER, " - argc = [%d]", argc); + + for (int i = 0; i < argc; i++) + { + fprintf(stderr, " - argv[%d] = [%s]\n", i, argv[i]); + AppLogTag(OSP_INSTALLER, " - argv[%d] = [%s]", i, argv[i]); + } + + ParseCommandArg(argc, argv, &mode, buf, &output); + + switch (mode) + { + case INSTALLER_MODE_INSTALL: + { + fprintf(stderr, "---------------------------------------------------\n"); + AppLogTag(OSP_INSTALLER, "---------------------------------------------------"); + fprintf(stderr, " # directory = [%s]\n", buf); + AppLogTag(OSP_INSTALLER, " # directory = [%s]", buf); + + result = InstallerManager::Request(buf, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL, appId, errorType); + + fprintf(stderr, " # appId = [%ls], error = [%d]\n", appId.GetPointer(), errorType); + AppLogTag(OSP_INSTALLER, " # appId = [%ls], error = [%d]", appId.GetPointer(), errorType); + + if (errorType != 0) + { + RemoveGarbage(buf); + fprintf(stderr, " # result = [Installation][failure]\n"); + AppLogTag(OSP_INSTALLER, " # result = [Installation][failure]"); + } + else + { + fprintf(stderr, " # result = [Installation][success]\n"); + AppLogTag(OSP_INSTALLER, " # result = [Installation][success]"); + } + } + break; + + case INSTALLER_MODE_UNINSTALL: + { + fprintf(stderr, "---------------------------------------------------\n"); + AppLogTag(OSP_INSTALLER, "---------------------------------------------------"); + fprintf(stderr, " # directory = [%s]\n", buf); + AppLogTag(OSP_INSTALLER, " # directory = [%s]", buf); + + result = Request(buf, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL, appId, errorType); + + fprintf(stderr, " # appId = [%ls], error = [%d]\n", appId.GetPointer(), errorType); + AppLogTag(OSP_INSTALLER, " # appId = [%ls], error = [%d]", appId.GetPointer(), errorType); + + if (errorType != 0) + { + fprintf(stderr, " # result = [Uninstallation][failure]\n"); + AppLogTag(OSP_INSTALLER, " # result = [Uninstallation][failure]"); + } + else + { + fprintf(stderr, " # result = [Uninstallation][success]\n"); + AppLogTag(OSP_INSTALLER, " # result = [Uninstallation][success]"); + } + } + break; + + case INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL: + { + fprintf(stderr, "---------------------------------------------------\n"); + AppLogTag(OSP_INSTALLER, "---------------------------------------------------"); + + result = RequestRecursiveDirectory(buf, errorType); + } + break; + + default: + { + fprintf(stderr, "__install_package_by_cmd, Invalid mode\n"); + } + break; + } + + fprintf(stderr, "---------------------------------------------------\n"); + AppLogTag(OSP_INSTALLER, "---------------------------------------------------"); + + if (output == true) + { + AppLogTag(OSP_INSTALLER, "stdout is updated by errorType"); + fprintf(stdout, "%d", errorType); + } + + return errorType; +} + +int +InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output) +{ + const char* pOpts_str = "u:i:r:v"; + int s = 0; + + if (mode == NULL) + { + fprintf(stderr, "mode is null\n"); + exit(-1); + } + + *mode = 0; + + while (1) + { + s = getopt(argc, argv, pOpts_str); + + if (s == -1) + { + break; + } + + switch (s) + { + case 'i': + if (*mode) + { + break; + } + + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: i"); + *mode = INSTALLER_MODE_INSTALL; + if (optarg[0] == 'v') + { + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v"); + *output = true; + strncpy(buf, argv[optind++], BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: buf = [%s]", buf); + } + else + { + strncpy(buf, optarg, BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + } + break; + + case 'u': + if (*mode) + { + break; + } + + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: u"); + *mode = INSTALLER_MODE_UNINSTALL; + if (optarg[0] == 'v') + { + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v"); + *output = true; + strncpy(buf, argv[optind++], BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: buf = [%s]", buf); + } + else + { + strncpy(buf, optarg, BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + } + break; + + case 'r': + if (*mode) + { + break; + } + + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: r"); + *mode = INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL; + strncpy(buf, optarg, BUFSIZE); + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + break; + + case 'v': + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v"); + *output = true; + AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg); + break; + + default: + fprintf(stderr, "Invalid option\n"); + exit(-1); + break; + } + } + + if (mode == 0) + { + fprintf(stderr, "Invalid mode\n"); + exit(-1); + } + + return 0; +} + +bool +InstallerManager::RemoveGarbage(const char* pDirectory) +{ + char pkgname[1024] = {0}; + + if (pDirectory == null) + { + return false; + } + + char* pStart = strrchr(const_cast<char*>(pDirectory), '/'); + if (pStart == null) + { + return false; + } + + strcpy(pkgname, pStart + 1); + AppLogTag(OSP_INSTALLER, "pkgname = %s", pkgname); + + AppLogTag(OSP_INSTALLER, "Remove Directory=(%s)", pDirectory); + InstallerUtil::Remove(pDirectory); + + return true; +} + +int +InstallerManager::ReqeustByTest(void) +{ + int errorType = 0; + String appId; + Osp::Io::File file; + Osp::Io::FileAttributes attr; + result r = E_SUCCESS; + char readBuf[512] = {0}; + + r = File::GetAttributes(L"/opt/apps/org.tizen.cmtamb4mtv/data/configuration", attr); + TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] file not found"); + + r = file.Construct(L"/opt/apps/org.tizen.cmtamb4mtv/data/configuration", L"r"); + TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] file.Construct failed"); + + if (file.Read(readBuf, sizeof(readBuf)-1) > 1) + { + String path; + path.Format(1024, L"%s", &readBuf[1]); + + if (readBuf[0] == '+') + { + errorType = Request(path, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL, appId, errorType); + } + else if (readBuf[0] == '-') + { + errorType = Request(path, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL, appId, errorType); + } + else if (readBuf[0] == '*') + { + errorType = RequestRecursiveDirectory(path, errorType); + } + } + +CATCH: + return errorType; +} + +void +InstallerManager::DisplayPackageInfo(const char* appId) +{ + _PackageInfoImpl* pPackageInfoImpl = null; + ArrayList* pAppList = null; + int totalCount = 0; + + pPackageInfoImpl = new (std::nothrow) _PackageInfoImpl; + if (pPackageInfoImpl == null) + { + return; + } + + pPackageInfoImpl->Construct(appId); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "PackageInfo"); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "# id = [%S]", pPackageInfoImpl->GetAppId().GetPointer()); + AppLogTag(OSP_INSTALLER, "# version = [%S]", pPackageInfoImpl->GetAppVersion().GetPointer()); + AppLogTag(OSP_INSTALLER, "# secret = [%S]", pPackageInfoImpl->GetAppSecret().GetPointer()); + AppLogTag(OSP_INSTALLER, "# name = [%S]", pPackageInfoImpl->GetAppName().GetPointer()); + AppLogTag(OSP_INSTALLER, "# vendor = [%S]", pPackageInfoImpl->GetAppVendor().GetPointer()); + AppLogTag(OSP_INSTALLER, "# description = [%S]", pPackageInfoImpl->GetAppDescription().GetPointer()); + AppLogTag(OSP_INSTALLER, "# mimeType = [%S]", pPackageInfoImpl->GetAppMimeType().GetPointer()); + AppLogTag(OSP_INSTALLER, "# api version = [%S]", pPackageInfoImpl->GetAppApiVersion().GetPointer()); + AppLogTag(OSP_INSTALLER, "# uri = [%S]", pPackageInfoImpl->GetAppUrl().GetPointer()); + AppLogTag(OSP_INSTALLER, "# cid = [%S]", pPackageInfoImpl->GetAppCid().GetPointer()); + AppLogTag(OSP_INSTALLER, "# parentId = [%S]", pPackageInfoImpl->GetAppParentId().GetPointer()); + AppLogTag(OSP_INSTALLER, "# installationDate = [%S]", pPackageInfoImpl->GetAppInstallationTime().ToString().GetPointer()); + AppLogTag(OSP_INSTALLER, "# rootpath = [%S]", pPackageInfoImpl->GetAppRootPath().GetPointer()); + AppLogTag(OSP_INSTALLER, "# readOnlySize = [%d]", pPackageInfoImpl->GetAppReadOnlySize()); + AppLogTag(OSP_INSTALLER, "# dataSize = [%d]", pPackageInfoImpl->GetAppDataSize()); + AppLogTag(OSP_INSTALLER, "# storageType = [%d]", pPackageInfoImpl->GetAppStorageType()); + AppLogTag(OSP_INSTALLER, "# state = [%d]", pPackageInfoImpl->GetAppState()); + AppLogTag(OSP_INSTALLER, "# initiator = [%d]", pPackageInfoImpl->GetAppInitiatior()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + + pAppList = pPackageInfoImpl->GetAppInfoListN(); + if (pAppList == null) + { + delete pPackageInfoImpl; + return; + } + + totalCount = pAppList->GetCount(); + + for (int i = 0; i < totalCount; i++) + { + _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "AppInfo(%d/%d)", i+1, totalCount); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + AppLogTag(OSP_INSTALLER, "# default = [%S]", pAppInfoImpl->GetDefault().GetPointer()); + AppLogTag(OSP_INSTALLER, "# appname = [%S]", pAppInfoImpl->GetName().GetPointer()); + AppLogTag(OSP_INSTALLER, "# packagename = [%S]", pAppInfoImpl->GetPackageName().GetPointer()); + AppLogTag(OSP_INSTALLER, "# mainmenu icon = [%S]", pAppInfoImpl->GetMainmenuIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "# setting icon = [%S]", pAppInfoImpl->GetSettingIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "# ticker icon = [%S]", pAppInfoImpl->GetTickerIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "# quickpanel icon = [%S]", pAppInfoImpl->GetQuickpanelIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "# launchImage icon = [%S]", pAppInfoImpl->GetLaunchImageIcon().GetPointer()); + AppLogTag(OSP_INSTALLER, "------------------------------------------"); + } + + pAppList->RemoveAll(); + delete pAppList; + pAppList = null; + + delete pPackageInfoImpl; +} + + diff --git a/src/Manager/InstallerManager.h b/src/Manager/InstallerManager.h new file mode 100755 index 0000000..2b583bb --- /dev/null +++ b/src/Manager/InstallerManager.h @@ -0,0 +1,86 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file InstallerManager.h + * @brief This is the header file for the %InstallerManager class. + * + * This header file contains the declarations of the %InstallerManager class. + */ +#ifndef _INSTALLER_MANAGER_H_ +#define _INSTALLER_MANAGER_H_ + +#include "InstallationContext.h" +#include "Installer.h" + +/** + * @class InstallerManager + * @brief This class represents the class of InstallerManager. + * @since 1.0 + * + * This class represents the class of InstallerManager. + * + */ +class InstallerManager +{ +public: + InstallerManager(void); + InstallerError Construct(const Osp::Base::String& path, InstallerType installerType, InstallerOperation op, RequesterType requesterType); + virtual ~InstallerManager(void); + + static InstallerManager* GetInstance(void); + void Release(void); + + int Request(const Osp::Base::String& path, InstallerOperation op, RequesterType requesterType, Osp::Base::String& appid, int& errorType); + int RequestRecursiveDirectory(const Osp::Base::String& path, int& errorType); + + bool RemoveGarbage(const char* pDirectory); + + int RequestByCommand(int argc, char **argv); + int ReqeustByTest(void); + + void DisplayPackageInfo(const char* appId); + +private: + InstallerManager(const InstallerManager& value); + InstallerManager& operator =(const InstallerManager& source); + + InstallationStep GetNext(void); + + InstallerError Init(void); + InstallerError Register(void); + InstallerError End(void); + + InstallerError Error(void); + InstallerError Rollback(void); + InstallerError UserCancel(void); + + InstallerError Activate(void); + InstallerError Progress(void); + + Installer* CreateInstaller(InstallerType installerType); + InstallationContext* GetContext(void); + + int ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output); + +private: + static InstallerManager* __pInstallerManager; + InstallationContext* __pContext; + Installer* __pInstaller; + +}; // InstallerManager + +#endif //_INSTALLER_MANAGER_H_ diff --git a/src/Manager/PermissionManager.cpp b/src/Manager/PermissionManager.cpp new file mode 100755 index 0000000..c6728ea --- /dev/null +++ b/src/Manager/PermissionManager.cpp @@ -0,0 +1,504 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PermissionManager.cpp + * @brief This is the implementation file for %PermissionManager class. + */ + +#include <stdio.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <FBaseUtilStringUtil.h> +#include <FIoFile.h> +#include <FIoDirectory.h> +#include <FBase_StringConverter.h> +#include <FIo_FileImpl.h> +#include <FApp_PackageManagerImpl.h> +#include <FApp_PackageInfoImpl.h> +#include <FApp_AppInfoImpl.h> + +#include "PermissionManager.h" +#include "InstallerUtil.h" + +using namespace Osp::Base; +using namespace Osp::Base::Collection; +using namespace Osp::Base::Utility; +using namespace Osp::Io; +using namespace Osp::App; + +PermissionManager::PermissionManager(void) +{ +} + +PermissionManager::~PermissionManager(void) +{ +} + +bool +PermissionManager::ChangeOwner(const Osp::Base::String& filePath) +{ + int res = -1; + char* pFilePath = null; + + pFilePath = _StringConverter::CopyToCharArrayN(filePath); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + res = chown(pFilePath, APP_OWNER_ID, APP_GROUP_ID); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to change owner[%s], res=[%d]", pFilePath, res); + } + + delete[] pFilePath; + + return true; +} + +bool +PermissionManager::ChangeHomeDirectoryOwner(const String& rootPath, int depth) +{ + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + result r = E_SUCCESS; + result res = false; + + pDir = new Directory; // Allocate %Directory instance + TryCatch(pDir, res = false, "[osp-installer] pDir is null"); + + r = pDir->Construct(rootPath); + TryCatch(!IsFailed(r), res = false, "[osp-installer] pDir->Construct() failed, rootPath=[%ls]", rootPath.GetPointer()); + + pDirEnum = pDir->ReadN(); + TryCatch(pDirEnum, res = false, "[osp-installer] pDirEnum is null"); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String entryDir = rootPath; + entryDir += L"/"; + entryDir += entryName; + + if (entryName == L".") + { + ChangeOwner(entryDir); + ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); + continue; + } + else if (entryName == L"..") + { + // if (depth != 0) + // { + // ChangeOwner(entryDir); + // } + + continue; + } + + if (entry.IsDirectory() == false) + { + ChangeOwner(entryDir); + ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); + } + else + { + ChangeHomeDirectoryOwner(entryDir, depth+1); + ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR); + } + } + + delete pDir; + pDir = null; + return true; + +CATCH: + delete pDir; + return false; +} + + +bool +PermissionManager::ApplyHomeDirectoryPolicy(const String& rootPath) +{ + String dataPath; + //char* pDataPath = null; + //int res = -1; + + dataPath = rootPath; + dataPath += DIR_DATA; + + AppLogTag(OSP_INSTALLER, "ApplyHomeDirectoryPolicy [%ls]", dataPath.GetPointer()); + + if (File::IsFileExist(dataPath) == false) + { + result r = E_SUCCESS; + r = Directory::Create(dataPath, false); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); + } +// else +// { +// if (File::IsFileExist(dataPath) == true) +// { +// AppLogTag(OSP_INSTALLER, "ApplyHomeDirectoryPolicy [%ls] is removed.", dataPath.GetPointer()); +// pDataPath = _StringConverter::CopyToCharArrayN(dataPath); +// remove(pDataPath); +// delete[] pDataPath; +// pDataPath = null; +// } +// } + + ChangeHomeDirectoryOwner(dataPath, 0); + ChangeMode(dataPath, S_IRUSR | S_IWUSR | S_IXUSR); + + return true; +} + +bool +PermissionManager::ChangeMode(const String& filePath, int mode) +{ + int res = -1; + char* pFilePath = null; + + pFilePath = _StringConverter::CopyToCharArrayN(filePath); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + res = chmod(pFilePath, mode); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to change mode, path=[%s], mode=[%o], res=[%d]", pFilePath, mode, res); + } + + delete[] pFilePath; + + return true; +} + +bool +PermissionManager::SetDirectory(InstallationContext* pContext) +{ + char destPath[772] = {0}; + int res = -1; + int err = 0; + String appRootPath; + _PackageInfoImpl *pPackageInfoImpl = null; + FileAttributes attribute; + result r = E_SUCCESS; + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + appRootPath = pPackageInfoImpl->GetAppRootPath(); + + // set permission(755) to default folders(AppRootPath) + sprintf(destPath, "%ls", appRootPath.GetPointer()); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=[%d].\n", destPath, res); + } + else + { + AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); + } + } + + // set permission(755) to default folders(BIN, INFO, DATA, RES) + sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_BIN); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res) + { + AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); + } + else + { + AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); + } + } + + sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_INFO); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); + } + else + { + AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); + } + } + + sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_RES); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + ChangeHomeDirectoryOwner(destPath, 0); + ChangeMode(destPath, S_IRUSR | S_IXUSR); + } + + sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_DATA); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); + } + else + { + AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); + } + } + + sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_LIB); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); + } + else + { + AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); + } + } + + sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_ICONS); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + ChangeHomeDirectoryOwner(destPath, 0); + ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR); + } + + sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_SETTING); + r = File::GetAttributes(destPath, attribute); + if (r == E_SUCCESS) + { + String appVersion = pPackageInfoImpl->GetAppVersion(); + char src[772] = {0}; + char dest[772] = {0}; + + sprintf(src, "%s/%s.%ls.%s", destPath, "setting", appVersion.GetPointer(), "xml"); + sprintf(dest, "%s/%s", destPath, "setting.xml"); + + unlink(dest); + + if (File::IsFileExist(src) == true) + { + err = symlink(src, dest); + AppLogTag(OSP_INSTALLER, "[%s]->[%s]\n", dest, src); + } + else + { + AppLogTag(OSP_INSTALLER, "[%s] is not existed.\n", src); + } + + ChangeHomeDirectoryOwner(destPath, 0); + ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR); + } + + ApplyHomeDirectoryPolicy(appRootPath); + + String packageId = pContext->GetAppId(); + String apiVersion = pPackageInfoImpl->GetAppApiVersion(); + AppLogTag(OSP_INSTALLER, "Osp::Io > installed path: %ls, packageId: %ls, API version: %ls", + appRootPath.GetPointer(), packageId.GetPointer(), apiVersion.GetPointer()); + + if (apiVersion.CompareTo(L"3.0") < 0) + { + AppLogTag(OSP_INSTALLER, "Osp::Io > API version <= 2.0"); + + if (_FileImpl::PrepareDataCaging(appRootPath, packageId) == false) + { + AppLogTag(OSP_INSTALLER, "Osp::Io > _FileImpl::PrepareDataCaging() failed"); + return false; + } + + SetSymLink(pContext); + } + else + { + AppLogTag(OSP_INSTALLER, "Osp::Io > API version >= 3.0"); + + if (_FileImpl::CreateOspApplicationDirectories(appRootPath, packageId) == false) + { + AppLogTag(OSP_INSTALLER, "Osp::Io > _FileImpl::CreateOspApplicationDirectories() failed."); + return false; + } + } + + CreateSystemDirectory(pContext, appRootPath); + + return true; +} + +bool +PermissionManager::SetFile(InstallationContext* pContext) +{ + char destPath[772] = {0}; + int res = -1; + + _PackageInfoImpl *pPackageInfoImpl = null; + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null."); + + String appRootPath; + appRootPath = pPackageInfoImpl->GetAppRootPath(); + + pAppList = pPackageInfoImpl->GetAppInfoList(); + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + // set permission(755) to bin file. + sprintf(destPath, "%ls%ls/%ls", appRootPath.GetPointer(), DIR_BIN, (pAppInfoImpl->GetName()).GetPointer()); + strcat(destPath, ".exe"); + res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res != 0) + { + AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); + } + else + { + AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); + } + } + } + + return true; +} + +bool +PermissionManager::CreateSystemDirectory(InstallationContext* pContext, const Osp::Base::String& rootpath) +{ + _PackageInfoImpl *pPackageInfoImpl = null; + _PackageAppInfoImpl* pAppInfoImpl = null; + ArrayList* pAppList = null; + int err = 0; + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null."); + + pAppList = pPackageInfoImpl->GetAppInfoList(); + + for (int i = 0 ; i < pAppList->GetCount(); i++) + { + pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); + if (pAppInfoImpl) + { + result r = E_SUCCESS; + String packageName = pAppInfoImpl->GetPackageName(); + String destPath; + String appRootPath; + appRootPath = pPackageInfoImpl->GetAppRootPath(); + char src[772] = {0}; + char dest[772] = {0}; + + destPath.Format(1024, L"%ls/%ls", SLP_APP_PATH, packageName.GetPointer()); + + sprintf(src, "%ls", appRootPath.GetPointer()); + sprintf(dest, "%ls", destPath.GetPointer()); + + unlink(dest); + + FileAttributes attr; + r = File::GetAttributes(destPath, attr); + if (r == E_SUCCESS) + { + InstallerUtil::Remove(destPath); + AppLogTag(OSP_INSTALLER, "Directory is removed. [%ls]\n", destPath.GetPointer()); + } + + err = symlink(src, dest); + } + } + + return true; +} + +bool +PermissionManager::SetSymLink(InstallationContext* pContext) +{ + char srcPath[772] = {0}; + char destPath[772] = {0}; + int err = 0; + String appRootPath; + _PackageInfoImpl *pPackageInfoImpl = null; + + pPackageInfoImpl = pContext->GetPackageInfoImpl(); + appRootPath = pPackageInfoImpl->GetAppRootPath(); + + sprintf(srcPath, "%ls%ls", appRootPath.GetPointer(), DIR_RES); + if (File::IsFileExist(srcPath) == true) + { + sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res"); + err = symlink("./res", destPath); + } + + sprintf(srcPath, "%ls%ls", appRootPath.GetPointer(), DIR_DATA); + if (File::IsFileExist(srcPath) == true) + { + sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Home"); + err = symlink("./data", destPath); + } + + sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-size-normal"); + if (File::IsFileExist(srcPath) == true) + { + sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenSize-Normal"); + err = symlink(srcPath, destPath); + } + + sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-density-high"); + if (File::IsFileExist(srcPath) == true) + { + sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenDensity-High"); + err = symlink(srcPath, destPath); + } + + sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-density-middle"); + if (File::IsFileExist(srcPath) == true) + { + sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenDensity-Middle"); + err = symlink(srcPath, destPath); + } + + sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-density-low"); + if (File::IsFileExist(srcPath) == true) + { + sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenDensity-Low"); + err = symlink(srcPath, destPath); + } + + return true; +} diff --git a/src/Manager/PermissionManager.h b/src/Manager/PermissionManager.h new file mode 100644 index 0000000..7bdd7a5 --- /dev/null +++ b/src/Manager/PermissionManager.h @@ -0,0 +1,56 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file PermissionManager.h + * @brief This is the header file for the %PermissionManager class. + * + * This header file contains the declarations of the %PermissionManager class. @n + */ +#ifndef _PERMISSION_MANAGER_H_ +#define _PERMISSION_MANAGER_H_ + +#include "InstallationContext.h" + +/** + * @class PermissionManager + * @brief This class represents the class of PermissionManager. + * @since 1.0 + * + * This class represents the class of PermissionManager. + * + */ +class PermissionManager +{ +public: + PermissionManager(void); + virtual ~PermissionManager(void); + + static bool SetDirectory(InstallationContext* pContext); + static bool SetFile(InstallationContext* pContext); + +private: + static bool ChangeOwner(const Osp::Base::String& filePath); + static bool ChangeHomeDirectoryOwner(const Osp::Base::String&, int depth); + static bool ApplyHomeDirectoryPolicy(const Osp::Base::String& rootpath); + static bool ChangeMode(const Osp::Base::String& filePath, int mode); + static bool CreateSystemDirectory(InstallationContext* pContext, const Osp::Base::String& rootpath); + static bool SetSymLink(InstallationContext* pContext); + static bool PrepareDataCaging(InstallationContext* pContext); + +}; // PermissionManager + +#endif // _PERMISSION_MANAGER_H_ diff --git a/src/Manager/SignatureManager.cpp b/src/Manager/SignatureManager.cpp new file mode 100755 index 0000000..dec8ef6 --- /dev/null +++ b/src/Manager/SignatureManager.cpp @@ -0,0 +1,314 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureManager.cpp + * @brief This is the implementation file for %SignatureManager class. + */ + +#include <FBase_StringConverter.h> + +#include "SignatureManager.h" + +using namespace Osp::Base; +using namespace Osp::Security::Cert; +using namespace Osp::Base::Collection; +using namespace Osp::Base::Utility; + +SignatureManager::SignatureManager(void) +:__pContext(null) +,__pSignature(null) +,__pAuthorCertPath(null) +,__pDistributorCertPath(null) +{ +} + +SignatureManager::~SignatureManager(void) +{ + delete __pSignature; + delete __pAuthorCertPath; + delete __pDistributorCertPath; +} + +bool +SignatureManager::Construct(InstallationContext* pContext) +{ + __pContext = pContext; + + return true; +} + +bool +SignatureManager::SetSignature() +{ + TryReturn(__pContext, false, "[osp-installer] __pContext is null."); + + bool ret = true; + char* pFilepath = _StringConverter::CopyToCharArrayN(__pContext->GetSignatureXmlPath()); + + __pSignature = new SignatureHandler; + TryCatch(__pSignature, ret = false, "[osp-installer] __pSignature is null"); + + ret = __pSignature->Construct(__pContext); + TryCatch(ret == true, ret = false, "[osp-installer] __pSignature->Construct is failed."); + + ret = __pSignature->Parse(pFilepath); + if (ret == false) + { + AppLogTag(OSP_INSTALLER, "__pSignature->Parse is failed. [%s]\n", pFilepath); + } + +CATCH: + delete[] pFilepath; + return ret; +} + +bool +SignatureManager::AddCert(RootCertificateType certType) +{ + TryReturn(__pSignature, false, "[osp-installer] __pSignature is null."); + + bool ret = true; + + if (certType == ROOT_CERTIFICATE_DEVELOPER) + { + IList* pAuthorCertChain = __pSignature->GetAuthorCertChain(); + + if (pAuthorCertChain) + { + AppLogTag(OSP_INSTALLER, "AddCertificate - AuthorCertChain"); + + __pAuthorCertPath = new X509CertificatePath(); + TryCatch(__pAuthorCertPath, ret = false, "[osp-installer] __pAuthorCertPath is null."); + + ret = AddCertificate(__pAuthorCertPath, pAuthorCertChain); + TryCatch(ret == true, ret = false, "[osp-installer] AddCertificate(AuthorCert) is failed."); + + ret = AddRootCertificate(__pAuthorCertPath, certType); + TryCatch(ret == true, ret = false, "[osp-installer] AddRootCertificate(AuthorCertPath) is failed."); + } + } + else + { + IList* pDistributorCertChain = __pSignature->GetDistributorCertChain(); + + if (pDistributorCertChain) + { + AppLogTag(OSP_INSTALLER, "AddCertificate - DistributorCert [%d]", certType); + + __pDistributorCertPath = new X509CertificatePath(); + TryCatch(__pDistributorCertPath, ret = false, "[osp-installer] __pDistributorCertPath is null."); + + ret = AddCertificate(__pDistributorCertPath, pDistributorCertChain); + TryCatch(ret == true, ret = false, "[osp-installer] AddCertificate(DistributorCert) is failed."); + + ret = AddRootCertificate(__pDistributorCertPath, certType); + TryCatch(ret == true, ret = false, "[osp-installer] AddRootCertificate(DistributorCert) is failed."); + } + } + +CATCH: + return ret; +} + +bool +SignatureManager::VerifyChain(RootCertificateType certType) +{ + bool ret = true; + + if (certType == ROOT_CERTIFICATE_DEVELOPER) + { + if (__pAuthorCertPath) + { + AppLogTag(OSP_INSTALLER, "__pAuthorCertPath Validate [START]"); + ret = Validate(__pAuthorCertPath); + AppLogTag(OSP_INSTALLER, "__pAuthorCertPath Validate [END]"); + TryCatch(ret == true, ret = false, "[osp-installer] Validate(AuthorCert) is failed."); + } + } + else + { + if (__pDistributorCertPath) + { + AppLogTag(OSP_INSTALLER, "__pDistributorCertPath Validate [START][%d]", certType); + ret = Validate(__pDistributorCertPath); + AppLogTag(OSP_INSTALLER, "__pDistributorCertPath Validate [END]"); + TryCatch(ret == true, ret = false, "[osp-installer] Validate(DistributorCert) is failed."); + } + } + +CATCH: + delete __pAuthorCertPath; + __pAuthorCertPath = null; + delete __pDistributorCertPath; + __pDistributorCertPath = null; + + return ret; +} + +bool +SignatureManager::Validate(X509CertificatePath* pCertPath) +{ + TryReturn(pCertPath, false, "[osp-installer] pCertPath is null."); + + AppLogTag(OSP_INSTALLER, "------------------------------"); + AppLogTag(OSP_INSTALLER, "# signature.xml"); + ValidationResult valResult = VALIDATION_SUCCESS; + valResult = pCertPath->Validate(); + + if (valResult != VALIDATION_SUCCESS) + { + + AppLogTag(OSP_INSTALLER, "Validate() fail! - ValidationResult = [%d]", valResult); + AppLogTag(OSP_INSTALLER, "------------------------------"); + return false; + } + else + { + int depth = pCertPath->GetLength(); + if (depth == 0) + { + AppLogTag(OSP_INSTALLER, "depth = 0"); + return false; + } + + AppLogTag(OSP_INSTALLER, "Validate() success!"); + AppLogTag(OSP_INSTALLER, "------------------------------"); + + ICertificate *pTrustCa = null; + pTrustCa = pCertPath->GetTrustAnchorN(); + if (pTrustCa) + { + String subjectName; + subjectName = pTrustCa->GetSubject(); + AppLogTag(OSP_INSTALLER, "TrustAnchor subjectName = [%ls]", subjectName.GetPointer()); + } + + delete pTrustCa; + } + + return true; +} + +bool +SignatureManager::AddCertificate(X509CertificatePath* pCertPath, IList* pCertChain) +{ + TryReturn(pCertChain, false, "[osp-installer] pCertChain is null."); + + bool ret = true; + X509Certificate* pCertificate = null; + + for (int i = 0; i < pCertChain->GetCount(); i++) + { + Osp::Base::ByteBuffer* pByteBuffer = dynamic_cast <ByteBuffer*>(pCertChain->GetAt(i)); + + if (pByteBuffer) + { + AppLogTag(OSP_INSTALLER, "[cert][%d]", i); + + result r = E_SUCCESS; + + pCertificate = new X509Certificate; + TryCatch(pCertificate, ret = false, "[osp-installer] pCertificate is null."); + + r = pCertificate->Construct(*pByteBuffer); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] pCertificate->Construct() is failed."); + + r = pCertPath->AddCertificate(*pCertificate); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] AddCertificate is failed."); + + delete pCertificate; + pCertificate = null; + } + } + +CATCH: + delete pCertificate; + return ret; +} + +bool +SignatureManager::AddRootCertificate(X509CertificatePath* pCertPath, RootCertificateType certType) +{ + TryReturn(pCertPath, false, "[osp-installer] pCertPath is null."); + + bool ret = true; + result r = E_SUCCESS; + ByteBuffer byteBuffer; + X509Certificate rootCert; + int length = 0; + const char* pRootCert = null; + + if (certType == ROOT_CERTIFICATE_NORMAL) + { + pRootCert = "MIIBsjCCAVwCCQD5jiS4Q6a7qDANBgkqhkiG9w0BAQUFADBgMRYwFAYDVQQKDA1U" + "aXplbiBUZXN0IENBMSIwIAYDVQQLDBlUaXplbiBEaXN0cmlidXRvciBUZXN0IENB" + "MSIwIAYDVQQDDBlUaXplbiBEaXN0cmlidXRvciBSb290IENBMB4XDTEyMDgyOTA4" + "Mjc1NFoXDTIyMDgyNzA4Mjc1NFowYDEWMBQGA1UECgwNVGl6ZW4gVGVzdCBDQTEi" + "MCAGA1UECwwZVGl6ZW4gRGlzdHJpYnV0b3IgVGVzdCBDQTEiMCAGA1UEAwwZVGl6" + "ZW4gRGlzdHJpYnV0b3IgUm9vdCBDQTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCr" + "rnWCo3PuzKK/K16AglIFCSrwDLTM09i8SRvDDwJ1edF1qbwVM98otkFNzABc6TY2" + "C/25PCJN7czuEBgD4CBvAgMBAAEwDQYJKoZIhvcNAQEFBQADQQAQxnxvYGO/pTmB" + "FZc9EvxIGgoFy8EQGIvlY5RjknFnn4OmKDmBNdnchF1kJTaazxddW+MZVh5GWU40" + "/sHxMAY0"; + } + else if (certType == ROOT_CERTIFICATE_PARTNER) + { + pRootCert = "MIIBwjCCAWwCCQDb4CukLXIwPDANBgkqhkiG9w0BAQUFADBoMRYwFAYDVQQKDA1U" + "aXplbiBUZXN0IENBMSIwIAYDVQQLDBlUaXplbiBEaXN0cmlidXRvciBUZXN0IENB" + "MSowKAYDVQQDDCFUaXplbiBQYXJ0bmVyIERpc3RyaWJ1dG9yIFJvb3QgQ0EwHhcN" + "MTIwOTAzMTA0NjExWhcNMjIwOTAxMTA0NjExWjBoMRYwFAYDVQQKDA1UaXplbiBU" + "ZXN0IENBMSIwIAYDVQQLDBlUaXplbiBEaXN0cmlidXRvciBUZXN0IENBMSowKAYD" + "VQQDDCFUaXplbiBQYXJ0bmVyIERpc3RyaWJ1dG9yIFJvb3QgQ0EwXDANBgkqhkiG" + "9w0BAQEFAANLADBIAkEA60SphdcNgCjT+kU/vrYl38u5JEMP4F7VqfBnb6SPNysn" + "O+AGwroauYXfPPmBcUIqu+BzfQE4ZITbPZrZG9yOowIDAQABMA0GCSqGSIb3DQEB" + "BQUAA0EA3biplInRqcYvhmWPyh06Db+QPYmDhk3RvJiCVdQyW4c5DGKHBM6+9t5r" + "ULlD7UoqK38PfVNJ6E/GEubQ5170GA=="; + } + else if (certType == ROOT_CERTIFICATE_DEVELOPER) + { + pRootCert = "MIIBqjCCAVQCCQCVqUeH46cT3zANBgkqhkiG9w0BAQUFADBcMRYwFAYDVQQKDA1U" + "aXplbiBUZXN0IENBMSAwHgYDVQQLDBdUaXplbiBEZXZlbG9wZXIgVGVzdCBDQTEg" + "MB4GA1UEAwwXVGl6ZW4gRGV2ZWxvcGVyIFJvb3QgQ0EwHhcNMTIwODI5MDgxODEw" + "WhcNMjIwODI3MDgxODEwWjBcMRYwFAYDVQQKDA1UaXplbiBUZXN0IENBMSAwHgYD" + "VQQLDBdUaXplbiBEZXZlbG9wZXIgVGVzdCBDQTEgMB4GA1UEAwwXVGl6ZW4gRGV2" + "ZWxvcGVyIFJvb3QgQ0EwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAqLhBbLpcF/sQ" + "c9/v0pejQC+IG8z+KKmgQ5NXNKx7fEFN3Y7CVSNtyvGHek/4BaCmTV4e118FwiZ5" + "LPDbwLnfEwIDAQABMA0GCSqGSIb3DQEBBQUAA0EAUz2Oe9Jyql5iJIW2sa89Ic0T" + "YGvdzyc7Kb7CtHUly7ja4rtRN3+pVUxiFPiyR59oZbh39NZyFwxBHpIm6BJ37A=="; + } + else + { + pRootCert = "NeedToAddCert"; + } + + length = strlen(pRootCert); + byteBuffer.Construct(length); + + r = byteBuffer.SetArray((byte*)pRootCert, 0, length); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] SetArray() is failed."); + + byteBuffer.Flip(); + + r = rootCert.Construct(byteBuffer); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] rootCert.Construct() is failed."); + + r = pCertPath->AddCertificate(rootCert); + TryCatch(!IsFailed(r), ret = false, "[osp-installer] AddCertificate(rootCert) is failed."); + +CATCH: + return ret; +} diff --git a/src/Manager/SignatureManager.h b/src/Manager/SignatureManager.h new file mode 100755 index 0000000..be036db --- /dev/null +++ b/src/Manager/SignatureManager.h @@ -0,0 +1,69 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file SignatureManager.h + * @brief This is the header file for the %SignatureManager class. + * + * This header file contains the declarations of the %SignatureManager class. + */ +#ifndef _SIGNATURE_MANAGER_H_ +#define _SIGNATURE_MANAGER_H_ + +#include <FSecCertX509CertificatePath.h> + +#include "InstallationContext.h" +#include "SignatureHandler.h" + +/** + * @class SignatureManager + * @brief This class represents the class of SignatureManager. + * @since 1.0 + * + * This class represents the class of SignatureManager. + * + */ + +class SignatureManager +{ +public: + SignatureManager(void); + virtual ~SignatureManager(void); + + bool Construct(InstallationContext *pConext); + bool SetSignature(); + bool AddCert(RootCertificateType certType); + bool VerifyChain(RootCertificateType certType); + //bool VerifySignature(); + +private: + SignatureManager(const SignatureManager& value); + SignatureManager& operator =(const SignatureManager& source); + + bool Validate(Osp::Security::Cert::X509CertificatePath* pCertPath); + bool AddCertificate(Osp::Security::Cert::X509CertificatePath* pCertPath, Osp::Base::Collection::IList* pCertChain); + bool AddRootCertificate(Osp::Security::Cert::X509CertificatePath* pCertPath, RootCertificateType certType); + +private: + InstallationContext* __pContext; + SignatureHandler* __pSignature; + Osp::Security::Cert::X509CertificatePath* __pAuthorCertPath; + Osp::Security::Cert::X509CertificatePath* __pDistributorCertPath; + + +}; // SignatureManager + +#endif // _SIGNATURE_MANAGER_H_ |