MCPcopy Create free account
hub / github.com/catboost/catboost / TSslCtxServer

Method TSslCtxServer

library/cpp/neh/https.cpp:704–753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

702 };
703 public:
704 TSslCtxServer(const TParsedLocation& loc) {
705 const SSL_METHOD* method = SSLv23_server_method();
706 if (Y_UNLIKELY(!method)) {
707 ythrow TSslException(TStringBuf("SSLv23_server_method"));
708 }
709
710 SslCtx_ = SSL_CTX_new(method);
711 if (Y_UNLIKELY(!SslCtx_)) {
712 ythrow TSslException(TStringBuf("SSL_CTX_new(server)"));
713 }
714
715 TString cert, key;
716 ParseUserInfo(loc, cert, key);
717
718 TUserDataHolder holder(SslCtx_, loc, cert, key);
719
720 SSL_CTX_set_default_passwd_cb(SslCtx_, [](char* buf, int size, int rwflag, void* userData) -> int {
721 Y_UNUSED(rwflag);
722 Y_UNUSED(userData);
723
724 if (THttpsOptions::KeyPasswdCallback == nullptr || userData == nullptr) {
725 return 0;
726 }
727
728 auto data = static_cast<TPasswordCallbackUserData*>(userData);
729 const auto& passwd = THttpsOptions::KeyPasswdCallback(data->Location, data->CertFileName, data->KeyFileName);
730
731 if (size < static_cast<int>(passwd.size())) {
732 return -1;
733 }
734
735 return passwd.copy(buf, size, 0);
736 });
737
738 if (!cert || !key) {
739 ythrow TSslException() << TStringBuf("no certificate or private key is specified for server");
740 }
741
742 if (1 != SSL_CTX_use_certificate_chain_file(SslCtx_, cert.data())) {
743 ythrow TSslException(TStringBuf("SSL_CTX_use_certificate_chain_file (server)"));
744 }
745
746 if (1 != SSL_CTX_use_PrivateKey_file(SslCtx_, key.data(), SSL_FILETYPE_PEM)) {
747 ythrow TSslException(TStringBuf("SSL_CTX_use_PrivateKey_file (server)"));
748 }
749
750 if (1 != SSL_CTX_check_private_key(SslCtx_)) {
751 ythrow TSslException(TStringBuf("SSL_CTX_check_private_key (server)"));
752 }
753 }
754 };
755
756 class TSslCtxClient: public TSslCtx {

Callers

nothing calls this directly

Calls 5

ParseUserInfoFunction · 0.85
Y_UNUSEDFunction · 0.85
sizeMethod · 0.45
copyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected