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 SignatureHandler.cpp
19 * @brief This is the implementation file for %SignatureHandler class.
22 #include "SignatureHandler.h"
23 #include "InstallerUtil.h"
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
28 SignatureHandler::SignatureHandler(void)
30 ,__pAuthorCertChain(null)
31 ,__pDistributorCertChain(null)
32 ,__isAuthorSignature(false)
33 ,__isDistributorSignature(false)
37 SignatureHandler::~SignatureHandler(void)
39 if (__pAuthorCertChain)
41 __pAuthorCertChain->RemoveAll(true);
42 delete __pAuthorCertChain;
45 if (__pDistributorCertChain)
47 __pDistributorCertChain->RemoveAll(true);
48 delete __pDistributorCertChain;
53 SignatureHandler::Construct(InstallationContext* pContext)
55 __pContext = pContext;
61 SignatureHandler::Parse(const char *pFilepath)
63 return ParseNormalizedDocument(pFilepath);
67 SignatureHandler::OnStartElement(const char *pName)
69 TryReturn(pName, true, "pName is null.");
73 if (strcasecmp(pName, "Signature") == 0)
75 AppLog("------------------------------------------");
76 AppLog("signature.xml");
77 AppLog("------------------------------------------");
78 AppLog("<%s>", pName);
79 status = OnSignatureElement();
91 SignatureHandler::OnEndElement(const char *pName)
93 TryReturn(pName, true, "pName is null.");
95 if (strcasecmp(pName, "Signature") == 0)
97 __isDistributorSignature = false;
98 __isAuthorSignature = false;
99 AppLog("</%s>", pName);
106 SignatureHandler::OnCharacters(const char *pCharacters)
111 pName = GetElementName();
112 TryReturn(pName, false, "pName is null.");
114 if (strcasecmp(pName, "X509Certificate") == 0)
116 status = OnCertificateValue(pCharacters);
128 SignatureHandler::OnSignatureElement(void)
130 XmlAttribute *pAttr = null;
133 pAttr = GetAttribute();
134 TryReturn(pAttr, true, "pAttr is null");
136 pId = pAttr->Find("Id");
139 AppLog("<Id = %s>", pId);
141 if (strcasecmp(pId, "AuthorSignature") == 0)
143 __isAuthorSignature = true;
145 else if (strcasecmp(pId, "DistributorSignature") == 0)
147 __isDistributorSignature = true;
155 SignatureHandler::OnCertificateValue(const char *pCharacters)
157 AppLog("<X509Certificate>%s</X509Certificate>", pCharacters);
159 result r = E_SUCCESS;
161 ByteBuffer* pByteBuffer = null;
163 if (__isAuthorSignature == true)
165 if (__pAuthorCertChain == null)
167 __pAuthorCertChain = new (std::nothrow) ArrayList;
168 TryCatch(__pAuthorCertChain, res = false, "__pAuthorCertChain is null");
171 pByteBuffer = new (std::nothrow) ByteBuffer;
172 TryCatch(pByteBuffer, res = false, "pByteBuffer is null");
174 int length = strlen(pCharacters);
175 pByteBuffer->Construct(length);
177 r = pByteBuffer->SetArray((byte*)pCharacters, 0, length);
178 TryCatch(!IsFailed(r), res = false, "SetArray() is failed.");
182 __pAuthorCertChain->Add(*pByteBuffer);
185 else if (__isDistributorSignature == true)
187 if (__pDistributorCertChain == null)
189 __pDistributorCertChain = new (std::nothrow) ArrayList;
190 TryCatch(__pDistributorCertChain, res = false, "__pDistributorCertChain is null");
193 pByteBuffer = new (std::nothrow) ByteBuffer;
194 TryCatch(pByteBuffer, res = false, "pByteBuffer is null");
196 int length = strlen(pCharacters);
197 pByteBuffer->Construct(length);
199 r = pByteBuffer->SetArray((byte*)pCharacters, 0, length);
200 TryCatch(!IsFailed(r), res = false, "SetArray() is failed.");
204 __pDistributorCertChain->Add(*pByteBuffer);
214 SignatureHandler::GetAuthorCertChain(void)
216 return __pAuthorCertChain;
220 SignatureHandler::GetDistributorCertChain(void)
222 return __pDistributorCertChain;