-
Notifications
You must be signed in to change notification settings - Fork 0
/
cabundle.cpp
57 lines (50 loc) · 1.22 KB
/
cabundle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright 2015–2019 Kullo GmbH
*
* This source code is licensed under the 3-clause BSD license. See LICENSE.txt
* in the root directory of this source tree for details.
*/
#include "httpclient/cabundle.h"
#include <fstream>
#include <vector>
#include <kulloclient/util/librarylogger.h>
// See for example
// * https://golang.org/src/crypto/x509/root_unix.go#L12
// * https://github.com/bagder/curl/blob/master/acinclude.m4#L2624
namespace {
const auto CA_BUNDLE_PATHS = std::vector<std::string>{
"/etc/ssl/certs/ca-certificates.crt", // Debian et al, Gentoo, Arch
"/etc/pki/tls/certs/ca-bundle.crt", // Red Hat et al
"/etc/ssl/ca-bundle.pem" // OpenSUSE
};
}
namespace HttpClient {
bool CaBundle::available()
{
#ifdef __linux__
return true;
#else
return false;
#endif
}
std::string CaBundle::path()
{
static std::string result;
if (result.empty())
{
for (const auto &path : CA_BUNDLE_PATHS)
{
if (std::ifstream(path).good())
{
result = path;
break;
}
}
if (result.empty())
{
Log.w() << "Couldn't find working CA bundle path";
}
}
return result;
}
}