当前位置: 首页>>代码示例>>Python>>正文


Python Parser.getChild方法代码示例

本文整理汇总了Python中suds.sax.parser.Parser.getChild方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.getChild方法的具体用法?Python Parser.getChild怎么用?Python Parser.getChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在suds.sax.parser.Parser的用法示例。


在下文中一共展示了Parser.getChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sending

# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import getChild [as 别名]
    def sending(self, context):
        '''Signs XML before sending'''

        signature_template = '''
            <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
              <SignedInfo>
              <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
              <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
              <Reference URI="#%(REFERENCE_ID)s">
                <Transforms>
                  <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                  <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                </Transforms>
                <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                <DigestValue></DigestValue>
              </Reference>
              </SignedInfo>
              <SignatureValue />
              <KeyInfo>
                <X509Data>
                  <X509Certificate />
                </X509Data>
              </KeyInfo>
            </Signature>
        '''

        envelope_element = Parser().parse(string=context.envelope).root()
        envelope_element.refitPrefixes()

        body = envelope_element.getChild('Body')
        payload = body[0]

        qname = payload.qname()
        if 'Echo' in qname:
            return

        reference_id = "refId:%s" % uuid4()
        payload.set('Id', reference_id)
        signature_template %= {'REFERENCE_ID': reference_id}

        signature_element = Parser().parse(string=signature_template).root()
        payload.append(signature_element)

        envelope = self.DTD_TEST_ID % qname
        envelope += envelope_element.str()
        envelope = envelope.encode('utf-8')

        signer = XMLDSIG()
        signer.load_key(self.key_path,
                        password=self.key_passphrase,
                        cert_path=self.cert_path)
        context.envelope = signer.sign(envelope)
        context.envelope = self.RE_DTD_TEST.sub('', context.envelope)
开发者ID:vvojvoda,项目名称:fiscal-hr-python,代码行数:55,代码来源:fiscal.py

示例2: parse_request

# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import getChild [as 别名]
    def parse_request(self, method_name, data):
        """"
        @args: method_name Short version of soap_action.
        @args: raw soap data (string)
        """
        root = Parser().parse(string=data)
        env = root.getChild('Envelope')
        env.promotePrefixes()
        body = env.getChild('Body')

        method = self.method = self._lookup(method_name)

        binding = method.binding.input
        # code extracted from "suds.bindings.binding.Binding.get_reply"
        body = binding.multiref.process(body)
        nodes = binding.replycontent(method, body)
        # Note: "method" has its input and output exchanged.
        # Therefore, "returned_types" in fact means "parameter_types".
        rtypes = binding.returned_types(method)
        params = binding.replycomposite(rtypes, nodes)
        # the normalization part does not seem to do anything usefull
        return method, params
开发者ID:BandwidthOnDemand,项目名称:OpenNSA,代码行数:24,代码来源:sudsservice.py

示例3: received

# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import getChild [as 别名]
    def received(self, context):
        '''Verifies XML signature of received message'''

        def _extract_keyinfo_cert(payload):
            '''Extract the signing certificate from KeyInfo.'''

            cert_der = payload.getChild('Signature')
            cert_der = cert_der.getChild('KeyInfo')
            cert_der = cert_der.getChild('X509Data')
            cert_der = cert_der.getChild('X509Certificate').getText().strip()
            cert_der = cert_der.decode('base64')
            return cert_der

        def _verify_cn(cert, cis_cert_cn):
            '''Verify signature certificate common name'''

            common_name = cert.get_subject().commonName

            if common_name != cis_cert_cn:
                raise Exception('Invalid certificate common name in response: '
                                '%s != %s' % (cis_cert_cn, common_name))

        def _fault(code, msg):
            '''Generate fault XML'''

            faultcode = Element('faultcode').setText(code)
            faultstring = Element('faultstring').setText(msg)
            fault = Element('Fault').append([faultcode, faultstring])
            body = Element('Body').append(fault)
            envelope = Element('Envelope', ns=soap_envns)
            envelope.append(body)
            envelope.refitPrefixes()

            return envelope.str()


        valid_signature = False

        try:
            if not self.cis_ca_path:
                raise Exception('Certificate Authority not defined')

            reply_element = Parser().parse(string=context.reply).root()
            body = reply_element.getChild('Body')
            payload = body[0]
            qname = payload.qname()
            cert_der = _extract_keyinfo_cert(payload)
            cert = crypto.load_certificate(crypto.FILETYPE_ASN1, cert_der)

            if 'Echo' in qname or 'Fault' in qname:
                LOGGER.warning('Not verifying certificate for qname: %s', qname)
                return

            if self.cis_cert_cn:
                _verify_cn(cert, self.cis_cert_cn)
            else:
                LOGGER.warning('CIS certificate common name not configured')

            reply = self.DTD_TEST_ID % qname
            reply += self.RE_XML_HEADER.sub('', context.reply)

            verifier = XMLDSIG()
            verifier.load_cert(self.cis_ca_path)
            valid_signature = verifier.verify(reply)

        except Exception as exc:
            LOGGER.exception('%s: %s', exc, context.reply)
            context.reply = _fault('Client',
                                   'Invalid response signature: %s' % exc)
        else:
            if not valid_signature:
                LOGGER.error('Invalid response signature: %s', context.reply)
                context.reply = _fault('Client',
                                       'Invalid response signature')
开发者ID:vvojvoda,项目名称:fiscal-hr-python,代码行数:76,代码来源:fiscal.py


注:本文中的suds.sax.parser.Parser.getChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。