Skip to content

Commit 26a5998

Browse files
authored
fix the botan backend always validating certificate and OpenSSL allow empty ALPN (#297)
1 parent f49cc3e commit 26a5998

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

trantor/net/inner/tlsprovider/BotanTLSProvider.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,12 @@ struct BotanTLSProvider : public TLSProvider,
234234

235235
virtual void startEncryption() override
236236
{
237+
auto certStorePtr = contextPtr_->certStore.get();
238+
if (certStorePtr == nullptr)
239+
certStorePtr = &certStore;
237240
credsPtr_ = std::make_shared<Credentials>(contextPtr_->key,
238241
contextPtr_->cert.get(),
239-
contextPtr_->certStore.get());
242+
certStorePtr);
240243
if (policyPtr_->getConfCmds().empty() == false)
241244
LOG_WARN << "BotanTLSConnectionImpl does not support sslConfCmds.";
242245

@@ -329,28 +332,24 @@ struct BotanTLSProvider : public TLSProvider,
329332
}
330333
}
331334

332-
void tls_session_established(
333-
const Botan::TLS::Session_Summary &session) override
335+
void tls_session_activated() override
334336
{
335-
(void)session;
336-
LOG_TRACE << "tls_session_established";
337+
LOG_TRACE << "tls_session_activated";
337338
tlsConnected_ = true;
338-
loop_->queueInLoop([this]() {
339-
setApplicationProtocol(channel_->application_protocol());
340-
if (handshakeCallback_)
341-
handshakeCallback_(conn_);
342-
});
339+
setApplicationProtocol(channel_->application_protocol());
340+
if (handshakeCallback_)
341+
handshakeCallback_(conn_);
343342
}
344343

345344
void tls_verify_cert_chain(
346345
const std::vector<Botan::X509_Certificate> &certs,
347346
const std::vector<std::optional<Botan::OCSP::Response>> &ocsp,
348347
const std::vector<Botan::Certificate_Store *> &trusted_roots,
349348
Botan::Usage_Type usage,
350-
const std::string &hostname,
351-
const Botan::TLS::Policy &policy)
349+
std::string_view hostname,
350+
const Botan::TLS::Policy &policy) override
352351
{
353-
setSniName(hostname);
352+
setSniName(std::string(hostname));
354353
if (policyPtr_->getValidate() && !policyPtr_->getAllowBrokenChain())
355354
Botan::TLS::Callbacks::tls_verify_cert_chain(
356355
certs, ocsp, trusted_roots, usage, hostname, policy);
@@ -379,6 +378,9 @@ struct BotanTLSProvider : public TLSProvider,
379378
std::string("Certificate validation failed: ") +
380379
Botan::to_string(result));
381380
}
381+
382+
if (certs.size() > 0)
383+
setPeerCertificate(std::make_shared<BotanCertificate>(certs[0]));
382384
}
383385

384386
std::shared_ptr<TrantorPolicy> validationPolicy_;

trantor/net/inner/tlsprovider/OpenSSLProvider.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,12 @@ struct OpenSSLProvider : public TLSProvider, public NonCopyable
620620
const unsigned char *alpn = nullptr;
621621
unsigned int alpnlen = 0;
622622
SSL_get0_alpn_selected(ssl_, &alpn, &alpnlen);
623-
if (!alpn)
623+
if (alpn)
624624
{
625-
handleSSLError(SSLError::kSSLHandshakeError);
626-
return false;
625+
assert(alpnlen > 0);
626+
setApplicationProtocol(
627+
std::string((char *)alpn, alpnlen));
627628
}
628-
setApplicationProtocol(std::string((char *)alpn, alpnlen));
629629
}
630630

631631
#if OPENSSL_VERSION_NUMBER >= 0x10101000L

0 commit comments

Comments
 (0)