mirror of https://github.com/secdev/scapy.git
Merge pull request #1050 from guedou/Issue_#1048
Replace str() with raw()
This commit is contained in:
commit
eb5edb9eac
File diff suppressed because one or more lines are too long
|
@ -68,7 +68,8 @@
|
|||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from scapy.all import *"
|
||||
"from scapy.all import *\n",
|
||||
"load_layer('tls')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -79,7 +80,7 @@
|
|||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"keystr = open('raw_data/pki/ca_key.der', 'r').read()\n",
|
||||
"keystr = open('raw_data/pki/ca_key.der', 'rb').read()\n",
|
||||
"print repr(keystr)\n",
|
||||
"# (btw, you can hide the output of a cell by double-clicking on the left of the output)"
|
||||
]
|
||||
|
@ -106,7 +107,7 @@
|
|||
"source": [
|
||||
"v = privkey.version\n",
|
||||
"print 'The \\'version\\' stripped from any ASN.1 encoding is 0x%02x.' % v.val\n",
|
||||
"print 'The \\'version\\' field correspond to bytes %r.' % str(v)"
|
||||
"print 'The \\'version\\' field corresponds to bytes %r.' % raw(v)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -131,9 +132,9 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"print 'Original data: %r...' % keystr[:13]\n",
|
||||
"print 'New version bytes: %r' % str(privkey.version)\n",
|
||||
"print 'New modulus bytes: %r...' % str(privkey.modulus)[:6]\n",
|
||||
"print 'Rebuilt data: %r...' % str(privkey)[:13]"
|
||||
"print 'New version bytes: %r' % raw(privkey.version)\n",
|
||||
"print 'New modulus bytes: %r...' % raw(privkey.modulus)[:6]\n",
|
||||
"print 'Rebuilt data: %r...' % raw(privkey)[:13]"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -155,7 +156,7 @@
|
|||
"source": [
|
||||
"# Let's reload the original key, then let's load a certificate associated with it\n",
|
||||
"privkey = RSAPrivateKey(keystr)\n",
|
||||
"cert = X509_Cert(open('raw_data/pki/ca_cert.der', 'r').read())\n",
|
||||
"cert = X509_Cert(open('raw_data/pki/ca_cert.der', 'rb').read())\n",
|
||||
"cert.show()"
|
||||
]
|
||||
},
|
||||
|
@ -256,7 +257,7 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"# We can compute the RSA signature over the part of the certificate which is to be signed\n",
|
||||
"privkey.sign(str(cert.tbsCertificate))"
|
||||
"privkey.sign(raw(cert.tbsCertificate))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -325,12 +325,14 @@ class ASN1_BIT_STRING(ASN1_Object):
|
|||
super(ASN1_Object, self).__setattr__(name, value)
|
||||
def __repr__(self):
|
||||
if len(self.val) <= 16:
|
||||
return "<%s[%s] (%d unused bit%s)>" % (self.__dict__.get("name", self.__class__.__name__), self.val.decode(), self.unused_bits, "s" if self.unused_bits>1 else "")
|
||||
v = plain_str(self.val)
|
||||
return "<%s[%s] (%d unused bit%s)>" % (self.__dict__.get("name", self.__class__.__name__), v, self.unused_bits, "s" if self.unused_bits>1 else "")
|
||||
else:
|
||||
s = self.val_readable
|
||||
if len(s) > 20:
|
||||
s = s[:10] + b"..." + s[-10:]
|
||||
return "<%s[%s] (%d unused bit%s)>" % (self.__dict__.get("name", self.__class__.__name__), s.decode(), self.unused_bits, "s" if self.unused_bits>1 else "")
|
||||
v = plain_str(self.val)
|
||||
return "<%s[%s] (%d unused bit%s)>" % (self.__dict__.get("name", self.__class__.__name__), v, self.unused_bits, "s" if self.unused_bits>1 else "")
|
||||
def __str__(self):
|
||||
return self.val_readable
|
||||
def __bytes__(self):
|
||||
|
|
|
@ -278,8 +278,8 @@ p.wait_and_stop()
|
|||
|
||||
results = rdpcap("t2.pcap")
|
||||
|
||||
assert str(results[0]) == str(req)
|
||||
assert str(results[1]) == str(rpy)
|
||||
assert raw(results[0]) == raw(req)
|
||||
assert raw(results[1]) == raw(rpy)
|
||||
|
||||
os.unlink("t.pcap")
|
||||
os.unlink("t2.pcap")
|
||||
|
|
|
@ -136,7 +136,7 @@ b = six.moves.cPickle.dumps(a)
|
|||
c = six.moves.cPickle.loads(b)
|
||||
|
||||
assert c[IP].dst == "192.168.0.1"
|
||||
assert str(c) == str(a)
|
||||
assert raw(c) == raw(a)
|
||||
|
||||
= Usage test
|
||||
|
||||
|
@ -777,6 +777,10 @@ a = ASN1_BIT_STRING("test", "value")
|
|||
a
|
||||
assert raw(a) == b'test'
|
||||
|
||||
a = ASN1_BIT_STRING(b"\xff"*16, "value")
|
||||
a
|
||||
assert raw(a) == b'\xff'*16
|
||||
|
||||
= ASN1 - ASN1_SEQUENCE
|
||||
a = ASN1_SEQUENCE([ASN1_Object(1), ASN1_Object(0)])
|
||||
assert a.strshow() == '# ASN1_SEQUENCE:\n <ASN1_Object[1]>\n <ASN1_Object[0]>\n'
|
||||
|
|
|
@ -182,7 +182,7 @@ t2.tls_session.rcs.seq_num == 6 and t2.tls_session.wcs.seq_num == 4
|
|||
|
||||
+ Check TLS-related scapy internals
|
||||
|
||||
= Check TLS-related scapy internals - Checking str() harmlessness (with RC4)
|
||||
= Check TLS-related scapy internals - Checking raw() harmlessness (with RC4)
|
||||
t1.show()
|
||||
assert(t1.msg[0].load == b'These are horrendous parameters for a TLS session.\n')
|
||||
assert(t1.tls_session.rcs.seq_num == 6 and t1.tls_session.wcs.seq_num == 4)
|
||||
|
|
Loading…
Reference in New Issue