Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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, '')
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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")
Exemplo n.º 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,
                       '')
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)