| 322 | } |
| 323 | |
| 324 | void SecureSocket::initContext(bool server) |
| 325 | { |
| 326 | SSL_library_init(); |
| 327 | |
| 328 | const SSL_METHOD *method; |
| 329 | |
| 330 | // load & register all cryptos, etc. |
| 331 | OpenSSL_add_all_algorithms(); |
| 332 | |
| 333 | // load all error messages |
| 334 | SSL_load_error_strings(); |
| 335 | SslLogger::logSecureLibInfo(); |
| 336 | |
| 337 | if (server) { |
| 338 | method = SSLv23_server_method(); |
| 339 | } else { |
| 340 | method = SSLv23_client_method(); |
| 341 | } |
| 342 | |
| 343 | // create new context from method |
| 344 | const auto *m = const_cast<SSL_METHOD *>(method); |
| 345 | m_ssl->m_context = SSL_CTX_new(m); |
| 346 | |
| 347 | // Prevent the usage of of all version prior to TLSv1.2 as they are known to |
| 348 | // be vulnerable |
| 349 | SSL_CTX_set_options( |
| 350 | m_ssl->m_context, |
| 351 | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_IGNORE_UNEXPECTED_EOF |
| 352 | ); |
| 353 | |
| 354 | if (m_ssl->m_context == nullptr) { |
| 355 | SslLogger::logError(); |
| 356 | } |
| 357 | |
| 358 | if (m_securityLevel == SecurityLevel::PeerAuth) { |
| 359 | // We want to ask for peer certificate, but not verify it. If we don't ask for peer |
| 360 | // certificate, e.g. client won't send it. |
| 361 | SSL_CTX_set_verify(m_ssl->m_context, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr); |
| 362 | SSL_CTX_set_cert_verify_callback(m_ssl->m_context, verifyIgnoreCertCallback, nullptr); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | void SecureSocket::createSSL() |
| 367 | { |
nothing calls this directly
no outgoing calls
no test coverage detected