Skip to content

Fix IPsec + TLS 1.3 notebook + re-enable tests #3650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 89 additions & 30 deletions doc/notebooks/tls/notebook4_tls13.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@
"<img src=\"images/handshake_tls13.png\" alt=\"Handshake TLS 1.3\" width=\"400\"/>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dissecting the handshake"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"from scapy.all import *\n",
"load_layer('tls')"
"load_layer('tls')\n",
"conf.logLevel = logging.INFO"
]
},
{
Expand All @@ -28,6 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"# ClientHello\n",
"record1_str = open('raw_data/tls_session_13/01_cli.raw', 'rb').read()\n",
"record1 = TLS(record1_str)\n",
"sess = record1.tls_session\n",
Expand All @@ -40,38 +47,42 @@
"metadata": {},
"outputs": [],
"source": [
"record2_str = open('raw_data/tls_session_13/02_srv.raw', 'rb').read()\n",
"record2 = TLS(record2_str, tls_session=sess.mirror())\n",
"record2.show()"
"# The PFS relies on the ECDH secret below being kept from observers, and deleted right after the key exchange\n",
"from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey\n",
"\n",
"# Used in records 2-6 + 8\n",
"x25519_client_privkey = open('raw_data/tls_session_13/cli_key.raw', 'rb').read()\n",
"sess.tls13_client_privshares[\"x25519\"] = X25519PrivateKey.from_private_bytes(x25519_client_privkey)\n",
"\n",
"# Used in records 7 + 9\n",
"x25519_server_privkey = open('raw_data/tls_session_13/srv_key.raw', 'rb').read()\n",
"sess.tls13_server_privshare[\"x25519\"] = X25519PrivateKey.from_private_bytes(x25519_server_privkey)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"record3_str = open('raw_data/tls_session_13/03_cli.raw', 'rb').read()\n",
"record3 = TLS(record3_str, tls_session=sess.mirror())\n",
"record3.show()"
"# ServerHello + ChangeCipherSpec (middlebox compatibility)\n",
"record2_str = open('raw_data/tls_session_13/02_srv.raw', 'rb').read()\n",
"record2 = TLS(record2_str, tls_session=sess.mirror())\n",
"record2.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# The PFS relies on the ECDH secret below being kept from observers, and deleted right after the key exchange\n",
"#from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateNumbers\n",
"#from cryptography.hazmat.backends import default_backend\n",
"#secp256r1_client_privkey = open('raw_data/tls_session_13/cli_key.raw', 'rb').read()\n",
"#pubnum = sess.tls13_client_pubshares[\"secp256r1\"].public_numbers()\n",
"#privnum = EllipticCurvePrivateNumbers(pkcs_os2ip(secp256r1_client_privkey), pubnum)\n",
"#privkey = privnum.private_key(default_backend())\n",
"#sess.tls13_client_privshares[\"secp256r1\"] = privkey"
"# Encrypted Extensions\n",
"record3_str = open('raw_data/tls_session_13/03_srv.raw', 'rb').read()\n",
"record3 = TLS(record3_str, tls_session=sess)\n",
"record3.show()"
]
},
{
Expand All @@ -82,8 +93,9 @@
},
"outputs": [],
"source": [
"# Certificate\n",
"record4_str = open('raw_data/tls_session_13/04_srv.raw', 'rb').read()\n",
"record4 = TLS(record4_str, tls_session=sess.mirror())\n",
"record4 = TLS(record4_str, tls_session=sess)\n",
"record4.show()"
]
},
Expand All @@ -93,6 +105,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Certificate verify\n",
"record5_str = open('raw_data/tls_session_13/05_srv.raw', 'rb').read()\n",
"record5 = TLS(record5_str, tls_session=sess)\n",
"record5.show()"
Expand All @@ -104,11 +117,57 @@
"metadata": {},
"outputs": [],
"source": [
"record6_str = open('raw_data/tls_session_13/06_cli.raw', 'rb').read()\n",
"record6 = TLS(record6_str, tls_session=sess.mirror())\n",
"# Finished\n",
"record6_str = open('raw_data/tls_session_13/06_srv.raw', 'rb').read()\n",
"record6 = TLS(record6_str, tls_session=sess)\n",
"record6.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Client ChangeCipherSpec (middlebox compatibility) + Finished\n",
"record7_str = open('raw_data/tls_session_13/07_cli.raw', 'rb').read()\n",
"record7 = TLS(record7_str, tls_session=sess.mirror())\n",
"record7.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dissecting some data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Client application data\n",
"record8_str = open('raw_data/tls_session_13/08_cli.raw', 'rb').read()\n",
"record8 = TLS(record8_str, tls_session=sess)\n",
"record8.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# Server application data\n",
"record9_str = open('raw_data/tls_session_13/09_srv.raw', 'rb').read()\n",
"record9 = TLS(record9_str, tls_session=sess.mirror())\n",
"record9.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -122,21 +181,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
"pygments_lexer": "ipython3",
"version": "3.10.5"
}
},
"nbformat": 4,
Expand Down
Binary file modified doc/notebooks/tls/raw_data/tls_session_13/01_cli.raw
Binary file not shown.
Binary file modified doc/notebooks/tls/raw_data/tls_session_13/02_srv.raw
Binary file not shown.
Binary file removed doc/notebooks/tls/raw_data/tls_session_13/03_cli.raw
Binary file not shown.
Binary file not shown.
Binary file modified doc/notebooks/tls/raw_data/tls_session_13/04_srv.raw
Binary file not shown.
Binary file modified doc/notebooks/tls/raw_data/tls_session_13/05_srv.raw
Binary file not shown.
Binary file removed doc/notebooks/tls/raw_data/tls_session_13/06_cli.raw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed doc/notebooks/tls/raw_data/tls_session_13/07_srv.raw
Binary file not shown.
Binary file modified doc/notebooks/tls/raw_data/tls_session_13/08_cli.raw
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/notebooks/tls/raw_data/tls_session_13/cli_key.raw
Original file line number Diff line number Diff line change
@@ -1 +1 @@
�H�S��؝�`�6&]9���-vmB��N�
!"#$%&'()*+,-./0123456789:;<=>?
1 change: 1 addition & 0 deletions doc/notebooks/tls/raw_data/tls_session_13/srv_key.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��������������������������������
Loading