Example #1
0
 def test_round_trip_failure(self):
     salt, iv, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, salt, iv, enc,
                       LONG_SYMMETRIC)
     salt, iv, enc = cipher.encrypt(NULL, SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, salt, iv, enc,
                       LONG_SYMMETRIC)
Example #2
0
 def test_bad_decrypt_final(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     decrypt_final = cipher.evp.EVP_DecryptFinal_ex
     cipher.evp.EVP_DecryptFinal_ex = lambda a, b, c: None
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc,
                       SHORT_SYMMETRIC)
     cipher.evp.EVP_DecryptFinal_ex = decrypt_final
Example #3
0
	def test_bad_ctx_new(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		new_ctx = cipher.evp.EVP_CIPHER_CTX_new
		cipher.evp.EVP_CIPHER_CTX_new = lambda: None
		self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc, SHORT_SYMMETRIC)
		cipher.evp.EVP_CIPHER_CTX_new = new_ctx
Example #4
0
 def test_bad_rand_bytes_1(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     rand_bytes = cipher.evp.RAND_bytes
     cipher.evp.RAND_bytes = lambda a, b: 0
     self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT,
                       SHORT_SYMMETRIC)
     cipher.evp.RAND_bytes = rand_bytes
Example #5
0
 def test_bad_decrypt_update(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     decrypt_update = cipher.evp.EVP_DecryptUpdate
     cipher.evp.EVP_DecryptUpdate = lambda a, b, c, d, e: None
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc,
                       SHORT_SYMMETRIC)
     cipher.evp.EVP_DecryptUpdate = decrypt_update
Example #6
0
	def test_bad_bytes_to_key(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		bytes_to_key = cipher.evp.EVP_BytesToKey
		cipher.evp.EVP_BytesToKey = lambda a,b,c,d,e,f,g,h: 0
		self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc, SHORT_SYMMETRIC)
		cipher.evp.EVP_BytesToKey = bytes_to_key
Example #7
0
 def test_bad_hash_by_name(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     hash_by_name = cipher.evp.EVP_get_digestbyname
     cipher.evp.EVP_get_digestbyname = lambda a: None
     self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT,
                       SHORT_SYMMETRIC)
     cipher.evp.EVP_get_digestbyname = hash_by_name
Example #8
0
 def test_bad_decrypt_init(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     decrypt_init = cipher.evp.EVP_DecryptInit_ex
     cipher.evp.EVP_DecryptInit_ex = lambda a, b, c, d, e: None
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc,
                       SHORT_SYMMETRIC)
     cipher.evp.EVP_DecryptInit_ex = decrypt_init
Example #9
0
	def test_bad_cipher_object(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		cipher_getter = cipher.evp.EVP_aes_192_cbc
		cipher.evp.EVP_aes_192_cbc= lambda: None
		self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc, SHORT_SYMMETRIC)
		cipher.evp.EVP_aes_192_cbc = cipher_getter
Example #10
0
 def test_bad_cipher_object(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     cipher_getter = cipher.evp.EVP_aes_192_cbc
     cipher.evp.EVP_aes_192_cbc = lambda: None
     self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT,
                       SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc,
                       SHORT_SYMMETRIC)
     cipher.evp.EVP_aes_192_cbc = cipher_getter
Example #11
0
 def test_bad_ctx_new(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     new_ctx = cipher.evp.EVP_CIPHER_CTX_new
     cipher.evp.EVP_CIPHER_CTX_new = lambda: None
     self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT,
                       SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc,
                       SHORT_SYMMETRIC)
     cipher.evp.EVP_CIPHER_CTX_new = new_ctx
Example #12
0
 def test_bad_bytes_to_key(self):
     iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
     bytes_to_key = cipher.evp.EVP_BytesToKey
     cipher.evp.EVP_BytesToKey = lambda a, b, c, d, e, f, g, h: 0
     self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT,
                       SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc,
                       SHORT_SYMMETRIC)
     cipher.evp.EVP_BytesToKey = bytes_to_key
Example #13
0
	def test_round_trip_failure(self):
		salt, iv, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, salt, iv, enc, LONG_SYMMETRIC)
		salt, iv, enc = cipher.encrypt(NULL, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, salt, iv, enc, LONG_SYMMETRIC)
Example #14
0
	def test_round_trip_no_password(self):
		iv, salt, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.encrypt, UNICODE, '')
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc, '')
Example #15
0
	def test_long_iv(self):
		salt, iv, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, salt, iv+iv[:-1], enc, SHORT_SYMMETRIC)
Example #16
0
 def test_long_iv(self):
     salt, iv, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, salt,
                       iv + iv[:-1], enc, SHORT_SYMMETRIC)
Example #17
0
	def round_trip(self, key, text):
		salt, iv, enc = cipher.encrypt(text, key)
		output = cipher.decrypt(salt, iv, enc, key)
		self.assertEqual(output, text, "Failed to round trip")
Example #18
0
	def test_bad_rand_bytes_2(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		rand_bytes = cipher.evp.RAND_bytes
		cipher.evp.RAND_bytes = run_n_times(cipher.evp.RAND_bytes, lambda a,b:0, 1)
		self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT, SHORT_SYMMETRIC)
		cipher.evp.RAND_bytes = rand_bytes
Example #19
0
	def test_bad_hash_by_name(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		hash_by_name = cipher.evp.EVP_get_digestbyname
		cipher.evp.EVP_get_digestbyname = lambda a: None
		self.assertRaises(cipher.CipherError, cipher.encrypt, SHORT, SHORT_SYMMETRIC)
		cipher.evp.EVP_get_digestbyname = hash_by_name
Example #20
0
	def test_bad_decrypt_update(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		decrypt_update = cipher.evp.EVP_DecryptUpdate
		cipher.evp.EVP_DecryptUpdate = lambda a,b,c,d,e: None
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc, SHORT_SYMMETRIC)
		cipher.evp.EVP_DecryptUpdate = decrypt_update
Example #21
0
 def round_trip(self, key, text):
     salt, iv, enc = cipher.encrypt(text, key)
     output = cipher.decrypt(salt, iv, enc, key)
     self.assertEqual(output, text, "Failed to round trip")
Example #22
0
 def test_round_trip_no_password(self):
     iv, salt, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.encrypt, UNICODE, '')
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc,
                       '')
Example #23
0
	def test_bad_decrypt_init(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		decrypt_init = cipher.evp.EVP_DecryptInit_ex
		cipher.evp.EVP_DecryptInit_ex = lambda a,b,c,d,e: None
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc, SHORT_SYMMETRIC)
		cipher.evp.EVP_DecryptInit_ex = decrypt_init
Example #24
0
 def test_no_data(self):
     iv, salt, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, '',
                       SHORT_SYMMETRIC)
Example #25
0
	def test_bad_decrypt_final(self):
		iv, salt, enc = cipher.encrypt(SHORT, SHORT_SYMMETRIC)
		decrypt_final = cipher.evp.EVP_DecryptFinal_ex
		cipher.evp.EVP_DecryptFinal_ex = lambda a,b,c: None
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, enc, SHORT_SYMMETRIC)
		cipher.evp.EVP_DecryptFinal_ex = decrypt_final
Example #26
0
	def test_short_salt(self):
		salt, iv, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, salt[:-1], iv, enc, SHORT_SYMMETRIC)
Example #27
0
	def test_no_data(self):
		iv, salt, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, '', SHORT_SYMMETRIC)
Example #28
0
 def test_short_salt(self):
     salt, iv, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
     self.assertRaises(cipher.CipherError, cipher.decrypt, salt[:-1], iv,
                       enc, SHORT_SYMMETRIC)