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 #include <openssl/x509v3.h>
19 #include <file_input_mapping.h>
20 #include <dpl/log/log.h>
23 using namespace ValidationCore;
28 const char *CRL_LOOKUP_DIR = "/opt/etc/ssl/certs/";
29 const char *beginCertificate = "-----BEGIN CERTIFICATE-----";
30 const char *endCertificate = "-----END CERTIFICATE-----";
31 const char *beginTrustedCertificate = "-----BEGIN TRUSTED CERTIFICATE-----";
32 const char *endTrustedCertificate = "-----END TRUSTED CERTIFICATE-----";
35 bool whiteCharacter(char a){
42 : CRLImpl (new CRLCacheDAO)
44 //Add additional lookup dir
45 int rv = X509_LOOKUP_add_dir(m_lookup, CRL_LOOKUP_DIR, X509_FILETYPE_PEM);
47 LogError("Failed to add lookup dir for PEM files.");
48 ThrowMsg(CRLException::StorageError,
49 "Failed to add lookup dir for PEM files.");
51 LogInfo("CRL storage initialization complete.");
54 std::string TestCRL::getFileContent(const std::string &filename)
56 //Only PEM formatted files allowed
57 LogInfo("Read file: " << filename);
58 FileInputMapping file(filename);
59 string content(reinterpret_cast<const char*>(file.GetAddress()),
62 size_t posBegin = content.find(beginCertificate);
63 size_t posEnd = content.find(endCertificate);
64 if (posBegin != string::npos &&
65 posEnd != string::npos) {
66 posBegin += strlen(beginCertificate);
68 posBegin = content.find(beginTrustedCertificate);
69 posEnd = content.find(endTrustedCertificate);
70 if (posBegin != string::npos &&
71 posEnd != string::npos) {
72 posBegin += strlen(beginTrustedCertificate);
74 LogError("Failed to parse PEM file");
79 string cert(content, posBegin, posEnd - posBegin);
80 cert.erase(std::remove_if(cert.begin(), cert.end(), whiteCharacter),
86 void TestCRL::addCRLToStore(const string &filename, const string &uri)
88 LogInfo("Read file: " << filename);
89 //Only PEM formatted files allowed
90 FileInputMapping file(filename);
91 char *buffer = new char[file.GetSize()];
92 memcpy(buffer, file.GetAddress(), file.GetSize());
93 CRLDataPtr crl(new CRLData(buffer, file.GetSize(), uri));