Exemple #1
0
 def test_two_sessions(self):
     session1 = None
     session2 = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         session1 = pk11._session(P11_MODULE, 0, "secret1")
         session2 = pk11._session(P11_MODULE, 0, "secret1")
         assert session1 != session2
         assert session1 is not None
         assert session2 is not None
     except Exception, ex:
         raise ex
Exemple #2
0
 def test_two_sessions(self):
     session1 = None
     session2 = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         session1 = pk11._session(P11_MODULE, 0, "secret1")
         session2 = pk11._session(P11_MODULE, 0, "secret1")
         assert session1 != session2
         assert session1 is not None
         assert session2 is not None
     except Exception, ex:
         raise ex
Exemple #3
0
 def test_two_sessions(self):
     session1 = None
     session2 = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session1 = pk11._session(component_path['P11_MODULE'],
                                  pk11_uri="pkcs11://%s/test?pin=secret1" %
                                  component_path['P11_MODULE'])
         session2 = pk11._session(component_path['P11_MODULE'],
                                  pk11_uri="pkcs11://%s/test?pin=secret1" %
                                  component_path['P11_MODULE'])
         assert session1 != session2
         assert session1 is not None
         assert session2 is not None
     except Exception, ex:
         raise ex
Exemple #4
0
 def test_bad_login(self):
     os.environ['SOFTHSM_CONF'] = softhsm_conf
     try:
         session = pk11._session(P11_MODULE, 0, "wrong")
         assert False, "We should have failed the last login"
     except PyKCS11Error, ex:
         assert ex.value == CKR_PIN_INCORRECT
         pass
Exemple #5
0
 def test_bad_login(self):
     os.environ['SOFTHSM_CONF'] = softhsm_conf
     try:
         session = pk11._session(P11_MODULE, 0, "wrong")
         assert False, "We should have failed the last login"
     except PyKCS11Error, ex:
         assert ex.value == CKR_PIN_INCORRECT
         pass
Exemple #6
0
 def test_open_session_no_pin(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         session = pk11._session(P11_MODULE, 0)
         assert session is not None
     except Exception, ex:
         traceback.print_exc()
         raise ex
Exemple #7
0
 def test_two_sessions(self):
     session1 = None
     session2 = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session1 = pk11._session(component_path['P11_MODULE'], pk11_uri="pkcs11://%s/test?pin=secret1" % component_path['P11_MODULE'])
         session2 = pk11._session(component_path['P11_MODULE'], pk11_uri="pkcs11://%s/test?pin=secret1" % component_path['P11_MODULE'])
         assert session1 != session2
         assert session1 is not None
         assert session2 is not None
     except Exception as ex:
         raise ex
     finally:
         if session1 is not None:
             pk11._close_session(session1)
         if session2 is not None:
             pk11._close_session(session2)
Exemple #8
0
 def test_open_session_no_pin(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         session = pk11._session(P11_MODULE, 0)
         assert session is not None
     except Exception, ex:
         traceback.print_exc()
         raise ex
Exemple #9
0
 def test_bad_login(self):
     os.environ['SOFTHSM_CONF'] = softhsm_conf
     os.environ['SOFTHSM2_CONF'] = softhsm_conf
     try:
         session = pk11._session(component_path['P11_MODULE'], pk11_uri="pkcs11://%s/test?pin=wrong" % component_path['P11_MODULE'])
         assert False, "We should have failed the last login"
     except PyKCS11Error as ex:
         assert ex.value == CKR_PIN_INCORRECT
         pass
Exemple #10
0
 def test_find_key(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         session = pk11._session(P11_MODULE, 0, "secret1")
         key, cert = pk11._find_key(session, "test")
         assert key is not None
         assert cert is not None
         assert cert.strip() == open(signer_cert_pem).read().strip()
     except Exception, ex:
         raise ex
Exemple #11
0
 def test_bad_login(self):
     os.environ['SOFTHSM_CONF'] = softhsm_conf
     os.environ['SOFTHSM2_CONF'] = softhsm_conf
     try:
         session = pk11._session(component_path['P11_MODULE'],
                                 pk11_uri="pkcs11://%s/test?pin=wrong" %
                                 component_path['P11_MODULE'])
         assert False, "We should have failed the last login"
     except PyKCS11Error, ex:
         assert ex.value == CKR_PIN_INCORRECT
         pass
Exemple #12
0
 def test_find_key(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         session = pk11._session(P11_MODULE, 0, "secret1")
         key, cert = pk11._find_key(session, "test")
         assert key is not None
         assert cert is not None
         assert cert.strip() == open(signer_cert_pem).read().strip()
     except Exception, ex:
         raise ex
Exemple #13
0
 def test_open_session(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         session = pk11._session(P11_MODULE, 0, "secret1")
         assert session is not None
     except Exception as ex:
         traceback.print_exc()
         raise ex
     finally:
         if session is not None:
             pk11._close_session(session)
 def test_open_session(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session = pk11._session(P11_MODULE,
                                 pk11_uri="pkcs11://%s/test?pin=secret1" %
                                 P11_MODULE)
         assert session is not None
     except Exception, ex:
         traceback.print_exc()
         raise ex
Exemple #15
0
 def test_open_session_no_pin(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session = pk11._session(component_path['P11_MODULE'],
                                 pk11_uri="pkcs11://%s/test" %
                                 component_path['P11_MODULE'])
         assert session is not None
     except Exception, ex:
         traceback.print_exc()
         raise ex
Exemple #16
0
 def test_open_session_no_pin(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session = pk11._session(component_path['P11_MODULE'], pk11_uri="pkcs11://%s/test" % component_path['P11_MODULE'])
         assert session is not None
     except Exception as ex:
         traceback.print_exc()
         raise ex
     finally:
         if session is not None:
             pk11._close_session(session)
Exemple #17
0
 def test_find_key(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session = pk11._session(component_path['P11_MODULE'],
                                 pk11_uri="pkcs11://%s/test?pin=secret1" %
                                 component_path['P11_MODULE'])
         key, cert = pk11._find_key(session, "test")
         assert key is not None
         assert cert is not None
         assert cert.strip() == open(signer_cert_pem).read().strip()
     except Exception, ex:
         raise ex
Exemple #18
0
 def test_open_session(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session = pk11._session(component_path['P11_MODULE'],
                                 pk11_uri="pkcs11://%s/test?pin=secret1" %
                                 component_path['P11_MODULE'])
         assert session is not None
     except Exception as ex:
         traceback.print_exc()
         raise ex
     finally:
         if session is not None:
             pk11._close_session(session)
Exemple #19
0
 def test_find_key(self):
     session = None
     try:
         os.environ['SOFTHSM_CONF'] = softhsm_conf
         os.environ['SOFTHSM2_CONF'] = softhsm_conf
         session = pk11._session(component_path['P11_MODULE'], pk11_uri="pkcs11://%s/test?pin=secret1" % component_path['P11_MODULE'])
         key, cert = pk11._find_key(session, "test")
         assert key is not None
         assert cert is not None
         assert cert.strip() == open(signer_cert_pem).read().strip().encode('utf-8')
     except Exception as ex:
         raise ex
     finally:
         if session is not None:
             pk11._close_session(session)