Replace str() with raw(), and Python3 modifications

This commit is contained in:
Guillaume Valadon 2018-01-13 19:26:43 +01:00
parent 74e9b4832d
commit ec088fb606
1 changed files with 9 additions and 8 deletions

View File

@ -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))"
]
},
{