Esempio n. 1
0
 def __init__(self, node, **kwargs):
     Object.__init__(self)
     self.node = node
     self.data = None
     self.text = None
     for k,v in kwargs.items():
         setattr(self, k, v)
def mp_setattr(self,name,value):
    try:
        udf = helpers.get_udf(self._wrapper,self,name)
    except AttributeError:
        sudsobject.__setattr__(self,name,value)
    else:
        udf.Value = value
Esempio n. 3
0
def buildSymmetricKey(block_encryption_algorithm=BLOCK_ENCRYPTION_AES128_CBC):
    sym_key = Object()
    block_encryption_props = blockEncryptionProperties[block_encryption_algorithm]
    sym_key.sym_key = ''.join([chr(random.getrandbits(8)) for i in range(0, block_encryption_props['key_size'])])
    sym_key.iv = ''.join([chr(random.getrandbits(8)) for i in range(0, block_encryption_props['iv_size'])])
    sym_key.block_encryption_algorithm = block_encryption_algorithm
    return sym_key
Esempio n. 4
0
 def __init__(self, node, **kwargs):
     Object.__init__(self)
     self.node = node
     self.data = None
     self.text = None
     for k, v in kwargs.items():
         setattr(self, k, v)
Esempio n. 5
0
    def __init__(self, name, expire, record_type, content):
        """
        Constructs a new DnsEntry of the form
        www  IN  86400   A       127.0.0.1
        mail IN  86400   CNAME   @

        Note that the IN class is always mandatory for this Entry and this is implied.

        :param name: the name of this DnsEntry, e.g. www, mail or @
        :param expire: the expiration period of the dns entry, in seconds. For example 86400 for a day
        :param record_type: the type of this entry, one of the TYPE_ constants in this class
        :param content: content of of the dns entry, for example '10 mail', '127.0.0.1' or 'www'
        :type name: basestring
        :type expire: int
        :type record_type: basestring
        :type content: basestring
        """

        # Call the parent __init__
        SudsObject.__init__(self)

        # Assign the fields
        self.name = name
        self.expire = expire
        self.type = record_type
        self.content = content
Esempio n. 6
0
def mp_setattr(self, name, value):
    try:
        udf = helpers.get_udf(self._wrapper, self, name)
    except AttributeError:
        sudsobject.__setattr__(self, name, value)
    else:
        udf.Value = value
    def __init__(self, name, expire, record_type, content):
        """
        Constructs a new DnsEntry of the form
        www  IN  86400   A       127.0.0.1
        mail IN  86400   CNAME   @

        Note that the IN class is always mandatory for this Entry and this is implied.

        :param name: the name of this DnsEntry, e.g. www, mail or @
        :param expire: the expiration period of the dns entry, in seconds. For example 86400 for a day
        :param record_type: the type of this entry, one of the TYPE_ constants in this class
        :param content: content of of the dns entry, for example '10 mail', '127.0.0.1' or 'www'
        :type name: basestring
        :type expire: int
        :type record_type: basestring
        :type content: basestring
        """

        # Call the parent __init__
        SudsObject.__init__(self)

        # Assign the fields
        self.name = name
        self.expire = expire
        self.type = record_type
        self.content = content
Esempio n. 8
0
 def __init__(self):
     """ """
     Object.__init__(self)
     self.mustUnderstand = True
     self.tokens = []
     self.signatures = []
     self.references = []
     self.keys = []
Esempio n. 9
0
 def __init__(self):
     """ """
     Object.__init__(self)
     self.mustUnderstand = True
     self.tokens = []
     self.signatures = []
     self.references = []
     self.keys = []
Esempio n. 10
0
 def __init__(self, options, sym_key=None):
     Object.__init__(self)
     self.key = options.key
     self.x509_issuer_serial = options.cert
     self.signed_parts = options.signedparts
     self.digest = options.digest
     self.keyReference = options.keyreference
     self.signatureAlgorithm = options.signaturealgorithm
     self.symmetricKey = sym_key
Esempio n. 11
0
 def __init__(self, options, sym_key=None):
     Object.__init__(self)
     self.key = options.key
     self.x509_issuer_serial = options.cert
     self.signed_parts = options.signedparts
     self.digest = options.digest
     self.keyReference = options.keyreference
     self.signatureAlgorithm = options.signaturealgorithm
     self.symmetricKey = sym_key
Esempio n. 12
0
 def __init__(self, options):
     Object.__init__(self)
     self.cert = options.cert
     self.encrypted_parts = options.encryptedparts
     self.second_pass_encrypted_parts = options.secondpassencryptedparts
     self.blockEncryption = options.blockencryption
     self.keyTransport = options.keytransport
     self.keyReference = options.keyreference
     self.includeRefList = options.includereflist
     self.symmetricKey = buildSymmetricKey(self.blockEncryption)
     self.buildEncryptedKey()
Esempio n. 13
0
 def __init__(self, root):
     """
     @param root: An XML root element.
     @type root: L{Element}
     """
     Object.__init__(self)
     self.root = root
     pmd = Metadata()
     pmd.excludes = ['root']
     pmd.wrappers = dict(qname=repr)
     self.__metadata__.__print__ = pmd
Esempio n. 14
0
 def __init__(self, options):
     Object.__init__(self)
     self.cert = options.cert
     self.encrypted_parts = options.encryptedparts
     self.second_pass_encrypted_parts = options.secondpassencryptedparts
     self.blockEncryption = options.blockencryption
     self.keyTransport = options.keytransport
     self.keyReference = options.keyreference
     self.includeRefList = options.includereflist
     self.symmetricKey = buildSymmetricKey(self.blockEncryption)
     self.buildEncryptedKey()
Esempio n. 15
0
    def test_error_handling(self):
        """See if our client returns the error properly"""
        # let's mock again
        self.locations.client.service.GetNearestLocations = mock.MagicMock()
        mock_error = SudsObject()
        mock_error.Fault = mock_error_result
        self.locations.client.service.GetNearestLocations.return_value = (500, mock_error)  # noqa

        # and call it
        result = self.locations.nearest_locations(postalcode="6821AD")
        self.assertEqual(result[0], 500)
Esempio n. 16
0
 def __init__(self, tag=None, value=None, **kwargs):
     """
     @param tag: The content tag.
     @type tag: str
     @param value: The content's value.
     @type value: I{any}
     """
     Object.__init__(self)
     self.tag = tag
     self.value = value
     for k,v in list(kwargs.items()):
         setattr(self, k, v)
Esempio n. 17
0
 def __init__(self, ref=None):
     """
     @param ref: The schema reference being queried.
     @type ref: qref
     """
     Object.__init__(self)
     self.id = objid(self)
     self.ref = ref
     self.history = []
     self.resolved = False
     if not isqref(self.ref):
         raise Exception('%s, must be qref' % tostr(self.ref))
Esempio n. 18
0
 def __init__(self, tag=None, value=None, **kwargs):
     """
     @param tag: The content tag.
     @type tag: str
     @param value: The content's value.
     @type value: I{any}
     """
     Object.__init__(self)
     self.tag = tag
     self.value = value
     for k, v in list(kwargs.items()):
         setattr(self, k, v)
Esempio n. 19
0
 def __init__(self, root, definitions=None):
     """
     @param root: An XML root element.
     @type root: L{Element}
     @param definitions: A definitions object.
     @type definitions: L{Definitions}
     """
     Object.__init__(self)
     self.root = root
     pmd = SFactory.metadata()
     pmd.excludes = ['root']
     pmd.wrappers = dict(qname=lambda x: repr(x))
     self.__metadata__.__print__ = pmd
Esempio n. 20
0
 def __init__(self, tag=None, value=None, type=None):
     """
     @param tag: The content tag.
     @type tag: str
     @param value: The content's value.
     @type value: I{any}
     @param type: The (optional) content schema type.
     @type type: L{xsd.sxbase.SchemaObject}
     """
     Object.__init__(self)
     self.tag = tag
     self.value = value
     self.type = type
Esempio n. 21
0
 def __init__(self, timestamp=False):
     """
     Create a new WS-Security object.
     @param timestamp: Whether or not to create a Security Timestamp
     @type timestamp: bool
     """
     Object.__init__(self)
     self.mustUnderstand = True
     self.timestamp = timestamp
     self.tokens = []
     self.signatures = []
     self.references = []
     self.keys = []
Esempio n. 22
0
 def __init__(self, root, definitions=None):
     """
     @param root: An XML root element.
     @type root: L{Element}
     @param definitions: A definitions object.
     @type definitions: L{Definitions}
     """
     Object.__init__(self)
     self.root = root
     pmd = SFactory.metadata()
     pmd.excludes = ['root']
     pmd.wrappers = dict(qname=lambda x: repr(x))
     self.__metadata__.__print__ = pmd
Esempio n. 23
0
 def __init__(self, root, definitions=None):
     """
     @param root: An XML root element.
     @type root: L{Element}
     @param definitions: A definitions object.
     @type definitions: L{Definitions}
     """
     Object.__init__(self)
     self.root = root
     pmd = Metadata()
     pmd.excludes = ["root"]
     pmd.wrappers = dict(qname=repr)
     self.__metadata__.__print__ = pmd
Esempio n. 24
0
 def __init__(self, tag=None, value=None, type=None):
     """
     @param tag: The content tag.
     @type tag: str
     @param value: The content's value.
     @type value: I{any}
     @param type: The (optional) content schema type.
     @type type: L{xsd.sxbase.SchemaObject}
     """
     Object.__init__(self)
     self.tag = tag
     self.value = value
     self.type = type
Esempio n. 25
0
    def test_nearest_locations(self):
        """Test nearest PostNL Pickup locations based on postal code"""
        # first create a mock for the soap result
        mock_object = SudsObject()
        mock_object.GetLocationsResult = SudsObject()
        mock_object.GetLocationsResult.ResponseLocation = mock_result

        # mock the function call and return a almost like soap object
        self.locations.client.service.GetNearestLocations = mock.MagicMock()
        # the first param is the http status code
        self.locations.client.service.GetNearestLocations.return_value = (200, mock_object)  # noqa

        # do the call
        result = self.locations.nearest_locations(postalcode="6821AD")
        self.assertEqual(result, (200, mock_result))
def mp_getattr(entity,attr):
    if attr != 'UserDefinedFields':
        try:
            return helpers.get_udf_value(entity._wrapper,entity,attr)
        except AttributeError:
            raise AttributeError( 'no attribute or udf named {}'.format(attr) )
    return sudsobject.__getattribute__(entity,attr)
Esempio n. 27
0
def mp_getattr(entity, attr):
    if attr != 'UserDefinedFields':
        try:
            return helpers.get_udf_value(entity._wrapper, entity, attr)
        except AttributeError:
            raise AttributeError('no attribute or udf named {}'.format(attr))
    return sudsobject.__getattribute__(entity, attr)
Esempio n. 28
0
    def __init__(self):
        Object.__init__(self)
        self.wsseEnabled = False
        self.includeTimestamp = False
        self.addressing = False
        self.headerLayout = None
        self.protectTokens = False
        self.onlySignEntireHeadersAndBody = False
        self.clientCertRequired = False
        self.blockEncryption = None
        self.digestAlgorithm = None
        self.keyTransport = None
        self.usernameRequired = False
        self.signatureRequired = False
        self.encryptionRequired = False
        self.encryptThenSign = False
        self.signedParts = []
        self.tokens = []
        self.signatures = []
        self.keys = []
	self.wsse11 = None
Esempio n. 29
0
 def __init__(self):
     Object.__init__(self)
     self.wsseEnabled = False
     self.includeTimestamp = False
     self.addressing = False
     self.headerLayout = None
     self.protectTokens = False
     self.onlySignEntireHeadersAndBody = False
     self.clientCertRequired = False
     self.blockEncryption = None
     self.digestAlgorithm = None
     self.keyTransport = None
     self.usernameRequired = False
     self.signatureRequired = False
     self.encryptionRequired = False
     self.encryptThenSign = False
     self.signedParts = []
     self.tokens = []
     self.signatures = []
     self.keys = []
     self.wsse11 = None
Esempio n. 30
0
    def visitOther(self, elt):
        policy = self.policy
        wsdl_policy = self.wsdl_policy

        if elt.name == 'TransportBinding' or elt.name == 'SymmetricBinding' or elt.name == 'AsymmetricBinding':
            self.bindingType = elt.name
            binding = elt.getChild('Policy')

            policy.wsseEnabled = True
            if binding.getChild("IncludeTimestamp") is not None:
                policy.includeTimestamp = True
            if binding.getChild("EncryptBeforeSigning") is not None:
                policy.encryptThenSign = True
            if binding.getChild("EncryptSignature") is not None:
                if policy.encryptThenSign:
                    self.secondPassEncryptedParts.append(('signature',))
                else:
                    self.baseEncryptedParts.append(('signature',))
            if binding.getChild("OnlySignEntireHeadersAndBody") is not None:
                policy.onlySignEntireHeadersAndBody = True
            if binding.getChild("ProtectTokens") is not None:
                policy.protectTokens = True
            if binding.getChild("Layout") is not None:
                layout = binding.getChild("Layout").getChild("Policy")[0]
                policy.headerLayout = layout.name
            if elt.name == 'TransportBinding':
                transport_token = binding.getChild("TransportToken")
                if transport_token is not None:
                    if transport_token.getChild("Policy").getChild("HttpsToken") is not None:
                        https_token = transport_token.getChild("Policy").getChild("HttpsToken")
                        client_cert_req = https_token.get("RequireClientCertificate")
                        if client_cert_req is None or client_cert_req == "false":
                            policy.clientCertRequired = False
                        elif client_cert_req == "true":
                            policy.clientCertRequired = True
            if binding.getChild("InitiatorToken") is not None or binding.getChild("ProtectionToken") is not None:
                token = binding.getChild("InitiatorToken") or binding.getChild("ProtectionToken")
                if token.getChild("Policy").getChild("X509Token") is not None:
                    signature = Object()
                    signature.signedParts = self.buildParts(token.getChild("Policy").getChild("SignedParts"))
                    signature.signedParts.append(('timestamp',))
                    # This would technically be the correct behavior, but WCF specifies that thumbprint references
                    # are supported, but it can't use them for a primary signature.  Support for BinarySecurityTokens
                    # is always required, so just use them
                    #if token.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireThumbprintReference") is not None:
                    #    signature.keyReference = KEY_REFERENCE_FINGERPRINT
                    #elif token.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireIssuerSerialReference") is not None:
                    #    signature.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                    #else:
                    #    signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                    if elt.name == 'AsymmetricBinding':
                        signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                        signature.signatureAlgorithm = SIGNATURE_RSA_SHA1
                    elif elt.name == 'SymmetricBinding':
                        signature.keyReference = KEY_REFERENCE_ENCRYPTED_KEY
                        signature.signatureAlgorithm = SIGNATURE_HMAC_SHA1
                    policy.signatures[0] = signature
            if (binding.getChild("InitiatorToken") is not None and binding.getChild("RecipientToken") is not None) or \
                binding.getChild("ProtectionToken") is not None:
                key = Object()
                token = binding.getChild("RecipientToken") or binding.getChild("ProtectionToken")
                if token.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireThumbprintReference") is not None:
                    key.keyReference = KEY_REFERENCE_FINGERPRINT
                elif token.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireIssuerSerialReference") is not None:
                    key.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                else:
                    key.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                if elt.name == 'AsymmetricBinding':
                    key.includeRefList = True
                elif elt.name == 'SymmetricBinding':
                    key.includeRefList = False
                key.encryptedParts = self.buildParts(token.getChild("Policy").getChild("EncryptedParts"))
                key.secondPassEncryptedParts = []
                policy.keys.append(key)
            if policy.blockEncryption is None:
                algorithm_suite = binding.getChild("AlgorithmSuite")
                if algorithm_suite is not None:
                    if algorithm_suite.getChild("Policy") is not None:
                        algorithm_policy_name = algorithm_suite.getChild("Policy").getChildren()[0].name
                        if "Basic128" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_AES128_CBC
                        elif "Basic192" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_AES192_CBC
                        elif "Basic256" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_AES256_CBC
                        elif "TripleDes" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_3DES_CBC
                        if "Sha256" in algorithm_policy_name:
                            policy.digestAlgorithm = DIGEST_SHA256
                        else:
                            policy.digestAlgorithm = DIGEST_SHA1
                        if "Rsa15" in algorithm_policy_name:
                            policy.keyTransport = KEY_TRANSPORT_RSA_1_5
                        else:
                            policy.keyTransport = KEY_TRANSPORT_RSA_OAEP

        if elt.name.endswith("Tokens") and self.initiator:
            type = None
            index = None
            if elt.getChild("Policy").getChild("UsernameToken") is not None:
                token = Object()
                policy.tokens.append(token)
                type = 'token'
                index = len(policy.tokens) - 1
            if 'Endorsing' in elt.name and elt.getChild("Policy").getChild("X509Token") is not None:
                signature = Object()
                signature.signedParts = self.buildParts(elt.getChild("Policy").getChild("SignedParts"))
                signature.signatureAlgorithm = SIGNATURE_RSA_SHA1
                if wsdl_policy.binding_type == 'TransportBinding':
                    signature.signedParts.append(('timestamp',))
                else:
                    signature.signedParts.append(('primary_signature',))
                    if policy.protectTokens:
                        signature.signedParts.append(('token', 'self'))
                # This would technically be the correct behavior, but WCF specifies that thumbprint references
                # are supported, but it can't use them for a primary signature.  Support for BinarySecurityTokens
                # is always required, so just use them
                #if elt.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireThumbprintReference") is not None:
                #    signature.keyReference = KEY_REFERENCE_FINGERPRINT
                #elif elt.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireIssuerSerialReference") is not None:
                #    signature.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                #else:
                #    signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                policy.signatures.append(signature)
                type = 'signature'
                index = len(policy.signatures) - 1
            if 'Signed' in elt.name and wsdl_policy.binding_type <> 'TransportBinding' and type is not None:
                self.baseSignedParts.append(('token', type, index))
            if 'Encrypted' in elt.name and wsdl_policy.binding_type <> 'TransportBinding' and type is not None:
                self.baseEncryptedParts.append(('token', type, index))

        if (elt.name == "Addressing" or elt.name == "UsingAddressing") and policy.addressing <> True:
            if self.optional == False:
                policy.addressing = True
            else:
                policy.addressing = None # use what the user specifies

        if elt.name == "SignedParts":
            self.baseSignedParts.extend(self.buildParts(elt))
        elif elt.name == "EncryptedParts":
            self.baseEncryptedParts.extend(self.buildParts(elt))

        if elt.name == "Wss10":
            policy.wsse11 = False
        elif elt.name == "Wss11":
            policy.wsse11 = True
Esempio n. 31
0
 def __init__(self, ids):
     Object.__init__(self)
     self.EntityId = ids
Esempio n. 32
0
 def __init__(self):
     Object.__init__(self)
Esempio n. 33
0
except WebFault, f:
    errors += 1
    print f
    print f.fault
except Exception, e:
    errors += 1
    print e
    tb.print_exc()

try:
    array = client.factory.create('ArrayOf_xsd_string')
    print 'ArrayOf_xsd_string=\n%s' % array
    array.item = ['my', 'dog', 'likes', 'steak']
    result = client.service.printList(array)
    print '\nreply( %s )\n' % str(result)
    array = Object()
    print 'ArrayOf_xsd_string=\n%s' % array
    array.item = ['my', 'dog', 'likes', 'steak']
    result = client.service.printList(array)
    print '\nreply( %s )\n' % str(result)
except WebFault, f:
    errors += 1
    print f
    print f.fault
except Exception, e:
    errors += 1
    print e
    tb.print_exc()

try:
    s = 'hello'
Esempio n. 34
0
    print(('person=\n%s' % (person, )))
    #
    # add the person (using the webservice)
    #
    print('addPersion()')
    result = client.service.addPerson(person)
    print(('\nreply(\n%s\n)\n' % (str(result), )))

    #
    # Async
    #
    client.options.nosend = True
    reply = '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:addPersonResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://basic.suds.fedora.org"><addPersonReturn xsi:type="xsd:string">person (jeff&#x4D2;,ortel) at age 43 with phone numbers (410-555-5138,919-555-4406,205-777-1212, and pets (Chance,) - added.</addPersonReturn></ns1:addPersonResponse></soapenv:Body></soapenv:Envelope>'
    request = client.service.addPerson(person)
    result = request.succeeded(reply)
    error = Object()
    error.httpcode = '500'
    client.options.nosend = False
    #    request.failed(error)

    #
    #
    # create a new name object used to update the person
    #
    newname = client.factory.create('ns0:Name')
    newname.first = 'Todd'
    newname.last = None
    #
    # create AnotherPerson using Person
    #
    ap = client.factory.create('ns0:AnotherPerson')
Esempio n. 35
0
 def __init__(self):
         Object.__init__(self)
Esempio n. 36
0
 def __init__(self, method):
     Object.__init__(self)
     self.method = method
Esempio n. 37
0
    print 'person=\n%s' % person
    #
    # add the person (using the webservice)
    #
    print 'addPersion()'
    result = client.service.addPerson(person)
    print '\nreply(\n%s\n)\n' % str(result)
    
    #
    # Async
    #
    client.options.nosend=True
    reply = '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:addPersonResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://basic.suds.fedora.org"><addPersonReturn xsi:type="xsd:string">person (jeff&#x4D2;,ortel) at age 43 with phone numbers (410-555-5138,919-555-4406,205-777-1212, and pets (Chance,) - added.</addPersonReturn></ns1:addPersonResponse></soapenv:Body></soapenv:Envelope>'
    request = client.service.addPerson(person)
    result = request.succeeded(reply)
    error = Object()
    error.httpcode = '500'
    client.options.nosend=False
#    request.failed(error)
    
    #
    #
    # create a new name object used to update the person
    #
    newname = client.factory.create('ns0:Name')
    newname.first = 'Todd'
    newname.last = None
    #
    # create AnotherPerson using Person
    #
    ap = client.factory.create('ns0:AnotherPerson')
Esempio n. 38
0
 def __init__(self, action):
     Object.__init__(self)
     self.action = action
Esempio n. 39
0
    def visitOther(self, elt):
        policy = self.policy
        wsdl_policy = self.wsdl_policy

        if elt.name == 'TransportBinding' or elt.name == 'SymmetricBinding' or elt.name == 'AsymmetricBinding':
            self.bindingType = elt.name
            binding = elt.getChild('Policy')

            policy.wsseEnabled = True
            if binding.getChild("IncludeTimestamp") is not None:
                policy.includeTimestamp = True
            if binding.getChild("EncryptBeforeSigning") is not None:
                policy.encryptThenSign = True
            if binding.getChild("EncryptSignature") is not None:
                if policy.encryptThenSign:
                    self.secondPassEncryptedParts.append(('signature', ))
                else:
                    self.baseEncryptedParts.append(('signature', ))
            if binding.getChild("OnlySignEntireHeadersAndBody") is not None:
                policy.onlySignEntireHeadersAndBody = True
            if binding.getChild("ProtectTokens") is not None:
                policy.protectTokens = True
            if binding.getChild("Layout") is not None:
                layout = binding.getChild("Layout").getChild("Policy")[0]
                policy.headerLayout = layout.name
            if elt.name == 'TransportBinding':
                transport_token = binding.getChild("TransportToken")
                if transport_token is not None:
                    if transport_token.getChild("Policy").getChild(
                            "HttpsToken") is not None:
                        https_token = transport_token.getChild(
                            "Policy").getChild("HttpsToken")
                        client_cert_req = https_token.get(
                            "RequireClientCertificate")
                        if client_cert_req is None or client_cert_req == "false":
                            policy.clientCertRequired = False
                        elif client_cert_req == "true":
                            policy.clientCertRequired = True
            if binding.getChild(
                    "InitiatorToken") is not None or binding.getChild(
                        "ProtectionToken") is not None:
                token = binding.getChild("InitiatorToken") or binding.getChild(
                    "ProtectionToken")
                if token.getChild("Policy").getChild("X509Token") is not None:
                    signature = Object()
                    signature.signedParts = self.buildParts(
                        token.getChild("Policy").getChild("SignedParts"))
                    signature.signedParts.append(('timestamp', ))
                    # This would technically be the correct behavior, but WCF specifies that thumbprint references
                    # are supported, but it can't use them for a primary signature.  Support for BinarySecurityTokens
                    # is always required, so just use them
                    #if token.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireThumbprintReference") is not None:
                    #    signature.keyReference = KEY_REFERENCE_FINGERPRINT
                    #elif token.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireIssuerSerialReference") is not None:
                    #    signature.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                    #else:
                    #    signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                    if elt.name == 'AsymmetricBinding':
                        signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                        signature.signatureAlgorithm = SIGNATURE_RSA_SHA1
                    elif elt.name == 'SymmetricBinding':
                        signature.keyReference = KEY_REFERENCE_ENCRYPTED_KEY
                        signature.signatureAlgorithm = SIGNATURE_HMAC_SHA1
                    policy.signatures[0] = signature
            if (binding.getChild("InitiatorToken") is not None and binding.getChild("RecipientToken") is not None) or \
                binding.getChild("ProtectionToken") is not None:
                key = Object()
                token = binding.getChild("RecipientToken") or binding.getChild(
                    "ProtectionToken")
                if token.getChild("Policy").getChild("X509Token").getChild(
                        "Policy").getChild(
                            "RequireThumbprintReference") is not None:
                    key.keyReference = KEY_REFERENCE_FINGERPRINT
                elif token.getChild("Policy").getChild("X509Token").getChild(
                        "Policy").getChild(
                            "RequireIssuerSerialReference") is not None:
                    key.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                else:
                    key.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                if elt.name == 'AsymmetricBinding':
                    key.includeRefList = True
                elif elt.name == 'SymmetricBinding':
                    key.includeRefList = False
                key.encryptedParts = self.buildParts(
                    token.getChild("Policy").getChild("EncryptedParts"))
                key.secondPassEncryptedParts = []
                policy.keys.append(key)
            if policy.blockEncryption is None:
                algorithm_suite = binding.getChild("AlgorithmSuite")
                if algorithm_suite is not None:
                    if algorithm_suite.getChild("Policy") is not None:
                        algorithm_policy_name = algorithm_suite.getChild(
                            "Policy").getChildren()[0].name
                        if "Basic128" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_AES128_CBC
                        elif "Basic192" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_AES192_CBC
                        elif "Basic256" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_AES256_CBC
                        elif "TripleDes" in algorithm_policy_name:
                            policy.blockEncryption = BLOCK_ENCRYPTION_3DES_CBC
                        if "Sha256" in algorithm_policy_name:
                            policy.digestAlgorithm = DIGEST_SHA256
                        else:
                            policy.digestAlgorithm = DIGEST_SHA1
                        if "Rsa15" in algorithm_policy_name:
                            policy.keyTransport = KEY_TRANSPORT_RSA_1_5
                        else:
                            policy.keyTransport = KEY_TRANSPORT_RSA_OAEP

        if elt.name.endswith("Tokens") and self.initiator:
            type = None
            index = None
            if elt.getChild("Policy").getChild("UsernameToken") is not None:
                token = Object()
                policy.tokens.append(token)
                type = 'token'
                index = len(policy.tokens) - 1
            if 'Endorsing' in elt.name and elt.getChild("Policy").getChild(
                    "X509Token") is not None:
                signature = Object()
                signature.signedParts = self.buildParts(
                    elt.getChild("Policy").getChild("SignedParts"))
                signature.signatureAlgorithm = SIGNATURE_RSA_SHA1
                if wsdl_policy.binding_type == 'TransportBinding':
                    signature.signedParts.append(('timestamp', ))
                else:
                    signature.signedParts.append(('primary_signature', ))
                    if policy.protectTokens:
                        signature.signedParts.append(('token', 'self'))
                # This would technically be the correct behavior, but WCF specifies that thumbprint references
                # are supported, but it can't use them for a primary signature.  Support for BinarySecurityTokens
                # is always required, so just use them
                #if elt.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireThumbprintReference") is not None:
                #    signature.keyReference = KEY_REFERENCE_FINGERPRINT
                #elif elt.getChild("Policy").getChild("X509Token").getChild("Policy").getChild("RequireIssuerSerialReference") is not None:
                #    signature.keyReference = KEY_REFERENCE_ISSUER_SERIAL
                #else:
                #    signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                signature.keyReference = KEY_REFERENCE_BINARY_SECURITY_TOKEN
                policy.signatures.append(signature)
                type = 'signature'
                index = len(policy.signatures) - 1
            if 'Signed' in elt.name and wsdl_policy.binding_type <> 'TransportBinding' and type is not None:
                self.baseSignedParts.append(('token', type, index))
            if 'Encrypted' in elt.name and wsdl_policy.binding_type <> 'TransportBinding' and type is not None:
                self.baseEncryptedParts.append(('token', type, index))

        if (elt.name == "Addressing" or elt.name
                == "UsingAddressing") and policy.addressing <> True:
            if self.optional == False:
                policy.addressing = True
            else:
                policy.addressing = None  # use what the user specifies

        if elt.name == "SignedParts":
            self.baseSignedParts.extend(self.buildParts(elt))
        elif elt.name == "EncryptedParts":
            self.baseEncryptedParts.extend(self.buildParts(elt))

        if elt.name == "Wss10":
            policy.wsse11 = False
        elif elt.name == "Wss11":
            policy.wsse11 = True
Esempio n. 40
0
 def __init__(self, method):
     Object.__init__(self)
     self.method = method
Esempio n. 41
0
 def __init__(self, node):
     Object.__init__(self)
     self.node = node
     self.data = None
     self.type = None
     self.text = None
Esempio n. 42
0
 def __init__(self, location):
     Object.__init__(self)
     self.location = location
Esempio n. 43
0
 def __init__(self, node):
     Object.__init__(self)
     self.node = node
     self.data = None
     self.type = None
     self.text = None