From 653d114f04a98dd7cc38c4f57a7cad78f28e50dc Mon Sep 17 00:00:00 2001 From: gpotter2 <gabriel@potter.fr> Date: Thu, 22 Jun 2017 10:19:02 +0200 Subject: [PATCH] [coverage] Several tests + coverage stability (#637) * Simplify construct_source_candidate_set * New tests: _CipherSuitesField and construct_source_candidate_set * Fix run_tests.bat * New nmap.uts tests * Add LLMNR tests * Add TLS failing tests * STP, linux + bpf random tests * Add DHCP6 tests --- .appveyor.yml | 2 +- .travis/test.sh | 3 + scapy/arch/linux.py | 2 +- scapy/arch/unix.py | 2 +- scapy/arch/windows/__init__.py | 2 +- scapy/layers/dhcp6.py | 8 +- scapy/layers/llmnr.py | 4 +- scapy/modules/nmap.py | 52 ++++++------ scapy/route6.py | 2 +- scapy/utils6.py | 4 +- test/bpf.uts | 14 ++++ test/configs/windows2.utsc | 3 +- test/linux.uts | 10 +++ test/mock_windows.uts | 2 +- test/nmap.uts | 32 +++++++ test/regression.uts | 148 +++++++++++++++++++++++++++++++-- test/run_tests.bat | 4 +- test/tls.uts | 16 ++++ test/x509.uts | 7 ++ 19 files changed, 264 insertions(+), 53 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 5c698a56..3a744d85 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -25,7 +25,7 @@ test_script: - set PATH="%APPVEYOR_BUILD_FOLDER%;C:\Program Files\Wireshark\;%PATH%" # Main unit tests - - "%PYTHON%\\python -m coverage run --parallel-mode bin\\UTscapy -f text -t test\\regression.uts -F -K mock_read_routes6_bsd || exit /b 42" + - "%PYTHON%\\python -m coverage run --parallel-mode bin\\UTscapy -f text -t test\\regression.uts -F -K mock_read_routes6_bsd -K ipv6 || exit /b 42" - 'del test\regression.uts' # Secondary and contrib unit tests diff --git a/.travis/test.sh b/.travis/test.sh index cb7a55f4..40d67ac1 100644 --- a/.travis/test.sh +++ b/.travis/test.sh @@ -62,6 +62,9 @@ then $SCAPY_SUDO ./run_tests -q -F -t bpf.uts $UT_FLAGS || exit $? fi UT_FLAGS+=" -K manufdb -K linux" +else + # IPv6 is not available yet on the linux machines (but is on OSX) + UT_FLAGS+=" -K ipv6" fi # Run all normal and contrib tests diff --git a/scapy/arch/linux.py b/scapy/arch/linux.py index 8d4d7d66..3b5eb8cf 100644 --- a/scapy/arch/linux.py +++ b/scapy/arch/linux.py @@ -335,7 +335,7 @@ def read_routes6(): cset = ['::1'] else: devaddrs = filter(lambda x: x[2] == dev, lifaddr) - cset = scapy.utils6.construct_source_candidate_set(d, dp, devaddrs, LOOPBACK_NAME) + cset = scapy.utils6.construct_source_candidate_set(d, dp, devaddrs) if len(cset) != 0: routes.append((d, dp, nh, dev, cset)) diff --git a/scapy/arch/unix.py b/scapy/arch/unix.py index f73ee70c..4a65495c 100644 --- a/scapy/arch/unix.py +++ b/scapy/arch/unix.py @@ -320,7 +320,7 @@ def read_routes6(): else: # Get possible IPv6 source addresses devaddrs = filter(lambda x: x[2] == dev, lifaddr) - cset = construct_source_candidate_set(destination, destination_plen, devaddrs, LOOPBACK_NAME) + cset = construct_source_candidate_set(destination, destination_plen, devaddrs) if len(cset): routes.append((destination, destination_plen, next_hop, dev, cset)) diff --git a/scapy/arch/windows/__init__.py b/scapy/arch/windows/__init__.py index 89a747d8..07aff9d7 100755 --- a/scapy/arch/windows/__init__.py +++ b/scapy/arch/windows/__init__.py @@ -684,7 +684,7 @@ def _append_route6(routes, dpref, dp, nh, iface, lifaddr): cset = ['::1'] else: devaddrs = filter(lambda x: x[2] == iface, lifaddr) - cset = scapy.utils6.construct_source_candidate_set(dpref, dp, devaddrs, scapy.consts.LOOPBACK_INTERFACE) + cset = scapy.utils6.construct_source_candidate_set(dpref, dp, devaddrs) if len(cset) == 0: return # APPEND (DESTINATION, NETMASK, NEXT HOP, IFACE, CANDIDATS) diff --git a/scapy/layers/dhcp6.py b/scapy/layers/dhcp6.py index 7887a8d3..2c97471f 100644 --- a/scapy/layers/dhcp6.py +++ b/scapy/layers/dhcp6.py @@ -1194,12 +1194,12 @@ class DHCPv6_am(AnsweringMachine): send_function = staticmethod(send) def usage(self): msg = """ -dhcp6d( dns="2001:500::1035", domain="localdomain, local", duid=None) - iface=conf.iface6, advpref=255, sntpservers=None, +DHCPv6_am.parse_options( dns="2001:500::1035", domain="localdomain, local", + duid=None, iface=conf.iface6, advpref=255, sntpservers=None, sipdomains=None, sipservers=None, nisdomain=None, nisservers=None, nispdomain=None, nispservers=None, - bcmcsdomain=None, bcmcsservers=None) + bcmcsdomains=None, bcmcsservers=None) debug : When set, additional debugging information is printed. @@ -1331,7 +1331,7 @@ dhcp6d( dns="2001:500::1035", domain="localdomain, local", duid=None) # Timeval from time import gmtime, strftime, mktime epoch = (2000, 1, 1, 0, 0, 0, 5, 1, 0) - delta = mktime(epoch) - mktime(gmtime(0)) + delta = mktime(epoch) - EPOCH timeval = time.time() - delta # Mac Address diff --git a/scapy/layers/llmnr.py b/scapy/layers/llmnr.py index 65ecad41..e4067061 100644 --- a/scapy/layers/llmnr.py +++ b/scapy/layers/llmnr.py @@ -50,8 +50,8 @@ class LLMNRResponse(LLMNRQuery): def _llmnr_dispatcher(x, *args, **kargs): cls = conf.raw_layer - if len(x) >= 3: - if (ord(x[4]) & 0x80): # Response + if len(x) >= 2: + if (ord(x[2]) & 0x80): # Response cls = LLMNRResponse else: # Query cls = LLMNRQuery diff --git a/scapy/modules/nmap.py b/scapy/modules/nmap.py index b879af7c..8ab7ab72 100644 --- a/scapy/modules/nmap.py +++ b/scapy/modules/nmap.py @@ -55,36 +55,32 @@ None. self.filename) except (IOError, TypeError): warning("Cannot open nmap database [%s]" % self.filename) + self.filename = None return self.base = [] name = None sig = {} - try: - for line in fdesc: - line = line.split('#', 1)[0].strip() - if not line: - continue - if line.startswith("Fingerprint "): - if name is not None: - self.base.append((name, sig)) - name = line[12:].strip() - sig = {} - continue - if line.startswith("Class "): - continue - line = _NMAP_LINE.search(line) - if line is None: - continue - test, values = line.groups() - sig[test] = dict(val.split('=', 1) for val in - (values.split('%') if values else [])) - if name is not None: - self.base.append((name, sig)) - except Exception: - self.base = None - warning("Cannot read nmap database [%s](new nmap version ?)" % - self.filename) + for line in fdesc: + line = line.split('#', 1)[0].strip() + if not line: + continue + if line.startswith("Fingerprint "): + if name is not None: + self.base.append((name, sig)) + name = line[12:].strip() + sig = {} + continue + if line.startswith("Class "): + continue + line = _NMAP_LINE.search(line) + if line is None: + continue + test, values = line.groups() + sig[test] = dict(val.split('=', 1) for val in + (values.split('%') if values else [])) + if name is not None: + self.base.append((name, sig)) fdesc.close() @@ -156,15 +152,15 @@ def nmap_sig(target, oport=80, cport=81, ucport=1): for snd, rcv in ans: if snd.sport == 5008: - res["PU"] = nmap_udppacket_sig(snd, rcv) + res["PU"] = (snd, rcv) else: test = "T%i" % (snd.sport - 5000) if rcv is not None and ICMP in rcv: warning("Test %s answered by an ICMP" % test) rcv = None - res[test] = nmap_tcppacket_sig(rcv) + res[test] = rcv - return res + return nmap_probes2sig(res) def nmap_probes2sig(tests): tests = tests.copy() diff --git a/scapy/route6.py b/scapy/route6.py index eef80393..3eed0c53 100644 --- a/scapy/route6.py +++ b/scapy/route6.py @@ -75,7 +75,7 @@ class Route6: # replace that unique address by the list of all addresses lifaddr = in6_getifaddr() devaddrs = filter(lambda x: x[2] == dev, lifaddr) - ifaddr = construct_source_candidate_set(prefix, plen, devaddrs, LOOPBACK_INTERFACE) + ifaddr = construct_source_candidate_set(prefix, plen, devaddrs) return (prefix, plen, gw, dev, ifaddr) diff --git a/scapy/utils6.py b/scapy/utils6.py index ace1db2e..7d1c62e4 100644 --- a/scapy/utils6.py +++ b/scapy/utils6.py @@ -22,7 +22,7 @@ from scapy.error import warning from functools import reduce -def construct_source_candidate_set(addr, plen, laddr, loiface): +def construct_source_candidate_set(addr, plen, laddr): """ Given all addresses assigned to a specific interface ('laddr' parameter), this function returns the "candidate set" associated with 'addr/plen'. @@ -58,7 +58,7 @@ def construct_source_candidate_set(addr, plen, laddr, loiface): cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr) elif in6_ismaddr(addr): if in6_ismnladdr(addr): - cset = [('::1', 16, loiface)] + cset = [('::1', 16, scapy.consts.LOOPBACK_INTERFACE)] elif in6_ismgladdr(addr): cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) elif in6_ismlladdr(addr): diff --git a/test/bpf.uts b/test/bpf.uts index 79c625c1..e78641ff 100644 --- a/test/bpf.uts +++ b/test/bpf.uts @@ -94,6 +94,20 @@ s.set_nonblock(set_flag=True) s.set_nonblock(set_flag=False) s.close() += L2bpfListenSocket - recv as nonblocking +~ needs_root + +s = L2bpfListenSocket() +s.set_nonblock(set_flag=True) + +def test_nonblock_recv(s): + for i in range(1, 100): + a = s.recv() + if not a: + return True + return False + +assert test_nonblock_recv(s) = L2bpfListenSocket - get_*() ~ needs_root diff --git a/test/configs/windows2.utsc b/test/configs/windows2.utsc index 445817e2..1cf7a6c5 100644 --- a/test/configs/windows2.utsc +++ b/test/configs/windows2.utsc @@ -10,6 +10,7 @@ "format": "html", "kw_ko": [ "combined_modes_ccm", - "mock_read_routes6_bsd" + "mock_read_routes6_bsd", + "appveyor_only" ] } diff --git a/test/linux.uts b/test/linux.uts index ed251ae4..23e1802a 100644 --- a/test/linux.uts +++ b/test/linux.uts @@ -53,3 +53,13 @@ for i in xrange(10): assert(os.system(IPTABLE_RULE % ('D', SECDEV_IP4)) == 0) assert(success) + += Supersocket _flush_fd +~ needs_root linux + +import select + +from scapy.arch.linux import _flush_fd +socket = conf.L2listen() +select.select([socket],[],[],2) +_flush_fd(socket.ins) diff --git a/test/mock_windows.uts b/test/mock_windows.uts index b7357456..ffab2ba7 100644 --- a/test/mock_windows.uts +++ b/test/mock_windows.uts @@ -67,7 +67,7 @@ ifIndex DestinationPrefix NextHop # Mocked in6_getifaddr() output mock_dev_from_index.side_effect = dev_from_index_custom # Random - mock_utils6cset.side_effect = lambda w,x,y,z: ["::1"] if w=="::" else ["fdbb:d995:ddd8:51fc::"] + mock_utils6cset.side_effect = lambda x,y,z: ["::1"] if x=="::" else ["fdbb:d995:ddd8:51fc::"] # Test the function routes = _read_routes6_post2008() for r in routes: diff --git a/test/nmap.uts b/test/nmap.uts index 7dfcadc4..6e3699ca 100644 --- a/test/nmap.uts +++ b/test/nmap.uts @@ -30,3 +30,35 @@ score, fprint = nmap_fp(conf.route.route('0.0.0.0')[2]) print score, fprint assert score > 0.5 assert fprint + += fingerprint test: to text +~ netaccess + +import re as re_ + +a = nmap_sig("www.secdev.org", 80, 81) +a +for x in nmap_sig2txt(a).split("\n"): + assert re_.match(r"\w{2,4}\(.*\)", x) + += nmap_udppacket_sig test: www.google.com +~ netaccess + +a = nmap_sig("www.google.com", ucport=80) +assert len(a) > 3 +assert len(a["PU"]) > 0 + ++ Nmap errors triggering + += Nmap base not available + +nmap_kdb.filename = "invalid" +nmap_kdb.reload() +assert nmap_kdb.filename == None + += Clear temp files +try: + os.remove('nmap-os-fingerprints') +except: + pass + diff --git a/test/regression.uts b/test/regression.uts index a4bd3bb6..1655caf7 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -207,6 +207,8 @@ except OSError: pass = Test temporary file creation +~ appveyor_only + tmpfile = get_temp_file(autoext=".ut") if WINDOWS: assert("scapy" in tmpfile and tmpfile.startswith('C:\\Users\\appveyor\\AppData\\Local\\Temp')) @@ -3464,6 +3466,9 @@ a.optcode == 6 and a.optlen == 0 and a.reqopts == [23,24] a=DHCP6OptOptReq(b'\x00\x06\x00\x08\x00\x01\x00\x02\x00\x03\x00\x04') a.optcode == 6 and a.optlen == 8 and a.reqopts == [1,2,3,4] += DHCP6OptOptReq - repr +a.show() + ############ ############ @@ -3502,6 +3507,9 @@ a.optcode == 8 and a.optlen == 2 and a.elapsedtime == 0 a=DHCP6OptElapsedTime(b'\x00\x08\x00\x02\x01\xa5') a.optcode == 8 and a.optlen == 2 and a.elapsedtime == 421 += DHCP6OptElapsedTime - Repr +a.show() + ############ ############ @@ -4245,6 +4253,11 @@ a.msgtype == 7 and a.trid == 0 a=UDP()/DHCP6_Reply() a.sport == 547 and a.dport == 546 += DHCP6_Reply - Answers + +assert not DHCP6_Reply(trid=0).answers(DHCP6_Request(trid=1)) +assert DHCP6_Reply(trid=1).answers(DHCP6_Request(trid=1)) + ############ ############ @@ -4326,6 +4339,17 @@ a = DHCP6_RelayForward(b'\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 a.msgtype == 12 and DHCP6OptRelayMsg in a and DHCP6OptClientId in a +############ +############ ++ Test DHCP6 Messages - DHCP6OptRelayMsg + += DHCP6OptRelayMsg - Basic Instantiation +str(DHCP6OptRelayMsg(optcode=37)) == b'\x00%\x00\x00' + += DHCP6OptRelayMsg - Basic Dissection +a=DHCP6OptRelayMsg(b'\x00\r\x00\x00') +assert a.optcode == 13 + ############ ############ + Test DHCP6 Messages - DHCP6_RelayReply @@ -4337,6 +4361,53 @@ str(DHCP6_RelayReply()) == b'\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ a=DHCP6_RelayReply(b'\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') a.msgtype == 13 and a.hopcount == 0 and a.linkaddr == "::" and a.peeraddr == "::" +############ +############ ++ Test DHCPv6_am + += DHCPv6_am - Basic Instantiaion +~ ipv6 netaccess +a = DHCPv6_am() +a.usage() + +a.parse_options(dns="2001:500::1035", domain="localdomain, local", duid=None, + iface=conf.iface6, advpref=255, sntpservers=None, + sipdomains=None, sipservers=None, + nisdomain=None, nisservers=None, + nispdomain=None, nispservers=None, + bcmcsdomains=None, bcmcsservers=None, + debug=1) + += DHCPv6_am - SOLICIT +~ ipv6 netaccess +req = IPv6(dst="::1")/UDP()/DHCP6(msgtype=1)/DHCP6OptClientId(duid=DUID_LLT()) +assert a.is_request(req) +res = a.make_reply(req) +assert not a.is_request(res) +assert res[DHCP6_Advertise] +assert res[DHCP6OptPref].prefval == 255 +assert res[DHCP6OptReconfAccept] +a.print_reply(req, res) + += DHCPv6_am - INFO-REQUEST +~ ipv6 netaccess +req = IPv6(dst="::1")/UDP()/DHCP6(msgtype=11)/DHCP6OptClientId(duid=DUID_LLT()) +assert a.is_request(req) +res = a.make_reply(req) +assert not a.is_request(res) +assert res[DHCP6_Reply] +assert "local" in res[DHCP6OptDNSDomains].dnsdomains +a.print_reply(req, res) + += DHCPv6_am - REQUEST +~ ipv6 netaccess +req = IPv6(dst="::1")/UDP()/DHCP6(msgtype=3)/DHCP6OptClientId(duid=DUID_LLT())/DHCP6OptServerId(duid=a.duid) +assert a.is_request(req) +res = a.make_reply(req) +assert not a.is_request(res) +assert res[UDP].dport == 546 +assert res[DHCP6_Solicit] +a.print_reply(req, res) ############ ############ @@ -5192,6 +5263,40 @@ wrpcap(filename, [IP()/UDP(), IPv6()/UDP()], linktype=DLT_RAW) packets = rdpcap(filename) assert(isinstance(packets[0], IP) and isinstance(packets[1], IPv6)) +############ +############ ++ LLMNR protocol + += Simple packet dissection +pkt = Ether(b'\x11\x11\x11\x11\x11\x11\x99\x99\x99\x99\x99\x99\x08\x00E\x00\x00(\x00\x01\x00\x00@\x11:\xa4\xc0\xa8\x00w\x7f\x00\x00\x01\x14\xeb\x14\xeb\x00\x14\x95\xcf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +assert pkt.sport == 5355 +assert pkt.dport == 5355 +assert pkt[LLMNRQuery].opcode == 0 + += Packet build / dissection +pkt = UDP(str(UDP()/LLMNRResponse())) +assert LLMNRResponse in pkt +assert pkt.qr == 1 +assert pkt.c == 0 +assert pkt.tc == 0 +assert pkt.z == 0 +assert pkt.rcode == 0 +assert pkt.qdcount == 0 +assert pkt.arcount == 0 +assert pkt.nscount == 0 +assert pkt.ancount == 0 + += Answers - building +a = UDP()/LLMNRResponse() +b = UDP()/LLMNRQuery() +assert a.answers(b) +assert not b.answers(a) + += Answers - dissecting +a = Ether(b'\xd0P\x99V\xdd\xf9\x14\x0cv\x8f\xfe(\x08\x00E\x00\x00(\x00\x01\x00\x00@\x11:\xa4\x7f\x00\x00\x01\xc0\xa8\x00w\x14\xeb\x14\xeb\x00\x14\x95\xcf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +b = Ether(b'\x14\x0cv\x8f\xfe(\xd0P\x99V\xdd\xf9\x08\x00E\x00\x00(\x00\x01\x00\x00@\x11:\xa4\xc0\xa8\x00w\x7f\x00\x00\x01\x14\xeb\x14\xeb\x00\x14\x15\xcf\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00') +assert b.answers(a) +assert not a.answers(b) ############ ############ @@ -5868,6 +5973,20 @@ ff02::%lo0/32 ::1 UC - test_netbsd_7_0() +############ +############ ++ STP tests + += STP - Basic Instantiation +assert str(STP()) == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x14\x00\x02\x00\x0f\x00' + += STP - Basic Dissection + +s = STP(b'\x00\x00\x00\x00\x00\x00\x00\x12\x13\x14\x15\x16\x17\x00\x00\x00\x00\x00\x00\xaa\xaa\xaa\xaa\xaa\xaa\x00\x00\x01\x00\x14\x00\x05\x00\x0f\x00') +assert s.rootmac == "12:13:14:15:16:17" +assert s.bridgemac == "aa:aa:aa:aa:aa:aa" +assert s.hellotime == 5 + ############ ############ + EAPOL class tests @@ -7788,14 +7907,27 @@ in6_isaddrllallservers("ff02::2") == True = in6_getscope() -in6_getscope("2001:db8::2807") == IPV6_ADDR_GLOBAL -in6_getscope("fec0::2807") == IPV6_ADDR_SITELOCAL -in6_getscope("fe80::2807") == IPV6_ADDR_LINKLOCAL -in6_getscope("ff02::2807") == IPV6_ADDR_LINKLOCAL -in6_getscope("ff0e::2807") == IPV6_ADDR_GLOBAL -in6_getscope("ff05::2807") == IPV6_ADDR_SITELOCAL -in6_getscope("ff01::2807") == IPV6_ADDR_LOOPBACK -in6_getscope("::1") == IPV6_ADDR_LOOPBACK +assert in6_getscope("2001:db8::2807") == IPV6_ADDR_GLOBAL +assert in6_getscope("fec0::2807") == IPV6_ADDR_SITELOCAL +assert in6_getscope("fe80::2807") == IPV6_ADDR_LINKLOCAL +assert in6_getscope("ff02::2807") == IPV6_ADDR_LINKLOCAL +assert in6_getscope("ff0e::2807") == IPV6_ADDR_GLOBAL +assert in6_getscope("ff05::2807") == IPV6_ADDR_SITELOCAL +assert in6_getscope("ff01::2807") == IPV6_ADDR_LOOPBACK +assert in6_getscope("::1") == IPV6_ADDR_LOOPBACK + += construct_source_candidate_set() + +dev_addresses = [('fe80::', IPV6_ADDR_LINKLOCAL, "linklocal"),('fec0::', IPV6_ADDR_SITELOCAL, "sitelocal"),('ff0e::', IPV6_ADDR_GLOBAL, "global")] + +assert construct_source_candidate_set("2001:db8::2807", 0, dev_addresses) == ["ff0e::"] +assert construct_source_candidate_set("fec0::2807", 0, dev_addresses) == ["fec0::"] +assert construct_source_candidate_set("fe80::2807", 0, dev_addresses) == ["fe80::"] +assert construct_source_candidate_set("ff02::2807", 0, dev_addresses) == ["fe80::"] +assert construct_source_candidate_set("ff0e::2807", 0, dev_addresses) == ["ff0e::"] +assert construct_source_candidate_set("ff05::2807", 0, dev_addresses) == ["fec0::"] +assert construct_source_candidate_set("ff01::2807", 0, dev_addresses) == ["::1"] +assert construct_source_candidate_set("::", 0, dev_addresses) == ["ff0e::"] = inet_pton() diff --git a/test/run_tests.bat b/test/run_tests.bat index fce8e76e..f11e866e 100644 --- a/test/run_tests.bat +++ b/test/run_tests.bat @@ -3,8 +3,8 @@ title UTscapy - All tests set MYDIR=%cd%\.. set PYTHONPATH=%MYDIR% if [%1]==[] ( - python "%MYDIR%\scapy\tools\UTscapy.py" -c configs\\windows2.utsc -T bpf.uts -o scapy_regression_test_%date:~6,4%_%date:~3,2%_%date:~0,2%.html + python "%MYDIR%\scapy\tools\UTscapy.py" -c configs\\windows2.utsc -T bpf.uts -T linux.uts -o scapy_regression_test_%date:~6,4%_%date:~3,2%_%date:~0,2%.html ) else ( python "%MYDIR%\scapy\tools\UTscapy.py" %@ ) -PAUSE +PAUSE \ No newline at end of file diff --git a/test/tls.uts b/test/tls.uts index 142534a6..0c087729 100644 --- a/test/tls.uts +++ b/test/tls.uts @@ -384,6 +384,13 @@ t1 and t2 and t3 and t4 ### Ciphers ### ############################################################################### ++ Test _CipherSuitesField + +a = _CipherSuitesField("test", None, {}) +assert a.i2repr(None, None) == "None" +assert isinstance(a.randval(), RandBin) +assert hash(a) == 8890308 + + Test RC4 = Crypto - RC4 stream cipher, encryption/decryption checks from RFC 6229 @@ -695,6 +702,9 @@ t2 = TLS(p2_sh, tls_session=t1.tls_session) t3 = TLS(p3_cert, tls_session=t1.tls_session) t4 = TLS(p4_certstat_ske_shd, tls_session=t1.tls_session) += Test TLS with bad data +a = TLS(b'\x00\x03\x03\x00\x03data') +assert a.haslayer(Raw) + Test TLS Record header = Reading test session - TLS Record header @@ -774,6 +784,8 @@ assert(sh.cipher == 0xc02f) assert(len(sh.ext) == 6) sh.ext[-1].protocols[-1].protocol == "http/1.1" += Useless function +assert not TLSHelloRequest().tls_session_update(None) + Test TLS Certificate = Reading test session - Certificate @@ -855,6 +867,10 @@ assert(isinstance(k, ClientECDiffieHellmanPublic)) assert(k.ecdh_Yclen == 65) assert(k.ecdh_Yc[:4] == b'\x04\xd2\x07\xce' and k.ecdh_Yc[-4:] == b'\xdc\x86[\xe7') += Bad data in TLSClientKeyExchange + +a = TLSClientKeyExchange(str(TLSClientKeyExchange(exchkeys="baddata"))) +assert a.haslayer(Raw) + Test TLS ChangeCipherSpec = Reading test session - ChangeCipherSpec diff --git a/test/x509.uts b/test/x509.uts index 1b3efbd0..6822e407 100644 --- a/test/x509.uts +++ b/test/x509.uts @@ -129,6 +129,13 @@ x.signatureValue == ASN1_BIT_STRING(b"6\xce\xdd\x01\xbdz\x1f\x89[\xc71i_\xb5\x90 = Cert class : Default X509_Cert from scratch str(X509_Cert(str(X509_Cert()))) == str(X509_Cert()) += Cert class : Error +try: + Cert("fail") +except: + assert True +else: + assert False ############ CRL class ############################################### -- GitLab