| 99 | struct SecurityFixture |
| 100 | { |
| 101 | void server(apache::thrift::transport::SSLProtocol protocol) |
| 102 | { |
| 103 | try |
| 104 | { |
| 105 | boost::mutex::scoped_lock lock(mMutex); |
| 106 | |
| 107 | shared_ptr<TSSLSocketFactory> pServerSocketFactory; |
| 108 | shared_ptr<TSSLServerSocket> pServerSocket; |
| 109 | |
| 110 | pServerSocketFactory.reset(new TSSLSocketFactory(static_cast<apache::thrift::transport::SSLProtocol>(protocol))); |
| 111 | #if OPENSSL_VERSION_NUMBER >= 0x10100000L |
| 112 | // OpenSSL 1.1.0 introduced @SECLEVEL. Modern distributions limit TLS 1.0/1.1 |
| 113 | // to @SECLEVEL=0 or 1, so specify it to test all combinations. |
| 114 | pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@SECLEVEL=0:@STRENGTH"); |
| 115 | #else |
| 116 | pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
| 117 | #endif |
| 118 | pServerSocketFactory->loadCertificate(certFile("server.crt").string().c_str()); |
| 119 | pServerSocketFactory->loadPrivateKey(certFile("server.key").string().c_str()); |
| 120 | pServerSocketFactory->server(true); |
| 121 | pServerSocket.reset(new TSSLServerSocket("localhost", 0, pServerSocketFactory)); |
| 122 | shared_ptr<TTransport> connectedClient; |
| 123 | |
| 124 | try |
| 125 | { |
| 126 | pServerSocket->listen(); |
| 127 | mPort = pServerSocket->getPort(); |
| 128 | mCVar.notify_one(); |
| 129 | lock.unlock(); |
| 130 | |
| 131 | connectedClient = pServerSocket->accept(); |
| 132 | uint8_t buf[2]; |
| 133 | buf[0] = 'O'; |
| 134 | buf[1] = 'K'; |
| 135 | connectedClient->write(&buf[0], 2); |
| 136 | connectedClient->flush(); |
| 137 | } |
| 138 | |
| 139 | catch (apache::thrift::transport::TTransportException& ex) |
| 140 | { |
| 141 | boost::mutex::scoped_lock lock(gMutex); |
| 142 | BOOST_TEST_MESSAGE(boost::format("SRV %1% Exception: %2%") % boost::this_thread::get_id() % ex.what()); |
| 143 | } |
| 144 | |
| 145 | if (connectedClient) |
| 146 | { |
| 147 | connectedClient->close(); |
| 148 | connectedClient.reset(); |
| 149 | } |
| 150 | |
| 151 | pServerSocket->close(); |
| 152 | pServerSocket.reset(); |
| 153 | } |
| 154 | catch (std::exception& ex) |
| 155 | { |
| 156 | BOOST_FAIL(boost::format("%1%: %2%") % typeid(ex).name() % ex.what()); |
| 157 | } |
| 158 | } |
no test coverage detected