2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 #include "CertificateConfigReader.h"
26 #include <dpl/assert.h>
29 const std::string XML_EMPTY_NAMESPACE = "";
31 const std::string TOKEN_CERTIFICATE_SET = "CertificateSet";
32 const std::string TOKEN_CERTIFICATE_DOMAIN = "CertificateDomain";
33 const std::string TOKEN_FINGERPRINT_SHA1 = "FingerprintSHA1";
35 const std::string TOKEN_ATTR_NAME = "name";
36 const std::string TOKEN_VALUE_WAC_ROOT = "wacroot";
37 const std::string TOKEN_VALUE_WAC_PUBLISHER = "wacpublisher";
38 const std::string TOKEN_VALUE_WAC_MEMBER = "wacmember";
39 const std::string TOKEN_VALUE_DEVELOPER = "developer";
41 int hexCharToInt(char c)
43 if (c >= 'a' && c <= 'f') {
44 return 10 + static_cast<int>(c) - 'a';
46 if (c >= 'A' && c <= 'F') {
47 return 10 + static_cast<int>(c) - 'A';
49 if (c >= '0' && c <= '9') {
50 return static_cast<int>(c) - '0';
54 } // anonymous namespace
56 namespace ValidationCore {
57 CertificateConfigReader::CertificateConfigReader() :
58 m_certificateDomain(0),
61 m_parserSchema.addBeginTagCallback(
62 TOKEN_CERTIFICATE_SET,
64 &CertificateConfigReader::blankFunction);
66 m_parserSchema.addBeginTagCallback(
67 TOKEN_CERTIFICATE_DOMAIN,
69 &CertificateConfigReader::tokenCertificateDomain);
71 m_parserSchema.addBeginTagCallback(
72 TOKEN_FINGERPRINT_SHA1,
74 &CertificateConfigReader::blankFunction);
76 m_parserSchema.addEndTagCallback(
77 TOKEN_CERTIFICATE_SET,
79 &CertificateConfigReader::blankFunction);
81 m_parserSchema.addEndTagCallback(
82 TOKEN_CERTIFICATE_DOMAIN,
84 &CertificateConfigReader::blankFunction);
86 m_parserSchema.addEndTagCallback(
87 TOKEN_FINGERPRINT_SHA1,
89 &CertificateConfigReader::tokenEndFingerprintSHA1);
92 void CertificateConfigReader::tokenCertificateDomain(CertificateIdentifier &)
94 std::string name = m_parserSchema.getReader().
95 attribute(TOKEN_ATTR_NAME, SaxReader::THROW_DISABLE);
98 LogWarning("Invalid fingerprint file. Domain name is mandatory");
99 ThrowMsg(Exception::InvalidFile,
100 "Invalid fingerprint file. Domain name is mandatory");
101 } else if (name == TOKEN_VALUE_DEVELOPER) {
102 m_certificateDomain = CertStoreId::DEVELOPER;
103 } else if (name == TOKEN_VALUE_WAC_ROOT) {
104 m_certificateDomain = CertStoreId::WAC_ROOT;
105 } else if (name == TOKEN_VALUE_WAC_PUBLISHER) {
106 m_certificateDomain = CertStoreId::WAC_PUBLISHER;
107 } else if (name == TOKEN_VALUE_WAC_MEMBER) {
108 m_certificateDomain = CertStoreId::WAC_MEMBER;
112 void CertificateConfigReader::tokenEndFingerprintSHA1(
113 CertificateIdentifier &identificator)
115 std::string text = m_parserSchema.getText();
116 text += ":"; // add guard at the end of fingerprint
117 Certificate::Fingerprint fingerprint;
120 for (size_t i = 0; i < text.size(); ++i) {
121 if (isxdigit(text[i])) {
123 s += hexCharToInt(text[i]);
125 if (byteDescLen > 2) {
126 Assert(0 && "Unsupported fingerprint format in xml file.");
128 } else if (text[i] == ':') {
129 fingerprint.push_back(static_cast<unsigned char>(s));
133 Assert(0 && "Unussported fingerprint format in xml file.");
136 identificator.add(fingerprint, m_certificateDomain);
138 } // namespace ValidationCore