Oct 12

Lecture Overview

Network Protocols

Network Protocols.

TCP/IP and the kernel provide an API where we specify the destination address, destination port, and an arbitrary data payload. It is up to the individual program like our python program to format the bits in the payload so that the recipient understands what we are trying to send. A network protocol is a set of rules for how messages are encoded into bits and what their meaning is. A network protocol consists of two things. A syntax which is the set of rules for how messages are encoded to bits and a semantics which are the meanings of each message.

For example, SMTP is the protocol for sending email. It is instructive to glance through the example: the lines starting with S are what is sent by the server and the lines starting with C are what is sent by the client. Each line is a single message and will usually be sent in a single packet. The protocol rules list the syntax of each message and what each message means. In python, the smtplib module implements the SMTP protocol.

Another important protocol is DNS. The kernel and TCP/IP only deal with addresses, not names like www.math.uic.edu. DNS is the protocol used to lookup names to addresses. Again DNS lookup is the responsibility of the program like our python program, but in python (and most languages) we can take advantage of modules to do it for us. Indeed, the smtplib module will first send a DNS packet requesting the address before sending the actual SMTP packets.

HTTP

The main protocol of the internet is HTTP. It is a document/resource request-response protocol.

HTTPS

Recall the encryption schemes I talked about a few weeks ago:

HTTPS is a protocol which specifies that the bits transmitted in the payload are AES encrypted HTTP requests and responses (the encryption part is specified under the name SSL). But that leaves open the question of how does Firefox and the web server obtain the shared secret key for AES? The danger is what we call a man in the middle attack. Say Alice is browsing with Firefox and Eve is attempting to eavesdrop on the transmitted messages. If Eve can intercept the packets between Firefox and the web server, she can modify them in the following way. When Alice and the web-server are initially transmitting the AES secret key, Eve can intercept Alice's packets and pretend to be the web-server. Eve can then send packets to the actual web server pretending to be Alice. So Alice sets up an AES secret key she shares with Eve, and Eve sets up an AES secret key she shares with the webserver. Now whenever a HTTPS request comes from Alice, Eve decrypts it using the shared secret with Alice and then re-encrypts it with the shared secret Eve has with the web-server. In this way Eve sees the contents of all messages.

SSL protects against this attack via the following technique:

Exercises

with urlopen(...) as webpage:
    reader = csv.reader(webpage.read().decode('utf-8').splitlines())

This decodes the webpage as UTF-8, splits it into lines, and passes that result to the csv reader function.