Skip to content

Reuse tls context #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Reuse tls context #11

wants to merge 6 commits into from

Conversation

DenisRazinkin
Copy link
Collaborator


Note: by creating a PR or an issue you automatically agree to the CLA. See CONTRIBUTING.md. Feel free to remove this note, the agreement holds.

@@ -6,6 +6,8 @@
#include <string>
#include <vector>

#include <userver/crypto/ssl_ctx.hpp>
//#include <userver/crypto/ssl.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented include

void* GetRawSslCtx() const noexcept;

private:
void AddCertAuthorities(const std::vector<Certificate>& cert_authorities);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use pimp idiom the private methods here seem unnecessary


if (cert_chain.size() > 1) {
auto it = std::next(cert_chain.begin());
for (; it != cert_chain.end(); ++it) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if could be removed and everything else simplified
for (auto it == std::next(...); ...) {}

SslCtx(const SslCtx&) = delete;
SslCtx& operator=(const SslCtx&) = delete;

void* GetRawSslCtx() const noexcept;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of removing the type information if it's casted to a specific type when this method is called?

void ReadTlsSettings(const storages::secdist::SecdistConfig& secdist);
void InitSslCtx();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have a separate method though? If they need to be called together anyway

throw KeyParseError(FormatSslError("Failed to get subject name from certificate"));
}

// Используем BIO для более гибкого форматирования
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why russian comments?
Was the code copied?

throw KeyParseError(FormatSslError("Failed to create BIO"));
}

// Флаги форматирования можно настроить по вкусу
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question here

}
#if OPENSSL_VERSION_NUMBER >= 0x010100000L
if (1 != SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION)) {
throw CryptoException(crypto::FormatSslError("Failed create an SSL context: SSL_CTX_set_min_proto_version"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems it's going to be a memory leak of ssl_ctx if we throw here


char* data = nullptr;
long len = BIO_get_mem_data(bio, &data);
std::string result(data, len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor may throw (although it's rare - it's still a possibility) which will leak bio

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use RAII as the reasoning about the exception safety is quite complex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants