4343CERT_PATH  =  os .path .join (os .path .dirname (os .path .realpath (__file__ )),
4444 'certificates' )
4545CLIENT_PEM  =  os .path .join (CERT_PATH , 'client.pem' )
46+ CLIENT_ENCRYPTED_PEM  =  os .path .join (CERT_PATH , 'client_encrypted.pem' )
4647CA_PEM  =  os .path .join (CERT_PATH , 'ca.pem' )
4748CRL_PEM  =  os .path .join (CERT_PATH , 'crl.pem' )
4849SIMPLE_SSL  =  False 
@@ -224,6 +225,38 @@ def test_simple_ssl(self):
224225 self .assertTrue (db .test .find_one ()['ssl' ])
225226 client .drop_database ('pymongo_ssl_test' )
226227
228+  def  test_ssl_pem_passphrase (self ):
229+  # Expects the server to be running with server.pem and ca.pem 
230+  # 
231+  # --sslPEMKeyFile=/path/to/pymongo/test/certificates/server.pem 
232+  # --sslCAFile=/path/to/pymongo/test/certificates/ca.pem 
233+  if  not  CERT_SSL :
234+  raise  SkipTest ("No mongod available over SSL with certs" )
235+ 
236+  vi  =  sys .version_info 
237+  if  vi [0 ] ==  2  and  vi  <  (2 , 7 , 9 ) or  vi [0 ] ==  3  and  vi  <  (3 , 3 ):
238+  self .assertRaises (
239+  ConfigurationError ,
240+  MongoClient ,
241+  'server' ,
242+  ssl = True ,
243+  ssl_certfile = CLIENT_ENCRYPTED_PEM ,
244+  ssl_pem_passphrase = "clientpassword" ,
245+  ssl_ca_certs = CA_PEM ,
246+  serverSelectionTimeoutMS = 100 )
247+  else :
248+  connected (MongoClient ('server' ,
249+  ssl = True ,
250+  ssl_certfile = CLIENT_ENCRYPTED_PEM ,
251+  ssl_pem_passphrase = "clientpassword" ,
252+  ssl_ca_certs = CA_PEM ,
253+  serverSelectionTimeoutMS = 100 ))
254+ 
255+  uri_fmt  =  ("mongodb://server/?ssl=true" 
256+  "&ssl_certfile=%s&ssl_pem_passphrase=clientpassword" 
257+  "&ssl_ca_certs=%s&serverSelectionTimeoutMS=100" )
258+  connected (MongoClient (uri_fmt  %  (CLIENT_ENCRYPTED_PEM , CA_PEM )))
259+ 
227260 def  test_cert_ssl (self ):
228261 # Expects the server to be running with server.pem and ca.pem. 
229262 # 
@@ -515,7 +548,7 @@ def test_validation_with_system_ca_certs(self):
515548 os .environ .pop ('SSL_CERT_FILE' )
516549
517550 def  test_system_certs_config_error (self ):
518-  ctx  =  get_ssl_context (None , None , None , ssl .CERT_NONE , None )
551+  ctx  =  get_ssl_context (None , None , None , None ,  ssl .CERT_NONE , None )
519552 if  ((sys .platform  !=  "win32" 
520553 and  hasattr (ctx , "set_default_verify_paths" ))
521554 or  hasattr (ctx , "load_default_certs" )):
@@ -547,11 +580,11 @@ def test_certifi_support(self):
547580 # Force the test on Windows, regardless of environment. 
548581 ssl_support .HAVE_WINCERTSTORE  =  False 
549582 try :
550-  ctx  =  get_ssl_context (None , None , CA_PEM , ssl .CERT_REQUIRED , None )
583+  ctx  =  get_ssl_context (None , None , None ,  CA_PEM , ssl .CERT_REQUIRED , None )
551584 ssl_sock  =  ctx .wrap_socket (socket .socket ())
552585 self .assertEqual (ssl_sock .ca_certs , CA_PEM )
553586
554-  ctx  =  get_ssl_context (None , None , None , None , None )
587+  ctx  =  get_ssl_context (None , None , None , None , None ,  None )
555588 ssl_sock  =  ctx .wrap_socket (socket .socket ())
556589 self .assertEqual (ssl_sock .ca_certs , ssl_support .certifi .where ())
557590 finally :
@@ -568,11 +601,11 @@ def test_wincertstore(self):
568601 if  not  ssl_support .HAVE_WINCERTSTORE :
569602 raise  SkipTest ("Need wincertstore to test wincertstore." )
570603
571-  ctx  =  get_ssl_context (None , None , CA_PEM , ssl .CERT_REQUIRED , None )
604+  ctx  =  get_ssl_context (None , None , None ,  CA_PEM , ssl .CERT_REQUIRED , None )
572605 ssl_sock  =  ctx .wrap_socket (socket .socket ())
573606 self .assertEqual (ssl_sock .ca_certs , CA_PEM )
574607
575-  ctx  =  get_ssl_context (None , None , None , None , None )
608+  ctx  =  get_ssl_context (None , None , None , None , None ,  None )
576609 ssl_sock  =  ctx .wrap_socket (socket .socket ())
577610 self .assertEqual (ssl_sock .ca_certs , ssl_support ._WINCERTS .name )
578611
0 commit comments