Пример #1
0
 def testItShouldCreateACertificate(self):
     ca = CA()
     ca.create_ca()
     
     key, certificate = ca.create_certificate()
     
     assert isinstance(key, OpenSSL.crypto.PKey)
     assert isinstance(certificate, OpenSSL.crypto.X509)
Пример #2
0
    def testItShouldCreateACertificate(self):
        ca = CA()
        ca.create_ca()

        key, certificate = ca.create_certificate()

        assert isinstance(key, OpenSSL.crypto.PKey)
        assert isinstance(certificate, OpenSSL.crypto.X509)
Пример #3
0
 def testItShouldNotCreateACertificateWithoutACA(self):
     ca = CA()
     
     try:
         ca.create_certificate()
         
         assert False, "expected NoKeyMaterialError"
     except NoKeyMaterialError:
         pass
     except:
         assert False, "expected NoKeyMaterialError"
Пример #4
0
    def testItShouldNotCreateACertificateWithoutACA(self):
        ca = CA()

        try:
            ca.create_certificate()

            assert False, "expected NoKeyMaterialError"
        except NoKeyMaterialError:
            pass
        except:
            assert False, "expected NoKeyMaterialError"
Пример #5
0
    def testItShouldLoadACA(self):
        old_ca = CA()
        old_ca.create_ca()

        key_pem = CA.pkey_to_pem(old_ca.ca_key)
        cert_pem = CA.certificate_to_pem(old_ca.ca_cert)

        ca = CA()
        assert ca.load(key_pem, cert_pem)
Пример #6
0
 def testItShouldNotLoadACAFromInvalidKeyMaterial(self):
     old_ca = CA()
     old_ca.create_ca()
     
     key_pem = CA.pkey_to_pem(old_ca.ca_key)
     
     old_ca.create_ca()
     
     cert_pem = CA.certificate_to_pem(old_ca.ca_cert)
     
     ca = CA()
     assert not ca.load(key_pem, cert_pem)
     assert not ca.has_ca()
Пример #7
0
    def testTheCAKeyMaterialShouldBeValid(self):
        ca = CA()
        ca.create_ca()

        ctx = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD)
        ctx.use_privatekey(ca.ca_key)
        ctx.use_certificate(ca.ca_cert)

        try:
            ctx.check_privatekey()
        except OpenSSL.SSL.Error:
            assert False, "key does not match certificate"
        except:
            pass
Пример #8
0
 def testTheCAKeyMaterialShouldBeValid(self):
     ca = CA()
     ca.create_ca()
     
     ctx = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD)
     ctx.use_privatekey(ca.ca_key)
     ctx.use_certificate(ca.ca_cert)
     
     try:
         ctx.check_privatekey()
     except OpenSSL.SSL.Error:
         assert False, "key does not match certificate"
     except:
         pass
Пример #9
0
 def testItShouldHaveACAAfterLoading(self):
     old_ca = CA()
     old_ca.create_ca()
     
     key_pem = CA.pkey_to_pem(old_ca.ca_key)
     cert_pem = CA.certificate_to_pem(old_ca.ca_cert)
     
     ca = CA()
     ca.load(key_pem, cert_pem)
     
     assert ca.has_ca()
Пример #10
0
 def testItShouldLoadACA(self):
     old_ca = CA()
     old_ca.create_ca()
     
     key_pem = CA.pkey_to_pem(old_ca.ca_key)
     cert_pem = CA.certificate_to_pem(old_ca.ca_cert)
     
     ca = CA()
     assert ca.load(key_pem, cert_pem)
Пример #11
0
    def testItShouldHaveACAAfterCreation(self):
        ca = CA()
        ca.create_ca()

        assert ca.has_ca()
Пример #12
0
    def testItShouldNotHaveACAByDefault(self):
        ca = CA()

        assert not ca.has_ca()
Пример #13
0
    def testItShouldGetTheCAPrivateKey(self):
        ca = CA()
        ca.create_ca()

        assert isinstance(ca.ca_key, OpenSSL.crypto.PKey)
Пример #14
0
    def testItShouldSerializeACertificateToPEM(self):
        ca = CA()
        ca.create_ca()

        assert CA.certificate_to_pem(ca.ca_cert).find("CERTIFICATE") >= 0
Пример #15
0
 def testItShouldNotHaveACAByDefault(self):
     ca = CA()
     
     assert not ca.has_ca()
Пример #16
0
    def testItShouldCreateACA(self):
        ca = CA()

        assert ca.create_ca()
Пример #17
0
 def testItShouldSerializeACertificateToPEM(self):
     ca = CA()
     ca.create_ca()
     
     assert CA.certificate_to_pem(ca.ca_cert).find("CERTIFICATE") >= 0
Пример #18
0
 def testItShouldGetTheCAPrivateKey(self):
     ca = CA()
     ca.create_ca()
     
     assert isinstance(ca.ca_key, OpenSSL.crypto.PKey)
Пример #19
0
 def testItShouldCreateACA(self):
     ca = CA()
     
     assert ca.create_ca()
Пример #20
0
 def testItShouldHaveACAAfterCreation(self):
     ca = CA()
     ca.create_ca()
     
     assert ca.has_ca()
Пример #21
0
    def testItShouldHaveACAAfterLoading(self):
        old_ca = CA()
        old_ca.create_ca()

        key_pem = CA.pkey_to_pem(old_ca.ca_key)
        cert_pem = CA.certificate_to_pem(old_ca.ca_cert)

        ca = CA()
        ca.load(key_pem, cert_pem)

        assert ca.has_ca()
Пример #22
0
 def testItShouldSerializeAPrivateKeyToPEM(self):
     ca = CA()
     ca.create_ca()
     
     assert CA.pkey_to_pem(ca.ca_key).find("PRIVATE KEY") >= 0
Пример #23
0
    def testItShouldNotLoadACAFromInvalidKeyMaterial(self):
        old_ca = CA()
        old_ca.create_ca()

        key_pem = CA.pkey_to_pem(old_ca.ca_key)

        old_ca.create_ca()

        cert_pem = CA.certificate_to_pem(old_ca.ca_cert)

        ca = CA()
        assert not ca.load(key_pem, cert_pem)
        assert not ca.has_ca()
Пример #24
0
    def testItShouldSerializeAPrivateKeyToPEM(self):
        ca = CA()
        ca.create_ca()

        assert CA.pkey_to_pem(ca.ca_key).find("PRIVATE KEY") >= 0
Пример #25
0
    def testItShouldGetTheCACertificate(self):
        ca = CA()
        ca.create_ca()

        assert isinstance(ca.ca_cert, OpenSSL.crypto.X509)
Пример #26
0
 def testItShouldGetTheCACertificate(self):
     ca = CA()
     ca.create_ca()
     
     assert isinstance(ca.ca_cert, OpenSSL.crypto.X509)