Example #1
0
	def test_bad_ctx(self):
		s = signature.sign(SHORT, KEY_1[0])
		new_ctx = signature.evp.EVP_MD_CTX_create
		signature.evp.EVP_MD_CTX_create = lambda: None
		self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0])
		self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1])
		signature.evp.EVP_MD_CTX_create = new_ctx
Example #2
0
	def test_bad_digest_init(self):
		s = signature.sign(SHORT, KEY_1[0])
		init = signature.evp.EVP_DigestInit
		signature.evp.EVP_DigestInit = lambda a,b: None
		self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0])
		self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1])
		signature.evp.EVP_DigestInit = init
Example #3
0
	def test_bad_hash(self):
		s = signature.sign(SHORT, KEY_1[0])
		new_hash = signature.evp.EVP_get_digestbyname
		signature.evp.EVP_get_digestbyname = lambda a: None
		self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0])
		self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1])
		signature.evp.EVP_get_digestbyname = new_hash
Example #4
0
 def test_bad_verify_final(self):
     s = signature.sign(SHORT, KEY_1[0])
     final = signature.evp.EVP_VerifyFinal
     signature.evp.EVP_VerifyFinal = lambda a, b, c, d: None
     self.assertRaises(signature.SignatureError, signature.verify, SHORT, s,
                       KEY_1[1])
     signature.evp.EVP_VerifyFinal = final
Example #5
0
 def test_bad_read_publickey(self):
     s = signature.sign(SHORT, KEY_1[0])
     read_public_key = signature.evp.PEM_read_PUBKEY
     signature.evp.PEM_read_PUBKEY = lambda a, b, c, d: None
     self.assertRaises(signature.SignatureError, signature.verify, SHORT, s,
                       KEY_1[1])
     signature.evp.PEM_read_PUBKEY = read_public_key
Example #6
0
	def test_bad_digest_update(self):
		s = signature.sign(SHORT, KEY_1[0])
		update = signature.evp.EVP_DigestUpdate
		signature.evp.EVP_DigestUpdate = lambda a,b,c: None
		self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[0])
		self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1])
		signature.evp.EVP_DigestUpdate = update
Example #7
0
	def test_bad_fopen(self):
		s = signature.sign(SHORT, KEY_1[0])
		file_open = signature.evp.fopen
		signature.evp.fopen = lambda a,b: None
		self.assertRaises(signature.SignatureError, signature.sign, SHORT, KEY_1[1])
		self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[0])
		signature.evp.fopen = file_open
Example #8
0
	def test_arguments(self):
		text = SHORT
		keys = KEY_1
		self.failUnlessRaises(signature.SignatureError, signature.sign, text, key=open(keys[0], 'rb').read(), keyfile=keys[0])
		self.failUnlessRaises(signature.SignatureError, signature.sign, text)
		s = signature.sign(text, keyfile=keys[0])
		self.failUnlessRaises(signature.SignatureError, signature.verify, text, s, key=open(keys[1], 'rb').read(), keyfile=keys[1])
		self.failUnlessRaises(signature.SignatureError, signature.verify, text, s)
Example #9
0
 def test_bad_digest_update(self):
     s = signature.sign(SHORT, KEY_1[0])
     update = signature.evp.EVP_DigestUpdate
     signature.evp.EVP_DigestUpdate = lambda a, b, c: None
     self.assertRaises(signature.SignatureError, signature.sign, SHORT,
                       KEY_1[0])
     self.assertRaises(signature.SignatureError, signature.verify, SHORT, s,
                       KEY_1[1])
     signature.evp.EVP_DigestUpdate = update
Example #10
0
 def test_bad_digest_init(self):
     s = signature.sign(SHORT, KEY_1[0])
     init = signature.evp.EVP_DigestInit
     signature.evp.EVP_DigestInit = lambda a, b: None
     self.assertRaises(signature.SignatureError, signature.sign, SHORT,
                       KEY_1[0])
     self.assertRaises(signature.SignatureError, signature.verify, SHORT, s,
                       KEY_1[1])
     signature.evp.EVP_DigestInit = init
Example #11
0
 def test_bad_hash(self):
     s = signature.sign(SHORT, KEY_1[0])
     new_hash = signature.evp.EVP_get_digestbyname
     signature.evp.EVP_get_digestbyname = lambda a: None
     self.assertRaises(signature.SignatureError, signature.sign, SHORT,
                       KEY_1[0])
     self.assertRaises(signature.SignatureError, signature.verify, SHORT, s,
                       KEY_1[1])
     signature.evp.EVP_get_digestbyname = new_hash
Example #12
0
 def test_bad_ctx(self):
     s = signature.sign(SHORT, KEY_1[0])
     new_ctx = signature.evp.EVP_MD_CTX_create
     signature.evp.EVP_MD_CTX_create = lambda: None
     self.assertRaises(signature.SignatureError, signature.sign, SHORT,
                       KEY_1[0])
     self.assertRaises(signature.SignatureError, signature.verify, SHORT, s,
                       KEY_1[1])
     signature.evp.EVP_MD_CTX_create = new_ctx
Example #13
0
 def test_bad_fopen(self):
     s = signature.sign(SHORT, KEY_1[0])
     file_open = signature.evp.fopen
     signature.evp.fopen = lambda a, b: None
     self.assertRaises(signature.SignatureError, signature.sign, SHORT,
                       KEY_1[1])
     self.assertRaises(signature.SignatureError, signature.verify, SHORT, s,
                       KEY_1[0])
     signature.evp.fopen = file_open
Example #14
0
 def test_arguments(self):
     text = SHORT
     keys = KEY_1
     self.failUnlessRaises(signature.SignatureError,
                           signature.sign,
                           text,
                           key=open(keys[0], 'rb').read(),
                           keyfile=keys[0])
     self.failUnlessRaises(signature.SignatureError, signature.sign, text)
     s = signature.sign(text, keyfile=keys[0])
     self.failUnlessRaises(signature.SignatureError,
                           signature.verify,
                           text,
                           s,
                           key=open(keys[1], 'rb').read(),
                           keyfile=keys[1])
     self.failUnlessRaises(signature.SignatureError, signature.verify, text,
                           s)
Example #15
0
	def test_bad_verify_final(self):
		s = signature.sign(SHORT, KEY_1[0])
		final = signature.evp.EVP_VerifyFinal
		signature.evp.EVP_VerifyFinal = lambda a,b,c,d: None
		self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, KEY_1[1])
		signature.evp.EVP_VerifyFinal = final
Example #16
0
 def round_trip_strings(self, keys, text):
     s = signature.sign(text, key=open(keys[0], 'rb').read())
     v = signature.verify(text, s, key=open(keys[1], 'rb').read())
     return v
Example #17
0
	def test_bad_read_bio_publickey(self):
		s = signature.sign(SHORT, KEY_1[0])
		read_public_key = signature.evp.PEM_read_bio_PUBKEY
		signature.evp.PEM_read_bio_PUBKEY = lambda a,b,c,d: None
		self.assertRaises(signature.SignatureError, signature.verify, SHORT, s, key=open(KEY_1[1], 'rb').read())
		signature.evp.PEM_read_bio_PUBKEY = read_public_key
Example #18
0
	def round_trip_strings(self, keys, text):
		s = signature.sign(text, key=open(keys[0], 'rb').read())
		v = signature.verify(text, s, key=open(keys[1], 'rb').read())
		return v
Example #19
0
	def round_trip(self, keys, text):
		s = signature.sign(text, keys[0])
		return signature.verify(text, s, keys[1])
Example #20
0
 def round_trip(self, keys, text):
     s = signature.sign(text, keys[0])
     return signature.verify(text, s, keys[1])