CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer:...

34
CS 43: Computer Networks 12: Email and SMTP September 28, 2018

Transcript of CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer:...

Page 1: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

CS 43: Computer Networks

12:EmailandSMTPSeptember28,2018

Page 2: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Mail servers communicate using…

A.  HTTP

B.  IMAP

C.  POP

D.  SMTP

Lecture12-Slide2

Page 3: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Mail servers typically…

A.  sendmessagesdirectlyfromthesendinguser’sservertothereceiver’sserver.

B.  sendmessagesthroughintermediaryserversonthewayfromsendertoreceiver.

Lecture12-Slide3

Page 4: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Users also use SMTP to retrieve their mail messages…

A.  True

B.  False

Lecture12-Slide4

Page 5: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Electronic mail usermailbox

outgoingmessagequeue

mailserver

mailserver

mailserver

SMTP

SMTP

SMTP

useragent

useragent

useragent

useragent

useragent

useragent

Threemajorcomponents:-  mailuseragent(MUA)-  mailtransferagent(MTA)-  simplemailtransferprotocolMailUserAgenta.k.a“mailreader”-  composing,editing,readingmailmessages

-  e.g.,Outlook,Thunderbird,iPhonemailclient

-  outgoing,incomingmessagesstoredonserver

Lecture12-Slide5

Page 6: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

MTAs: Mail Transfer Agent

mailservers:•  mailboxcontainsincoming

messagesforuser•  messagequeueofoutgoing(to

besent)mailmessages•  SMTPprotocolbetweenmail

serverstosendemailmessages(one-way)–  client:sendingmailserver–  “server”:receivingmailserver

usermailbox

outgoingmessagequeue

mailserver

mailserver

mailserver

SMTP

SMTP

useragent

useragent

useragent

useragent

useragent

useragent

Lecture12-Slide6

Page 7: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

If you were designing email, what would happen when Alice sends an email to Bob?

A.  Hermailclientsendsamessagetohismailserver

B.  Hermailserversendsamessagetohismailserver

C.  Hermailserversendsamessagetohismailclient

D.  Hermailclientsendsamessagetohismailclient

Lecture12-Slide7

Page 8: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

useragent

Scenario: Alice sends message to Bob 1)AliceusesaMUAtocompose

message“to”

[email protected])Alice’sMUAsendsmessageto

hermailserver;messageplacedinmessagequeue

3)clientsideofSMTPopensTCPconnectionwithBob’smailserver

4)SMTPclientsendsAlice’smessageovertheTCPconnection

5)Bob’smailserverplacesthemessageinBob’smailbox

6)BobinvokeshisMUAtoreadmessage

1 mailserver

2 3

Alice’smailserver

mailserver

45

Bob’smailserver

6

useragent

Lecture12-Slide8

Page 9: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Mail Servers: Ever Vigilant

•  Alwayson,becausetheyalwaysneedtobereadytoacceptmail.

•  UsuallyownedbyISP–  YouusetheemailserverforeitherSwarthmoreCollege,ortheCSdepartment.

Lecture12-Slide9

Page 10: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Simple Mail Transfer: SMTP [RFC 2821]

•  TCP:reliablytransferemailmessagefromclienttoserver,port25

•  Directtransfer:sendingservertoreceivingserver•  Threephasesoftransfer–  handshaking(greeting)–  transferofmessages–  closure

•  Command/responseinteraction(likeHTTP,FTP)–  commands:ASCIItext–  response:statuscodeandphrase

•  Messagesmustbein7-bitASCII

Lecture12-Slide10

Page 11: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

SMTP Message Format

RFC822:standardfortextmessageformat:

•  headerlines,e.g.,–  To:–  From:–  Subject:differentfromSMTPMAILFROM,RCPTTO:commands!

•  Body:the“message”–  ASCIIcharactersonly–  SignalEOMwith“\r\n.\r\n”

header

body

blankline

SMTPProtocol

Lecture12-Slide11

Page 12: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Try SMTP interaction for yourself:

•  telnet allspice.cs.swarthmore.edu 25 •  Youshouldseea220replyfromtheserver.•  enterHELO,MAILFROM,RCPTTO,DATA,QUIT

commands(letsyousendemailwithoutusingemailclient(MUA))

Lecture12-Slide12

Page 13: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Demo

Lecture12-Slide13

Page 14: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Sample SMTP interaction

$telnetallspice.cs.swarthmore.edu25Trying130.58.68.9…Connectedtoallspice.cs.swarthmore.edu220allspice.cs.swarthmore.eduESMTPPostfixHELOcs.swarthmore.edu250allspice.cs.swarthmore.eduMAILFROM:<[email protected]>2502.1.0OKRCPTTO:<[email protected]>2502.1.5OKDATA354Enddatawith<CR><LF>.<CR><LF>To:VasantaChaganti<[email protected]>From:VasantaChaganti<[email protected]>Subject:TelnettestmessageThisisatestmessage,viatelnet,tomyself.. Lecture12-Slide14

Page 15: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Sample SMTP interaction

Endofmessage:Dot

$telnetallspice.cs.swarthmore.edu25Trying130.58.68.9…Connectedtoallspice.cs.swarthmore.edu220allspice.cs.swarthmore.eduESMTPPostfixHELOcs.swarthmore.edu250allspice.cs.swarthmore.eduMAILFROM:<[email protected]>2502.1.0OKRCPTTO:<[email protected]>2502.1.5OKDATA354Enddatawith<CR><LF>.<CR><LF>To:VasantaChaganti<[email protected]>From:VasantaChaganti<[email protected]>Subject:TelnettestmessageThisisatestmessage,viatelnet,tomyself.

Lecture12-Slide15

Page 16: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

What keeps us from entering a fake information (e.g., FROM address)?

A.  Nothing.

B.  TheMTAchecksthattheFROMisvalid.

C.  Weenteraname/passwordloggingintotheMTA.

Lecture12-Slide16

Page 17: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Fun Demo

Lecture12-Slide17

Page 18: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Wait, this seems too horrible to be true. Surely we can prevent header forging?

(How or why not?)

A.  Yes

B.  No

Lecture12-Slide18

Page 19: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Message Signing

1.  Sendercreatescryptographicpublic/privatekeypair,publishespublickeytotheworld.

2.  Senderusesprivatekeytosignmessages.

3.  Receivercanverify*,usingpublishedpublickey,thatonlytheholderofthecorrespondingprivatekeycouldhavesentthemessage.

*Withveryhighprobability.

Lecture12-Slide19

Page 20: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Message Signing: Challenges

•  Disseminatingpublickeys– Howdoyoutrustthatthepublishedpublickeyisn’talsoalie?

•  It’smorework,can’tbebothered…– Adoptionisverylow

Lecture12-Slide20

Page 21: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

useragent

Logging In / Passwords

mailserver

mailserver

Alice’smailserver Bob’smailserver

useragent

LoggedIn LoggedIn?

Lecture12-Slide21

Page 22: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Logging In / Passwords

mailserver

mailserver

Bob’smailserver

useragent

mailservermail

server

AnymailservermayneedtosendamessagetoBob’s.Toughforthemalltosharecredentials…

Lecture12-Slide22

Page 23: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

SMTP versus HTTP

•  HTTP:pull•  SMTP:push

•  BothhaveASCIIcommand/responseinteraction,statuscodes

•  HTTP:eachobjectencapsulatedinitsownresponsemessage

•  SMTP:multipleobjectssentinmultipartmessage

Lecture12-Slide23

Page 24: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

SMTP: final words

•  SMTPusespersistentconnections– Cansendmultipleemailsinonesession

•  SMTPrequiresmessage(header&body)tobein7-bitASCII

•  SMTPserverusesCRLF.CRLFtodetermineendofmessage

Lecture12-Slide24

Page 25: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

If SMTP only allows 7-bit ASCII, how do we send pictures/videos/files via email?

A.  Weencodetheseobjectsas7-bitASCII

B.  WeuseadifferentprotocolinsteadofSMTP

C.  We’rereallysendinglinkstotheobjects,ratherthantheobjectsthemselves

Lecture12-Slide25

Page 26: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Base 64

•  Designedtobeanefficientwaytosendbinarydataasastring

•  UsesA-Z,a-z,0-9,“+”and“/”asdigits

•  Anumberwithdigitsdndn-1…..d1d0=64n*dn+64n-1*dn-1+...+64*d1+d0

•  RecallfromCS31:Othernon-base-10numbersystems(binary,octal,hex).

Lecture12-Slide26

Page 27: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Multipurpose Internet Mail Extensions (MIME)

•  Specialformattinginstructions

•  Indicatedintheheaderportionofmessage(notSMTP)–  SMTPdoesnotcare,justlookslikemessagedata

•  Supports–  TextincharactersetsotherthanASCII–  Non-textattachments– Messagebodieswithmultipleparts–  Headerinformationinnon-ASCIIcharactersets

Lecture12-Slide27

Page 28: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

MIME

•  Addsoptionalheaders–  Designedtobecompatiblewithnon-MIMEemailclients–  Bothclientsmustunderstandittomakesenseofit

•  Specifiescontenttype,othernecessaryinformation

•  Designatesaboundarybetweenemailtextandattachments

Lecture12-Slide28

Page 29: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Mail access protocols

•  SMTP:delivery/storagetoreceiver’sserver•  mailaccessprotocol:retrievalfromserver

–  POP:PostOfficeProtocol:authorization,download–  IMAP:InternetMailAccessProtocol:morefeatures,includingmanipulationofstoredmessagesonserver

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

sender’smailserver

SMTP SMTPmailaccessprotocol

receiver’smailserver

(e.g.,POP,IMAP)

useragent

useragent

Lecture12-Slide29

Page 30: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

POP3 protocol authorizationphase•  clientcommands:–  user:declareusername–  pass:password

•  serverresponses–  +OK–  -ERR

transactionphase,client:•  list:listmessagenumbers•  retr:retrievemessageby

number•  dele:delete•  quit

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

Lecture12-Slide30

Page 31: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

More about POP3

•  Previousexampleuses“downloadanddelete”mode–  Bobcannotre-reade-mailifhechangesclient

•  POP3“download-and-keep”:copiesofmessagesondifferentclients

•  POP3isstatelessacrosssessions

•  Limitations:–  Can’tretrievejusttheheaders–  Can’timposestructureonmessages

Lecture12-Slide31

Page 32: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

IMAP

•  Keepsallmessagesinoneplace:atserver

•  Allowsusertoorganizemessagesinfolders

•  Keepsuserstateacrosssessions:–  namesoffoldersandmappingsbetweenmessageIDsandfoldername

•  Canrequestpiecesofamessage(e.g.,textpartswithoutlargeattachments)

Lecture12-Slide32

Page 33: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Webmail

•  Usesawebbrowser

•  SendsemailsusingHTTPratherthanPOP3orIMAP

•  Mailisstoredonthe3rdpartywebmailcompany’sservers

Lecture12-Slide33

Page 34: CS 43: Computer Networkschaganti/cs43/f18/lecs/12... · 2018. 9. 27. · • Direct transfer: sending server to receiving server • Three phases of transfer – handshaking (greeting)

Summary

•  Threemainpartstoemail:– MailUserAgent(mailclient):read/writeforhumans– MailTransferAgent:serverthataccepts/sendsmessages–  SMTPprotocolusedtonegotiatetransfers

•  NoSMTPsupportforfrauddetection

•  Extensions(MIME)andencodings(Base64)forsendingnon-textdata

Lecture12-Slide34