bd62d2cfec14e7635e53df3f70afed354c7ac259
[platform/core/security/key-manager.git] / src / manager / service / ocsp-logic.cpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  *
16  *
17  * @file        ocsp-logic.cpp
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       OCSP logic implementation.
21  */
22 #include <ckm/ckm-error.h>
23
24 #include <dpl/log/log.h>
25 #include <dpl/serialization.h>
26
27 #include <message-buffer.h>
28
29 #include <ocsp-logic.h>
30 #include <ocsp.h>
31
32 namespace CKM {
33
34 RawBuffer OCSPLogic::ocspCheck(int commandId, const RawBufferVector &rawChain) {
35     CertificateImplVector certChain;
36     OCSPModule ocsp;
37     int retCode = CKM_API_SUCCESS;
38     int ocspStatus = CKM_API_OCSP_STATUS_INTERNAL_ERROR;
39
40     for (auto &e: rawChain) {
41         certChain.push_back(CertificateImpl(e, DataFormat::FORM_DER));
42         if (certChain.rbegin()->empty()) {
43             LogDebug("Error in parsing certificates!");
44             retCode = CKM_API_ERROR_INPUT_PARAM;
45             break;
46         }
47     }
48
49     if (retCode == CKM_API_SUCCESS)
50         ocspStatus = ocsp.verify(certChain);
51
52     return MessageBuffer::Serialize(commandId, retCode, ocspStatus).Pop();
53 }
54
55 } // namespace CKM
56