Beispiel #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)
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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)
Beispiel #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, '')
Beispiel #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)
Beispiel #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)
Beispiel #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")
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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")
Beispiel #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,
                       '')
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #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)
Beispiel #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)
Beispiel #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)