@@ -271,9 +271,11 @@ def construct(self):
271
271
channel_ssl_creds = None
272
272
channel_metadata_creds = None
273
273
channel_creds = None
274
- channel_ssl_creds = grpc .ssl_channel_credentials (
275
- self .__root_certificates , self .__private_key , self .__certificate_chain
276
- )
274
+ channel_ssl_creds = None
275
+ if any ((self .__root_certificates , self .__private_key , self .__certificate_chain )):
276
+ channel_ssl_creds = grpc .ssl_channel_credentials (
277
+ self .__root_certificates , self .__private_key , self .__certificate_chain
278
+ )
277
279
if self .__username and self .__password :
278
280
channel_metadata_creds = grpc .metadata_call_credentials (
279
281
CiscoAuthPlugin (self .__username , self .__password )
@@ -284,25 +286,28 @@ def construct(self):
284
286
channel_ssl_creds , channel_metadata_creds
285
287
)
286
288
logging .debug ("Using SSL/metadata authentication composite credentials." )
287
- else :
289
+ elif channel_ssl_creds :
288
290
channel_creds = channel_ssl_creds
289
291
logging .debug ("Using SSL credentials, no metadata authentication." )
290
- if self .__ssl_target_name_override is not False :
291
- if self .__ssl_target_name_override is None :
292
- if not self .__root_certificates :
293
- raise Exception ("Deriving override requires root certificate!" )
294
- self .__ssl_target_name_override = get_cn_from_cert (
295
- self .__root_certificates
292
+ if channel_creds :
293
+ if self .__ssl_target_name_override is not False :
294
+ if self .__ssl_target_name_override is None :
295
+ if not self .__root_certificates :
296
+ raise Exception ("Deriving override requires root certificate!" )
297
+ self .__ssl_target_name_override = get_cn_from_cert (
298
+ self .__root_certificates
299
+ )
300
+ logging .warning (
301
+ "Overriding SSL option from certificate could increase MITM susceptibility!"
302
+ )
303
+ self .set_channel_option (
304
+ "grpc.ssl_target_name_override" , self .__ssl_target_name_override
296
305
)
297
- logging .warning (
298
- "Overriding SSL option from certificate could increase MITM susceptibility!"
299
- )
300
- self .set_channel_option (
301
- "grpc.ssl_target_name_override" , self .__ssl_target_name_override
306
+ channel = grpc .secure_channel (
307
+ self .__target_netloc .netloc , channel_creds , self .__channel_options
302
308
)
303
- channel = grpc .secure_channel (
304
- self .__target_netloc .netloc , channel_creds , self .__channel_options
305
- )
309
+ else :
310
+ channel = grpc .insecure_channel (self .__target_netloc .netloc )
306
311
if self .__client_class is None :
307
312
self .set_os ()
308
313
client = self .__client_class (channel )
0 commit comments