Beispiel #1
0
	sample = """<?xml version="1.0"?>
<library>
	<administrator>Héléna Utf8</administrator>
	<book>
		<isbn>89084-89089</isbn>
		<author>Philippe Kendall</author>
		<author>Mickaël Orangina</author>
		<title>Tropic thunder</title>
	</book>
</library>
"""

	for codec in [ 'xer.lite', 'xer.noprolog', 'xer.iso', 'xer.canonical' ]:
		print "%s %s %s" % (40*'=', codec, 40*'=')
		print "decoded with %s:" % codec
		(decoded, _) = CodecManager.decode(codec, sample)
		print decoded
		print
		print "re-encoded with %s:" % codec
		(reencoded, _) = CodecManager.encode(codec, decoded)
		print
		print reencoded
		print "re-decoded with %s:" % codec
		(redecoded, _) = CodecManager.decode(codec,reencoded)
		print redecoded
		assert(decoded == redecoded)
		print


	
	
Beispiel #2
0
		<title locale="es">No <i>habla</i> espagnol</title>
		<b:summary><![CDATA[This is a CDATA section <-> <-- this is a tie fighter]]></b:summary>
	</book>
</library>
   </soapenv:Body>
</soapenv:Envelope>
"""

    for codec in ['ds']:
        for sample in [sampleEnv]:
            print "%s %s %s" % (40 * '=', codec, 40 * '=')
            print "signed with %s:" % codec
            (signed, summary) = CodecManager.encode(codec, sample)
            print
            print "Summary: %s" % summary
            print
            print signed
            print
            print "verifying signature with %s:" % codec
            (output, summary) = CodecManager.decode(codec, signed)
            verified = output['message']
            signedBy = output['signedBy']
            print verified
            print
            assert (signedBy[0] == 'certificate')
            assert (signedBy[1].strip() == DEFAULT_SIGNING_CERTIFICATE.strip())
            print
            print "Summary: %s" % summary
            assert (signed == verified)
            print
Beispiel #3
0
# From gsm_map_with_ussd_string.pcap sample
	tcapBegin2 = \
	 "626a48042f3b46026b3a2838060700118605010101a02d602b80020780a109060704000001001302be1a2818060704000001010101a00da00b80099656051124006913f66c26a12402010102013b301c04010f040eaa180da682dd6c31192d36bbdd468007917267415827f2"

	dialoguePDU = \
	"601aa109060704000001001902be0d280ba009a00780059691214365"

	print (80*'-')
	print ("TCAP (ITU-T) Codec unit tests")
	print (80*'-')
	samples = [	
		('tcap', tcapBegin),
		('tcap', tcapBegin2),
		('tcap.DialoguePDU', dialoguePDU)
	]

	for pdu, s in samples:
		print ()
		print (80*'-')
		print ("Testing: %s" % s)
		s = binascii.unhexlify(s)
		(decoded, summary) = CodecManager.decode(pdu, s)
		print ("Decoded: %s\nSummary: %s" % (decoded, summary))
		(reencoded, summary) = CodecManager.encode(pdu, decoded)
		print ("Reencoded: %s\nSummary: %s" % (binascii.hexlify(reencoded), summary))
		print ("Original : %s" % binascii.hexlify(s))
#		assert(s == reencoded) # Cannot always work due to default value decoding/reencoding
		(redecoded, summary) = CodecManager.decode(pdu, reencoded)
		print ("Decoded: %s\nSummary: %s" % (redecoded, summary))
		assert(redecoded == decoded)
Beispiel #4
0
	print "Codec unit tests"
	print 80*'-'
	samples = [	
		('snmp.v1', trap1),
		('snmp.v1', getRequest1),
		('snmp.v1', getNextRequest1),
		('snmp.v1', setRequest1),
		('snmp.v1', getResponse1),
		('snmp.v2c', trap2c),
		('snmp.v2c', getRequest2c),
		('snmp.v2c', getNextRequest2c),
		('snmp.v2c', setRequest2c),
		('snmp.v2c', getResponse2c),
		('snmp.v2c', getResponse2cNoSuchObject),
	]

	for pdu, s in samples:
		print
		print 80*'-'
		print "Testing: %s" % s
		s = binascii.unhexlify(s)
		(decoded, summary) = CodecManager.decode(pdu, s)
		print "Decoded: %s\nSummary: %s" % (decoded, summary)
		(reencoded, summary) = CodecManager.encode(pdu, decoded)
		print "Reencoded: %s\nSummary: %s" % (binascii.hexlify(reencoded), summary)
		print "Original : %s" % binascii.hexlify(s)
		assert(s == reencoded)
		(redecoded, summary) = CodecManager.decode(pdu, reencoded)
		print "Decoded: %s\nSummary: %s" % (redecoded, summary)
		assert(redecoded == decoded)
	</book>
</library>
   </soapenv:Body>
</soapenv:Envelope>
"""
	
	for codec in [ 'ds' ]:
		for sample in [ sampleEnv ]:
			print "%s %s %s" % (40*'=', codec, 40*'=')
			print "signed with %s:" % codec
			(signed, summary) = CodecManager.encode(codec, sample)
			print
			print "Summary: %s" % summary
			print
			print signed
			print
			print "verifying signature with %s:" % codec
			(output, summary) = CodecManager.decode(codec,signed)
			verified = output['message']
			signedBy = output['signedBy']
			print verified
			print
			assert(signedBy[0] == 'certificate')
			assert(signedBy[1].strip() == DEFAULT_SIGNING_CERTIFICATE.strip())
			print
			print "Summary: %s" % summary
			assert(signed == verified)
			print
	
	
Beispiel #6
0
    print 80 * '-'
    print "TBCD Codec unit tests"
    print 80 * '-'
    samples = [
        ('\x21\xf3', "123"),
        ('\x21\x43', "1234"),
    ]

    for e, d in samples:
        print
        print 80 * '-'
        (encoded, _) = CodecManager.encode('tbcd', d)
        print "encoded: %s (%s)" % (repr(encoded), oo(encoded))
        assert (encoded == e)
        (decoded, _) = CodecManager.decode('tbcd', e)
        print "decoded: %s" % repr(decoded)
        assert (decoded == d)

    print
    print 80 * '-'
    print "GSM AddressString Codec unit tests"
    print 80 * '-'
    samples = [
        ('\x80\x21\xf3', {
            'digits': "123",
            'numberingPlanIndicator': 'unknown',
            'natureOfAddress': 'unknown'
        }),
        ('\x91\x21\x43', {
            'digits': "1234",
Beispiel #7
0
if __name__ == '__main__':
    import binascii

    def o(x):
        return binascii.unhexlify(x.replace(' ', ''))

    def oo(x):
        return binascii.hexlify(x)

    tpduSmsDeliver = "04039177f70010901091215571406fd3373b2c4fcf41311828168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1584c36a3d500"

    print(80 * '-')
    print("SMS TPDU SM-TL Codec unit tests")
    print(80 * '-')
    samples = [
        ('sms.tpdu.SMS-DELIVER', tpduSmsDeliver),
    ]

    for pdu, s in samples:
        print()
        print(80 * '-')
        print("Testing: %s" % s)
        s = o(s)
        (decoded, summary) = CodecManager.decode(pdu, s)
        print("Decoded: %s\nSummary: %s" % (decoded, summary))
        (reencoded, summary) = CodecManager.encode(pdu, decoded)
        print("Reencoded: %s\nSummary: %s" % (oo(reencoded), summary))
        print("Original : %s" % oo(s))
        assert (s == reencoded)
Beispiel #8
0
	sample = """<?xml version="1.0"?>
<library>
	<administrator>Héléna Utf8</administrator>
	<book>
		<isbn>89084-89089</isbn>
		<author>Philippe Kendall</author>
		<author>Mickaël Orangina</author>
		<title>Tropic thunder</title>
	</book>
</library>
"""

	for codec in [ 'xer.lite', 'xer.noprolog', 'xer.iso', 'xer.canonical' ]:
		print ("%s %s %s" % (40*'=', codec, 40*'='))
		print ("decoded with %s:" % codec)
		(decoded, _) = CodecManager.decode(codec, sample)
		print (decoded)
		print ()
		print ("re-encoded with %s:" % codec)
		(reencoded, _) = CodecManager.encode(codec, decoded)
		print ()
		print (reencoded)
		print ("re-decoded with %s:" % codec)
		(redecoded, _) = CodecManager.decode(codec,reencoded)
		print (redecoded)
		assert(decoded == redecoded)
		print ()


	
	
Beispiel #9
0

if __name__ == '__main__':
	import binascii
	def o(x):
		return binascii.unhexlify(x.replace(' ', ''))

	def oo(x):
		return binascii.hexlify(x)
	
	tpduSmsDeliver = "04039177f70010901091215571406fd3373b2c4fcf41311828168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1582c168bc562b1584c36a3d500"
	
	print 80*'-'
	print "SMS TPDU SM-TL Codec unit tests"
	print 80*'-'
	samples = [	
		('sms.tpdu.SMS-DELIVER', tpduSmsDeliver),
	]

	for pdu, s in samples:
		print
		print 80*'-'
		print "Testing: %s" % s
		s = o(s)
		(decoded, summary) = CodecManager.decode(pdu, s)
		print "Decoded: %s\nSummary: %s" % (decoded, summary)
		(reencoded, summary) = CodecManager.encode(pdu, decoded)
		print "Reencoded: %s\nSummary: %s" % (oo(reencoded), summary)
		print "Original : %s" % oo(s)
		assert(s == reencoded)
Beispiel #10
0
	
	print 80*'-'
	print "TBCD Codec unit tests"
	print 80*'-'
	samples = [
		('\x21\xf3', "123"),
		('\x21\x43', "1234"),
	]

	for e, d in samples:
		print
		print 80*'-'
		(encoded, _) = CodecManager.encode('tbcd', d)
		print "encoded: %s (%s)" % (repr(encoded), oo(encoded))
		assert(encoded == e)
		(decoded, _) = CodecManager.decode('tbcd', e)
		print "decoded: %s" % repr(decoded)
		assert(decoded == d)

	print
	print 80*'-'
	print "GSM AddressString Codec unit tests"
	print 80*'-'
	samples = [
		('\x80\x21\xf3', { 'digits': "123", 'numberingPlanIndicator': 'unknown', 'natureOfAddress': 'unknown' }),
		('\x91\x21\x43', { 'digits': "1234", 'numberingPlanIndicator': 'isdn', 'natureOfAddress': 'international' }),
		('\x91\x09\x56\x43\x21\x78', { 'digits': "9065341287", 'numberingPlanIndicator': 'isdn', 'natureOfAddress': 'international' }),
	]

	for e, d in samples:
		print
Beispiel #11
0
	sendRoutingInfoForSMArg = \
	"30158007910026151101008101ff820791261010101010"
	
	print (80*'-')
	print ("MAP (Phase 2+) Codec unit tests")
	print (80*'-')
	samples = [	
		('RoutingInfoForSM-Arg', sendRoutingInfoForSMArg),
	]

	for pdu, s in samples:
		print ()
		print (80*'-')
		print ("Testing: %s" % s)
		s = binascii.unhexlify(s)
		(decoded, summary) = CodecManager.decode('map.%s' % pdu, s)
		print ("Decoded: %s\nSummary: %s" % (decoded, summary))
		(reencoded, summary) = CodecManager.encode('map.%s' % pdu, decoded)
		print ("Reencoded: %s\nSummary: %s" % (binascii.hexlify(reencoded), summary))
		print ("Original : %s" % binascii.hexlify(s))
		assert(s == reencoded)
	

	print ()
	print (80*'-')
	print ("Direct encoding testing")
	# Explicit encoding test
	sriSmRes = { 
		'imsi': '\x91\x10\x32\x54',
		'locationInfoWithLMSI': {
			'lmsi': '\x01\x02\x03\x04',
Beispiel #12
0
    def run(self):
        buf = ''
        while not self._stopEvent.isSet():
            try:
                r, w, e = select.select([self._socket], [], [], 0.1)
                if self._socket in r:
                    read = self._socket.recv(1024 * 1024)
                    buf += read

                    # In RTSP/1.0, content-length is mandatory if there is a body.
                    decodedMessage = None
                    try:
                        self._probe.getLogger().debug(
                            'data received (bytes %d), decoding attempt...' %
                            len(buf))
                        decodedMessage, summary = CodecManager.decode(
                            'rtsp.response',
                            buf,
                            lower_case=(not self._probe['strict_mode']))
                    except Exception as e:
                        # Incomplete message. Wait for more data.
                        self._probe.getLogger().debug('unable to decode: %s' %
                                                      str(e))
                        pass

                    if decodedMessage:
                        fromAddr = "%s:%s" % self._socket.getpeername()

                        # System log, always
                        self._probe.logReceivedPayload(summary, buf, fromAddr)

                        # Should we check the cseq locally ?
                        if self._cseq is None:
                            # Let the user check the cseq
                            self._probe.getLogger().info(
                                'message decoded, enqueuing without checking CSeq...'
                            )
                            self._probe.triEnqueueMsg(decodedMessage, fromAddr)
                            self._stopEvent.set()
                        else:
                            # Conditional enqueing - let's found the cseq
                            cseq = None
                            for k, v in decodedMessage['headers'].items():
                                # Stop on the first cseq header found
                                if k.lower() == 'cseq':
                                    cseq = v
                                    break
                            if cseq == self._cseq:
                                self._probe.getLogger().info(
                                    'message decoded, CSeq matched, enqueuing...'
                                )
                                self._probe.triEnqueueMsg(
                                    decodedMessage, fromAddr)
                                self._stopEvent.set()
                            else:
                                self._probe.getLogger().warning(
                                    'Invalid CSeq received. Not enqueuing, ignoring message'
                                )
                                buf = ''
                                decodedMessage = None
                                # Wait for a possible next message...

                    elif not read:
                        # Message not decoded, nothing to read anymore.
                        raise Exception(
                            'Incomplete message received, stream interrupted')
                        # .. and we should disconnect, too...

            except Exception as e:
                self._probe.getLogger().error(
                    'Error while waiting for rtsp response: %s' % str(e))
                self._stopEvent.set()
        if not self._probe['maintain_connection']:
            # Well, maintain connection in RTSP ?
            self._probe.disconnect()
Beispiel #13
0
	sendRoutingInfoForSMArg = \
	"30158007910026151101008101ff820791261010101010"
	
	print 80*'-'
	print "MAP (Phase 2+) Codec unit tests"
	print 80*'-'
	samples = [	
		('RoutingInfoForSM-Arg', sendRoutingInfoForSMArg),
	]

	for pdu, s in samples:
		print
		print 80*'-'
		print "Testing: %s" % s
		s = binascii.unhexlify(s)
		(decoded, summary) = CodecManager.decode('map.%s' % pdu, s)
		print "Decoded: %s\nSummary: %s" % (decoded, summary)
		(reencoded, summary) = CodecManager.encode('map.%s' % pdu, decoded)
		print "Reencoded: %s\nSummary: %s" % (binascii.hexlify(reencoded), summary)
		print "Original : %s" % binascii.hexlify(s)
		assert(s == reencoded)
	

	print
	print 80*'-'
	print "Direct encoding testing"
	# Explicit encoding test
	sriSmRes = { 
		'imsi': '\x91\x10\x32\x54',
		'locationInfoWithLMSI': {
			'lmsi': '\x01\x02\x03\x04',