m2crypto open file in rb mode for pub key

This commit is contained in:
Ch3LL 2018-06-29 14:43:06 -04:00
parent a964db4663
commit 8fdd34d430
No known key found for this signature in database
GPG key ID: 132B55A7C13EFA73
2 changed files with 5 additions and 5 deletions

View file

@ -206,8 +206,8 @@ def get_rsa_pub_key(path):
'''
log.debug('salt.crypt.get_rsa_pub_key: Loading public key')
if HAS_M2:
with salt.utils.files.fopen(path) as f:
data = salt.utils.stringutils.to_bytes(f.read()).replace(b'RSA ', b'')
with salt.utils.files.fopen(path, 'rb') as f:
data = f.read().replace(b'RSA ', b'')
bio = BIO.MemoryBuffer(data)
key = RSA.load_pub_key_bio(bio)
else:

View file

@ -215,7 +215,7 @@ class M2CryptTestCase(TestCase):
self.assertEqual(SIG, crypt.sign_message('/keydir/keyname.pem', MSG, passphrase='password'))
def test_verify_signature(self):
with patch('salt.utils.files.fopen', mock_open(read_data=PUBKEY_DATA)):
with patch('salt.utils.files.fopen', mock_open(read_data=six.b(PUBKEY_DATA))):
self.assertTrue(crypt.verify_signature('/keydir/keyname.pub', MSG, SIG))
def test_encrypt_decrypt_bin(self):
@ -289,13 +289,13 @@ class TestM2CryptoRegression47124(TestCase):
@skipIf(not HAS_M2, "Skip when m2crypto is not installed")
def test_m2crypto_verify_bytes(self):
message = salt.utils.stringutils.to_unicode('meh')
with patch('salt.utils.files.fopen', mock_open(read_data=PUBKEY_DATA)):
with patch('salt.utils.files.fopen', mock_open(read_data=six.b(PUBKEY_DATA))):
salt.crypt.verify_signature('/keydir/keyname.pub', message, self.SIGNATURE)
@skipIf(not HAS_M2, "Skip when m2crypto is not installed")
def test_m2crypto_verify_unicode(self):
message = salt.utils.stringutils.to_bytes('meh')
with patch('salt.utils.files.fopen', mock_open(read_data=PUBKEY_DATA)):
with patch('salt.utils.files.fopen', mock_open(read_data=six.b(PUBKEY_DATA))):
salt.crypt.verify_signature('/keydir/keyname.pub', message, self.SIGNATURE)
@skipIf(not HAS_M2, "Skip when m2crypto is not installed")