Tizen 2.1 base
[framework/web/wrt-commons.git] / modules / vcore / src / vcore / RevocationCheckerBase.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @author      Piotr Marcinkiewicz(p.marcinkiew@samsung.com)
18  * @version     0.4
19  * @file        CommonCertValidator.cpp
20  * @brief       Common routines for certificate validation over OCSP and CRL
21  */
22
23 #include "RevocationCheckerBase.h"
24
25 #include <cstdlib>
26
27 #include <openssl/pem.h>
28
29 #include <dpl/scoped_fclose.h>
30
31 #include "Certificate.h"
32 #include "CertificateCollection.h"
33
34 namespace {
35 const char DefaultBundlePatch[] = "/opt/etc/ssl/certs/ca-certificates.crt";
36 } //Anonymous name space
37
38 namespace ValidationCore {
39 CertificatePtr RevocationCheckerBase::loadPEMFile(const char* fileName)
40 {
41     DPL::ScopedFClose fd(fopen(fileName, "rb"));
42
43     // no such file, return NULL
44     if (!fd.Get()) {
45         return CertificatePtr();
46     }
47
48     // create a new X509 certificate basing on file
49     CertificatePtr cert(new Certificate(PEM_read_X509(fd.Get(),
50                                                       NULL,
51                                                       NULL,
52                                                       NULL)));
53     return cert;
54 }
55
56 bool RevocationCheckerBase::sortCertList(CertificateList &lCertificates)
57 {
58     CertificateCollection collection;
59     collection.load(lCertificates);
60
61     if (collection.sort()) {
62         lCertificates = collection.getChain();
63         return true;
64     }
65     return false;
66 }
67
68 } // ValidationCore