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.
17 * @author Bartlomiej Grzelewski (b.grzelewski@gmail.com)
19 * @file CertificateVerifier.cpp
20 * @brief This class integrates OCSP and CRL.
22 #include "CertificateVerifier.h"
24 #include <dpl/assert.h>
25 #include <dpl/foreach.h>
26 #include <dpl/log/log.h>
28 namespace ValidationCore {
30 CertificateVerifier::CertificateVerifier(bool enableOcsp, bool enableCrl)
31 : m_enableOcsp(enableOcsp)
32 , m_enableCrl(enableCrl)
35 VerificationStatus CertificateVerifier::check(
36 CertificateCollection &certCollection) const
38 LogDebug("== Certificate collection validation start ==");
39 Assert(certCollection.isChain() && "Collection must form chain.");
41 VerificationStatus statusOcsp;
42 VerificationStatus statusCrl;
45 statusOcsp = obtainOcspStatus(certCollection);
47 statusOcsp = VERIFICATION_STATUS_GOOD;
51 statusCrl = obtainCrlStatus(certCollection);
53 statusCrl = VERIFICATION_STATUS_GOOD;
55 LogDebug("== Certificate collection validation end ==");
56 return getStatus(statusOcsp, statusCrl);
59 VerificationStatus CertificateVerifier::obtainOcspStatus(
60 const CertificateCollection &chain) const
62 LogDebug("== Obtain ocsp status ==");
64 return ocsp.check(chain);
67 VerificationStatus CertificateVerifier::obtainCrlStatus(
68 const CertificateCollection &chain) const
70 LogDebug("== Obtain crl status ==");
72 return crl.check(chain);
75 VerificationStatus CertificateVerifier::getStatus(
76 VerificationStatus ocsp,
77 VerificationStatus crl) const
79 if (ocsp == VERIFICATION_STATUS_REVOKED ||
80 crl == VERIFICATION_STATUS_REVOKED)
82 LogDebug("Return status: REVOKED");
83 return VERIFICATION_STATUS_REVOKED;
86 if (ocsp == VERIFICATION_STATUS_GOOD) {
87 LogDebug("Return status: GOOD");
88 return VERIFICATION_STATUS_GOOD;
91 if (ocsp == VERIFICATION_STATUS_UNKNOWN) {
92 LogDebug("Return status: UNKNOWN");
93 return VERIFICATION_STATUS_UNKNOWN;
96 if (ocsp == VERIFICATION_STATUS_NOT_SUPPORT) {
97 LogDebug("Return status: NOT_SUPPORT");
98 return VERIFICATION_STATUS_GOOD;
101 LogDebug("Return status: ERROR");
102 return VERIFICATION_STATUS_ERROR;
105 VerificationStatus CertificateVerifier::checkEndEntity(
106 CertificateCollectionList &collectionList) const
108 VerificationStatusSet statusOcsp;
109 VerificationStatusSet statusCrl;
113 FOREACH(it, collectionList){
114 statusOcsp.add(ocsp.checkEndEntity(*it));
117 statusOcsp.add(VERIFICATION_STATUS_GOOD);
122 FOREACH(it, collectionList){
123 statusCrl.add(crl.checkEndEntity(*it));
126 statusCrl.add(VERIFICATION_STATUS_GOOD);
128 LogDebug("== Certificate collection validateion end ==");
129 return getStatus(statusOcsp.convertToStatus(), statusCrl.convertToStatus());
132 } // namespace ValidationCore