soap - Unable to decrypt MTOM/XOP attachment using SUDS (python) -
i have soap client downloads file server. request has body , attachment (the file) encrypted using 2 separate keys. both keys included in respective <xenc:encryptedkey>
tags. can decrypt body no problem using 1 of keys, attachment giving me issues.
my code:
from crypto.cipher import aes crypto import random class aescipher: def __init__( self, key, bs = 16): self.key = key self.bs = bs def _pad(self, s): return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs) def _unpad(self, s): return s[:-ord(s[len(s)-1:])] def decrypt( self, enc ): enc = base64.b64decode(enc) iv = enc[:self.bs] cipher = aes.new(self.key, aes.mode_cbc, iv ) return self._unpad(cipher.decrypt( enc[self.bs:])) open('test/resp-down-file','rb') f: encfile = f.read() #...the key extracted elsewhere... cryptor = aescipher(key) cryptor.decrypt(encfile)
at best i'm getting garbled result, says error while decrypting in cbc mode
. question: has come across issue? i'm open suggetions in python, java, php, perl, c, pretty runs on linux. there special way mtom/xop attachments encrypted?
i saw this question already, doesn't have correct answer. octet/stream refers content type, not delivery mechanism, answer incorrect.
edit: server spec says encrypt message using aes128-cbc algorithm pkcs5 padding. doesn't make sense me use des padding aes encryption, they're adamant that.
edit2: attached message doesn't have correct length aes128 decryption (e.g. 6023 bytes or 4071 bytes).
for reference message comes in in format:
--mimeboundaryurn_uuid_641b9d88b371c8a80c1501095406237 content-type: text/xml; charset=utf-8 content-transfer-encoding: binary content-id: <0.urn:uuid:641b9d88b371c8a80c1501095406238@apache.org> <?xml version="1.0" encoding="utf-8"?> <soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> ... </soapenv:envelope> --mimeboundaryurn_uuid_641b9d88b371c8a80c1501095406237 content-type: application/octet-stream content-transfer-encoding: binary content-id: <urn:uuid:641b9d88b371c8a80c1501095406240@apache.org> 8ej¨%• }\ Œ“\ò½<( nË%¸£käö0 ‡xw�5ìr Ë�¾p�Áëş3Âå'¹5¥#=zg¡øø{i~fp�n ×aµr^föž¤¥eÍf«Îê�0qÊmö²È€]®pÌ>a@‡ cş®±9>Áf7p’#ã …fç~yxÔ.å–×v›±cô„Ê ... --mimeboundaryurn_uuid_641b9d88b371c8a80c1501095406237--
i figured out problem. turns out, way received data (using result = requests.post(....)
trimmed non-printable characters because using result.text
.
now i've switched result.raw.read()
, issue resolved.
Comments
Post a Comment