{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# The lack of PFS: a danger to privacy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from scapy.all import *\n",
    "load_layer('tls')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "record1_str = open('raw_data/tls_session_compromised/01_cli.raw', 'rb').read()\n",
    "record1 = TLS(record1_str)\n",
    "record1.msg[0].show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "record2_str = open('raw_data/tls_session_compromised/02_srv.raw', 'rb').read()\n",
    "record2 = TLS(record2_str, tls_session=record1.tls_session.mirror())\n",
    "record2.msg[0].show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Suppose we possess the private key of the server\n",
    "# Try registering it to the session\n",
    "#key = PrivKey('raw_data/pki/srv_key.pem')\n",
    "#record2.tls_session.server_rsa_key = key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "record3_str = open('raw_data/tls_session_compromised/03_cli.raw', 'rb').read()\n",
    "record3 = TLS(record3_str, tls_session=record2.tls_session.mirror())\n",
    "record3.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "record4_str = open('raw_data/tls_session_compromised/04_srv.raw', 'rb').read()\n",
    "record4 = TLS(record4_str, tls_session=record3.tls_session.mirror())\n",
    "record4.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "record5_str = open('raw_data/tls_session_compromised/05_cli.raw', 'rb').read()\n",
    "record5 = TLS(record5_str, tls_session=record4.tls_session.mirror())\n",
    "record5.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
