@@ -199,9 +199,9 @@ def __getattr__(self, item):
199199
200200class _BasicClient (object ):
201201 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 ,
203203 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 ,
205205 proxy_username = None , proxy_password = None , security_token = None ,
206206 custom_ciphers = None , use_http2 = False , is_signature_negotiation = True , is_cname = False ,
207207 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
239239 self .is_signature_negotiation = is_signature_negotiation
240240 self .is_cname = is_cname
241241 self .max_redirect_count = max_redirect_count
242-
242+ self .is_use_gmssl = is_use_gmssl
243+ self .client_verify = client_verify
243244 if client_mode == 'obs' :
244245 if self .path_style or self .is_cname :
245246 self .is_signature_negotiation = False
@@ -364,30 +365,45 @@ def _init_connHolder(self):
364365 self .connHolder = {'connSet' : Queue (), 'lock' : threading .Lock ()}
365366
366367 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 :
370376 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
391407
392408 def close (self ):
393409 if self .connHolder is not None :
@@ -502,7 +518,7 @@ def _make_request_with_retry(self, methodType, bucketName, objectKey=None, pathA
502518 if flag >= self .max_retry_count or readable :
503519 return self ._make_error_result (e , ret )
504520 flag += 1
505- time .sleep (math .pow (2 , flag ) * 0.05 )
521+ time .sleep (math .pow (2 , flag ) * 0.1 )
506522 self .log_client .log (WARNING , 'request again, time:%d' % int (flag ))
507523 continue
508524
@@ -824,7 +840,9 @@ def _parse_content(self, objectKey, conn, response, download_start='',
824840 result_wrapper = ResponseWrapper (conn , response , self .connHolder , content_length , notifier , obs_crc64 = obs_crc64 )
825841 self .log_client .log (DEBUG , 'CRC64 from the server is {0}' .format (obs_crc64 ))
826842 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+
828846 else :
829847 result_wrapper = ResponseWrapper (conn , response , self .connHolder , content_length , notifier )
830848 if loadStreamInMemory :
@@ -1248,9 +1266,7 @@ def _createPostSignature(self, bucketName=None, objectKey=None, expires=300, for
12481266 if matchAnyKey :
12491267 policy .append ('["starts-with", "$key", ""],' )
12501268
1251- policy .append (']}' )
1252-
1253- originPolicy = '' .join (policy )
1269+ originPolicy = '' .join (policy ).rstrip (',' ) + ']}'
12541270
12551271 policy = util .base64_encode (originPolicy )
12561272
0 commit comments