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)
23 #include <vcore/CertificateConfigReader.h>
25 #include <dpl/assert.h>
30 const std::string XML_EMPTY_NAMESPACE = "";
32 const std::string TOKEN_CERTIFICATE_SET = "CertificateSet";
33 const std::string TOKEN_CERTIFICATE_DOMAIN = "CertificateDomain";
34 const std::string TOKEN_FINGERPRINT_SHA1 = "FingerprintSHA1";
36 const std::string TOKEN_ATTR_NAME = "name";
37 const std::string TOKEN_VALUE_TIZEN_DEVELOPER = "tizen-developer";
38 const std::string TOKEN_VALUE_TIZEN_TEST = "tizen-test";
39 const std::string TOKEN_VALUE_TIZEN_VERIFY = "tizen-verify";
40 const std::string TOKEN_VALUE_TIZEN_STORE = "tizen-store";
41 const std::string TOKEN_VALUE_VISIBILITY_PUBLIC = "tizen-public";
42 const std::string TOKEN_VALUE_VISIBILITY_PARTNER = "tizen-partner";
43 const std::string TOKEN_VALUE_VISIBILITY_PARTNER_OPERATOR = "tizen-partner-operator";
44 const std::string TOKEN_VALUE_VISIBILITY_PARTNER_MANUFACTURER = "tizen-partner-manufacturer";
45 const std::string TOKEN_VALUE_VISIBILITY_PLATFORM = "tizen-platform";
47 int hexCharToInt(char c)
49 if (c >= 'a' && c <= 'f') {
50 return 10 + static_cast<int>(c) - 'a';
52 if (c >= 'A' && c <= 'F') {
53 return 10 + static_cast<int>(c) - 'A';
55 if (c >= '0' && c <= '9') {
56 return static_cast<int>(c) - '0';
60 } // anonymous namespace
62 namespace ValidationCore {
63 CertificateConfigReader::CertificateConfigReader()
64 : m_certificateDomain(0)
65 , m_parserSchema(this)
67 m_parserSchema.addBeginTagCallback(
68 TOKEN_CERTIFICATE_SET,
70 &CertificateConfigReader::blankFunction);
72 m_parserSchema.addBeginTagCallback(
73 TOKEN_CERTIFICATE_DOMAIN,
75 &CertificateConfigReader::tokenCertificateDomain);
77 m_parserSchema.addBeginTagCallback(
78 TOKEN_FINGERPRINT_SHA1,
80 &CertificateConfigReader::blankFunction);
82 m_parserSchema.addEndTagCallback(
83 TOKEN_CERTIFICATE_SET,
85 &CertificateConfigReader::blankFunction);
87 m_parserSchema.addEndTagCallback(
88 TOKEN_CERTIFICATE_DOMAIN,
90 &CertificateConfigReader::blankFunction);
92 m_parserSchema.addEndTagCallback(
93 TOKEN_FINGERPRINT_SHA1,
95 &CertificateConfigReader::tokenEndFingerprintSHA1);
98 void CertificateConfigReader::initialize(
99 const std::string &file,
100 const std::string &scheme)
102 m_parserSchema.initialize(file, true, SaxReader::VALIDATION_XMLSCHEME, scheme);
105 void CertificateConfigReader::read(CertificateIdentifier &identificator)
107 m_parserSchema.read(identificator);
110 void CertificateConfigReader::blankFunction(CertificateIdentifier &)
114 void CertificateConfigReader::tokenCertificateDomain(CertificateIdentifier &)
116 std::string name = m_parserSchema.getReader().attribute(TOKEN_ATTR_NAME);
119 VcoreThrowMsg(CertificateConfigReader::Exception::InvalidFile,
120 "Invalid fingerprint file. Domain name is mandatory");
121 } else if (name == TOKEN_VALUE_TIZEN_DEVELOPER) {
122 m_certificateDomain = CertStoreId::TIZEN_DEVELOPER;
123 } else if (name == TOKEN_VALUE_TIZEN_TEST) {
124 m_certificateDomain = CertStoreId::TIZEN_TEST;
125 } else if (name == TOKEN_VALUE_TIZEN_VERIFY) {
126 m_certificateDomain = CertStoreId::TIZEN_VERIFY;
127 } else if (name == TOKEN_VALUE_TIZEN_STORE) {
128 m_certificateDomain = CertStoreId::TIZEN_STORE;
129 } else if (name == TOKEN_VALUE_VISIBILITY_PUBLIC) {
130 m_certificateDomain = CertStoreId::VIS_PUBLIC;
131 } else if (name == TOKEN_VALUE_VISIBILITY_PARTNER) {
132 m_certificateDomain = CertStoreId::VIS_PARTNER;
133 } else if (name == TOKEN_VALUE_VISIBILITY_PARTNER_OPERATOR) {
134 m_certificateDomain = CertStoreId::VIS_PARTNER_OPERATOR;
135 } else if (name == TOKEN_VALUE_VISIBILITY_PARTNER_MANUFACTURER) {
136 m_certificateDomain = CertStoreId::VIS_PARTNER_MANUFACTURER;
137 } else if (name == TOKEN_VALUE_VISIBILITY_PLATFORM) {
138 m_certificateDomain = CertStoreId::VIS_PLATFORM;
140 m_certificateDomain = 0;
144 void CertificateConfigReader::tokenEndFingerprintSHA1(
145 CertificateIdentifier &identificator)
147 std::string text = m_parserSchema.getText();
148 text += ":"; // add guard at the end of fingerprint
149 Certificate::Fingerprint fingerprint;
152 for (size_t i = 0; i < text.size(); ++i) {
153 if (isxdigit(text[i])) {
155 s += hexCharToInt(text[i]);
157 if (byteDescLen > 2) {
158 Assert(0 && "Unsupported fingerprint format in xml file.");
160 } else if (text[i] == ':') {
161 fingerprint.push_back(static_cast<unsigned char>(s));
165 Assert(0 && "Unussported fingerprint format in xml file.");
169 identificator.add(fingerprint, m_certificateDomain);
171 } // namespace ValidationCore