MCPcopy Create free account
hub / github.com/apache/thrift / client

Method client

lib/cpp/test/SecurityTest.cpp:160–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158 }
159
160 void client(apache::thrift::transport::SSLProtocol protocol)
161 {
162 try
163 {
164 shared_ptr<TSSLSocketFactory> pClientSocketFactory;
165 shared_ptr<TSSLSocket> pClientSocket;
166
167 try
168 {
169 pClientSocketFactory.reset(new TSSLSocketFactory(static_cast<apache::thrift::transport::SSLProtocol>(protocol)));
170 pClientSocketFactory->authenticate(true);
171 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
172 // OpenSSL 1.1.0 introduced @SECLEVEL. Modern distributions limit TLS 1.0/1.1
173 // to @SECLEVEL=0 or 1, so specify it to test all combinations.
174 pClientSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@SECLEVEL=0");
175 #endif
176 pClientSocketFactory->loadCertificate(certFile("client.crt").string().c_str());
177 pClientSocketFactory->loadPrivateKey(certFile("client.key").string().c_str());
178 pClientSocketFactory->loadTrustedCertificates(certFile("CA.pem").string().c_str());
179 pClientSocket = pClientSocketFactory->createSocket("localhost", mPort);
180 pClientSocket->open();
181
182 uint8_t buf[3];
183 buf[0] = 0;
184 buf[1] = 0;
185 BOOST_CHECK_EQUAL(2, pClientSocket->read(&buf[0], 2));
186 BOOST_CHECK_EQUAL(0, memcmp(&buf[0], "OK", 2));
187 mConnected = true;
188 }
189 catch (apache::thrift::transport::TTransportException& ex)
190 {
191 boost::mutex::scoped_lock lock(gMutex);
192 BOOST_TEST_MESSAGE(boost::format("CLI %1% Exception: %2%") % boost::this_thread::get_id() % ex.what());
193 }
194
195 if (pClientSocket)
196 {
197 pClientSocket->close();
198 pClientSocket.reset();
199 }
200 }
201 catch (std::exception& ex)
202 {
203 BOOST_FAIL(boost::format("%1%: %2%") % typeid(ex).name() % ex.what());
204 }
205 }
206
207 static const char *protocol2str(size_t protocol)
208 {

Callers

nothing calls this directly

Calls 13

authenticateMethod · 0.80
ciphersMethod · 0.80
loadCertificateMethod · 0.80
loadPrivateKeyMethod · 0.80
certFileFunction · 0.70
readMethod · 0.65
closeMethod · 0.65
resetMethod · 0.45
createSocketMethod · 0.45
openMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected