48
Application Application Layer Layer CE-143 CE-143 CNE-0802 CNE-0802

Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Embed Size (px)

Citation preview

Page 1: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Application LayerApplication Layer

CE-143CE-143

CNE-0802CNE-0802

Page 2: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Applications and application-layer Applications and application-layer protocolsprotocols

Application: communicating, Application: communicating, distributed processesdistributed processes e.g., e-mail, Web, P2P file e.g., e-mail, Web, P2P file

sharing, instant messaging sharing, instant messaging running in end systems running in end systems

(hosts) (hosts) exchange messages to exchange messages to

implement applicationimplement application

Application-layer protocolsApplication-layer protocols one “piece” of an appone “piece” of an app define messages exchanged define messages exchanged

by apps and actions takenby apps and actions taken use communication services use communication services

provided by lower layer provided by lower layer protocols (TCP, UDP)protocols (TCP, UDP)

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

Page 3: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

App-layer protocol App-layer protocol definesdefines

Types of messages Types of messages exchangedexchanged, eg, request , eg, request & response messages& response messages

Syntax of messageSyntax of message types: what fields in types: what fields in messages & how fields messages & how fields are delineatedare delineated

Semantics of the Semantics of the fieldsfields, ie, meaning of , ie, meaning of information in fieldsinformation in fields

RulesRules for when and how for when and how processes send & processes send & respond to messagesrespond to messages

Public-domain protocols:Public-domain protocols: defined in RFCsdefined in RFCs allows for allows for

interoperabilityinteroperability eg, HTTP, SMTPeg, HTTP, SMTP

Proprietary protocols:Proprietary protocols: eg, KaZaAeg, KaZaA

Page 4: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Client-server paradigmClient-server paradigmTypical network app has two Typical network app has two

pieces: pieces: clientclient and and serverserverapplicatio

ntransportnetworkdata linkphysical

application

transportnetworkdata linkphysical

ClientClient:: initiates contact with server initiates contact with server

(“speaks first”)(“speaks first”) typically requests service from typically requests service from

server, server, Web: client implemented in Web: client implemented in

browser; e-mail: in mail readerbrowser; e-mail: in mail reader

request

reply

ServerServer:: provides requested service to clientprovides requested service to client e.g., Web server sends requested Web e.g., Web server sends requested Web

page, mail server delivers e-mailpage, mail server delivers e-mail

Page 5: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

What transport service does an What transport service does an app need?app need?

Data lossData loss some apps (e.g., audio) some apps (e.g., audio)

can tolerate some losscan tolerate some loss other apps (e.g., file other apps (e.g., file

transfer, telnet) transfer, telnet) require 100% reliable require 100% reliable data transferdata transfer

TimingTiming some apps (e.g., some apps (e.g.,

Internet telephony, Internet telephony, interactive games) interactive games) require low delay to require low delay to be “effective”be “effective”

BandwidthBandwidth some apps (e.g., some apps (e.g.,

multimedia) multimedia) require minimum require minimum amount of amount of bandwidth to be bandwidth to be “effective”“effective”

other apps (“elastic other apps (“elastic apps”) make use of apps”) make use of whatever whatever bandwidth they get bandwidth they get

Page 6: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Aplikasi InternetAplikasi InternetDNS, WEB, DNS, WEB,

EMAILEMAIL

Page 7: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Domain Name Domain Name SystemSystem(DNS)(DNS)

Page 8: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

DNS: Domain Name SystemDNS: Domain Name System

Internet hosts:Internet hosts: IP address (32 bit) - used for addressing IP address (32 bit) - used for addressing

datagramsdatagrams ““name”, e.g., ww.yahoo.com - used by name”, e.g., ww.yahoo.com - used by

humanshumans

DNS:DNS: provides translation between host provides translation between host name and IP addressname and IP address distributed databasedistributed database implemented in implemented in

hierarchy of many hierarchy of many name serversname servers Distributed for scalability & reliabilityDistributed for scalability & reliability

Page 9: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

DNS Services DNS Services

Hostname to IP address translationHostname to IP address translation Host aliasingHost aliasing

Canonical and alias namesCanonical and alias names Mail server aliasingMail server aliasing Load distributionLoad distribution

Replicated Web servers: set of IP Replicated Web servers: set of IP addresses for one canonical nameaddresses for one canonical name

Page 10: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

requesting hostCe1.poltek.ac.id

www.google.com

root DNS server

local DNS serverdns.poltek.ac.id

1

23

4

5

6

authoritative DNS serverNs1.google.com

78

TLD DNS server

DNS DNS InfrastructureInfrastructure Host at Host at

cis.poly.edu wants cis.poly.edu wants IP address for IP address for gaia.cs.umass.edugaia.cs.umass.edu

Infrastructure:Infrastructure: Client resolverClient resolver Local DNS serverLocal DNS server Authoritative DNS Authoritative DNS

ServerServer Root DNS ServerRoot DNS Server Top-Level Domain Top-Level Domain

DNS ServerDNS Server

Page 11: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Distributed, Hierarchical Distributed, Hierarchical DatabaseDatabase

Root servers and TLD servers typically do Root servers and TLD servers typically do not contain hostname to IP mappings; not contain hostname to IP mappings; they contain mappings for locating they contain mappings for locating authoritative servers. authoritative servers.

Root DNS Servers

com DNS servers ca DNS servers id DNS servers

co.idDNS servers

ac.idDNS servers

yahoo.comDNS servers

amazon.comDNS servers

ucalgary.caDNS servers

TLDServers

usask.caDNS servers

Page 12: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

requesting hostCe1.poltek.ac.id

www.google.com

root DNS server

local DNS serverNs1.poltek.ac.id

1

2

45

6

authoritative DNS serverNs1.google.com

7

8

TLD DNS server

3

Recursive Recursive queriesqueriesrecursive queryrecursive query::

puts burden of puts burden of name resolution name resolution on contacted on contacted name servername server

heavy load?heavy load?

iterated queryiterated query:: contacted server contacted server

replies with name replies with name of server to of server to contactcontact

““I don’t know this I don’t know this name, but ask name, but ask this server”this server”

Page 13: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

DNS recordsDNS recordsDNSDNS:: distributed db storing resource records distributed db storing resource records (RR)(RR)

Type=NSType=NS namename is domain (e.g. is domain (e.g.

foo.com)foo.com) valuevalue is IP address of is IP address of

authoritative name server authoritative name server for this domainfor this domain

RR format: (name, value, type, ttl)

Type=AType=A namename is hostname is hostname valuevalue is IP address is IP address

Type=CNAMEType=CNAME namename is alias name for some is alias name for some

“cannonical” (the real) name“cannonical” (the real) name

www.ibm.com www.ibm.com is reallyis really servereast.backup2.ibm.comservereast.backup2.ibm.com

valuevalue is cannonical name is cannonical name

Type=MXType=MX valuevalue is name of mailserver is name of mailserver

associated with associated with namename

Page 14: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

DNS protocol, messagesDNS protocol, messagesDNS protocolDNS protocol : : queryquery and and replyreply messages, both with same messages, both with same message formatmessage format

msg headermsg header identificationidentification:: 16 bit 16 bit

# for query, reply to # for query, reply to query uses same #query uses same #

flagsflags:: query or replyquery or reply recursion desired recursion desired recursion availablerecursion available reply is reply is

authoritativeauthoritative

Page 15: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

DNS protocol, messagesDNS protocol, messages

Name, type fields for a query

RRs in reponseto query

records forauthoritative servers

additional “helpful”info that may be used

Page 16: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

DNS Server Configuration DNS Server Configuration (Sample)(Sample)

; zone file for example.com $TTL 2d ; 172800 secs ; zone file for example.com $TTL 2d ; 172800 secs default TTL for zone @ IN SOA ns1.example.com. default TTL for zone @ IN SOA ns1.example.com. hostmaster.example.com. ( hostmaster.example.com. (

2003080800 ; 2003080800 ;

se = serial number 12h ; se = serial number 12h ;

ref = refresh 15m ; ref = refresh 15m ;

ret = update retry 3w ; ret = update retry 3w ;

ex = expiry 3h ; ex = expiry 3h ;

min = minimum ) min = minimum )

IN NS ns1.example.com. IN NS ns1.example.com.

IN MX 10 mail.example.net. IN MX 10 mail.example.net.

joe IN A 192.168.254.3 joe IN A 192.168.254.3

www IN CNAME joe www IN CNAME joe

Page 17: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Security Issue on DNSSecurity Issue on DNS

DNS is plain text DNS is plain text easy to capture easy to capture No security mechanism to secure No security mechanism to secure

requestrequest Even easy to do Name Server Even easy to do Name Server

HijackingHijacking It is vulnerable for Buffer Overflow It is vulnerable for Buffer Overflow

AttackAttack

Page 18: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

World Wide WebWorld Wide Web

Page 19: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

WWW BackgroundWWW Background

1989-1990 – Tim Berners-Lee invents the 1989-1990 – Tim Berners-Lee invents the World Wide Web at CERNWorld Wide Web at CERN Means for transferring text and graphics Means for transferring text and graphics

simultaneouslysimultaneously Client/Server data transfer protocolClient/Server data transfer protocol

Communication via application level protocolCommunication via application level protocol System ran on top of standard networking infrastructureSystem ran on top of standard networking infrastructure

Text mark up languageText mark up language Not invented by Bernes-LeeNot invented by Bernes-Lee Simple and easy to useSimple and easy to use Requires a client application to render text/graphicsRequires a client application to render text/graphics

Page 20: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

WWW ComponentsWWW Components

Structural ComponentsStructural Components Clients/browsers – to dominant implementationsClients/browsers – to dominant implementations Servers – run on sophisticated hardwareServers – run on sophisticated hardware Caches – many interesting implementationsCaches – many interesting implementations Internet – the global infrastructure which Internet – the global infrastructure which

facilitates data transferfacilitates data transfer Semantic ComponentsSemantic Components

Hyper Text Transfer Protocol (HTTP)Hyper Text Transfer Protocol (HTTP) Hyper Text Markup Language (HTML)Hyper Text Markup Language (HTML)

eXtensible Markup Language (XML)eXtensible Markup Language (XML) Uniform Resource Identifiers (URI)Uniform Resource Identifiers (URI) Uniform Resource Locator (URL)Uniform Resource Locator (URL)

Page 21: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Uniform Resource Uniform Resource IdentifiersIdentifiers

Web resources need names/identifiers – Web resources need names/identifiers – Uniform Resource Identifiers (URIs)Uniform Resource Identifiers (URIs) Resource can reside anywhere on the InternetResource can reside anywhere on the Internet

URIs are a somewhat abstract notionURIs are a somewhat abstract notion A pointer to a resource to which request methods A pointer to a resource to which request methods

can be applied to generate potentially different can be applied to generate potentially different responsesresponses

A request method is eg. fetching or changing the objectA request method is eg. fetching or changing the object

Instance: Instance: http://www.foo.com/index.htmlhttp://www.foo.com/index.html Protocol, server, resourceProtocol, server, resource

Most popular form of a URI is the Uniform Most popular form of a URI is the Uniform Resource Locator (URL)Resource Locator (URL) FIND THE DIFFERENCE BETWEEN URL AND FIND THE DIFFERENCE BETWEEN URL AND

URI!!!URI!!!

Page 22: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP BasicsHTTP Basics Protocol for client/server communicationProtocol for client/server communication

The heart of the WebThe heart of the Web Very simple request/response protocolVery simple request/response protocol

Client sends request message, server replies with response Client sends request message, server replies with response messagemessage

StatelessStateless Relies on URI naming mechanismRelies on URI naming mechanism

Three versions have been usedThree versions have been used 09/1.0 – very close to Berners-Lee’s original 09/1.0 – very close to Berners-Lee’s original

RFC 1945 (original RFC is now expired)RFC 1945 (original RFC is now expired) 1.1 – developed to enhance performance, caching, 1.1 – developed to enhance performance, caching,

compressioncompression RFC 2068RFC 2068

1.0 dominates today but 1.1 is catching up1.0 dominates today but 1.1 is catching up

Page 23: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP Request MessagesHTTP Request Messages GET – retrieve document specified by URLGET – retrieve document specified by URL PUT – store specified document under given URLPUT – store specified document under given URL HEAD – retrieve info. about document specified by HEAD – retrieve info. about document specified by

URLURL OPTIONS – retrieve information about available OPTIONS – retrieve information about available

optionsoptions POST – give information (eg. annotation) to the POST – give information (eg. annotation) to the

serverserver DELETE – remove document specified by URLDELETE – remove document specified by URL TRACE – loopback request messageTRACE – loopback request message CONNECT – for use by cachesCONNECT – for use by caches

Page 24: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP Request FormatHTTP Request Format

First type of HTTP message: First type of HTTP message: requestsrequests Client browsers construct and send messageClient browsers construct and send message

Typical HTTP request:Typical HTTP request: GET GET http://www.cs.wisc.edu/index.htmlhttp://www.cs.wisc.edu/index.html

HTTP/1.0HTTP/1.0

request-line ( request request-URI HTTP-version)headers (0 or more)<blank line>body (only for POST request)

Page 25: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP Response FormatHTTP Response Format

Second type of HTTP message: Second type of HTTP message: responseresponse Web servers construct and send response messagesWeb servers construct and send response messages

Typical HTTP response:Typical HTTP response: HTTP/1.0 301 Moved PermanentlyHTTP/1.0 301 Moved Permanently

Location: http://www.wisc.edu/cs/index.htmlLocation: http://www.wisc.edu/cs/index.html

status-line (HTTP-version response-code response-phrase)headers (0 or more)<blank line>body

Page 26: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP Response CodesHTTP Response Codes 1xx – Informational – request received, 1xx – Informational – request received,

processingprocessing 2xx – Success – action received, 2xx – Success – action received,

understood, acceptedunderstood, accepted 3xx – Redirection – further action 3xx – Redirection – further action

necessarynecessary 4xx – Client Error – bad syntax or 4xx – Client Error – bad syntax or

cannot be fulfilledcannot be fulfilled 5xx – Server Error – server failed5xx – Server Error – server failed

Page 27: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP HeadersHTTP Headers Both requests and responses can contain a Both requests and responses can contain a

variable number of header fieldsvariable number of header fields Consists of field name, colon, space, field valueConsists of field name, colon, space, field value 17 possible header types divided into three 17 possible header types divided into three

categoriescategories RequestRequest ResponseResponse BodyBody

Example: Date: Friday, 27-Apr-01 13:30:01 Example: Date: Friday, 27-Apr-01 13:30:01 GMTGMT

Example: Content-length: 3001Example: Content-length: 3001

Page 28: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP/1.0 Network HTTP/1.0 Network InteractionInteraction

Clients make requests to port 80 on serversClients make requests to port 80 on servers Uses DNS to resolve server nameUses DNS to resolve server name

Clients make separate TCP connection for each URLClients make separate TCP connection for each URL Some browsers open multiple TCP connectionsSome browsers open multiple TCP connections

Netscape default = 4, WATCH OUT ON PIPELININGNetscape default = 4, WATCH OUT ON PIPELINING

Server returns HTML pageServer returns HTML page Many types of servers with a variety of implementationsMany types of servers with a variety of implementations Apache is the most widely usedApache is the most widely used

Freely available in source formFreely available in source form

Client parses pageClient parses page Requests embedded objectsRequests embedded objects

Page 29: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTTP/1.1 Performance HTTP/1.1 Performance EnhancementsEnhancements

HTTP/1.0 is a “stop and wait” protocolHTTP/1.0 is a “stop and wait” protocol Separate TCP connection for each fileSeparate TCP connection for each file

Connect setup and tear down is incurred for each fileConnect setup and tear down is incurred for each file Inefficient use of packetsInefficient use of packets Server must maintain many connections in TIME_WAITServer must maintain many connections in TIME_WAIT

ISSUE on HTTP/1.0ISSUE on HTTP/1.0 Resulted in HTTP/1.1 specification focused on Resulted in HTTP/1.1 specification focused on

performance enhancementsperformance enhancements Persistent connectionsPersistent connections PipeliningPipelining Enhanced caching optionsEnhanced caching options Support for compressionSupport for compression

Page 30: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Persistent Connections Persistent Connections and Pipeliningand Pipelining

Persistent connectionsPersistent connections Use the same TCP connection(s) for transfer of multiple filesUse the same TCP connection(s) for transfer of multiple files Reduces packet traffic significantlyReduces packet traffic significantly May or may not increase performance from client May or may not increase performance from client

perspectiveperspective Load on server increasesLoad on server increases

PipeliningPipelining Pack as much data into a packet as possiblePack as much data into a packet as possible Requires length field(s) within headerRequires length field(s) within header May or may not reduce packet traffic or increase May or may not reduce packet traffic or increase

performanceperformance Page structure is criticalPage structure is critical

Page 31: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTML BasicsHTML Basics

Hyper-Text Markup LanguageHyper-Text Markup Language A subset of Standardized General Markup Language (SGML)A subset of Standardized General Markup Language (SGML) Facilitates a hyper-media environmentFacilitates a hyper-media environment

Embedded links to other documents Embedded links to other documents and applicationsand applications Documents use elements to “mark up” or identify Documents use elements to “mark up” or identify

sections of text for different purposes or display sections of text for different purposes or display characteristicscharacteristics

Mark up elements are not seen by the user when page Mark up elements are not seen by the user when page is displayedis displayed

Documents are rendered by browsersDocuments are rendered by browsers NOTE: Not all documents in the Web are HTML!NOTE: Not all documents in the Web are HTML! Most people use WYSIWYG editors (MS Word) to Most people use WYSIWYG editors (MS Word) to

generate HTMLgenerate HTML

Page 32: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

HTML ExampleHTML Example

<HTML><HEAD><TITLE> PB’s HomePage </TITLE></HEAD><BODY><CENTER><IMG SRC = “bad_picture.gif” ALT = “ “><BR></CENTER><P><CENTER><H1>UW Computer Science Department</H1></CENTER>Welcome to my goofy HomePage!…<A HREF = http://www.cs.wisc.edu/~pb/mydogs_page.html> Spot’s Page </A></BODY></HTML>

Page 33: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Security Issue on WebSecurity Issue on Web

By UserBy User DefacingDefacing SQL or Shell InjectSQL or Shell Inject DoSDoS

By OwnerBy Owner Phissing (try this: http://www.kilkbca.com)Phissing (try this: http://www.kilkbca.com) Malware (Nice app to be downloded, Malware (Nice app to be downloded,

contain malware)contain malware) Trojan/Virus/Worm (via sec’ hole in the Trojan/Virus/Worm (via sec’ hole in the

Browser)Browser)

Page 34: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

EMAILEMAIL

Page 35: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

EMail protocolsEMail protocols

SMTP: delivery/storage to receiver’s serverSMTP: delivery/storage to receiver’s server Mail access protocol: retrieval from serverMail access protocol: retrieval from server

POP: Post Office Protocol [RFC 1939]POP: Post Office Protocol [RFC 1939] authorization (agent <-->server) and download authorization (agent <-->server) and download

IMAP: Internet Mail Access Protocol [RFC 1730]IMAP: Internet Mail Access Protocol [RFC 1730] more features (secure, database intragration, broad authentication, etcmore features (secure, database intragration, broad authentication, etc

HTTP: Hotmail , Yahoo! Mail, etc.HTTP: Hotmail , Yahoo! Mail, etc.

useragent

sender’s mail server

useragent

SMTP SMTP POP3/IMAP/

WebMailreceiver’s mail

server

Page 36: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Electronic MailElectronic MailThree major componentsThree major components:: user agents user agents mail servers mail servers simple mail transfer simple mail transfer

protocol: SMTPprotocol: SMTP

User Agent (User Agent (mail reader)mail reader) composing, editing, composing, editing,

reading mail messagesreading mail messages e.g., Eudora, Outlook, elm, e.g., Eudora, Outlook, elm,

Netscape MessengerNetscape Messenger outgoing, incoming outgoing, incoming

messages stored on servermessages stored on server

user mailbox

outgoing message queue

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 37: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Electronic Mail: mail Electronic Mail: mail serversservers

Mail ServersMail Servers mailboxmailbox contains incoming contains incoming

messages for usermessages for user messagemessage queuequeue of of

outgoing (to be sent) mail outgoing (to be sent) mail messagesmessages

SMTP protocolSMTP protocol between between mail servers to send email mail servers to send email messagesmessages client: sending mail client: sending mail

serverserver ““server”: receiving mail server”: receiving mail

serverserver

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 38: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Electronic Mail: SMTP Electronic Mail: SMTP [RFC [RFC 2821]2821]

uses uses TCPTCP to reliably transfer email message from to reliably transfer email message from client to server, port 25client to server, port 25

direct transfer: sending server to receiving serverdirect transfer: sending server to receiving server three phases of transferthree phases of transfer

handshaking (greeting)handshaking (greeting) transfer of messagestransfer of messages closureclosure

command/response interactioncommand/response interaction commands:commands: ASCII text ASCII text response:response: status code and phrase status code and phrase

messages must be in 7-bit ASCIImessages must be in 7-bit ASCII

Page 39: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Scenario: Alice sends Scenario: Alice sends message to Bobmessage to Bob

1) 1) Alice uses UA to Alice uses UA to compose message and compose message and “to” “to” [email protected]@someschool.edu

2) Alice’s UA sends 2) Alice’s UA sends message to her mail message to her mail server; message placed server; message placed in message queuein message queue

3) Client side of SMTP 3) Client side of SMTP opens TCP connection opens TCP connection with Bob’s mail serverwith Bob’s mail server

4) 4) SMTP client sends SMTP client sends Alice’s message over Alice’s message over the TCP connectionthe TCP connection

5) Bob’s mail server 5) Bob’s mail server places the message in places the message in Bob’s mailboxBob’s mailbox

6) Bob invokes his user 6) Bob invokes his user agent to read messageagent to read message

useragent

mailserver

mailserver user

agent

1

2 3 4 56

Page 40: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Sample SMTP interactionSample SMTP interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <[email protected]> S: 250 [email protected]... Sender ok C: RCPT TO: <[email protected]> S: 250 [email protected] ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection

Page 41: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Try SMTP interaction for Try SMTP interaction for yourself:yourself:

telnet servername 25telnet servername 25 see 220 reply from serversee 220 reply from server enter HELO, MAIL FROM, RCPT TO, enter HELO, MAIL FROM, RCPT TO,

DATA, QUIT commandsDATA, QUIT commands above lets you send email without using above lets you send email without using

email client (reader)email client (reader)

Page 42: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

SMTP: final wordsSMTP: final words SMTP uses persistent SMTP uses persistent

connectionsconnections SMTP requires SMTP requires

message (header & message (header & body) to be in 7-bit body) to be in 7-bit ASCIIASCII

SMTP server uses SMTP server uses CRLF.CRLFCRLF.CRLF to to determine end of determine end of messagemessage

Comparison with Comparison with HTTPHTTP::

HTTP: pullHTTP: pull SMTP: pushSMTP: push

both have ASCII both have ASCII command/response command/response interaction, status interaction, status codescodes

HTTP: each object HTTP: each object encapsulated in its own encapsulated in its own response msgresponse msg

SMTP: multiple objects SMTP: multiple objects sent in multipart msgsent in multipart msg

Page 43: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Mail message formatMail message format

SMTP: protocol for SMTP: protocol for exchanging email msgsexchanging email msgs

RFC 822: standard for text RFC 822: standard for text message format:message format:

header lines, e.g.,header lines, e.g., To:To: From:From: Subject:Subject:

differentdifferent from SMTP from SMTP commandscommands!!

bodybody the “message”, ASCII the “message”, ASCII

characters onlycharacters only

header

body

blankline

Page 44: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Message format: multimedia Message format: multimedia extensionsextensions

MIME: multimedia mail extension, RFC MIME: multimedia mail extension, RFC 2045, 20562045, 2056

additional lines in msg header declare additional lines in msg header declare MIME content typeMIME content type

From: [email protected] To: [email protected] Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg

base64 encoded data ..... ......................... ......base64 encoded data

multimedia datatype, subtype,

parameter declaration

method usedto encode data

MIME version

encoded data

Page 45: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

MIME typesMIME typesContent-Type: type/subtype; Content-Type: type/subtype;

parametersparametersTextText example subtypes: example subtypes: plain, plain,

htmlhtml

ImageImage example subtypes: example subtypes: jpeg, jpeg,

gifgif

AudioAudio exampe subtypes: exampe subtypes: basicbasic

(8-bit mu-law encoded), (8-bit mu-law encoded), 32kadpcm 32kadpcm (32 kbps coding)(32 kbps coding)

VideoVideo example subtypes: example subtypes: mpeg, mpeg,

quicktimequicktime

ApplicationApplication other data that must be other data that must be

processed by reader processed by reader before “viewable”before “viewable”

example subtypes: example subtypes: msword, octet-stream msword, octet-stream

Page 46: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

Multipart TypeMultipart TypeFrom: [email protected] To: [email protected] Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=StartOfNextPart --StartOfNextPartDear Bob, Please find a picture of a crepe.--StartOfNextPartContent-Transfer-Encoding: base64Content-Type: image/jpegbase64 encoded data ..... ......................... ......base64 encoded data --StartOfNextPartDo you want the reciple?

Page 47: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

POP3 protocolPOP3 protocolauthorization phaseauthorization phase client commands: client commands:

user:user: declare username declare username pass:pass: password password

server responsesserver responses +OK+OK -ERR-ERR

transaction phase, transaction phase, client:client: list:list: list message list message

numbersnumbers retr:retr: retrieve message by retrieve message by

numbernumber dele:dele: delete delete quitquit

C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off

S: +OK POP3 server ready C: user bob S: +OK C: pass hungry S: +OK user successfully logged on

Page 48: Application Layer CE-143CNE-0802. Applications and application-layer protocols Application: communicating, distributed processes e.g., e-mail, Web, P2P

POP3 (more) and IMAPPOP3 (more) and IMAPMore about POP3More about POP3 Previous example Previous example

uses “download and uses “download and delete” mode.delete” mode.

Bob cannot re-read e-Bob cannot re-read e-mail if he changes mail if he changes clientclient

““Download-and-keep”: Download-and-keep”: copies of messages on copies of messages on different clientsdifferent clients

POP3 is stateless POP3 is stateless across sessionsacross sessions

IMAPIMAP Keep all messages in Keep all messages in

one place: the serverone place: the server Allows user to Allows user to

organize messages in organize messages in foldersfolders

IMAP keeps user IMAP keeps user state across sessions:state across sessions: names of folders and names of folders and

mappings between mappings between message IDs and message IDs and folder namefolder name