| 186 | |
| 187 | |
| 188 | void SecureSocketImpl::connectSSL(bool performHandshake) |
| 189 | { |
| 190 | ScopedLock lock(*_mutex); |
| 191 | poco_assert (!_pSSL); |
| 192 | poco_assert (_pSocket->initialized()); |
| 193 | |
| 194 | BIO* pBIO = BIO_new(getBioMethod()); |
| 195 | if (!pBIO) throw SSLException("Cannot create SSL BIO object"); |
| 196 | BIO_set_fd(pBIO, static_cast<int>(_pSocket->sockfd()), BIO_NOCLOSE); |
| 197 | |
| 198 | if (_bioMethod) |
| 199 | BIO_set_data(pBIO, _pSocket.get()); |
| 200 | |
| 201 | _pSSL = SSL_new(_pContext->sslContext()); |
| 202 | if (!_pSSL) |
| 203 | { |
| 204 | BIO_free(pBIO); |
| 205 | throw SSLException("Cannot create SSL object"); |
| 206 | } |
| 207 | SSL_set_bio(_pSSL, pBIO, pBIO); |
| 208 | |
| 209 | #if !defined(OPENSSL_NO_TLSEXT) |
| 210 | if (!_peerHostName.empty()) |
| 211 | { |
| 212 | SSL_set_tlsext_host_name(_pSSL, _peerHostName.c_str()); |
| 213 | } |
| 214 | #endif |
| 215 | |
| 216 | if (_pSession) |
| 217 | { |
| 218 | SSL_set_session(_pSSL, _pSession->sslSession()); |
| 219 | } |
| 220 | |
| 221 | try |
| 222 | { |
| 223 | if (performHandshake && _pSocket->getBlocking()) |
| 224 | { |
| 225 | int ret; |
| 226 | Poco::Timespan remaining_time = getMaxTimeoutOrLimit(); |
| 227 | do |
| 228 | { |
| 229 | RemainingTimeCounter counter(remaining_time); |
| 230 | ret = SSL_connect(_pSSL); |
| 231 | } |
| 232 | while (mustRetry(ret, remaining_time)); |
| 233 | handleError(ret); |
| 234 | verifyPeerCertificate(); |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | SSL_set_connect_state(_pSSL); |
| 239 | _needHandshake = true; |
| 240 | } |
| 241 | } |
| 242 | catch (...) |
| 243 | { |
| 244 | SSL_free(_pSSL); |
| 245 | _pSSL = 0; |
no test coverage detected