|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectssbm.net.TLSConnection
public abstract class TLSConnection
Questa classe rappresenta una connessione tra il client ed il server attraverso il protocollo TLS
(Transport Layer Security).
Fornisce dei metodi per eseguire le seguenti attività:
Field Summary | |
---|---|
private int |
applicationBufferSize
La dimensione dei buffer che ospitano i dati in chiaro. |
private boolean |
client
true se l'host locale è il client, false se l'host locale è il server. |
private boolean |
handshakeDone
Indica se è stato eseguito o meno l'handshake iniziale. |
private java.nio.ByteBuffer |
inboundApplData
Il buffer che ospita i dati in chiaro ricevuti dall'host remoto. |
private java.nio.ByteBuffer |
inboundNetData
Il buffer che ospita i dati crittati ricevuti dall'host remoto. |
protected static java.lang.String |
KEYSTORE_MANAGER_FACTORY_ALGORITHM
Il nome che identifica l'algoritmo utilizzato per istanziare esemplari di KeyManagerFactory . |
protected static java.lang.String |
KEYSTORE_TYPE
Il tipo di keystore. |
private static byte |
LAST_BLOCK_BYTE
Il valore del primo byte dell'ultimo blocco di byte ricevuto/da inviare. |
private int |
netBufferSize
La dimensione dei buffer che ospitano i dati crittati. |
private java.nio.channels.SocketChannel |
netChannel
Il canale socket utilizzato per la lettura e la scrittura dei dati scambiati tra gli host connessi. |
private static byte |
NORMAL_BLOCK_BYTE
Il valore del primo byte dei blocchi di byte diversi dall'ultimo. |
private java.nio.ByteBuffer |
outboundApplData
Il buffer che ospita i dati in chiaro da inviare all'host remoto. |
private java.nio.ByteBuffer |
outboundNetData
Il buffer che ospita i dati crittati da inviare all'host remoto. |
private javax.net.ssl.SSLEngine |
tlsEngine
L'esemplare di SSLEngine che rappresenta la TLSEngine. |
protected static java.lang.String |
TRUSTSTORE_MANAGER_FACTORY_ALGORITHM
Il nome che identifica l'algoritmo utilizzato per istanziare esemplari di TrustManagerFactory . |
private static java.nio.charset.Charset |
UTF8
Il set di caratteri che determina la conversione dei dati in chiaro in byte. |
Constructor Summary | |
---|---|
protected |
TLSConnection(java.nio.channels.SocketChannel hostChannel,
boolean client)
Inizializza i campi d'esemplare in modo tale che rappresentino una connessione TLS con le seguenti caratteristiche: utilizza il canale socket hostConnection per la comunicazione con l'host remoto; ha un contesto ed una TLSEngine impostate attraverso il metodo buildEngine(String, int) . |
Method Summary | |
---|---|
protected abstract javax.net.ssl.SSLEngine |
buildEngine(java.lang.String hostAddress,
int hostPort)
Costruisce un esemplare di SSLContext da utilizzare per la costruzione dell'esemplare di SSLEngine restituito da questo metodo. |
void |
close()
Chiude la connessione TLS disattivando la TLSEngine e chiudendo il canale socket. |
private void |
closeEngineInbound()
Chiude il flusso in entrata della TLSEngine. |
private void |
closeEngineOutbound()
Chiude il flusso in uscita della TLSEngine. |
private void |
closeNetConnection()
Chiude il canale socket. |
private void |
createBuffers()
Alloca i byte-buffer utilizzati dalla TLSEngine. |
private void |
executeHandshake()
Esegue l'handshake TLS iniziale. |
private void |
handleUnwrap(javax.net.ssl.SSLEngineResult.Status opStatus)
Gestisce i possibili stati della TLSEngine in seguito all'unwrapping dei buffer. |
private void |
handleWrap(javax.net.ssl.SSLEngineResult.Status opStatus)
Gestisce i possibili stati della TLSEngine in seguito al wrapping dei buffer. |
boolean |
isClosed()
Indica se la connessione TLS è chiusa. |
private int |
read(boolean acceptClosedChannel)
Legge dal canale socket e inserisce i byte letti nel buffer inboundNetData . |
private java.lang.String |
readApplData()
Legge i dati applicativi dal canale socket e li decritta (unwrapping) per ricostruire il messaggio in chiaro inviato dall'host remoto. |
java.lang.String |
receiveData()
Riceve il messaggio di testo inviato dall'host remoto e contenente i dati applicativi . |
private java.nio.ByteBuffer |
resizeByteBuffer(java.nio.ByteBuffer source,
int size)
Ridimensiona un buffer. |
private void |
rewindInboundNetBuffer()
Riavvolge il buffer inboundNetData per consentire la lettura dei byte non ancora letti. |
private void |
runDelegatedTasks()
Esegue i task incontrati durante il processo di handshaking. |
void |
sendData(java.lang.String data)
Invia un messaggio di testo contenente i dati applicativi all’host remoto. |
private void |
shutdownTLSEngine()
Disattiva la TLSEngine chiudendo il flusso di dati in uscita e in ingresso. |
private void |
wrapApplData(byte[] data,
int offset,
int length,
byte flag)
Popola il buffer outboundApplData con il byte di flag e i
length byte contenuti in data a partire dalla
posizione offset. |
private void |
write()
Scrive il contenuto del buffer outboundNetData sul canale socket. |
private void |
writeApplData(java.lang.String data)
Invia all'host remoto un messaggio di testo opportunamente crittato. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private javax.net.ssl.SSLEngine tlsEngine
private java.nio.ByteBuffer inboundApplData
private java.nio.ByteBuffer inboundNetData
private java.nio.ByteBuffer outboundApplData
private java.nio.ByteBuffer outboundNetData
private java.nio.channels.SocketChannel netChannel
private boolean client
private static final java.nio.charset.Charset UTF8
private int applicationBufferSize
private int netBufferSize
private boolean handshakeDone
private static final byte LAST_BLOCK_BYTE
private static final byte NORMAL_BLOCK_BYTE
protected static final java.lang.String KEYSTORE_TYPE
protected static final java.lang.String KEYSTORE_MANAGER_FACTORY_ALGORITHM
KeyManagerFactory
.
protected static final java.lang.String TRUSTSTORE_MANAGER_FACTORY_ALGORITHM
TrustManagerFactory
.
Constructor Detail |
---|
protected TLSConnection(java.nio.channels.SocketChannel hostChannel, boolean client) throws SSBMSecurityException
buildEngine(String, int)
.
hostChannel
- il canale socket utilizzato per la comunicazione con l'host remoto.client
- true se l'host locale è un client, false se l'host locale è un server.
SSBMSecurityException
- se si verificano errori nella costruzione degli esemplari di
SSLContext e SSLEngine.buildEngine(String, int)
Method Detail |
---|
protected abstract javax.net.ssl.SSLEngine buildEngine(java.lang.String hostAddress, int hostPort) throws SSBMSecurityException
hostAddress
- l'indirizzo IP dell'host remoto.hostPort
- la porta d'ascolto dell'host remoto.
tlsEngine
.
SSBMSecurityException
- se si verificano errori nella costruzione degli esemplari di
SSLContext e SSLEngine.private void createBuffers()
inboundNetData
e outboundNetData
)
è quella restituita dal metodo SSLSession.getPacketBufferSize();
La dimensione iniziale dei buffer che ospitano i dati applicativi in chiaro
(outboundNetData
e inboundApplData
) è quella restituita dal metodo
SSLSession.getApplicationBufferSize().
public java.lang.String receiveData() throws NetException, SSBMSecurityException
NetException
- se si verifica un errore nella lettura del canale socket o nella scrittura
sullo stesso canale.
SSBMSecurityException
- se la connessione TLS è chiusa o l'utilizzo della TLSEngine
provoca il lancio di una SSLException.executeHandshake()
,
readApplData()
public void sendData(java.lang.String data) throws NetException, SSBMSecurityException
data
- il messaggio di testo in chiaro da inviare all'host remoto.
NetException
- se si verifica un errore nella lettura del canale socket o nella scrittura
sullo stesso canale.
SSBMSecurityException
- se la connessione TLS è chiusa o l'utilizzo della TLSEngine
provoca il lancio di una SSLException.executeHandshake()
,
writeApplData(String)
public void close() throws NetException, SSBMSecurityException
NetException
- se si verifica un errore nella lettura del canale socket o nella scrittura
sullo stesso canale.
SSBMSecurityException
- se l'utilizzo della TLSEngine provoca il lancio di una
SSLException.shutdownTLSEngine()
,
closeNetConnection()
private void executeHandshake() throws javax.net.ssl.SSLException, NetException, SSBMSecurityException
javax.net.ssl.SSLException
- se si verificano errori nell'avvio dell'handshake, nella gestione
del wrapping e dell'unwrapping dei byte-buffer.
NetException
- se si verifica un errore nella lettura del canale socket o nella scrittura
sullo stesso canale.
SSBMSecurityException
- se l'utilizzo della TLSEngine provoca il lancio di una
SSLException.private void rewindInboundNetBuffer()
private void shutdownTLSEngine() throws javax.net.ssl.SSLException, NetException, SSBMSecurityException
javax.net.ssl.SSLException
- se si verificano degli errori nel wrapping e nell'unwrapping
dei byte-buffer o se non è stato ricevuto il messaggio di chiusura dell'host remoto .
NetException
- se si verificano errori nelle lettura o nella scrittura dei
dati sul canale socket.
SSBMSecurityException
- se il messaggio di testo prodotto dalla TLSEngine e da inviare
all'host remoto non è un messaggio di chiusura.closeEngineInbound()
,
closeEngineOutbound()
,
closeNetConnection()
private void closeEngineOutbound() throws javax.net.ssl.SSLException, NetException, SSBMSecurityException
javax.net.ssl.SSLException
- se si verifica un errore nel wrapping del buffer.
NetException
- se si verifica un errore nella scrittura dei dati crittati
sul canale socket.
SSBMSecurityException
- se il messaggio di testo prodotto dalla TLSEngine da inviare
all'host remoto non è un messaggio di chiusura.private void closeEngineInbound() throws NetException, SSBMSecurityException, javax.net.ssl.SSLException
NetException
- se si verifica un errore nella lettura dei dati crittati dal canale socket.
SSBMSecurityException
- se il messaggio di testo prodotto dalla TLSEngine da inviare
all'host remoto non è un messaggio di chiusura (invocazione del metodo closeEngineOutbound()
se il canale socket è chiuso in lettura).
javax.net.ssl.SSLException
- se si verifica un errore nell'unwrapping
del buffer o non è stato ricevuto il messaggio di chiusura dell'host remoto.private void closeNetConnection()
public boolean isClosed()
private void runDelegatedTasks()
private void handleUnwrap(javax.net.ssl.SSLEngineResult.Status opStatus) throws NetException, javax.net.ssl.SSLException, SSBMSecurityException
opStatus
- il valore dell'enumerazione SSLEngineResult.Status
che denota lo stato corrente della TLSEngine.
NetException
- se si verifica un errore nella chiusura della connessione TLS (solo se
opStatus == SSLEngineResult.Status.CLOSED).
javax.net.ssl.SSLException
- se si verifica un errore nella chiusura della connessione TLS (solo se
opStatus == SSLEngineResult.Status.CLOSED).
SSBMSecurityException
- se si verifica un errore nella chiusura della connessione TLS (solo se
opStatus == SSLEngineResult.Status.CLOSED).invocato se opStatus == {@linkplain javax.net.ssl.SSLEngineResult.Status#CLOSED}.
private void handleWrap(javax.net.ssl.SSLEngineResult.Status opStatus) throws NetException, SSBMSecurityException, javax.net.ssl.SSLException
opStatus
- il valore dell'enumerazione SSLEngineResult.Status
che denota lo stato corrente della TLSEngine.
NetException
- se si verificano degli errori nella scrittura dei dati sul canale socket o
nella chiusura della connessione TLS (solo se opStatus ==
SSLEngineResult.Status.CLOSED).
SSBMSecurityException
- se opStatus ==
SSLEngineResult.Status.BUFFER_UNDERFLOW
o si verifica un errore nella chiusura della connessione TLS (solo se
opStatus == SSLEngineResult.Status.CLOSED).
javax.net.ssl.SSLException
- se si verifica un errore nella chiusura della connessione TLS (solo se
opStatus == SSLEngineResult.Status.CLOSED).private java.nio.ByteBuffer resizeByteBuffer(java.nio.ByteBuffer source, int size)
source
- il buffer da ridimensionare.size
- la nuova dimensione del buffer.
private java.lang.String readApplData() throws NetException, SSBMSecurityException, javax.net.ssl.SSLException
NetException
- se si verifica un errore nella lettura dal canale socket o se è
lanciata dal metodo #handleUnwrap(Status)
.
SSBMSecurityException
- lanciata dal metodo #handleUnwrap(Status)
.
javax.net.ssl.SSLException
- lanciata dal metodo #handleUnwrap(Status)
.read(boolean)
private void writeApplData(java.lang.String data) throws javax.net.ssl.SSLException, NetException, SSBMSecurityException
data
- il messaggio di testo in chiaro da inviare all'host remoto.
javax.net.ssl.SSLException
- lanciata dal metodo wrapApplData(byte[], int, int, byte)
.
NetException
- lanciata dal metodo wrapApplData(byte[], int, int, byte)
.
SSBMSecurityException
- lanciata dal metodo wrapApplData(byte[], int, int, byte)
.wrapApplData(byte[], int, int, byte)
private void wrapApplData(byte[] data, int offset, int length, byte flag) throws javax.net.ssl.SSLException, NetException, SSBMSecurityException
outboundApplData
con il byte di flag e i
length byte contenuti in data a partire dalla
posizione offset. Il contenuto del buffer è crittato (wrappato) e scritto
nel canale socket.
data
- l'array di byte dal quale prelevare i byte da inserire nel buffer.offset
- la posizione dalla quale iniziare il prelievo dei byte.length
- il numero di byte da prelevareflag
- indica se il blocco di byte è l'ultimo; può essere uno tra
LAST_BLOCK_BYTE
o NORMAL_BLOCK_BYTE
.
javax.net.ssl.SSLException
- lanciata dal metodo #handleWrap(Status)
o se si verifica
un errore nel wrapping del buffer.
NetException
- lanciata dal metodo #handleWrap(Status)
.
SSBMSecurityException
- lanciata dal metodo #handleWrap(Status)
.private void write() throws NetException
outboundNetData
sul canale socket.
NetException
- se si verifica un errore nella scrittura sul canale socket.private int read(boolean acceptClosedChannel) throws NetException, SSBMSecurityException
inboundNetData
.
acceptClosedChannel
- false se il riscontro della chiusura del flusso
in input del canale socket deve provocare il lancio di una NetException,
true altrimenti.
NetException
- se si verifica un errore nella lettura del canale socket o
lanciata dal metodo closeEngineOutbound()
invocato
se acceptClosedChannel è false e il flusso in input del canale socket è chiuso.
SSBMSecurityException
- lanciata dal metodo closeEngineOutbound()
invocato
se acceptClosedChannel è false e il flusso in input del canale socket è chiuso.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |