class StringTests(unittest.TestCase): ghost_emoji = portable_b64decode('8J+Ruwo=') some_binary = portable_b64decode('uRo/OptvvkT790yaPjql5OItfFUBSM2tM42QJkPM7qvMTn4tQClPjB6mpdSFDtyzuqGVrMGaHRKv7XuzlZPpWGbVzlCjIvN0nOUiBXSQsockEJwCwIaiwm/xxWSE9+P2zWdqt1J/Iuwv6Rq60qpMRTqWNJD5dDzbw4VdDQhxzgK4zN2Er+JQQqQctsj1XuM8xJtzBQsozt5ZCJso4/jsUsWrFgHPp5nu4whuT7ZSgthsGz+NXo1f6v4njJ705ZMjLW0zdnkx/14E8qGJCsDs8pCkekDn+K4gTLfzZHga/du8xtN6e/X97K2BbdVC8Obz684wnqdHLWc+bNNso+5XFtQbFbK6vBtGtZNmBeiVBo594Zr5xRxFPSfOHIKz0jB4U5He7xgh2C7AFh2SCy4fW1fwC5XxQoz1pRSiFTRbUr/dMHMn0ZaspVYUNPdZccM4xj8ip5k4fXVRTKFF1qEiFGohcfLdabCBXAkckOmGogdN0swOpoiNEohYksW0bkof89q1aRJl6tM9E2spH62XZXDmQFHIdxFFHP6zAl2t7zGB2vxDCpLgQg3l8RytryMfDR7MXXXy2kbhtFpIl45gFl/8u+aOc7fP4dLxacCbJNz3cO3iMXIPytwiaq5HJbgQ6ZgeGjZBniTCRLwRpOv3l3GRsLstdRJSk2KP+kwY9Tk=') def test_is_unicode(self): assert aomi.validation.is_unicode_string("foo") == None assert aomi.validation.is_unicode_string("70758F21-946C-4C14-AD67-53DDCA5C9F4B") == None assert aomi.validation.is_unicode_string(self.ghost_emoji) == None with self.assertRaises(aomi.exceptions.Validation): aomi.validation.is_unicode_string(self.some_binary)
def do_decrypt(filename): """GPG decrypt things in files""" if not os.path.exists(filename): return None handle = open(filename, 'r') datas = handle.read().strip() handle.close() datas_bin = portable_b64decode(datas) return decrypt_var(datas_bin)
def raw_file(client, src, dest, opt): """Write the contents of a vault path/key to a file. Is smart enough to attempt and handle binary files that are base64 encoded.""" path, key = path_pieces(src) resp = client.read(path) if not resp: client.revoke_self_token() raise aomi.exceptions.VaultData("Unable to retrieve %s" % path) else: if 'data' in resp and key in resp['data']: secret = resp['data'][key] if is_base64(secret): LOG.debug('decoding base64 entry') secret = portable_b64decode(secret) if is_aws(resp['data']): renew_secret(client, resp, opt) write_raw_file(secret, dest) else: client.revoke_self_token() e_msg = "Key %s not found in %s" % (key, path) raise aomi.exceptions.VaultData(e_msg)
def raw_file(client, src, dest, opt): """Write the contents of a vault path/key to a file. Is smart enough to attempt and handle binary files that are base64 encoded.""" path, key = path_pieces(src) resp = client.read(path) if not resp: client.revoke_self_token() raise aomi.exceptions.VaultData("Unable to retrieve %s" % path) else: if 'data' in resp and key in resp['data']: secret = resp['data'][key] if is_base64(secret): LOG.debug('decoding base64 entry') secret = portable_b64decode(secret) if is_aws(resp['data']) and 'sts' not in path: renew_secret(client, resp, opt) write_raw_file(secret, dest) else: client.revoke_self_token() e_msg = "Key %s not found in %s" % (key, path) raise aomi.exceptions.VaultData(e_msg)
def decrypt_var(passphrase=None): """Decrypt what comes in from stdin (base64'd) and write it out to stdout""" encrypted = cryptorito.portable_b64decode(sys.stdin.read()) print(cryptorito.decrypt_var(encrypted, passphrase))
def f_b64decode(a_string): """Wrapper that ensures only strings are returned into templates""" return polite_string(portable_b64decode(a_string))
def test_happy_path(self): print("AAAA %s" % portable_b64decode(portable_b64encode("foo"))) assert polite_string(portable_b64decode( portable_b64encode("foo"))) == "foo"