Closed tintinweb closed 9 years ago
Nice addition. Allows fined grain fuzzing of client side certificate handling also I guess ;)?
Scapy's built-in fuzzer is pretty dumb but with some nice tweaks and as long as the asn.1 fields support it it should work :)
I get unittest failures on this. Looks like input DER cert might be invalid. Haven't checked yet, but might be quick fix.
======================================================================
ERROR: test_tls_certificate_x509 (tests.test_ssl_tls.TestTLSCertificate)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/amoneger/projects/scapy-ssl_tls-upstream/tests/test_ssl_tls.py", line 172, in test_tls_certificate_x509
pkt = tls.TLSRecord()/tls.TLSHandshake()/tls.TLSCertificateList(certificates=[tls.TLSCertificate(data=x509.X509Cert(self.der_cert))])
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/base_classes.py", line 198, in __call__
i.__init__(*args, **kargs)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/packet.py", line 84, in __init__
self.dissect(_pkt)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/packet.py", line 594, in dissect
s = self.do_dissect(s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1packet.py", line 24, in do_dissect
return self.ASN1_root.dissect(self, x)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 222, in dissect
s = obj.dissect(pkt,s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 222, in dissect
s = obj.dissect(pkt,s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 222, in dissect
s = obj.dissect(pkt,s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 98, in dissect
v,s = self.m2i(pkt, s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 65, in m2i
return self.ASN1_tag.get_codec(pkt.ASN1_codec).safedec(x, context=self.context)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 180, in safedec
return cls.dec(s, context, safe=True)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 169, in dec
return cls.do_dec(s, context, safe)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 361, in do_dec
return cls.asn1_object(".".join([str(k) for k in lst])), t
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 121, in asn1_object
return cls.tag.asn1_object(val)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/asn1.py", line 96, in asn1_object
return self._asn1_obj(val)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/asn1.py", line 296, in __init__
val = conf.mib._oid(val)
AttributeError: 'Conf' object has no attribute 'mib'
======================================================================
ERROR: test_tls_certificate_x509_pubkey (tests.test_ssl_tls.TestTLSCertificate)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/amoneger/projects/scapy-ssl_tls-upstream/tests/test_ssl_tls.py", line 193, in test_tls_certificate_x509_pubkey
pkt = tls.TLSRecord()/tls.TLSHandshake()/tls.TLSCertificateList(certificates=[tls.TLSCertificate(data=x509.X509Cert(self.der_cert))])
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/base_classes.py", line 198, in __call__
i.__init__(*args, **kargs)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/packet.py", line 84, in __init__
self.dissect(_pkt)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/packet.py", line 594, in dissect
s = self.do_dissect(s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1packet.py", line 24, in do_dissect
return self.ASN1_root.dissect(self, x)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 222, in dissect
s = obj.dissect(pkt,s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 222, in dissect
s = obj.dissect(pkt,s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 222, in dissect
s = obj.dissect(pkt,s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 98, in dissect
v,s = self.m2i(pkt, s)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1fields.py", line 65, in m2i
return self.ASN1_tag.get_codec(pkt.ASN1_codec).safedec(x, context=self.context)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 180, in safedec
return cls.dec(s, context, safe=True)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 169, in dec
return cls.do_dec(s, context, safe)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 361, in do_dec
return cls.asn1_object(".".join([str(k) for k in lst])), t
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/ber.py", line 121, in asn1_object
return cls.tag.asn1_object(val)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/asn1.py", line 96, in asn1_object
return self._asn1_obj(val)
File "/Users/amoneger/.virtualenvs/scapy-ssl_tls-upstream/lib/python2.7/site-packages/scapy/asn1/asn1.py", line 296, in __init__
val = conf.mib._oid(val)
AttributeError: 'Conf' object has no attribute 'mib'
im on it :) thx
fixed with 8e65b57805fe68ceaf08f2fc2ef0d1e4877d88ab - unittest runs, but there are some import error warnings atm. will fix that later.
test_tls_certificate_x509 (test_ssl_tls.TestTLSCertificate) ... ok
test_tls_certificate_x509_pubkey (test_ssl_tls.TestTLSCertificate) ... ok
test_all_hooks_are_called_when_defined (test_ssl_tls.TestToRaw) ... ok
test_invalid_tls_session_context_raises_error (test_ssl_tls.TestToRaw) ... ok
test_record_payload_is_identical_to_raw_payload (test_ssl_tls.TestToRaw) ... ok
test_tls_record_header_is_updated_when_output (test_ssl_tls.TestToRaw) ... ok
test_unsupported_layer_raises_error (test_ssl_tls.TestToRaw) ... ok
TLSCertificate() payload was not dissected and ended up being raw data. Luckily scapy provides an ASN1.BER parser with definitions for x509Cert that we can try to apply in order to nicely show certificate fields. This also allows us to easily pull the pubkey from the certificate without having to look for certain ASN.1 sequences which should be less error prone as long as the received raw certificate data is complete. If it is not complete x509Cert type will resolve to Raw(), therefore we only gain information and do not lose anything.
TLSCertificate.data is now of type x509Cert but can be accessed as if it was a raw string if required.
Also let the old pubkey extraction code in place as a fallback as this method should also be able to extract the pubkey from incomplete/erroneous and usually too short ASN.1 sequences (recv. buffer!).
old output:
new output: