Beispiel #1
0
    def test_asymmetric_verify(self):
        """Tests asymmetric signature verification"""
        pub_keys = [self._server_pub_key1, self._client_pub_key2]
        priv_keys = [self._server_priv_key1, self._client_priv_key2]
        original_plaintext = b'''I do things like get in a taxi and say, \'The
                             library, and step on it.\''''

        # The enumeration assumes both key lists are of same size and the index
        # of one list holds a key that corresponds to the same index of the
        # other list.
        for i, pub_key in enumerate(pub_keys):
            ciphertext, original_signature = _asymmetric_encrypt_sign(
                original_plaintext, pub_key, priv_keys[i])
            msg = unpack(asymmetric_decrypt(ciphertext, priv_keys[i]))
            plaintext, signature = msg['msg'], msg['signature']
            self.assertEqual(original_plaintext, plaintext)
            self.assertEqual(original_signature, signature)
            self.assertTrue(asymmetric_verify(signature, plaintext, pub_key))

            for other_priv_key in priv_keys:
                if other_priv_key != priv_keys[i]:
                    # making sure other private keys don't work if they are not
                    # equal
                    other_ciphtext, other_sig = _asymmetric_encrypt_sign(
                        original_plaintext, pub_key, other_priv_key)
                    self.assertNotEqual(other_ciphtext, ciphertext)
                    self.assertNotEqual(other_sig, signature)
                    for other_pub_key in pub_keys:
                        if other_pub_key != pub_key:
                            self.assertTrue(asymmetric_verify(
                                other_sig, original_plaintext, other_pub_key))
                            self.assertFalse(asymmetric_verify(
                                other_sig, original_plaintext, pub_key))
                            self.assertFalse(asymmetric_verify(
                                signature, original_plaintext, other_pub_key))
Beispiel #2
0
    def test_asymmetric_sign(self):
        """Tests asymmetric signatures"""
        plaintext = "I do things like get in a taxi and say, 'The\
                     library, and step on it.'"

        signature = asymmetric_sign(plaintext, self._server_priv_key1)
        self.assertTrue(
            asymmetric_verify(signature, plaintext, self._server_pub_key1))
Beispiel #3
0
 def test_asymmetric_sign(self):
     """Tests asymmetric signatures"""
     plaintext = "I do things like get in a taxi and say, 'The\
                  library, and step on it.'"
     signature = asymmetric_sign(plaintext, self._server_priv_key1)
     self.assertTrue(asymmetric_verify(signature,
                                       plaintext,
                                       self._server_pub_key1))
Beispiel #4
0
    def test_asymmetric_verify(self):
        """Tests asymmetric signature verification"""
        pub_keys = [self._server_pub_key1, self._client_pub_key2]
        priv_keys = [self._server_priv_key1, self._client_priv_key2]
        original_plaintext = b'''I do things like get in a taxi and say, \'The
                             library, and step on it.\''''

        # The enumeration assumes both key lists are of same size and the index
        # of one list holds a key that corresponds to the same index of the
        # other list.
        for i, pub_key in enumerate(pub_keys):
            ciphertext, original_signature = _asymmetric_encrypt_sign(
                original_plaintext, pub_key, priv_keys[i])
            msg = unpack(asymmetric_decrypt(ciphertext, priv_keys[i]))
            plaintext, signature = msg['msg'], msg['signature']
            self.assertEqual(original_plaintext, plaintext)
            self.assertEqual(original_signature, signature)
            self.assertTrue(asymmetric_verify(signature, plaintext, pub_key))

            for other_priv_key in priv_keys:
                if other_priv_key != priv_keys[i]:
                    # making sure other private keys don't work if they are not
                    # equal
                    other_ciphtext, other_sig = _asymmetric_encrypt_sign(
                        original_plaintext, pub_key, other_priv_key)
                    self.assertNotEqual(other_ciphtext, ciphertext)
                    self.assertNotEqual(other_sig, signature)
                    for other_pub_key in pub_keys:
                        if other_pub_key != pub_key:
                            self.assertTrue(
                                asymmetric_verify(other_sig,
                                                  original_plaintext,
                                                  other_pub_key))
                            self.assertFalse(
                                asymmetric_verify(other_sig,
                                                  original_plaintext, pub_key))
                            self.assertFalse(
                                asymmetric_verify(signature,
                                                  original_plaintext,
                                                  other_pub_key))