Ejemplo n.º 1
0
    def test_encrypt_public_cert_without_ca_aes_128_cbc(self):
        crt_path = self.__get_cert_path('P1_public.cer')
        alg = "aes_128_cbc"

        rst = SMIMEHelper.encrypt_to_mime(self.clearText, crt_path, alg)

        assert_not_equal(None, rst._headers)
        assert_equal(('MIME-Version', '1.0'), rst._headers[0])
Ejemplo n.º 2
0
    def test_encrypt_public_cert_with_ca_des_ede3_cbc(self):
        crt_path = self.__get_cert_path('mercury_ingrammicro_com.sha256.cer')
        alg = "des_ede3_cbc"

        rst = SMIMEHelper.encrypt_to_mime(self.clearText, crt_path, alg)

        assert_not_equal(None, rst._headers)
        assert_equal(('MIME-Version', '1.0'), rst._headers[0])
Ejemplo n.º 3
0
    def test_encrypt_public_cert_with_ca_des_ede3_cbc(self):
        crt_path = self.__get_cert_path('edi04_with_ca.crt')
        alg = "des_ede3_cbc"

        rst = SMIMEHelper.encrypt_to_mime(self.clearText, crt_path, alg)

        assert_not_equal(None, rst._headers)
        assert_equal(('MIME-Version', '1.0'), rst._headers[0])
Ejemplo n.º 4
0
    def test_mime_to_string_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, 0)

        assert_not_equal(None, msg)
        assert_equal(True, "MIME-Version" in msg)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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])