@@ -199,9 +199,9 @@ def __getattr__(self, item):
199
199
200
200
class _BasicClient (object ):
201
201
def __init__ (self , access_key_id = '' , secret_access_key = '' , is_secure = True , server = None ,
202
- signature = 'obs' , region = 'region' , path_style = False , ssl_verify = False ,
202
+ signature = 'obs' , region = 'region' , path_style = False , ssl_verify = False , is_use_gmssl = False ,
203
203
port = None , max_retry_count = 3 , timeout = 60 , chunk_size = const .READ_ONCE_LENGTH ,
204
- long_conn_mode = False , proxy_host = None , proxy_port = None ,
204
+ long_conn_mode = False , proxy_host = None , proxy_port = None , client_verify = None ,
205
205
proxy_username = None , proxy_password = None , security_token = None ,
206
206
custom_ciphers = None , use_http2 = False , is_signature_negotiation = True , is_cname = False ,
207
207
max_redirect_count = 10 , security_providers = None , security_provider_policy = None , client_mode = 'obs' ,
@@ -239,7 +239,8 @@ def __init__(self, access_key_id='', secret_access_key='', is_secure=True, serve
239
239
self .is_signature_negotiation = is_signature_negotiation
240
240
self .is_cname = is_cname
241
241
self .max_redirect_count = max_redirect_count
242
-
242
+ self .is_use_gmssl = is_use_gmssl
243
+ self .client_verify = client_verify
243
244
if client_mode == 'obs' :
244
245
if self .path_style or self .is_cname :
245
246
self .is_signature_negotiation = False
@@ -364,30 +365,45 @@ def _init_connHolder(self):
364
365
self .connHolder = {'connSet' : Queue (), 'lock' : threading .Lock ()}
365
366
366
367
def _init_ssl_context (self , custom_ciphers ):
367
- try :
368
- import ssl
369
- if hasattr (ssl , 'SSLContext' ):
368
+ import ssl
369
+ if hasattr (ssl , 'SSLContext' ):
370
+ if self .is_use_gmssl :
371
+ if not hasattr (ssl , 'PROTOCOL_GMTLS' ):
372
+ raise Exception ('ssl not support PROTOCOL_GMTLS.' )
373
+ context = ssl .SSLContext (ssl .PROTOCOL_GMTLS )
374
+ context .set_ciphers ('ECC-SM4-SM3:ECDHE-SM4-SM3' )
375
+ else :
370
376
context = ssl .SSLContext (ssl .PROTOCOL_SSLv23 )
371
- context .options |= ssl .OP_NO_SSLv2
372
- context .options |= ssl .OP_NO_SSLv3
373
- if custom_ciphers is not None :
374
- custom_ciphers = util .to_string (custom_ciphers ).strip ()
375
- if custom_ciphers != '' and hasattr (context , 'set_ciphers' ) and callable (context .set_ciphers ):
376
- context .set_ciphers (custom_ciphers )
377
- if self .ssl_verify :
378
- import _ssl
379
- cafile = util .to_string (self .ssl_verify )
380
- context .options |= getattr (_ssl , "OP_NO_COMPRESSION" , 0 )
381
- context .verify_mode = ssl .CERT_REQUIRED
382
- if os .path .isfile (cafile ):
383
- context .load_verify_locations (cafile )
384
- else :
385
- context .verify_mode = ssl .CERT_NONE
386
- if hasattr (context , 'check_hostname' ):
387
- context .check_hostname = False
388
- self .context = context
389
- except Exception :
390
- print (traceback .format_exc ())
377
+ context .options |= ssl .OP_NO_SSLv2
378
+ context .options |= ssl .OP_NO_SSLv3
379
+ if custom_ciphers is not None :
380
+ custom_ciphers = util .to_string (custom_ciphers ).strip ()
381
+ if custom_ciphers != '' and hasattr (context , 'set_ciphers' ) and callable (context .set_ciphers ):
382
+ context .set_ciphers (custom_ciphers )
383
+ if self .ssl_verify :
384
+ import _ssl
385
+ cafile = util .to_string (self .ssl_verify )
386
+ context .options |= getattr (_ssl , "OP_NO_COMPRESSION" , 0 )
387
+ context .verify_mode = ssl .CERT_REQUIRED
388
+ if os .path .isfile (cafile ):
389
+ context .load_verify_locations (cafile )
390
+ else :
391
+ context .verify_mode = ssl .CERT_NONE
392
+ is_client_sign_verify = self .client_verify and self .client_verify .clientCert and \
393
+ self .client_verify .clientKey
394
+ is_client_enc_verify = self .client_verify and self .client_verify .clientEncCert and \
395
+ self .client_verify .clientEncKey
396
+ if is_client_sign_verify :
397
+ context .load_cert_chain (certfile = util .to_string (self .client_verify .clientCert ),
398
+ keyfile = util .to_string (self .client_verify .clientKey ),
399
+ password = util .to_string (self .client_verify .clientKeyPassword ))
400
+ if is_client_enc_verify :
401
+ context .load_cert_chain (certfile = util .to_string (self .client_verify .clientEncCert ),
402
+ keyfile = util .to_string (self .client_verify .clientEncKey ),
403
+ password = util .to_string (self .client_verify .clientEncKeyPassword ))
404
+ if hasattr (context , 'check_hostname' ):
405
+ context .check_hostname = False
406
+ self .context = context
391
407
392
408
def close (self ):
393
409
if self .connHolder is not None :
@@ -502,7 +518,7 @@ def _make_request_with_retry(self, methodType, bucketName, objectKey=None, pathA
502
518
if flag >= self .max_retry_count or readable :
503
519
return self ._make_error_result (e , ret )
504
520
flag += 1
505
- time .sleep (math .pow (2 , flag ) * 0.05 )
521
+ time .sleep (math .pow (2 , flag ) * 0.1 )
506
522
self .log_client .log (WARNING , 'request again, time:%d' % int (flag ))
507
523
continue
508
524
@@ -824,7 +840,9 @@ def _parse_content(self, objectKey, conn, response, download_start='',
824
840
result_wrapper = ResponseWrapper (conn , response , self .connHolder , content_length , notifier , obs_crc64 = obs_crc64 )
825
841
self .log_client .log (DEBUG , 'CRC64 from the server is {0}' .format (obs_crc64 ))
826
842
else :
827
- raise Exception ('No CRC64 is obtained from the server.' )
843
+ result_wrapper = ResponseWrapper (conn , response , self .connHolder , content_length , notifier )
844
+ self .log_client .log (WARNING , 'object {0} not get CRC64 from the server.' .format (objectKey ))
845
+
828
846
else :
829
847
result_wrapper = ResponseWrapper (conn , response , self .connHolder , content_length , notifier )
830
848
if loadStreamInMemory :
@@ -1248,9 +1266,7 @@ def _createPostSignature(self, bucketName=None, objectKey=None, expires=300, for
1248
1266
if matchAnyKey :
1249
1267
policy .append ('["starts-with", "$key", ""],' )
1250
1268
1251
- policy .append (']}' )
1252
-
1253
- originPolicy = '' .join (policy )
1269
+ originPolicy = '' .join (policy ).rstrip (',' ) + ']}'
1254
1270
1255
1271
policy = util .base64_encode (originPolicy )
1256
1272
0 commit comments