How to use keyper - 10 common examples

To help you get started, we’ve selected a few keyper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / keyper / tests / test_certificates.py View on Github external
def test_using_codesign(self):
        """Test that an added cert works with codesign."""

        with keyper.TemporaryKeychain() as keychain:
            certificate = keyper.Certificate(KeyperCertificateTests.TEST_CERT_PATH, password=KeyperCertificateTests.TEST_CERT_PASSWORD)
            keychain.install_cert(certificate)

            temp_file_path = tempfile.mktemp()

            with open(temp_file_path, 'w') as temp_file:
                temp_file.write("Test")

            try:
                subprocess.run(
                    f"codesign -s TestCertificate_CodeSign --keychain {keychain.path} {temp_file_path}",
                    shell=True,
                    check=True
                )
            except subprocess.CalledProcessError as ex:
                self.fail(f"Failed to use codesign: {ex}")
github microsoft / keyper / tests / test_certificates.py View on Github external
def test_adding_cert(self):
        """Test that we can add a cert to the keychain."""

        with keyper.TemporaryKeychain() as keychain:
            certificate = keyper.Certificate(KeyperCertificateTests.TEST_CERT_PATH, password=KeyperCertificateTests.TEST_CERT_PASSWORD)
            self.assertEqual(certificate.path, KeyperCertificateTests.TEST_CERT_PATH)
            self.assertEqual(certificate.password, KeyperCertificateTests.TEST_CERT_PASSWORD)
            keychain.install_cert(certificate)
github microsoft / keyper / tests / test_passwords.py View on Github external
def test_password_write_read(self):
        """Test that passwords written to a keychain can be read back."""

        with keyper.TemporaryKeychain() as keychain:
            for index, password in enumerate(KeyperPasswordTests.SAMPLE_PASSWORDS):
                keyper.set_password(password, account=f"account_{index}", service=f"service_{index}", keychain=keychain)
                returned_password = keyper.get_password(account=f"account_{index}", service=f"service_{index}", keychain=keychain)
                self.assertEqual(password, returned_password)
github microsoft / keyper / tests / test_keychain.py View on Github external
def test_temporary_keychain_context(self):
        """Test that a temporary keychain can be created, read and destroyed via the context manager."""

        with keyper.TemporaryKeychain() as keychain:
            self.assertIsNotNone(keychain.path)
            self.assertIsNotNone(keychain.password)
            self.assertTrue(os.path.exists(keychain.path))
            self.assertTrue(keychain.is_temporary)

        self.assertFalse(os.path.exists(keychain.path))
github microsoft / keyper / tests / test_certificates.py View on Github external
def test_using_codesign(self):
        """Test that an added cert works with codesign."""

        with keyper.TemporaryKeychain() as keychain:
            certificate = keyper.Certificate(KeyperCertificateTests.TEST_CERT_PATH, password=KeyperCertificateTests.TEST_CERT_PASSWORD)
            keychain.install_cert(certificate)

            temp_file_path = tempfile.mktemp()

            with open(temp_file_path, 'w') as temp_file:
                temp_file.write("Test")

            try:
                subprocess.run(
                    f"codesign -s TestCertificate_CodeSign --keychain {keychain.path} {temp_file_path}",
                    shell=True,
                    check=True
                )
            except subprocess.CalledProcessError as ex:
                self.fail(f"Failed to use codesign: {ex}")
            finally:
github microsoft / keyper / tests / test_certificates.py View on Github external
def test_creating_cert(self):
        """Test creating a certificate."""

        certificate = keyper.Certificate(KeyperCertificateTests.TEST_CERT_PATH, password=KeyperCertificateTests.TEST_CERT_PASSWORD)
        self.assertEqual(certificate.sha1, "75:22:4C:AD:D6:A0:BD:0C:88:5F:B1:77:85:2F:83:A4:F6:80:69:70")
        self.assertEqual(certificate.common_name, "TestCertificate_CodeSign")
        self.assertEqual(certificate.private_key_name, "TestCertificate_CodeSign")
github microsoft / keyper / tests / test_certificates.py View on Github external
def test_adding_cert(self):
        """Test that we can add a cert to the keychain."""

        with keyper.TemporaryKeychain() as keychain:
            certificate = keyper.Certificate(KeyperCertificateTests.TEST_CERT_PATH, password=KeyperCertificateTests.TEST_CERT_PASSWORD)
            self.assertEqual(certificate.path, KeyperCertificateTests.TEST_CERT_PATH)
            self.assertEqual(certificate.password, KeyperCertificateTests.TEST_CERT_PASSWORD)
            keychain.install_cert(certificate)
github microsoft / keyper / tests / test_keychain.py View on Github external
def test_temporary_keychain(self):
        """Test that a temporary keychain can be created, read and destroyed."""

        keychain = keyper.Keychain.create_temporary()

        self.assertIsNotNone(keychain.path)
        self.assertIsNotNone(keychain.password)
        self.assertTrue(os.path.exists(keychain.path))
        self.assertTrue(keychain.is_temporary)

        keychain.delete_temporary()

        self.assertFalse(os.path.exists(keychain.path))
github microsoft / keyper / tests / test_passwords.py View on Github external
def test_password_write_read(self):
        """Test that passwords written to a keychain can be read back."""

        with keyper.TemporaryKeychain() as keychain:
            for index, password in enumerate(KeyperPasswordTests.SAMPLE_PASSWORDS):
                keyper.set_password(password, account=f"account_{index}", service=f"service_{index}", keychain=keychain)
                returned_password = keyper.get_password(account=f"account_{index}", service=f"service_{index}", keychain=keychain)
                self.assertEqual(password, returned_password)
github microsoft / keyper / tests / test_passwords.py View on Github external
def test_password_write_read(self):
        """Test that passwords written to a keychain can be read back."""

        with keyper.TemporaryKeychain() as keychain:
            for index, password in enumerate(KeyperPasswordTests.SAMPLE_PASSWORDS):
                keyper.set_password(password, account=f"account_{index}", service=f"service_{index}", keychain=keychain)
                returned_password = keyper.get_password(account=f"account_{index}", service=f"service_{index}", keychain=keychain)
                self.assertEqual(password, returned_password)