Esame 2settembre2010

Transcript

Esame 2settembre2010
Corso di Laurea
Ingegneria Informatica
TELEMATICA II
ESAME SCRITTO 2 Settembre 2010
NOTE SULLO SVOLGIMENTO DELLA PROVA SCRITTA:
1. SCRIVERE IL PROPRIO NOME, COGNOME E NUMERO DI MATRICOLA IN ALTO SU OGNI FOGLIO
UTILIZZATO
2. NON E’ POSSIBILE CONSULTARE NESSUN TIPO DI DOCUMENTAZIONE
3. NON E’ POSSIBILE UTILIZZARE DISPOSITIVI ELETTRONICI. SPEGNERE I CELLULARI
4. PRIMA DI SCRIVERE LA SOLUZIONE DELL’ESERCIZIO, INSERIRE IL NUMERO DI ESERCIZIO CHE
SI STA RISOLVENDO
5. NON COPIARE DAL VICINO E NON PERMETTETE AL VICINO DI COPIARE (IN TAL CASO I DUE
COMPITI VERRANNO ANNULLATI)
6. ALLA FINE DELLA PROVA, RICONSEGNARE TUTTI I FOGLI UTILIZZATI. LA CONSEGNA DEVE
ESSERE EFFETTUATA ENTRO E NON OLTRE L’ORARIO INDICATO SULLA LAVAGNA
PARTE 1 : TEORIA DEI PROTOCOLLI
ESERCIZIO 1 (2 punti)
Illustrare le caratteristiche dei proxy server. Descrivere in particolare i meccanismi di
caching.
ESERCIZIO 2 (2 punti)
Descrivere le JAVA Framework Collections. Inoltre descrivere l’utilizzo della classe
ArrayList aiutandosi con un esempio.
ESERCIZIO 3 (2 punti)
Investigare il seguente frammento di file .torrent decodificando in benconding il piu’
possibile i vari campi e descrivendo la sintassi.
d8:announce40:http://tracker.thepiratebay.org/announce7:comment34:la
storia
di
cappuccetto rosso.avi10:created by19:TorrentSpy/0.2.4.2613:creation datei1147792122
e4:infod6:lengthi3786069e6:md5sum32:f627b59a6148cc6e1ac1da5d74da38044:name34:l
a storia di cappuccetto rosso.avi12:piece lengthi262144e6:pieces300:zt Vaà etc, etc fino a
300 caratteri7:privatei1eee
1
Corso di Laurea
Ingegneria Informatica
TELEMATICA II
ESAME SCRITTO 2 Settembre 2010
PARTE 2 : APPLICAZIONI TELEMATICHE
ESERCIZIO 4 (8 punti)
La RFC 2616 (HTTP 1.1 Protocol) evidenzia che a fronte di una GET da parte di un client,
il server puo’ rispondere con una risposta di tipo “301 Moved permanently” che permette
la redirezione della richiesta su un nuovo sito. Tale risposta è utile nel caso di
trasferimento di un URI in un altro dominio. In tale circostanza il server indica nell’header
Location di risposta l’indirizzo del nuovo URI. Tale informazione è utile al client per fare
in automatico un’ulteriore richiesta diretta al nuovo indirizzo URI, senza l’intervento
dell’operatore.
1) Implementare in JAVA lato client un metodo autoRedirection( ) che permetta le
redirezioni lato client a seguito della ricezione di una risposta del tipo “HTTP1.1/ 301
Moved permanently”. Il metodo deve generare una richiesta automatica che segua il
nuovo URI e riempia i vari campi header. Si supponga che il metodo “autoRedirection( )”
faccia parte di una classe già esistente denominata “ClientHTTP” di cui non serve
scrivere il codice: si richiede solo l’implementazione del metodo suddetto.
2) Si ipotizzi una risposta da parte del server con la redirezione con riferimento ad un
determinato URI (per esempio www.primeeng.it/risultati_esame.pdf)
3) Implementare in JAVA l’applicativo lato server in versione minimale --> solo
l’implementazione della gestione della risposta ipotizzata al punto 2).
4) Si spieghi infine il significato degli header “Referer”, “Set-Cookies” e “Cookies”
ESERCIZIO 5 (13 punti)
Supponiamo di avere un’architettura di tipo client/server come in figura.
UDP
H2
MAILSERVER
H1
CLIENT
SMTP
H3
CRYPTOMAIL
Sull’host H1 con indirizzo IP (192.63.2.1) è residente l’applicativo client.
Sull’host H2 con indirizzo IP (193.45.123.20) è residente l’applicativo MAIL-SERVER.
Sull’host H3 con indirizzo IP (200.12.94.12) è residente l’applicativo server CRYPTO-Mail
per i processi di codifica degli allegati di posta.
2
Corso di Laurea
Ingegneria Informatica
L’obiettivo è di trasferire un file di testo (max 16KBytes) dal client H1 al Mail-Server H2
con protocollo UDP. Il Mail-Server H2 provvederà ad inviare tramite protocollo SMTP il
file di testo in allegato ad un messaggio SMTP al server CRYPTO-MAIL, il quale
provvederà a codificare il file allegato.
Dopo aver fatto eventuali ipotesi aggiuntive ed esemplificative, implementare in
linguaggio JAVA i seguenti applicativi client o server richiesti:
1) Implementazione del client UDP su H1.
2) Implementazione del mail-server su H2 per la ricezione del messaggio UDP da H1 e
l’invio contestuale con protocollo SMTP ad H3. Si implementi l’applicazione mini-client
SMTP lato H2 (anche se non completamente conforme alla RFC, ma in linea con le
indicazioni ricevute durante il corso) con la sola gestione dei comandi HELO, MAIL From,
RCPT To, DATA, QUIT, NOOP verso il server H3. Il comando DATA deve prevedere l’invio
in allegato del file ricevuto da H1 dopo il carattere “.” nel comando DATA.
3) Implementazione del server di codifica (CRYPTO-MAIL) su H3 per ricevere il
messaggio da H2 ed effettuare la successiva codifica del file ricevuto in allegato. Il file
codificato deve essere salvato sul server H3.
L’implementazione del mini-server SMTP deve prevedere la gestione dei comandi MAIL
From, RCPT To, DATA, QUIT, NOOP. Il comando Data deve prevedere la ricezione in
allegato di un file.
La codifica sarà basata sul cifrario polialfabetico, per il quale si applicano in maniera
alternata due codifiche C1 e C2 con cifrario di Cesare rispettivamente il primo con k=5 e
il secondo con k=19:
origine
C1
C2
a
f
t
b c d e f g h i j k l m
g h i j k l m n o p q r
u v x y w z a b c d e f
n o p q r
s t u v x
g h i j k
s t
u v x y w
y w z a b c d
l m n o p q r
z
e
s
In pratica la codifica del file sarà effettuata in questa maniera sulle singole lettere:
C1, C2, C1, C2, C1, C2, ecc
3
Corso di Laurea
Ingegneria Informatica
TELEMATICA II
ESAME SCRITTO 2 Settembre 2010
Javadoc
java.lang.Integer
¾ public static int parseInt(String s) throws NumberFormatException
Parses the string argument as a signed decimal integer.
Parameters: s - a String containing the int representation to be parsed
Returns: the integer value represented by the argument in decimal.
Throws: NumberFormatException - if the string does not contain a parsable
integer.
java.lang.String
¾ public boolean endsWith(String suffix)
Tests if this string ends with the specified suffix.
¾ public boolean equals(Object o)
Compares this string to the specified object.
¾ public int length()
Returns the length of this string.
¾ public boolean startsWith(String prefix)
Tests if this string starts with the specified prefix.
¾ public String substring(int beginIndex)
Returns a new string that is a substring of this string.
¾ public String substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string.
¾ public String(byte[ ] bytes,int offset,int length)
Constructs a new String by decoding the specified subarray of bytes using the
platform's default charset.
¾ public int indexOf(String str,int fromIndex)
Returns the index within this string of the first occurrence of the specified
substring, starting at the specified index.
¾ public byte[ ] getBytes()
Encodes this String into a sequence of bytes using the platform's default
charset, storing the result into a new byte array.
java.lang.StringBuffer
¾ public StringBuffer append(String str)
Appends the string to this string buffer.
Parameters: str - a string.
Returns: a reference to this StringBuffer
¾ public String toString()
Returns a string representing the data in this sequence
java.util.Map<K,V>
¾ public V get(K key)
Returns the value to which this map maps the specified key. Returns null if the
map contains no mapping for this key.
Parameters: key - key whose associated value is to be returned.
Returns: the value to which this map maps the specified key, or null if the map
contains no mapping for this key.
4