2 * Copyright (c) 2017 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.
17 * @file signature-validator-since-4.0.cpp
18 * @author Sangwan Kwon (sangwan.kwon@samsung.com)
20 * @brief Signature Validator example (Tizen_4.0 ~ )
25 #include <vcore/SignatureValidator.h>
27 const std::string PKG_PATH(CERT_SVC_EXAMPLES "/resource/player");
31 // Step 1. Validate signature files.
32 ValidationCore::SignatureValidator validator(PKG_PATH);
33 ValidationCore::SignatureDataMap sigDataMap;
34 ValidationCore::VCerr result = validator.checkAll(true, // OCSP
35 true, // reverse reference check
38 If you want to validate specific files, use checkListAll().
41 uriList.emplace_back("author-siganture.xml");
42 uriList.emplace_back("res/res.xml");
43 uriList.emplace_back("shared/res/preference.png");
44 uriList.emplace_back("tizen-manifest.xml");
46 validator.checkListAll(true, // OCSP
52 case ValidationCore::E_SIG_DISREGARDED:
53 std::cout << "This signature is disregarded." << std::endl;
56 case ValidationCore::E_SIG_NONE:
57 std::cout << "Success to validate signature." << std::endl;
61 std::cout << "Failed to validate signature : "
62 << validator.errorToString(result) << std::endl;
66 // Step 2. Get certificate list from signature.
67 auto authorSigData = sigDataMap[ValidationCore::SignatureType::AUTHOR];
68 for (const auto &certPtr : authorSigData.getCertList())
69 std::cout << "Author certificate > "
70 << certPtr->getBase64() << std::endl;
72 auto dist1SigData = sigDataMap[ValidationCore::SignatureType::DISTRIBUTOR1];
73 for (const auto &certPtr : dist1SigData.getCertList())
74 std::cout << "Distributor1 certificate > "
75 << certPtr->getBase64() << std::endl;
77 auto dist2SigData = sigDataMap[ValidationCore::SignatureType::DISTRIBUTOR2];
78 for (const auto &certPtr : dist2SigData.getCertList())
79 std::cout << "Distributor2 certificate > "
80 << certPtr->getBase64() << std::endl;
82 // Step 3. Check visibility about distributor1.
83 switch (dist1SigData.getVisibilityLevel()) {
84 case ValidationCore::CertStoreId::VIS_PUBLIC:
85 std::cout << "This signature has public visibility." << std::endl;
87 case ValidationCore::CertStoreId::VIS_PARTNER:
88 std::cout << "This signature has partner visibility." << std::endl;
90 case ValidationCore::CertStoreId::VIS_PLATFORM:
91 std::cout << "This signature has platform visibility." << std::endl;
94 std::cout << "Failed to get proper visibility." << std::endl;