コード例 #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)
コード例 #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
コード例 #3
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #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
コード例 #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
コード例 #6
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #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
コード例 #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
コード例 #9
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #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
コード例 #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
コード例 #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
コード例 #13
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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)
コード例 #14
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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, '')
コード例 #15
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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)
コード例 #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)
コード例 #17
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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")
コード例 #18
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #19
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #20
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #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")
コード例 #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,
                       '')
コード例 #23
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #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)
コード例 #25
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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
コード例 #26
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	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)
コード例 #27
0
ファイル: test.py プロジェクト: monzum/tuf-legacy
	def test_no_data(self):
		iv, salt, enc = cipher.encrypt(UNICODE, SHORT_SYMMETRIC)
		self.assertRaises(cipher.CipherError, cipher.decrypt, iv, salt, '', SHORT_SYMMETRIC)
コード例 #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)