Exemplo n.º 1
0
    def test_apppend_zeroes(self):
        """Apppending the signature with zeroes should be detected."""

        message = b'je moeder'
        signature = pkcs1.sign(message, self.priv, 'SHA-256')
        signature = signature + bytes.fromhex('0000')
        with self.assertRaises(rsa.VerificationError):
            pkcs1.verify(message, signature, self.pub)
Exemplo n.º 2
0
    def test_prepend_zeroes(self):
        """Prepending the signature with zeroes should be detected."""

        message = b'je moeder'
        signature = pkcs1.sign(message, self.priv, 'SHA-256')
        signature = b'\00\00' + signature
        with self.assertRaises(rsa.VerificationError):
            pkcs1.verify(message, signature, self.pub)
Exemplo n.º 3
0
    def test_prepend_zeroes(self):
        """Prepending the signature with zeroes should be detected."""

        message = b"je moeder"
        signature = pkcs1.sign(message, self.priv, "SHA-256")
        signature = bytes.fromhex("0000") + signature
        with self.assertRaises(rsa.VerificationError):
            pkcs1.verify(message, signature, self.pub)
Exemplo n.º 4
0
    def test_sign_verify(self):
        """Test happy flow of sign and verify"""

        message = b'je moeder'
        signature = pkcs1.sign(message, self.priv, 'SHA-256')
        self.assertEqual('SHA-256', pkcs1.verify(message, signature, self.pub))

        signature = pkcs1.sign(message, self.priv, 'SHA3-256')
        self.assertEqual('SHA3-256', pkcs1.verify(message, signature, self.pub))
Exemplo n.º 5
0
    def test_sign_verify(self):
        '''Test happy flow of sign and verify'''
        
        message = b('je moeder')
        print("\tMessage:   %r" % message)

        signature = pkcs1.sign(message, self.priv, 'SHA-256')
        print("\tSignature: %r" % signature)

        pkcs1.verify(message, signature, self.pub)
Exemplo n.º 6
0
    def test_sign_verify_sha3(self):
        """Test happy flow of sign and verify with SHA3-256"""

        message = b"je moeder"
        signature = pkcs1.sign(message, self.priv, "SHA3-256")
        self.assertEqual("SHA3-256", pkcs1.verify(message, signature,
                                                  self.pub))
Exemplo n.º 7
0
    def test_hash_sign_verify(self):
        """Test happy flow of hash, sign, and verify"""

        message = b'je moeder'
        msg_hash = pkcs1.compute_hash(message, 'SHA-256')
        signature = pkcs1.sign_hash(msg_hash, self.priv, 'SHA-256')

        self.assertTrue(pkcs1.verify(message, signature, self.pub))
Exemplo n.º 8
0
    def test_sign_verify_bigfile(self):

        # Large enough to store MD5-sum and ASN.1 code for MD5
        pub_key, priv_key = rsa.newkeys((34 + 11) * 8)

        # Sign the file
        msgfile = BytesIO(b('123456Sybren'))
        signature = pkcs1.sign(msgfile, priv_key, 'MD5')

        # Check the signature
        msgfile.seek(0)
        pkcs1.verify(msgfile, signature, pub_key)

        # Alter the message, re-check
        msgfile = BytesIO(b('123456sybren'))
        self.assertRaises(pkcs1.VerificationError,
            pkcs1.verify, msgfile, signature, pub_key)
Exemplo n.º 9
0
    def test_sign_verify_bigfile(self):

        # Large enough to store MD5-sum and ASN.1 code for MD5
        pub_key, priv_key = rsa.newkeys((34 + 11) * 8)

        # Sign the file
        msgfile = BytesIO(b('123456Sybren'))
        signature = pkcs1.sign(msgfile, priv_key, 'MD5')

        # Check the signature
        msgfile.seek(0)
        pkcs1.verify(msgfile, signature, pub_key)

        # Alter the message, re-check
        msgfile = BytesIO(b('123456sybren'))
        self.assertRaises(pkcs1.VerificationError, pkcs1.verify, msgfile,
                          signature, pub_key)
Exemplo n.º 10
0
def verify_sig(message, signature, pub_key):
    #wraps the RSA function
    try:
        result = verify(message, signature, pub_key)
        if result == 'SHA-256':
            result = True
    except:
        result = False
    return result
Exemplo n.º 11
0
    def test_sign_verify(self):
        """Test happy flow of sign and verify"""

        message = b('je moeder')
        print("\tMessage:   %r" % message)

        signature = pkcs1.sign(message, self.priv, 'SHA-256')
        print("\tSignature: %r" % signature)

        self.assertTrue(pkcs1.verify(message, signature, self.pub))
Exemplo n.º 12
0
    def test_sign_verify(self):
        """Test happy flow of sign and verify"""

        message = b('je moeder')
        print("\tMessage:   %r" % message)

        signature = pkcs1.sign(message, self.priv, 'SHA-256')
        print("\tSignature: %r" % signature)

        self.assertTrue(pkcs1.verify(message, signature, self.pub))