Ejemplo n.º 1
0
    def test_is_pkcs12(self):
        with self.assertRaises(TypeError):
            is_pkcs12("just a string")
        with self.assertRaises(TypeError):
            is_pkcs12(None)

        with open_file("rsa_2048_key.pem") as rsa_2048_key_pem:
            self.assertFalse(is_pkcs12(rsa_2048_key_pem.read()))

        with open_file("rsa_2048_key_encrypted.pem") as f:
            self.assertFalse(is_pkcs12(f.read()))

        with open_file("rsa_2048_cert.pem") as rsa_2048_cert_pem:
            self.assertFalse(is_pkcs12(rsa_2048_cert_pem.read()))

        with open_file("rsa_2048_key_cert.pfx") as rsa_2048_key_cert_pfx:
            self.assertTrue(is_pkcs12(rsa_2048_key_cert_pfx.read()))

        with open_file("rsa_2048_key_cert_encrypted.pfx"
                       ) as rsa_2048_key_cert_encrypted_pfx:
            self.assertTrue(is_pkcs12(rsa_2048_key_cert_encrypted_pfx.read()))
Ejemplo n.º 2
0
    def test_is_pkcs12(self):
        self.assertFalse(is_pkcs12('just a string'))
        self.assertFalse(is_pkcs12(None))

        with open_file('rsa_2048_key.pem') as rsa_2048_key_pem:
            self.assertFalse(is_pkcs12(rsa_2048_key_pem.read()))

        with open_file('rsa_2048_key_encrypted.pem') as f:
            self.assertFalse(is_pkcs12(f.read()))

        with open_file('rsa_2048_cert.pem') as rsa_2048_cert_pem:
            self.assertFalse(is_pkcs12(rsa_2048_cert_pem.read()))

        with open_file('rsa_2048_key_cert.pfx') as rsa_2048_key_cert_pfx:
            self.assertTrue(is_pkcs12(rsa_2048_key_cert_pfx.read()))

        with open_file(
            'rsa_2048_key_cert_encrypted.pfx') as \
                rsa_2048_key_cert_encrypted_pfx:
            self.assertTrue(is_pkcs12(rsa_2048_key_cert_encrypted_pfx.read()))
Ejemplo n.º 3
0
    def test_is_pkcs12(self):
        self.assertFalse(is_pkcs12('just a string'))
        self.assertFalse(is_pkcs12(None))

        def _open(filename):
            return open(os.path.join(PKG_DIR, 'files', filename), 'rb')

        with _open('rsa_2048_key.pem') as rsa_2048_key_pem:
            self.assertFalse(is_pkcs12(rsa_2048_key_pem.read()))

        with _open('rsa_2048_key_encrypted.pem') as rsa_2048_key_encrypted_pem:
            self.assertFalse(is_pkcs12(rsa_2048_key_encrypted_pem.read()))

        with _open('rsa_2048_cert.pem') as rsa_2048_cert_pem:
            self.assertFalse(is_pkcs12(rsa_2048_cert_pem.read()))

        with _open('rsa_2048_key_cert.pfx') as rsa_2048_key_cert_pfx:
            self.assertTrue(is_pkcs12(rsa_2048_key_cert_pfx.read()))

        with _open(
            'rsa_2048_key_cert_encrypted.pfx') as \
                rsa_2048_key_cert_encrypted_pfx:
            self.assertTrue(is_pkcs12(rsa_2048_key_cert_encrypted_pfx.read()))
Ejemplo n.º 4
0
    def test_is_pkcs12(self):
        with self.assertRaises(TypeError):
            is_pkcs12(None)

        with open_file("rsa_2048_key.pem") as rsa_2048_key_pem:
            self.assertFalse(is_pkcs12(rsa_2048_key_pem.read()))

        with open_file("rsa_2048_key_encrypted.pem") as f:
            self.assertFalse(is_pkcs12(f.read()))

        with open_file("rsa_2048_cert.pem") as rsa_2048_cert_pem:
            self.assertFalse(is_pkcs12(rsa_2048_cert_pem.read()))

        with open_file("rsa_2048_key_cert.pfx") as rsa_2048_key_cert_pfx:
            data = rsa_2048_key_cert_pfx.read()
        self.assertTrue(is_pkcs12(data))
        parse_private_key(data, None)
        parse_certificates(data, None)

        with open_file(
            "rsa_2048_key_cert_encrypted.pfx"
        ) as rsa_2048_key_cert_encrypted_pfx:
            self.assertTrue(is_pkcs12(rsa_2048_key_cert_encrypted_pfx.read()))