示例#1
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_ctx_new(self):
		iv, aes_key, enc = envelope.encrypt(SHORT, KEY_1[1])
		new_ctx = envelope.evp.EVP_CIPHER_CTX_new
		envelope.evp.EVP_CIPHER_CTX_new = lambda: None
		self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT, KEY_1[1])
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, aes_key, enc, KEY_1[0])
		envelope.evp.EVP_CIPHER_CTX_new = new_ctx
示例#2
0
 def test_bad_open_init(self):
     iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
     decrypt_init = envelope.evp.EVP_OpenInit
     envelope.evp.EVP_OpenInit = lambda a, b, c, d, e, f: None
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key,
                       enc, KEY_1[0])
     envelope.evp.EVP_OpenInit = decrypt_init
示例#3
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_fopen(self):
		iv, aes_key, enc = envelope.encrypt(SHORT, KEY_1[1])
		file_open = envelope.evp.fopen
		envelope.evp.fopen = lambda a,b: None
		self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT, KEY_1[1])
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, aes_key, enc, KEY_1[0])
		envelope.evp.fopen = file_open
示例#4
0
 def round_trip_strings(self, keys, text):
     iv, sym_key, enc = envelope.encrypt(text,
                                         key=open(keys[1], 'rb').read())
     return envelope.decrypt(iv,
                             sym_key,
                             enc,
                             key=open(keys[0], 'rb').read())
示例#5
0
 def test_bad_decrypt_update(self):
     iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
     decrypt_update = envelope.evp.EVP_DecryptUpdate
     envelope.evp.EVP_DecryptUpdate = lambda a, b, c, d, e: None
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key,
                       enc, KEY_1[0])
     envelope.evp.EVP_DecryptUpdate = decrypt_update
示例#6
0
 def test_bad_read_privatekey(self):
     iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
     read_private_key = envelope.evp.PEM_read_PrivateKey
     envelope.evp.PEM_read_PrivateKey = lambda a, b, c, d: None
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key,
                       enc, KEY_1[0])
     envelope.evp.PEM_read_PrivateKey = read_private_key
示例#7
0
 def test_bad_call(self):
     # neither key nor keyfile
     self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT)
     # both
     self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT,
                       KEY_1[0],
                       open(KEY_1[0], 'rb').read())
     # string key instead of bytes
     self.assertRaises(envelope.EnvelopeError,
                       envelope.encrypt,
                       SHORT,
                       key=open(KEY_1[0], 'r').read())
     # string data instead of bytes
     self.assertRaises(envelope.EnvelopeError, envelope.encrypt, str(SHORT),
                       KEY_1[0],
                       open(KEY_1[0], 'rb').read())
     # get valid encryption data
     iv, aes_key, enc = envelope.encrypt(SHORT, KEY_1[1])
     # neither key nor keyfile
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv,
                       aes_key, enc)
     # both
     self.assertRaises(envelope.EnvelopeError,
                       envelope.decrypt,
                       iv,
                       aes_key,
                       enc,
                       KEY_1[1],
                       key=open(KEY_1[1], 'rb').read())
     # string key instead of bytes
     self.assertRaises(envelope.EnvelopeError,
                       envelope.decrypt,
                       iv,
                       aes_key,
                       enc,
                       key=open(KEY_1[1], 'r').read())
     # string data instead of bytes
     self.assertRaises(envelope.EnvelopeError,
                       envelope.decrypt,
                       iv,
                       aes_key,
                       str(enc),
                       KEY_1[1],
                       key=open(KEY_1[1], 'rb').read())
     # string iv instead of bytes
     self.assertRaises(envelope.EnvelopeError,
                       envelope.decrypt,
                       str(iv),
                       aes_key,
                       enc,
                       KEY_1[1],
                       key=open(KEY_1[1], 'rb').read())
     # string key instead of bytes
     self.assertRaises(envelope.EnvelopeError,
                       envelope.decrypt,
                       iv,
                       str(aes_key),
                       enc,
                       KEY_1[1],
                       key=open(KEY_1[1], 'rb').read())
示例#8
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_cipher_object(self):
		iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
		cipher_getter = envelope.evp.EVP_aes_192_cbc
		envelope.evp.EVP_aes_192_cbc= lambda: None
		self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT, KEY_1[1])
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key, enc, KEY_1[0])
		envelope.evp.EVP_aes_192_cbc = cipher_getter
示例#9
0
 def test_bad_decrypt_final(self):
     iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
     decrypt_final = envelope.evp.EVP_DecryptFinal_ex
     envelope.evp.EVP_DecryptFinal_ex = lambda a, b, c: None
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key,
                       enc, KEY_1[0])
     cipher.evp.EVP_DecryptFinal_ex = decrypt_final
示例#10
0
 def test_bad_cipher_object(self):
     iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
     cipher_getter = envelope.evp.EVP_aes_192_cbc
     envelope.evp.EVP_aes_192_cbc = lambda: None
     self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT,
                       KEY_1[1])
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key,
                       enc, KEY_1[0])
     envelope.evp.EVP_aes_192_cbc = cipher_getter
示例#11
0
 def test_bad_ctx_new(self):
     iv, aes_key, enc = envelope.encrypt(SHORT, KEY_1[1])
     new_ctx = envelope.evp.EVP_CIPHER_CTX_new
     envelope.evp.EVP_CIPHER_CTX_new = lambda: None
     self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT,
                       KEY_1[1])
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv,
                       aes_key, enc, KEY_1[0])
     envelope.evp.EVP_CIPHER_CTX_new = new_ctx
示例#12
0
 def test_bad_fopen(self):
     iv, aes_key, enc = envelope.encrypt(SHORT, KEY_1[1])
     file_open = envelope.evp.fopen
     envelope.evp.fopen = lambda a, b: None
     self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT,
                       KEY_1[1])
     self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv,
                       aes_key, enc, KEY_1[0])
     envelope.evp.fopen = file_open
示例#13
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_call(self):
		# neither key nor keyfile
		self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT)
		# both
		self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT, KEY_1[0], open(KEY_1[0], 'rb').read())
		# string key instead of bytes
		self.assertRaises(envelope.EnvelopeError, envelope.encrypt, SHORT, key=open(KEY_1[0], 'r').read())
		# string data instead of bytes
		self.assertRaises(envelope.EnvelopeError, envelope.encrypt, str(SHORT), KEY_1[0], open(KEY_1[0], 'rb').read())
		# get valid encryption data		
		iv, aes_key, enc = envelope.encrypt(SHORT, KEY_1[1])
		# neither key nor keyfile
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, aes_key, enc)
		# both
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, aes_key, enc, KEY_1[1], key=open(KEY_1[1], 'rb').read())
		# string key instead of bytes
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, aes_key, enc, key=open(KEY_1[1], 'r').read())
		# string data instead of bytes
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, aes_key, str(enc), KEY_1[1], key=open(KEY_1[1], 'rb').read())
		# string iv instead of bytes
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, str(iv), aes_key, enc, KEY_1[1], key=open(KEY_1[1], 'rb').read())
		# string key instead of bytes
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, str(aes_key), enc, KEY_1[1], key=open(KEY_1[1], 'rb').read())
示例#14
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_read_bio_privatekey(self):
		iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
		read_private_key = envelope.evp.PEM_read_bio_PrivateKey
		envelope.evp.PEM_read_bio_PrivateKey = lambda a,b,c,d: None
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key, enc, key=open(KEY_1[0], 'rb').read())
		envelope.evp.PEM_read_bio_PrivateKey = read_private_key
示例#15
0
文件: test.py 项目: monzum/tuf-legacy
	def round_trip_strings(self, keys, text):
		iv, sym_key, enc = envelope.encrypt(text, key=open(keys[1], 'rb').read())
		return envelope.decrypt(iv, sym_key, enc, key=open(keys[0], 'rb').read())
示例#16
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_decrypt_update(self):
		iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
		decrypt_update = envelope.evp.EVP_DecryptUpdate
		envelope.evp.EVP_DecryptUpdate = lambda a,b,c,d,e: None
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key, enc, KEY_1[0])
		envelope.evp.EVP_DecryptUpdate = decrypt_update
示例#17
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_open_init(self):
		iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
		decrypt_init = envelope.evp.EVP_OpenInit
		envelope.evp.EVP_OpenInit = lambda a,b,c,d,e,f: None
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key, enc, KEY_1[0])
		envelope.evp.EVP_OpenInit = decrypt_init
示例#18
0
文件: test.py 项目: monzum/tuf-legacy
	def round_trip(self, keys, text):
		iv, sym_key, enc = envelope.encrypt(text, keys[1])
		return envelope.decrypt(iv, sym_key, enc, keys[0])
示例#19
0
文件: test.py 项目: monzum/tuf-legacy
	def test_bad_decrypt_final(self):
		iv, key, enc = envelope.encrypt(SHORT, KEY_1[1])
		decrypt_final = envelope.evp.EVP_DecryptFinal_ex
		envelope.evp.EVP_DecryptFinal_ex = lambda a,b,c: None
		self.assertRaises(envelope.EnvelopeError, envelope.decrypt, iv, key, enc, KEY_1[0])
		cipher.evp.EVP_DecryptFinal_ex = decrypt_final
示例#20
0
 def round_trip(self, keys, text):
     iv, sym_key, enc = envelope.encrypt(text, keys[1])
     return envelope.decrypt(iv, sym_key, enc, keys[0])