@@ -110,6 +110,23 @@ void NtcChannelFactory::processListenerResult(
110
110
<< AddressFormatter (alias.get ()) << " to "
111
111
<< alias->peerUri () << " registered"
112
112
<< BALL_LOG_END;
113
+
114
+ // Check if we need to upgrade the connection to TLS
115
+ if (d_encryptionServer) {
116
+ alias->upgrade (d_encryptionServer,
117
+ ntca::UpgradeOptions (),
118
+ bdlf::BindUtil::bindS (
119
+ d_allocator_p,
120
+ &NtcChannelFactory::processUpgrade,
121
+ this ,
122
+ event,
123
+ status,
124
+ channel,
125
+ bdlf::PlaceHolders::_1,
126
+ bdlf::PlaceHolders::_2,
127
+ callback));
128
+ return ; // RETURN
129
+ }
113
130
}
114
131
}
115
132
}
@@ -145,6 +162,7 @@ void NtcChannelFactory::processChannelResult(
145
162
const bsl::shared_ptr<bmqio::Channel>& channel,
146
163
const bmqio::ChannelFactory::ResultCallback& callback)
147
164
{
165
+ // Result callback for connect
148
166
BALL_LOG_TRACE << " NTC factory event " << event << " status " << status
149
167
<< BALL_LOG_END;
150
168
@@ -155,6 +173,23 @@ void NtcChannelFactory::processChannelResult(
155
173
if (alias) {
156
174
d_createSignaler (alias, alias);
157
175
}
176
+
177
+ // Check if we need to upgrade the connection to TLS
178
+ if (d_encryptionClient) {
179
+ alias->upgrade (
180
+ d_encryptionClient,
181
+ ntca::UpgradeOptions (),
182
+ bdlf::BindUtil::bindS (d_allocator_p,
183
+ &NtcChannelFactory::processUpgrade,
184
+ this ,
185
+ event,
186
+ status,
187
+ channel,
188
+ bdlf::PlaceHolders::_1,
189
+ bdlf::PlaceHolders::_2,
190
+ callback));
191
+ return ; // RETURN
192
+ }
158
193
}
159
194
}
160
195
@@ -184,12 +219,25 @@ void NtcChannelFactory::processChannelClosed(int handle)
184
219
}
185
220
186
221
void NtcChannelFactory::processUpgrade (
187
- const bsl::shared_ptr<ntci::Upgradable>& upgradable,
188
- const ntca::UpgradeEvent& event,
189
- const UpgradeCallback& onUpgrade)
222
+ bmqio::ChannelFactoryEvent::Enum event,
223
+ const bmqio::Status& status,
224
+ const bsl::shared_ptr<bmqio::NtcChannel>& channel,
225
+ const bsl::shared_ptr<ntci::Upgradable>& upgradable,
226
+ const ntca::UpgradeEvent& upgradeEvent,
227
+ const bmqio::ChannelFactory::ResultCallback& callback)
190
228
{
191
- bslmt::LockGuard<bslmt::Mutex> lock (&d_stateMutex); // LOCKED
192
- onUpgrade (upgradable, event);
229
+ if (upgradeEvent.isError ()) {
230
+ BALL_LOG_ERROR << " Received error during TLS negotiation: " << event;
231
+ bmqio::Status st (bmqio::StatusCategory::e_GENERIC_ERROR,
232
+ d_allocator_p);
233
+ channel->close (st);
234
+ callback (ChannelFactoryEvent::e_CONNECT_FAILED, st, channel);
235
+ return ; // RETURN
236
+ }
237
+
238
+ channel->setUpgradable (upgradable);
239
+
240
+ callback (event, status, channel);
193
241
}
194
242
195
243
// CREATORS
@@ -206,6 +254,8 @@ NtcChannelFactory::NtcChannelFactory(
206
254
, d_stateMutex()
207
255
, d_stateCondition()
208
256
, d_state(e_STATE_DEFAULT)
257
+ , d_encryptionServer()
258
+ , d_encryptionClient()
209
259
, d_allocator_p(bslma::Default::allocator(basicAllocator))
210
260
{
211
261
}
@@ -223,6 +273,8 @@ NtcChannelFactory::NtcChannelFactory(
223
273
, d_stateMutex()
224
274
, d_stateCondition()
225
275
, d_state(e_STATE_DEFAULT)
276
+ , d_encryptionServer()
277
+ , d_encryptionClient()
226
278
, d_allocator_p(bslma::Default::allocator(basicAllocator))
227
279
{
228
280
bsl::shared_ptr<bdlbb::BlobBufferFactory> blobBufferFactory_sp (
@@ -469,22 +521,18 @@ int NtcChannelFactory::lookupChannel(
469
521
return d_channels.find (channelId, result);
470
522
}
471
523
472
- ntsa::Error NtcChannelFactory::createEncryptionServer (
473
- bsl::shared_ptr<ntci::EncryptionServer>* result,
474
- const ntca::EncryptionServerOptions& options)
524
+ NtcChannelFactory& NtcChannelFactory::setEncryptionServer (
525
+ const bsl::shared_ptr<ntci::EncryptionServer>& encryptionServer)
475
526
{
476
- return d_interface_sp->createEncryptionServer (result,
477
- options,
478
- d_allocator_p);
527
+ d_encryptionServer = encryptionServer;
528
+ return *this ;
479
529
}
480
530
481
- ntsa::Error NtcChannelFactory::createEncryptionClient (
482
- bsl::shared_ptr<ntci::EncryptionClient>* result,
483
- const ntca::EncryptionClientOptions& options)
531
+ NtcChannelFactory& NtcChannelFactory::setEncryptionClient (
532
+ const bsl::shared_ptr<ntci::EncryptionClient>& encryptionClient)
484
533
{
485
- return d_interface_sp->createEncryptionClient (result,
486
- options,
487
- d_allocator_p);
534
+ d_encryptionClient = encryptionClient;
535
+ return *this ;
488
536
}
489
537
490
538
NtcCertificateLoader NtcChannelFactory::createCertificateLoader ()
0 commit comments