def _signature(self): if not self.is_signed: self.context.trace("signature ignored") return cert_thumbprint = self.context.agreement.outbound_agreement.message_signature_certificate.thumbprint cert_local_file_path = self.context.agreement.outbound_agreement.message_signature_certificate.local_file_path cert_pass_phrase = self.context.agreement.outbound_agreement.message_signature_certificate.pass_phrase cert_signature_algorithm = self.context.agreement.outbound_agreement.message_signature_algorithm try: f_mime_string = SMIMEHelper.format_with_cr_lf( SMIMEHelper.mime_to_string(self.mime_message)) self.mic_content = f_mime_string self.mic_algorithm = self.context.agreement.outbound_agreement.message_signature_algorithm detached_signed_message = SMIMEHelper.sign_to_mime_detached( f_mime_string, cert_local_file_path, cert_pass_phrase, cert_signature_algorithm) signature = SMIMEHelper.get_signature_from_mime(detached_signed_message) if signature is None: raise Exception("signature is none from detached signed mime message") signed_mime_message = MIMEMultipart('signed', boundary=SMIMEHelper.get_random_boundary(), protocol="application/pkcs7-signature") del signed_mime_message['MIME-Version'] signed_mime_message.set_param('micalg', self.mic_algorithm) signed_mime_message.attach(self.mime_message) signed_mime_message.attach(signature) self.body = SMIMEHelper.format_with_cr_lf(SMIMEHelper.extract_payload(signed_mime_message)) self.mime_message = signed_mime_message self.context.trace("signature finished; thumbprint: {thumbprint}, algorithm: {algorithm}", thumbprint=cert_thumbprint, algorithm=cert_signature_algorithm) except: logger.exception("signature failed; message-id: {id}".format(id=self.message_id)) raise AS2SignatureException( "signature failed; thumbprint: {thumbprint}, algorithm: {algorithm}, due to: {message}", thumbprint=cert_thumbprint, algorithm=cert_signature_algorithm, message=sys.exc_info()[1])
def _verify_signed_message(self, content_type): if content_type != 'multipart/signed': raise AS2MdnException('content-type invalid when signed required') mdn_signature_thumbprint = self.context.agreement.outbound_agreement.message_encryption_certificate.thumbprint mdn_signature_cert_path = self.context.agreement.outbound_agreement.message_encryption_certificate.local_file_path mdn_signature_cert_ca_path = self.context.agreement.outbound_agreement.message_encryption_certificate.local_ca_file_path mdn_signature_cert_verify = self.context.agreement.outbound_agreement.message_encryption_certificate.is_need_verify try: if is_none_or_whitespace(mdn_signature_cert_ca_path): mdn_signature_cert_ca_path = mdn_signature_cert_path f_mime_string = SMIMEHelper.format_with_cr_lf( SMIMEHelper.mime_to_string(self.mime_message)) SMIMEHelper.verify_signed_text(f_mime_string, mdn_signature_cert_path, mdn_signature_cert_ca_path, mdn_signature_cert_verify) self.context.trace( "mdn signature verify finished; thumbprint: {thumbprint}, verify certificate: {verify}", thumbprint=mdn_signature_thumbprint, verify=mdn_signature_cert_verify) except: logger.exception( "mdn signature verify failed; mdn-message-id: {id}".format( id=self.mdn_message_id)) raise AS2MdnException( "mdn signature verify failed; thumbprint: {thumbprint}, verify certificate: {verify}, due to: {message}", thumbprint=mdn_signature_thumbprint, verify=mdn_signature_cert_verify, message=sys.exc_info()[1])
def _verify_signature(self): if not self.is_signed: self.context.trace("verify signature ignored") return content_type = self.mime_message.get_content_type().lower() if content_type != 'multipart/signed': raise AS2VerifySignatureException('verify signature failed; content-type:{type} invalid', type=content_type) cert_thumbprint = self.context.agreement.inbound_agreement.message_verify_certificate.thumbprint cert_local_file_path = self.context.agreement.inbound_agreement.message_verify_certificate.local_file_path cert_ca_local_file_path = self.context.agreement.inbound_agreement.message_verify_certificate.local_ca_file_path cert_verify = self.context.agreement.inbound_agreement.message_verify_certificate.is_need_verify try: if is_none_or_whitespace(cert_ca_local_file_path): cert_ca_local_file_path = cert_local_file_path for part in self.mime_message.get_payload(): if not isinstance(part, email.message.Message): continue part_type = part.get_content_type().lower() part_encoding = part.get('Content-Transfer-Encoding', '').lower() if 'application/pkcs7-signature' == part_type and 'base64' != part_encoding: del part['Content-Transfer-Encoding'] email.encoders.encode_base64(part) self.context.trace('signature content transfer encoding to base64') f_mime_string = SMIMEHelper.format_with_cr_lf( SMIMEHelper.mime_to_string(self.mime_message)) SMIMEHelper.verify_signed_text( f_mime_string, cert_local_file_path, cert_ca_local_file_path, cert_verify) self.mic_algorithm = self.mime_message.get_param('micalg').lower() parts = [part for part in self.mime_message.walk() if part.get_content_type() not in ['multipart/signed', 'application/pkcs7-signature']] if len(parts) != 1: raise AS2VerifySignatureException( "verify signature failed; due to multiple part content in mime message") self.mime_message = parts[0] self.context.trace("verify signature finished; thumbprint: {thumbprint}, verify certificate: {verify}", thumbprint=cert_thumbprint, verify=cert_verify) except: logger.exception("verify signature failed; message-id: {id}".format(id=self.message_id)) raise AS2VerifySignatureException( "verify signature failed; thumbprint: {thumbprint}, verify certificate: {verify}, due to: {message}", thumbprint=cert_thumbprint, verify=cert_verify, message=sys.exc_info()[1])
def test_format_with_cr_lf_public_cert_without_ca_des_ede3_cbc(self): crt_path = self.__get_cert_path('P1_public.cer') alg = "des_ede3_cbc" rst = SMIMEHelper.encrypt_to_mime(self.clearText, crt_path, alg) msg = SMIMEHelper.mime_to_string(rst) f_msg = SMIMEHelper.format_with_cr_lf(msg) assert_not_equal(msg, f_msg) assert_equal(True, "\r\n" in f_msg)
def _decrypt(self): if not self.is_encrypted: self.context.trace("decrypt ignored") return content_type = self.mime_message.get_content_type().lower() s_mime_type = self.mime_message.get_param('smime-type') if content_type != 'application/pkcs7-mime': raise AS2DecryptException('decrypt failed; content-type:{type} invalid', type=content_type) if s_mime_type != 'enveloped-data': raise AS2DecryptException('decrypt failed; s/mime-type:{type} invalid', type=s_mime_type) cert_thumbprint = self.context.agreement.inbound_agreement.message_decrypt_certificate.thumbprint cert_local_file_path = self.context.agreement.inbound_agreement.message_decrypt_certificate.local_file_path cert_pass_phrase = self.context.agreement.inbound_agreement.message_decrypt_certificate.pass_phrase try: content_transfer_encoding = self.mime_message.get('Content-Transfer-Encoding', '').lower() if 'base64' != content_transfer_encoding: del self.mime_message['Content-Transfer-Encoding'] email.encoders.encode_base64(self.mime_message) self.context.trace('content transfer encoding to base64') f_mime_string = SMIMEHelper.format_with_cr_lf( SMIMEHelper.mime_to_string(self.mime_message, 78) ) decrypted_content = SMIMEHelper.decrypt_from_text( f_mime_string, cert_local_file_path, cert_pass_phrase ) self.mime_message = email.message_from_string(decrypted_content) self.context.trace("decrypt finished; thumbprint: {thumbprint}", thumbprint=cert_thumbprint) except: logger.exception("decrypt failed; message-id: {id}".format(id=self.message_id)) raise AS2DecryptException("decrypt failed; thumbprint: {thumbprint}, due to: {message}", thumbprint=cert_thumbprint, message=sys.exc_info()[1])
def _compress(self): if not self.is_compressed: self.context.trace("compress ignored") return try: f_mime_string = SMIMEHelper.format_with_cr_lf( SMIMEHelper.mime_to_string(self.mime_message)) self.mic_content = f_mime_string self.mime_message = SMIMEHelper.compress_to_mime(f_mime_string) del self.mime_message['MIME-Version'] self.body = self.mime_message.get_payload() self.context.trace("compress finished") except: logger.exception("compress failed; message-id: {id}".format(id=self.message_id)) raise AS2CompressException("compress failed; due to: {message}", message=sys.exc_info()[1])
def encode(self): try: self._init_mode(self.context.message.message_mdn.mdn_mode) self._init_message_id(self.context.message.message_mdn) self._init_disposition(self.context.message.message_mdn) self._init_mic(self.context.message.message_is_mic, self.context.message.message_mdn) mdn_report = MIMEMultipart( 'report', boundary=SMIMEHelper.get_random_boundary(), report_type="disposition-notification") mdn_confirmation_text = self._build_confirmation_mime() mdn_feedback_content = self._build_feedback_content_mime() mdn_report.attach(mdn_confirmation_text) mdn_report.attach(mdn_feedback_content) del mdn_report['MIME-Version'] if self.context.agreement.inbound_agreement.is_mdn_signed: mdn_message = self._signature_mdn_mime(mdn_report) else: mdn_message = mdn_report self.context.trace("mdn signature ignore") mdn_headers = self._build_mdn_headers(mdn_message) mdn_body = SMIMEHelper.format_with_cr_lf( SMIMEHelper.extract_payload(mdn_message)) return mdn_headers, mdn_body except AS2MdnException as ex: self.context.trace_error(ex.msg) raise except: self.context.trace_error(sys.exc_info()[1]) raise
def _signature_mdn_mime(self, mdn_report): signed_mdn_report = MIMEMultipart( 'signed', boundary=SMIMEHelper.get_random_boundary(), protocol="application/pkcs7-signature") signed_mdn_report.attach(mdn_report) cert_thumbprint = self.context.agreement.outbound_agreement.message_signature_certificate.thumbprint cert_local_file_path = self.context.agreement.outbound_agreement.message_signature_certificate.local_file_path cert_pass_phrase = self.context.agreement.outbound_agreement.message_signature_certificate.pass_phrase cert_signature_algorithm = self.context.agreement.inbound_agreement.mdn_signature_algorithm try: mime_message = SMIMEHelper.sign_to_mime_detached( SMIMEHelper.format_with_cr_lf( SMIMEHelper.mime_to_string(mdn_report)), cert_local_file_path, cert_pass_phrase, cert_signature_algorithm) signature = SMIMEHelper.get_signature_from_mime(mime_message) del signature['MIME-Version'] signed_mdn_report.set_param('micalg', cert_signature_algorithm) signed_mdn_report.attach(signature) self.context.trace( "mdn signature finished; thumbprint: {thumbprint}, algorithm: {algorithm}", thumbprint=cert_thumbprint, algorithm=cert_signature_algorithm) except: logger.exception('sign mdn failed') raise AS2MdnException( "mdn signature failed; thumbprint: {thumbprint}, algorithm: {algorithm}, due to: {message}", thumbprint=cert_thumbprint, algorithm=cert_signature_algorithm, message=sys.exc_info()[1]) return signed_mdn_report
def _encryption(self): if not self.is_encrypted: self.context.trace("encryption ignored") return cert_thumbprint = self.context.agreement.outbound_agreement.message_encryption_certificate.thumbprint cert_local_file_path = self.context.agreement.outbound_agreement.message_encryption_certificate.local_file_path cert_encrypt_algorithm = self.context.agreement.outbound_agreement.message_encryption_algorithm try: f_mime_string = SMIMEHelper.format_with_cr_lf( SMIMEHelper.mime_to_string(self.mime_message)) # encrypt without sign and compress if not self.is_signed and not self.is_compressed: self.mic_content = f_mime_string encrypted_mime_message = SMIMEHelper.encrypt_to_mime( f_mime_string, cert_local_file_path, cert_encrypt_algorithm) encrypted_mime_message.set_type('application/pkcs7-mime') self.body = encrypted_mime_message.get_payload() self.mime_message = encrypted_mime_message self.context.trace("encryption finished; thumbprint: {thumbprint}, algorithm: {algorithm}", thumbprint=cert_thumbprint, algorithm=cert_encrypt_algorithm) except: logger.exception("encryption failed; message-id: {id}".format(id=self.message_id)) raise AS2EncryptException( "encryption failed; thumbprint: {thumbprint}, algorithm: {algorithm}, due to: {message}", thumbprint=cert_thumbprint, algorithm=cert_encrypt_algorithm, message=sys.exc_info()[1])
def test_verify_signed_data_no_verify_cert_without_ca(self): signed_msg = '''MIME-Version: 1.0 Content-Disposition: attachment; filename="smime.p7m" Content-Type: application/x-pkcs7-mime; smime-type=signed-data; name="smime.p7m" Content-Transfer-Encoding: base64 MIIJxAYJKoZIhvcNAQcCoIIJtTCCCbECAQExDzANBglghkgBZQMEAgEFADAnBgkq hkiG9w0BBwGgGgQYVGhpcyBpcyB0ZXN0IG1lc3NhZ2UuIA0KoIIHsjCCA9UwggK9 oAMCAQICCQC2XhVbIaoZvjANBgkqhkiG9w0BAQsFADCBgDELMAkGA1UEBhMCQ04x CzAJBgNVBAgMAlNDMQswCQYDVQQHDAJDRDEPMA0GA1UECgwGTmV3ZWdnMQwwCgYD VQQLDANFREkxGDAWBgNVBAMMD0FTMiBDZXJ0aWZpY2F0ZTEeMBwGCSqGSIb3DQEJ ARYPdHIyOUBuZXdlZ2cuY29tMB4XDTE3MDMyODA5Mzc1NloXDTE4MDMyODA5Mzc1 NlowgYAxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJTQzELMAkGA1UEBwwCQ0QxDzAN BgNVBAoMBk5ld2VnZzEMMAoGA1UECwwDRURJMRgwFgYDVQQDDA9BUzIgQ2VydGlm aWNhdGUxHjAcBgkqhkiG9w0BCQEWD3RyMjlAbmV3ZWdnLmNvbTCCASIwDQYJKoZI hvcNAQEBBQADggEPADCCAQoCggEBANmjQYcuDWY3E/2vhyazv3PqI6VoalRg1ESH 5BouIRW7TB9yCB4O7gWuWNfSR+JnECUZDzDaTZxoY5Hb90MAfBdTzMZzH61nMJdZ vf3P86QyuV0MTw+N0E/u2yuOwZAbNM6xAjd78hJNoQsMj+UCv5cnRhPtLE0H5j+X 4VRlPEVPwGZaKAB7EAZJZQj6vGkMA0ib3OhwH/osjWtMGZXxqaA6HeeHNBAGIU++ gIo9V60isr1XgjuRsdAjtedxZO0ptvgprAlZ+xsctnFiEpNykevvbyHnLrYp7nEP ijCZz72AlqFQOUxNa1RrETNj4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6rHFeH+HgLY4Amie2D cpUHTclMZzz4uEh8S9+o1fLGH4kORah5ndHuuR6LZMukzHFfbiY0Qk2h9HF0cPTj fvbGT6N8sMj/1aNl2GfNMdOeFxuXIH8TXELJrYrmdOpWA+RYGg96989beC9j54eB 2VX9KRtpG5576jeDH2iuCztEwksMqKxBeRw/byj4wryiKIcm+ThnM2/kKH/cFJbz HMlT8fyoImZ3gTRUMtWie32REMtmm32MLMMbgYAYRsnAV4ZVa+5mUx84hihWmmPK uxtwCuo/x84= ''' f_signed_msg = SMIMEHelper.format_with_cr_lf(signed_msg) crt_path = self.__get_cert_path('P1_public.cer') ca_crt_path = self.__get_cert_path('P1_public.cer') is_verify_cert = False rst = SMIMEHelper.verify_signed_text(f_signed_msg, crt_path, ca_crt_path, is_verify_cert) assert_equal(self.clearText, rst.strip())
def test_verify_signed_data_without_ca(self): signed_msg = '''MIME-Version: 1.0 Content-Disposition: attachment; filename="smime.p7m" Content-Type: application/x-pkcs7-mime; smime-type=signed-data; name="smime.p7m" Content-Transfer-Encoding: base64 MIIKqwYJKoZIhvcNAQcCoIIKnDCCCpgCAQExDzANBglghkgBZQMEAgEFADAnBgkq hkiG9w0BBwGgGgQYVGhpcyBpcyB0ZXN0IG1lc3NhZ2UuIA0KoIIHsjCCA9UwggK9 oAMCAQICCQC2XhVbIaoZvjANBgkqhkiG9w0BAQsFADCBgDELMAkGA1UEBhMCQ04x CzAJBgNVBAgMAlNDMQswCQYDVQQHDAJDRDEPMA0GA1UECgwGTmV3ZWdnMQwwCgYD VQQLDANFREkxGDAWBgNVBAMMD0FTMiBDZXJ0aWZpY2F0ZTEeMBwGCSqGSIb3DQEJ ARYPdHIyOUBuZXdlZ2cuY29tMB4XDTE3MDMyODA5Mzc1NloXDTE4MDMyODA5Mzc1 NlowgYAxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJTQzELMAkGA1UEBwwCQ0QxDzAN BgNVBAoMBk5ld2VnZzEMMAoGA1UECwwDRURJMRgwFgYDVQ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) crt_path = self.__get_cert_path('P1_public.cer') ca_crt_path = self.__get_cert_path('P1_public.cer') is_verify_cert = True rst = SMIMEHelper.verify_signed_text(f_signed_msg, crt_path, ca_crt_path, is_verify_cert) assert_equal(self.clearText, rst.strip())
def test_verify_multipart_signed_text_with_ca(self): signed_msg = '''MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha1"; boundary="----61FD602D4D31C5FCAE3D9C6C0E9789D2" This is an S/MIME signed message ------61FD602D4D31C5FCAE3D9C6C0E9789D2 This is test message. ------61FD602D4D31C5FCAE3D9C6C0E9789D2 Content-Type: application/x-pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" MIIIPwYJKoZIhvcNAQcCoIIIMDCCCCwCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3 DQEHAaCCBTUwggUxMIIEGaADAgECAhAecXgg/TkHXQAAAABQ3DVzMA0GCSqGSIb3 DQEBCwUAMIG6MQswCQYDVQQGEwJVUzEWMBQGA1UEChMNRW50cnVzdCwgSW5jLjEo MCYGA1UECxMfU2VlIHd3dy5lbnRydXN0Lm5ldC9sZWdhbC10ZXJtczE5MDcGA1UE CxMwKGMpIDIwMTIgRW50cnVzdCwgSW5jLiAtIGZvciBhdXRob3JpemVkIHVzZSBv bmx5MS4wLAYDVQQDEyVFbnRydXN0IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IC0g TDFLMB4XDTE3MDQxNDAwMTAxOVoXDTIwMDUwMjAwNDAxOFowbTELMAkGA1UEBhMC VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExGTAXBgNVBAcTEENpdHkgb2YgSW5kdXN0 cnkxEzARBgNVBAoTCk5ld2VnZyBJbmMxGTAXBgNVBAMTEGVkaTA0Lm5ld2VnZy5j b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC/UKcNeFVX30ZANlx6 ElFDGDVGfV0s/qWOduQxsP6WRm4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iBL9nviLp+L76qTx2xYDyqOBx0sfxZD83zAvRqGOWzUU 25bW ------61FD602D4D31C5FCAE3D9C6C0E9789D2-- ''' f_signed_msg = SMIMEHelper.format_with_cr_lf(signed_msg) crt_path = self.__get_cert_path('edi04_with_ca.crt') ca_crt_path = self.__get_cert_path('edi04_ca_cert_chain.crt') is_verify_cert = False rst = SMIMEHelper.verify_signed_text(f_signed_msg, crt_path, ca_crt_path, is_verify_cert) assert_equal(self.clearText, rst.strip())
def test_verify_multipart_signed_text_without_ca(self): signed_msg = '''MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha1"; boundary="----E67033C32AF07C4C5BE242D36DB48F2F" This is an S/MIME signed message ------E67033C32AF07C4C5BE242D36DB48F2F This is test message. ------E67033C32AF07C4C5BE242D36DB48F2F Content-Type: application/x-pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" MIIGogYJKoZIhvcNAQcCoIIGkzCCBo8CAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3 DQEHAaCCA9kwggPVMIICvaADAgECAgkAtl4VWyGqGb4wDQYJKoZIhvcNAQELBQAw gYAxCzAJBgNVBAYTAkNOMQswCQYDVQQIDAJTQzELMAkGA1UEBwwCQ0QxDzANBgNV BAoMBk5ld2VnZzEMMAoGA1UECwwDRURJMRgwFgYDVQQDDA9BUzIgQ2VydGlmaWNh dGUxHjAcBgkqhkiG9w0BCQEWD3RyMjlAbmV3ZWdnLmNvbTAeFw0xNzAzMjgwOTM3 NTZaFw0xODAzMjgwOTM3NTZaMIGAMQswCQYDVQQGEwJDTjELMAkGA1UECAwCU0Mx CzAJBgNVBAcMAkNEMQ8wDQYDVQQKDAZOZXdlZ2cxDDAKBgNVBAsMA0VESTEYMBYG A1UEAwwPQVMyIENlcnRpZmljYXRlMR4wHAYJKoZIhvcNAQkBFg90cjI5QG5ld2Vn Zy5jb20wggEiMA0GCSqGSIb3DQEBAQUAA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aBQCggdgwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0B CQUxDxcNMTcwNDI2MDUwOTU2WjAjBgkqhkiG9w0BCQQxFgQUTbJjGEsYI0NLdMKR +03JnqOANJIweQYJKoZIhvcNAQkPMWwwajALBglghkgBZQMEASowCwYJYIZIAWUD BAEWMAsGCWCGSAFlAwQBAjAKBggqhkiG9w0DBzAOBggqhkiG9w0DAgICAIAwDQYI KoZIhvcNAwICAUAwBwYFKw4DAgcwDQYIKoZIhvcNAwICASgwDQYJKoZIhvcNAQEB BQAEggEAckjU1ukVvN09owL+L9SCBm9yHcmIdzWI5EQOY0nbRLA08+a6gg2Ox6Hn 4Aa3iMFiSpaOWHUtE1IWOlUN9CdFTvkg3hTDya2hQHVM/6/zSuacsJvZf4WeT08Y ktp6zpEteaccswB0XFYHqt+jEA+lvwTcwKAQsEporSuL1Md1I99vcs19C5f/1fcD smk0rbKNs4ZvLaL3/LNdq4OLVKle0RmwX7UOn8ZWg7Ktr6SuBE8MvxFFgXDGpdto kps3+1aYZMB3Oal0n4nTwF28Fjem1aQNY8KSqV4/WhgPsdByDkSd+P+K40SD4NkN LrhHEL4SK7yeHG0bSM/D+t4EzgRohA== ------E67033C32AF07C4C5BE242D36DB48F2F-- ''' f_signed_msg = SMIMEHelper.format_with_cr_lf(signed_msg) crt_path = self.__get_cert_path('P1_public.cer') ca_crt_path = self.__get_cert_path('P1_public.cer') is_verify_cert = True rst = SMIMEHelper.verify_signed_text(f_signed_msg, crt_path, ca_crt_path, is_verify_cert) assert_equal(self.clearText, rst.strip())
def test_verify_mdn_multipart_signed_text_without_ca(self): signed_msg = '''message-id: <MOKOavlb2bapp02-node1-15d249455c2-1450468007ScanSourcePRD@avlb2bapp02> Content-Type: multipart/signed;protocol="application/pkcs7-signature";micalg=sha1;boundary="_=32151894939666303Sterling32151894939666303MOKO" --_=32151894939666303Sterling32151894939666303MOKO Content-Type: multipart/report;Report-Type=disposition-notification;boundary="_=6597787784037321Sterling6597787784037321MOKO" --_=6597787784037321Sterling6597787784037321MOKO Your message was successfully received and processed. --_=6597787784037321Sterling6597787784037321MOKO Content-Type: message/disposition-notification Original-Recipient: rfc822;ScanSourcePRD Final-Recipient: rfc822;ScanSourcePRD Original-Message-ID: <5787E1CB-1471-4262-BD68-1E06F3D5AE28@tr29-VirtualBox> Received-Content-MIC: 9mVaiezSK13edeEvNeXcRMIS4YQ=,sha1 Disposition: Automatic-action/mdn-sent-automatically;processed --_=6597787784037321Sterling6597787784037321MOKO-- --_=32151894939666303Sterling32151894939666303MOKO Content-Type: Application/pkcs7-signature;name=EDIINTSIG.p7s Content-Transfer-Encoding: base64 MIIIHgYJKoZIhvcNAQcCoIIIDzCCCAsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCCBmcw ggZjMIIFS6ADAgECAhBfmdlsShevBcAkKDoJXbq9MA0GCSqGSIb3DQEBCwUAMEQxCzAJBgNVBAYT AlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMR0wGwYDVQQDExRHZW9UcnVzdCBTU0wgQ0EgLSBH MzAeFw0xNjA4MDEwMDAwMDBaFw0xODA4MTcyMzU5NTlaMG0xCzAJBgNVBAYTAlVTMRcwFQYDVQQI DA5Tb3V0aCBDYXJvbGluYTETMBEGA1UEBwwKR3JlZW52aWxsZTETMBEGA1UECgwKU2NhblNvdXJj ZTEbMBkGA1UEAwwSYjJiLnNjYW5zb3VyY2UuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB CgKCAQEApwghg+IJ36HDfedTdRi0CRfEFsD6KmCG+t0g33LAEcV0NjWN+xmJOwEII63dFiJnPL65 lrMHP8bS2vWjVENbPv6FDxa0izAdbcumaNRGjawEe9tuLyvA1f5zLpVnN2mO2nhJWfM4ObNMqq4v eurRh2ExefnYKE3cUbutAVxdtSdau4Jjy0OvsZlK/XLMh4/AouY3ANINlo6l+zqYmFJsatiqdXDE b3JvzE3yuCF999exbD9ab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P+8QAAAFWR57T5gAABAMARzBFAiB8Z/fKljEg29Pw/e3T+oJn 38RhZEUcLDYKK1z+Xa4uGgIhAIV5Mw0a7CdwsQLfxYxZvCUlcCArsg8aZNsfOYOsgWaxMA0GCSqG SIb3DQEBCwUAA4IBAQA9sbdzznGxTvuQMCMj7/LVuV6n9/nAt19dUcv8yWQZAC31hO0eQ6p0UE9I I7YnjcnDmdWeLk8T0VzUO7vNU09InoMVKVald697kW7Wii3pSXHE56pZJbGrKKgtqLaMsBBhti+j lT2Y3I2B4dNlpM6uQhf9anEc9eaN++bVnem8vndiT9OK8NItDrjRGtOlqPR8f0+6D+42wx8jQ/p/ lHvTtN/+ogSStUtXfvLErrsG0iDtzV4M5ihSo8uqn6Gj3tP+qePvFTwz0MUSZ8G0gm68xnD/MWMm hbQRw+4DlDzU9y5fUQumFQHJQ/EL2whP0YlTgshuoayqogLqQY7kSCxCMYIBfzCCAXsCAQEwWDBE MQswCQYDVQQGEwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEdMBsGA1UEAxMUR2VvVHJ1c3Qg U1NMIENBIC0gRzMCEF+Z2WxKF68FwCQoOgldur0wCQYFKw4DAhoFADANBgkqhkiG9w0BAQEFAASC AQAFzW995IHYSfrYAlQbUkkCCQE5ewD+oQ1NUNsaMkxpFfmfNKcf/1xGImHBZiS70WbibR1/0REq e1vDxVPwFXjGZeu+vMC1hSYpB7+i1ryJH5IQqcUcch+/KmYprEvV30xstwi1lt4M/uqO0Wmjoq+j BZy6whjyXfxdoqlNdR+Cfj748Awo2VBOFUvbKQc8nuE1Nx7N03cu4PKeCad4z9eEMLULysBLNz1L RqGb0+IJTT1lvLJc7YLBk2+EVnfoyZJy02HlVc/6ETaKI1DhhSoUh9p21vnZIZN9azo6h34MFxhn x7bKm3h7pv/rnq/MuteNVqjpTk6/aQhzhjjZRueI --_=32151894939666303Sterling32151894939666303MOKO-- ''' s = email.message_from_string(signed_msg) # email parse issue fixed for m in s.walk(): if m.get_content_type() == 'message/disposition-notification': disposition = m.get_payload() if isinstance(disposition, (list, tuple)) and len(disposition) == 1: notify = disposition[0] notify_body = notify.get_payload() if notify_body is None or notify_body == '': m.set_payload(notify.as_string(unixfrom=False)[:-1]) f_signed_msg = SMIMEHelper.format_with_cr_lf(s.as_string(unixfrom=False)) crt_path = self.__get_cert_path('ScanSource_public.cer') ca_crt_path = self.__get_cert_path('ScanSource_CA_Cert_Chain.crt') is_verify_cert = False rst = SMIMEHelper.verify_signed_text(f_signed_msg, crt_path, ca_crt_path, is_verify_cert) assert_not_equal('', rst.strip())