Skip to content
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

I sugest change initSSL, as a client, it's not necessary use certificates when connecting to a SSL server . #143

Open
mbsteixeira opened this issue May 31, 2024 · 3 comments

Comments

@mbsteixeira
Copy link

bool initSSL(const std::string& certificate,
const std::string& privatekey,
bool isclient=false)
{
std::call_once(initCryptoThreadSafeSupportOnceFlag,
InitCryptoThreadSafeSupport);

    if (mOpenSSLCTX != nullptr)
    {
        return false;
    }
	
    mOpenSSLCTX = SSL_CTX_new(SSLv23_method());
	if(isclient && mOpenSSLCTX)
	  return true;
	
    if (certificate.empty() || privatekey.empty())
    {
        return false;
    }

    SSL_CTX_set_client_CA_list(mOpenSSLCTX,
                               SSL_load_client_CA_file(certificate.c_str()));
    SSL_CTX_set_verify_depth(mOpenSSLCTX, 10);

    if (SSL_CTX_use_certificate_chain_file(mOpenSSLCTX,
                                           certificate.c_str()) <= 0)
    {
        SSL_CTX_free(mOpenSSLCTX);
        mOpenSSLCTX = nullptr;
        return false;
    }

    if (SSL_CTX_use_PrivateKey_file(mOpenSSLCTX,
                                    privatekey.c_str(),
                                    SSL_FILETYPE_PEM) <= 0)
    {
        SSL_CTX_free(mOpenSSLCTX);
        mOpenSSLCTX = nullptr;
        return false;
    }

    if (!SSL_CTX_check_private_key(mOpenSSLCTX))
    {
        SSL_CTX_free(mOpenSSLCTX);
        mOpenSSLCTX = nullptr;
        return false;
    }

    return true;
}
@IronsDu
Copy link
Owner

IronsDu commented Jun 3, 2024

Or we could put the initialization of the lock in a separate function?

@mbsteixeira
Copy link
Author

Agree, this option is more efficient!

@IronsDu
Copy link
Owner

IronsDu commented Jun 3, 2024

@mbsteixeira Hello, I do it in #144 . please try the master branch.

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

No branches or pull requests

2 participants