31 if (!bio || !BIO_read_filename(bio.get(), certFilename)) {
32 const auto x = ERR_get_error();
55 candidates.emplace_back(c);
60 while (!candidates.empty()) {
69 const auto issuerPos = std::find_if(candidates.begin(), candidates.end(), [&](
const CertPointer &i) {
70 return IssuedBy(*precedingCert, *i);
72 if (issuerPos == candidates.end())
75 const auto &issuer = *issuerPos;
77 chain.emplace_back(issuer);
78 candidates.erase(issuerPos);
81 for (
const auto &c: candidates)
82 debugs(83,
DBG_IMPORTANT,
"WARNING: Ignoring certificate that does not extend the chain: " << *c);
94 if (x != GNUTLS_E_SUCCESS) {
100 x = gnutls_pcert_import_x509_raw(&pcrt, &data, GNUTLS_X509_FMT_PEM, 0);
101 if (x != GNUTLS_E_SUCCESS) {
105 gnutls_free(data.data);
107 gnutls_x509_crt_t certificate;
108 x = gnutls_pcert_export_x509(&pcrt, &certificate);
109 if (x != GNUTLS_E_SUCCESS) {
116 debugs(83, 5,
"gnutls_x509_crt_deinit cert=" << (
void*)p);
117 gnutls_x509_crt_deinit(p);
122 debugs(83, 2,
"Loading certificate chain from PEM files not implemented in this Squid.");
141 debugs(83, 2,
"from " << privateKeyFile);
144 const char *keyFilename = privateKeyFile.c_str();
150 if (pkey && !X509_check_private_key(cert.get(), pkey.get())) {
151 debugs(83,
DBG_IMPORTANT,
"WARNING: '" << privateKeyFile <<
"' X509_check_private_key() failed");
156 const char *keyFilename = privateKeyFile.c_str();
158 if (gnutls_load_file(keyFilename, &data) == GNUTLS_E_SUCCESS) {
159 gnutls_privkey_t key;
160 (void)gnutls_privkey_init(&key);
161 Security::ErrorCode x = gnutls_privkey_import_x509_raw(key, &data, GNUTLS_X509_FMT_PEM,
nullptr, 0);
162 if (x == GNUTLS_E_SUCCESS) {
163 gnutls_x509_privkey_t xkey;
164 gnutls_privkey_export_x509(key, &xkey);
165 gnutls_privkey_deinit(key);
166 pkey = Security::PrivateKeyPointer(xkey, [](gnutls_x509_privkey_t p) {
167 debugs(83, 5,
"gnutls_x509_privkey_deinit pkey=" << (
void*)p);
168 gnutls_x509_privkey_deinit(p);
172 gnutls_free(data.data);
185 if (!loadCertificates()) {
186 debugs(83,
DBG_IMPORTANT,
"WARNING: '" << portType <<
"_port " <<
port.s.toUrl(buf,
sizeof(buf)) <<
"' missing certificate in '" << certFile <<
"'");
191 if (!loadX509PrivateKeyFromFile()) {
192 debugs(83,
DBG_IMPORTANT,
"WARNING: '" << portType <<
"_port " <<
port.s.toUrl(buf,
sizeof(buf)) <<
"' missing private key in '" << privateKeyFile <<
"'");
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
static std::ostream & Extra(std::ostream &)
SBuf certFile
path of file containing PEM format X.509 certificate
void loadFromFiles(const AnyP::PortCfg &, const char *portType)
load the contents of certFile and privateKeyFile into memory cert, pkey and chain
Security::CertPointer cert
public X.509 certificate from certFile
Security::CertList chain
any certificates which must be chained from cert
bool loadX509PrivateKeyFromFile()
void reset()
Forget the raw pointer - unlock if any value was set. Become a nil pointer.
struct SquidConfig::@83 Program
#define DBG_PARSE_NOTE(x)
#define debugs(SECTION, LEVEL, CONTENT)
void ReadPrivateKeyFromFile(char const *keyFilename, Security::PrivateKeyPointer &pkey, pem_password_cb *passwd_callback)
int ErrorCode
Squid-defined error code (<0), an error code returned by X.509 API, or zero.
unsigned long LibErrorCode
TLS library-reported non-validation error.
Security::LockingPointer< X509, X509_free_cpp, HardFun< int, X509 *, X509_up_ref > > CertPointer
bool SelfSigned(Certificate &c)
Whether the given certificate is self-signed.
std::list< Security::CertPointer > CertList
const char * ErrorString(const LibErrorCode code)
converts numeric LibErrorCode into a human-friendlier string
std::unique_ptr< BIO, HardFun< void, BIO *, &BIO_vfree > > BIO_Pointer
Security::CertPointer ReadOptionalCertificate(const BIO_Pointer &)
Security::CertPointer ReadCertificate(const BIO_Pointer &)
int AskPasswordCb(char *buf, int size, int rwflag, void *userdata)