2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file SignatureStep.cpp
19 * @brief This is the implementation file for %SignatureStep class.
23 #include <FApp_PackageInfoImpl.h>
24 #include <FBase_StringConverter.h>
26 #include "InstallationContext.h"
27 #include "PrivilegeHandler.h"
28 #include "SignatureHandler.h"
29 #include "SignatureStep.h"
31 using namespace Osp::App;
32 using namespace Osp::Base;
33 using namespace Osp::Base::Collection;
34 using namespace Osp::Io;
36 SignatureStep::SignatureStep(void)
37 :__state(STATE_SIGNER_CERT)
39 ,__pSignatureManager(null)
43 SignatureStep::~SignatureStep(void)
45 delete __pSignatureManager;
49 SignatureStep::Run(InstallationContext* pContext)
51 InstallerError error = INSTALLER_ERROR_NONE;
52 AppLogTag(OSP_INSTALLER, "------------------------------------------");
53 AppLogTag(OSP_INSTALLER, " SignatureStep - START");
54 AppLogTag(OSP_INSTALLER, "------------------------------------------");
56 __pContext = pContext;
58 // signature.xml for beta
62 r = File::GetAttributes(__pContext->GetSignatureXmlPath(), attr);
65 AppLogTag(OSP_INSTALLER, "Signature file not found. path = [%ls]\n", __pContext->GetSignatureXmlPath().GetPointer());
66 return INSTALLER_ERROR_NONE;
73 case STATE_SIGNER_CERT:
74 AppLogTag(OSP_INSTALLER, "[STATE_SIGNER_CERT]");
75 error = OnStateSignerCert();
78 case STATE_CERT_CHAIN:
79 AppLogTag(OSP_INSTALLER, "[STATE_CERT_CHAIN]");
80 error = OnStateCertChain();
84 AppLogTag(OSP_INSTALLER, "[STATE_ROOT_CERT]");
85 error = OnStateRootCert();
89 AppLogTag(OSP_INSTALLER, "[STATE_DONE]");
90 error = OnStateDone();
97 if (error != INSTALLER_ERROR_NONE)
99 AppLogTag(OSP_INSTALLER, "SignatureStep::Run - ErrorType [%d]\n", error);
100 //fprintf(stderr, "SignatureStep::Run - ErrorType [%d]\n", error);
104 if (__state > STATE_DONE)
106 AppLogTag(OSP_INSTALLER, "------------------------------------------");
107 AppLogTag(OSP_INSTALLER, " SignatureStep - END");
108 AppLogTag(OSP_INSTALLER, "------------------------------------------");
117 SignatureStep::GoNextState(void)
123 SignatureStep::OnStateSignerCert(void)
125 InstallerError error = INSTALLER_ERROR_NONE;
128 __pSignatureManager = new SignatureManager();
129 TryCatch(__pSignatureManager, error = INSTALLER_ERROR_MEMORY, "[osp-installer] __pSignatureManager is null.");
131 ret = __pSignatureManager->Construct(__pContext);
132 TryCatch(ret == true, error = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Construct() failed");
134 ret = __pSignatureManager->SetSignature();
135 TryCatch(ret == true, error = INSTALLER_ERROR_INVALID_SIGNATURE, "[osp-installer] SetSignature() failed");
143 SignatureStep::OnStateCertChain(void)
145 InstallerError error = INSTALLER_ERROR_NONE;
147 int rootCert = ROOT_CERTIFICATE_PUBLIC;
149 ret = __pSignatureManager->AddCert(ROOT_CERTIFICATE_DEVELOPER);
150 TryCatch(ret == true, error = INSTALLER_ERROR_INVALID_SIGNATURE, "[osp-installer] AddCert(DEVELOPER_ROOT_CERTIFICATE) failed");
152 ret = __pSignatureManager->VerifyChain(ROOT_CERTIFICATE_DEVELOPER);
153 TryCatch(ret == true, error = INSTALLER_ERROR_INVALID_SIGNATURE, "[osp-installer] VerifyChain(DEVELOPER_ROOT_CERTIFICATE) failed");
155 for(rootCert = ROOT_CERTIFICATE_PUBLIC; rootCert <= ROOT_CERTIFICATE_PRIVATE; rootCert++)
157 ret = __pSignatureManager->AddCert((RootCertificateType)rootCert);
158 TryCatch(ret == true, error = INSTALLER_ERROR_INVALID_SIGNATURE, "[osp-installer] AddCert() failed");
160 ret = __pSignatureManager->VerifyChain((RootCertificateType)rootCert);
163 AppLogTag(OSP_INSTALLER, "VerifyChain() success(Cert = [%d])", rootCert);
164 __pContext->SetRootCertType((RootCertificateType)rootCert);
165 error = INSTALLER_ERROR_NONE;
170 AppLogTag(OSP_INSTALLER, "VerifyChain() fail(Cert = [%d])", rootCert);
171 error = INSTALLER_ERROR_INVALID_SIGNATURE;
181 SignatureStep::OnStateRootCert(void)
183 InstallerError error = INSTALLER_ERROR_NONE;
184 result r = E_SUCCESS;
186 String hmacPrivileges;
188 const ArrayList* pPrivilegeList = __pContext->GetPrivilegeList();
189 RootCertificateType certType = __pContext->GetRootCertType();
190 _PackageInfoImpl* pPackageInfoImpl = __pContext->GetPackageInfoImpl();
191 String appId = pPackageInfoImpl->GetAppId();
192 int apiVisibility = GetApiVisibility(certType);
194 AppLogTag(OSP_INSTALLER, "AppId = [%ls], CertType = [%d], ApiVisibility = [%d]", appId.GetPointer(), certType, apiVisibility);
196 r = PrivilegeHandler::GenerateCipherPrivilege(appId, *pPrivilegeList, apiVisibility, privileges, hmacPrivileges);
199 fprintf(stderr, "PrivilegeHandler::GenerateCipherPrivilege is failded. [%ls][%ls][%ls]\n", appId.GetPointer(), privileges.GetPointer(), hmacPrivileges.GetPointer());
201 TryCatch(!IsFailed(r), error = INSTALLER_ERROR_PRIVILEGE, "[osp-installer] privMgr.GeneratePrivilegeString() failed");
203 pPackageInfoImpl->SetPrivilegesValue(privileges, hmacPrivileges);
204 pPackageInfoImpl->SetCertType(apiVisibility);
212 SignatureStep::OnStateDone(void)
214 InstallerError error = INSTALLER_ERROR_NONE;
221 SignatureStep::GetApiVisibility(RootCertificateType certType)
223 int apiVisibility = _API_VISIBILITY_NONE;
225 if (certType == ROOT_CERTIFICATE_PUBLIC)
227 apiVisibility = _API_VISIBILITY_PUBLIC;
229 else if (certType == ROOT_CERTIFICATE_PARTNER)
231 apiVisibility = _API_VISIBILITY_PARTNER;
233 else if (certType == ROOT_CERTIFICATE_PARTNER_OPERATOR)
235 apiVisibility = _API_VISIBILITY_PARTNER_OPERATOR;
237 else if (certType == ROOT_CERTIFICATE_PARTNER_MANUFACTURER)
239 apiVisibility = _API_VISIBILITY_PARTNER_MANUFACTURER;
241 else if (certType == ROOT_CERTIFICATE_PRIVATE)
243 apiVisibility = _API_VISIBILITY_PRIVATE;
246 return apiVisibility;