public abstract class SSLContext
extends java.lang.Object
implements java.lang.Cloneable
SSLClientContext
and
SSLServerContext
.
new ChainVerifier()
new CipherSuiteList(CipherSuiteList.L_DEFAULT)
NullCompression only
SessionManager.getDefault()
SecurityProvider.getProvider().getSecureRandom()
false
VERSION_TLS10, VERSION_TLS13
null
null
(ignored)
See method documentation
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AVAIL_MODE_DECRYPTED
SSLInputInputStream.available mode "decrypted".
|
static java.lang.String |
AVAIL_MODE_ENCRYPTED
SSLInputInputStream.available mode "encrypted".
|
static java.lang.String |
AVAIL_MODE_ONE_BYTE
SSLInputInputStream.available mode "onebyte".
|
static int |
CERTTYPE_DSS_FIXED_DH
Certificate containing a Diffie-Hellman key.
|
static int |
CERTTYPE_DSS_SIGN
Certificate containing a DSA key.
|
static int |
CERTTYPE_ECDSA_EC
Certificate containing an ECC key that maybe used for signing or encryption (key
agreement).
|
static int |
CERTTYPE_ECDSA_FIXED_ECDH
Certificate containing an ECDH key.
|
static int |
CERTTYPE_ECDSA_SIGN
Certificate containing an ECDSA key.
|
static int |
CERTTYPE_RSA_ENCRYPT
Certificate containing an RSA key that can be used for encryption.
|
static int |
CERTTYPE_RSA_FIXED_DH
Certificate containing a Diffie-Hellman key.
|
static int |
CERTTYPE_RSA_FIXED_ECDH
Certificate containing an ECDH key.
|
static int |
CERTTYPE_RSA_SIGN
Certificate containing an RSA key that can be used for signatures.
|
static int |
CERTTYPE_UNKNOWN
Certificate of unknown type.
|
static double |
LIBRARY_VERSION
iSaSiLk library version.
|
static java.lang.String |
LIBRARY_VERSION_STRING
iSaSiLk library version as a String.
|
static java.lang.String |
SEND_EMPTY_FRAGMENT
Name of the system property, which controls the default empty fragement
behaviour.
|
static int |
VERSION_NOT_CONNECTED
Version number constant for not yet connected.
|
static int |
VERSION_SSL20
Deprecated.
shall not be used anymore
|
static int |
VERSION_SSL30
Deprecated.
shall not be used anymore
|
static int |
VERSION_TLS10
Deprecated.
(for backwards compatibility still min default version but should not be used anymore)
|
static int |
VERSION_TLS11
Deprecated.
shall not be used anymore
|
static int |
VERSION_TLS12
Version number constant for TLS 1.2.
|
static int |
VERSION_TLS13
Version number constant for TLS 1.3.
|
Modifier and Type | Method and Description |
---|---|
void |
addPSKCredential(PSKCredential pskCredential)
Adds the given PSKCredential.
|
void |
addTrustedCertificate(java.security.cert.X509Certificate cert)
Add a trusted certificate.
|
int |
addTrustedCertificates(java.security.KeyStore trustStore)
Add some trusted certificates.
|
int |
addTrustedCertificates(java.security.KeyStore trustStore,
java.lang.String[] aliases)
Add some trusted certificates.
|
int |
addTrustedCertificates(java.lang.String trustStoreFile,
char[] trustStorePassword,
java.lang.String trustStoreType,
java.lang.String trustStoreProvider)
Add some trusted certificates.
|
void |
clearPSKCredentials()
Clears the database of pre-shared keys.
|
java.lang.Object |
clone() |
static java.security.cert.X509Certificate[] |
convertCertificateChain(java.security.cert.Certificate[] certificateChain)
Deprecated.
no replacement
|
java.lang.String[] |
getAllowedProtocolVersionNames()
Get the protocol versions enabled for this context.
|
int[] |
getAllowedProtocolVersions()
Get the protocol versions enabled for this context.
|
boolean |
getAllowIdentityChangeDuringRenegotiation()
Gets whether to allow peer identity change during renegotiation.
|
boolean |
getAllowLegacyRenegotiation()
Gets whether to allow legacy renegotiation.
|
static java.lang.String[] |
getAllSupportedProtocolVersionNames()
Gets an array with all supported protocol version names
supported by iSaSiLk (except for "SSL20" which is not
listed in the array but -- client side -- supported by
iSaSiLk).
|
static int[] |
getAllSupportedProtocolVersions()
Gets an array with all available protocol version numbers
supported by iSaSiLk (except for SSL20 which is not
listed in the array but -- client side -- supported by
iSaSiLk).
|
boolean |
getCacheTerminatedSessions()
Returns whether to cache incorrectly terminated sessions.
|
ChainVerifier |
getChainVerifier()
Get the ChainVerifier for this context.
|
ChannelBindings |
getChannelBindings()
Gets any ChannelBindings the application may be interested in.
|
java.io.PrintWriter |
getDebugStream()
Get the debug stream for this context.
|
boolean |
getDisableRenegotiation()
Gets whether renegotiation is disabled at all.
|
boolean |
getDoNotSendServerCloseNotify()
Returns whether a close_notify alert shall be sent by the server at shutdown or not.
|
CipherSuiteList |
getEnabledCipherSuiteList()
Returns the cipher suites which are enabled in this SSLContext.
|
CipherSuite[] |
getEnabledCipherSuites()
Deprecated.
use getEnabledCipherSuiteList() instead
|
CompressionMethod[] |
getEnabledCompressionMethods()
Returns the compression methods which are enabled in this SSLContext.
|
PSKCredential |
getPSKCredential(byte[] identity,
SSLTransport transport)
Gets the PSKCredential identified by the given identity and/or
information provided by the given SSLTransport object.
|
PSKManager |
getPSKManager()
Returns the PSK manager used by this SSLContext.
|
java.security.SecureRandom |
getRandomGenerator()
Returns the random number generator currently used by this SSLContext.
|
boolean |
getSendEmptyFragment()
Returns the actual empty fragment settings.
|
SessionManager |
getSessionManager()
Returns the session manager defined by this SSLContext.
|
TrustDecider |
getTrustDecider()
Deprecated.
TrustDeciders should no longer be used. See ChainVerifier
|
boolean |
getUseNoRenegotiationWarnings()
Gets whether to allow old renegotiation.
|
void |
setAllowedProtocolVersions(int minimumVersion,
int maximumVersion)
Set the SSL/TLS protocol versions to be accepted during the handshake.
|
void |
setAllowedProtocolVersions(java.lang.String minVersion,
java.lang.String maxVersion)
Set the SSL/TLS protocol versions to be accepted during the handshake.
|
void |
setAllowIdentityChangeDuringRenegotiation(boolean allowIdentityChange)
Sets whether to allow that the peer identity may be changed during
renegotiation.
|
void |
setAllowLegacyRenegotiation(boolean allowLegacyRenegotation)
Sets whether to allow legacy renegotiation.
|
void |
setCacheTerminatedSessions(boolean value)
Sets whether to cache incorrectly terminated sessions.
|
void |
setChainVerifier(ChainVerifier chainVerifier)
Set the ChainVerifier for this context.
|
void |
setChannelBindings(ChannelBindings channelBindings)
Sets any ChannelBindings the application may be interested in.
|
static void |
setCheckTypeOfNextHandshakeMessage(boolean check)
Sets whether to check the type of a received handshake message
if being allowed/expected at the current handshake state.
|
void |
setDebugStream(java.io.OutputStream out)
The default debug stream to use for all Transports created using this context.
|
void |
setDebugStream(java.io.Writer out)
The default debug stream to use for all Transports created using this context.
|
void |
setDisableRenegotiation(boolean disableRenegotation)
Sets whether to disable renegotiation at all.
|
void |
setDoNotPackHandshakeMessages(boolean doNotPackMessages)
Sets whether not to pack handshake messages together where possible
and send them within one SSL/TLS fragment.
|
void |
setDoNotSendServerCloseNotify(boolean doNotSendServerCloseNotify)
Sets whether a close_notify alert shall be sent by the server at shutdown or not.
|
static void |
setDowngradeMaxVersionToTLS12IfNoTLS13CipherSuitesAvailable(boolean downgrade)
Sets whether
shall automatically downgrade
the maximum protocol version number to TLS 1.2 if no TLS 1.3 cipher suites are enabled (and TLS 1.3 is
configured as maximum protocol version number). |
void |
setEnabledCipherSuiteList(CipherSuiteList enabledCipherSuites)
Sets the cipher suites which are enabled in this SSLContext.
|
void |
setEnabledCipherSuites(CipherSuite[] enabledCipherSuites)
Sets the cipher suites which are enabled in this SSLContext.
|
void |
setEnabledCompressionMethods(CompressionMethod[] enabledCompressionMethods)
Sets the compression methods which are enabled in this SSLContext.
|
void |
setExtensions(ExtensionList extensions)
Sets any TLS extensions that shall be used by this context.
|
void |
setInputStreamAvailableMode(java.lang.String availableMode)
Sets the SSLInputInputStream.available mode.
|
void |
setPSKCredential(PSKCredential pskCredential)
Sets the exclusive PSKCredential to be used by this SSLContext.
|
void |
setPSKManager(PSKManager pskManager)
Sets the PSK manager to be used by this SSLContext.
|
void |
setRandomGenerator(java.security.SecureRandom randomGenerator)
Sets the random number generator of this SSLContext.
|
void |
setRecordOverheadSize(int size)
Sets the TLS record overhead size.
|
void |
setSendEmptyFragment(boolean sendEmptyFragment)
To enable IV randomization in CBC mode, an empty fragment will be sent before the encrypted
plaintext fragment.
|
void |
setSendRecordOverflowAlert(boolean send)
Sets whether a
record_overflow alert shall be
sent if a record is received that exceeds the max record size. |
void |
setSessionManager(SessionManager sessionManager)
Sets the session manager defined by this SSLContext.
|
static void |
setTls13MiddleboxCompatibilityMode(boolean mode)
Sets whether to send change_cipher_spec messages when TLS 1.3
is used.
|
void |
setTLS13WaitOnPeerCloseNotify(int size)
Sets whether to wait until the peer has sent its
close_notify
alert when closing the transport. |
void |
setTrustDecider(TrustDecider trustDecider)
Deprecated.
TrustDeciders should no longer be used. See ChainVerifier
|
void |
setUseNoRenegotiationWarnings(boolean useNoRenegotiationWarnings)
Sets whether to use (send)
no_renegotiation warnings as response
to unsupported renegotiation requests. |
void |
setUseRecordSplitting(boolean splitRecords)
Sets whether to use 1/n-1 record splitting in CBC mode as a countermeasure against the
Rizzo/Duong BEAST (Browser Exploit Against SSL/TLS) attack against the
SSL 3.0 / TLS 1.0 protocol.
|
java.lang.String |
toString()
Returns a string representation of this SSLContext.
|
void |
updateCipherSuites()
Update the list of enabled cipher suites to remove all cipher suites
that cannot be used with the enabled protocol version interval and/or
are not supported by the current SecurityProvider.
|
public static final double LIBRARY_VERSION
public static final java.lang.String LIBRARY_VERSION_STRING
public static final int VERSION_NOT_CONNECTED
public static final int VERSION_SSL20
public static final int VERSION_SSL30
public static final int VERSION_TLS10
public static final int VERSION_TLS11
public static final int VERSION_TLS12
public static final int VERSION_TLS13
public static final java.lang.String SEND_EMPTY_FRAGMENT
public static final java.lang.String AVAIL_MODE_ONE_BYTE
SSLInputStream.available
behaviour
to return 1 (byte) if available
is called before the
data has been already decrypted by a preceding read()
call.
A subsequent read()
call will decrypt the next SSL message to return
the exact number of (unencrypted) bytes.public static final java.lang.String AVAIL_MODE_ENCRYPTED
SSLInputStream.available
behaviour
to return the number of encrypted bytes if available
is called before the data has been already decrypted by a preceding
read()
call. This is the default behaviour. Note that
the number of (encrypted) bytes maybe greater than
the number of (decrypted) bytes that are actually available. You may
change the default behaviour by calling method setInputStreamAvailableMode
.public static final java.lang.String AVAIL_MODE_DECRYPTED
SSLInputStream.available
behaviour
to return the number of decrypted bytes if available
is called before the data has been already decrypted by a preceding
read()
call. If this option is selected a read()
call may be necessary within method available
to read (and decrypt)
the next SSL record. This may cause method available
to block if
not enough bytes are available from the underlying stream to read a full
SSL record. You may enable this behaviour by calling method setInputStreamAvailableMode
.public static final int CERTTYPE_UNKNOWN
public static final int CERTTYPE_RSA_SIGN
public static final int CERTTYPE_RSA_ENCRYPT
public static final int CERTTYPE_DSS_SIGN
public static final int CERTTYPE_RSA_FIXED_DH
public static final int CERTTYPE_DSS_FIXED_DH
public static final int CERTTYPE_ECDSA_SIGN
public static final int CERTTYPE_RSA_FIXED_ECDH
public static final int CERTTYPE_ECDSA_FIXED_ECDH
public static final int CERTTYPE_ECDSA_EC
public static void setCheckTypeOfNextHandshakeMessage(boolean check)
By default iSaSiLk checks for any received handshake message if its type is allowed/expected at the current handshake state. Although iSaSiLk performs a handshake state check in any case, disabling the handshake message type check is not recommended any maybe only done for error detecting purposes.
check
- whether to check the type of an handshake message
(default: true
)public static void setTls13MiddleboxCompatibilityMode(boolean mode)
TLS 1.3 does not require to use change_cipher_spec messages in TLS 1.3
handshakes. However, for middlebox compatibility it may be
preferable to send (dummy) change_cipher_spec messages.
Note that the spec requires that a TLS 1.3 server must send
send (dummy) change_cipher_spec messages in a TLS 1.3 handshake if the
client uses a non-empty session id. iSaSiLk clients use non-empty
session ids and iSaSiLk clienst and servers send (dummy) change_chipher_spec
messages in TLS 1.3 handshakes, too.
When switching off the middle box compatibility mode by calling
setTls13MiddleboxCompatibilityMode(false)
iSaSiLk does not send change_chipher_spec messages. This means that
in this case an iSaSiLk server does not send a change_cipher_spec
message even if the client uses a non-empty sessio id.
mode
- whether to send chenge_cipher_spec messages
when TLS 1.3 is used (default: true
;
change_cipher_spec messages are sent)public static void setDowngradeMaxVersionToTLS12IfNoTLS13CipherSuitesAvailable(boolean downgrade)
updateCipherSuites
shall automatically downgrade
the maximum protocol version number to TLS 1.2 if no TLS 1.3 cipher suites are enabled (and TLS 1.3 is
configured as maximum protocol version number). By default updateCipherSuites()
will throw
an exception in this case indicating that the SSLContext is no properly configured and TLS 1.3 cannot
be enabled without any TLS 1.2 cipher suites.
Deciding whether setting downgrade
to true
should be done with special care
only. Having TLS 1.3 but not any TLS 1.3 cipher suites enabled is a clear indication of some mis-configuration
which might not be detected when automatically downgrading to TLS 1.2. Thus considering to set downgrade
to
true
might be done only if required for backwards compatibility.
downgrade
- whether to automatically downgrade to TLS 1.3 if no TLS 1.3 cipher suites are enabled
(default: false; updateCipherSuites() will throw an exception)public static java.lang.String[] getAllSupportedProtocolVersionNames()
Note the difference to method
which returns
the protocol versions enabled for some specific
getAllowedProtocolVersionNames()
SSLContext
object.
public static int[] getAllSupportedProtocolVersions()
Note the difference to method
which returns
the protocol versions enabled for some specific
getAllowedProtocolVersions()
SSLContext
object.
public void updateCipherSuites()
Since cipher suite availability also depends on the enabled protocol
version interval method
shall be called
before calling method setAllowedProtocolVersions
updateCipherSuites
Also cipher suite availability may depend on the extension list
(TLS 1.2 SignatureAlgorithms), thus -- if you want to explicitly
set an SignatureAlgorithms
extension -- you may call
method
before method setExtensions
updateCipherSuites
. This is not necessary
if you rely on the default SignatureAlgorithms selection.
java.lang.NullPointerException
- if no cipher suite cannot be enabled
because none of the configured suites
is supportedpublic ChainVerifier getChainVerifier()
ChainVerifier
public void setChainVerifier(ChainVerifier chainVerifier)
ChainVerifier
public void addTrustedCertificate(java.security.cert.X509Certificate cert)
null
if want to accept if the peer does not
send a certificate (i.e. you want to trust an anonymous peer).public int addTrustedCertificates(java.lang.String trustStoreFile, char[] trustStorePassword, java.lang.String trustStoreType, java.lang.String trustStoreProvider) throws java.security.KeyStoreException
Any trusted certificate entry contained in the KeyStore is added as
trusted certificate.
trustStoreFile
- the name of the KeyStore file from which to read trusted certificatestrustStorePassword
- the password of the trusted KeyStoretrustStoreType
- the type of the trusted KeyStore; default: IAIKKeyStore
trustStoreProvider
- the provider of the trusted KeyStore; default: IAIK
java.security.KeyStoreException
- if an error occurs while getting certificates
from the KeyStorepublic int addTrustedCertificates(java.security.KeyStore trustStore) throws java.security.KeyStoreException
The KeyStore must have been already loaded when calling this method.
Any trusted certificate entry contained in the KeyStore is added as
trusted certificate.
trustStore
- the KeyStore from which to read the trusted certificatesjava.security.KeyStoreException
- if an error occurs while getting certificates
from the KeyStorepublic int addTrustedCertificates(java.security.KeyStore trustStore, java.lang.String[] aliases) throws java.security.KeyStoreException
This method is similar to method addTrustedCertificates(KeyStore)
except that only those certificate entries
are added that are specified by their aliases. If no aliases are specified, all
trusted certificate entry contained in the KeyStore is added as trusted certificate
(in this case this method does the same as method
addTrustedCertificates(KeyStore)
).
trustStore
- the KeyStore from which to read the trusted certificatesaliases
- the alias names of the certificate entries to be added as
trusted certificatesjava.security.KeyStoreException
- if an error occurs while getting certificates
from the KeyStore, or no certificate entry is
available for any of the specified alias namespublic java.security.SecureRandom getRandomGenerator()
public void setRandomGenerator(java.security.SecureRandom randomGenerator)
randomGenerator
- the random number generator to usepublic SessionManager getSessionManager()
public void setSessionManager(SessionManager sessionManager)
sessionManager
- the session manager defined by this SSLContextpublic PSKManager getPSKManager()
set
for managing pre shared keys
for psk based cipher suites. If no
PSK manager has been explicitly set by the application,
the DefaultPSKManager
is used.public void setPSKManager(PSKManager pskManager)
DefaultPSKManager
is used for managing pre shared keys
for
psk based cipher suites.pskManager
- the PSK manager to be used by this SSLContextpublic void addPSKCredential(PSKCredential pskCredential)
PSKCredential
identifies a pre shared key to be used with psk cipher suites.
If an exclusive PSKCredential has been set (or will be set) by
calling method setPSKCredential
any PSKCredential added by this method will be ignored by any further
call to method getPSKCredential
.pskCredential
- the PSKCredential to be addedpublic void setPSKCredential(PSKCredential pskCredential)
PSKCredential
identifies a pre-shared key to be used with psk cipher suites. If this
method is used for exclusively setting a PSKCredential, any other
PSKCredential that may have been added
so far (or may be added later) is ignored.
If a PSKManager is installed, it is ignored too.
Be careful to use setPSKCredential
on the server side.
In this case your server will only have one single pre-shared key to be used with any
client that requests a PSK based TLS communication.
However, on the client side you already will know the server when creating the
SSLClientContext, thus you also will know the pre-shared key to be used for
establishing a TLS-PSK session with this server. For that reason you may not need a
PSKManager and may explicitly set the corresponding PSKCredential to be used with
this specific SSLClientContext, e.g.:
// psk identity String identity = ...; // server name (remote peer id) String serverName = ...; // the pre-shared key PreSharedKey psk = ...; // create PSKCredential PSKCredential pskCredential = new PSKCredential(identity, psk); // set remote peer id pskCredential.setRemotePeerId(serverName); // create client context SSLClientContext context = new SSLClientContext(); // set pre-shared key context.setPSKCredential(pskCredential); // enable PSK cipher suites CipherSuiteList suites = new CipherSuiteList(); suites.add(CipherSuite.CS_ALL_PSK); context.setEnabledCipherSuiteList(suites); context.updateCipherSuites(); ...Of course you can use a
PSKManager
on the client side, too (for maintaining several pre-shared key and
let the PSKManager search for the right psk when connecting to some server).
In this case you may add PSKCredentials by calls of method addPSKCredential
.pskCredential
- the PSKCredential to be used by this SSLContext
with psk cipher suitesjava.lang.IllegalArgumentException
- when trying to set an exclusive PSK credential
on the server sidepublic PSKCredential getPSKCredential(byte[] identity, SSLTransport transport) throws SSLException
This method maybe called by iSaSiLk in two different situations, depending
on if the identity
argument is null
or
not. If not null
iSaSiLk asks for a PSKCredential
with the specific psk identity (see 1. below). If null
iSaSiLK searches based on identification information provided by
the second (SSLTransport
) argument (see 2. below).
identity
argument is not null
this method is called by iSaSiLk to search for a pre-shared key for
the given identity. On the client side, the given identity
represents the psk identity hint that may have been sent by the server
within the ServerKeyExchange message. Note that the TLS-PSK specification
(RFC 4279) does NOT recommend to use a psk identity hint. Unless not explicitly
required by the application environment, the server SHOULD NOT send
a psk identity hint,
and the client MUST ignore
a psk
identity hint if sent by the server.
PSKManager
.
The default
PSKManager implementation requires that each
identity is unique for the whole application environment. Thus, if the identity
argument is not null
the second argument (SSLTransport
) of
this method is not used by the DefaultPSKManager except for on the client side when
having received a psk identity hint but not found a proper PSKCredential. In this case
the DefaultPSKManager looks if he has a PSKCredential with the peer id of the server
(got from the SSLTransport
argument).
identity
argument is null
this method is called by iSaSiLk to search for a pre-shared key based
on peer information provided by the given SSLTransport object.
The default
PSKManager implementation asks the given
SSLTransport for peer identification information by calling the following methods
(in that order):
transport.getRemotePeerName()
transport.getRemoteIndetAddress()
.getHostAddress()
transport.getRemotePeerId()
If you are, for instance, on the client side and want to go into a psk based TLS session with a server "pskserver.iaik.tugraz.at" with ip address "129.27.142.47" listening on port 4433, the SSL(Socket)Transport methods above will return the following values (in that order):
pskserver.iaik.tugraz.at
129.27.142.47
129.27.142.47:4433
Thus, when registering
a
PSKCredential to be used for a TLS communication with the "pskserver.iaik.tugraz.at"
server, it must have one of the three identification information values
from above as remote peer id, e.g.:
// the psk identity String identity = ...; // the pre-shared key PreSharedKey psk = ...; // create PSKCredential PSKCredential pskCredential = new PSKCredential(identity, psk); // set remote peer id int serverPort = 4433; String serverName = "pskserver.iaik.tugraz.at"; pskCredential.setRemotePeerId(serverName); // create SSLClientContext and add the credential SSLClientContext context = new SSLClientContext(); // calling this method forwards the PSKCredential to the internal PSKManager context.addPSKCredential(pskCredential);When now connecting to server "pskserver.iaik.tugraz.at", iSaSiLk asks the PSK manager for a PSKCredential with remote peer id "pskserver.iaik.tugraz.at" and the connection can succeed if both parties support the negotiated cipher suite and have a corresponding pre-shared key:
// enable PSK cipher suites CipherSuiteList suites = new CipherSuiteList(); suites.add(CipherSuite.CS_ALL_PSK); SSLSocket socket = new SSLSocket(serverName, serverPort, context); // start handshake socket.startHandshake(); // psk identity String pskIdentity = socket.getPSKIdentity(); if (pskIdentity != null) { System.out.println("PSK Identity: " + pskIdentity); } // send GET-request System.out.println("Sending HTTPS request to " + serverName); PrintWriter writer = Utils.getASCIIWriter(socket.getOutputStream()); BufferedReader reader = Utils.getASCIIReader(socket.getInputStream()); writer.println("GET / HTTP/1.0"); writer.println(); writer.flush(); // read response while( true ) { String line = reader.readLine(); if( line == null ) { break; } System.out.print(":"); System.out.println(line); } socket.close();Note, that if the psk identity already represents any of the remote peer ids, it may be not necessary to explicitly set it as remote peer id for the psk credential (the
DefaultPSKManager
implementation looks for the id in this case, too), e.g.:
String serverName = "pskserver.iaik.tugraz.at"; // the psk identity String identity = serverName; // the pre-shared key PreSharedKey psk = ...; // create PSKCredential PSKCredential pskCredential = new PSKCredential(identity, psk);In similar way, if the remote peer id is equal to the psk identity hint, it may be sufficient to only set the psk identity hint.
By default pre-shared keys are maintained by the iSaSiLk
PSKManager
. However,
you can disable the PSKManager at all by using method setPSKCredential
for specifying an exclusive PSKCredential to be used only with some specific
SSLContext
. This may be suitable on the
client side: since you already know the server when creating the SSLClientContext
you also will know the pre-shared key to be used for establishing a TLS-PSK session
with this server. Thus you may not neet a PSKManager and may explicitly set the
corresponding PSKCredential to be used with this specific SSLClientContext.
However, be careful to use setPSKCredential
on the server side.
In this case your server will only have one single pre-shared key to be used with any
client that requests a PSK based TLS communication.
An application also may bypass the default iSaSiLk PSK management by
extending class SSLClientContext and overriding this getPSKCredential
method to follow some different strategy (for instance poping up some
dialog window etc. to ask the user for entering a pre-shared key...).
identity
- the (UTF-8 encoded) identity, if not null
identifying
the PSK for which to searchtransport
- the SSLTransport to maybe used for getting information
about the remote peer (if identity
is
null
or if required by the psk management
implementation)null
if no such PSKCredential is includedSSLException
- if the given identity is invalid encoded (not UTF-8)public void clearPSKCredentials()
public CipherSuiteList getEnabledCipherSuiteList()
public void setEnabledCipherSuiteList(CipherSuiteList enabledCipherSuites)
enabledCipherSuites
- the cipher suites which are enabled in this SSLContextpublic void setEnabledCipherSuites(CipherSuite[] enabledCipherSuites)
enabledCipherSuites
- the cipher suites which are enabled in this SSLContextpublic CompressionMethod[] getEnabledCompressionMethods()
public void setEnabledCompressionMethods(CompressionMethod[] enabledCompressionMethods)
enabledCompressionMethods
- the compression methods which
are enabled in this SSLContext
(the enabledCompressionMethods
array is not cloned or copied by this method)public boolean getCacheTerminatedSessions()
Unfortunately a number of SSL/TLS applications, seemingly including most or all
versions of the Microsoft IIS server and IE explorer, do not correctly shutdown
the SSL/TLS layer before closing the connection on the TCP level. Depending on
the protocol version this may cause EOFExceptions to be thrown and also may
cause iSaSiLk to invalidate the session resulting in a full handshake for each
connection and consequently lower performance.
Note that this is a bug in those client/server implementations and not in iSaSiLk!
Anyway, you can tell iSaSiLk to ignore this (i.e. no EOFException will be thrown
and the session is cached as usually) by using method
:
setCacheTerminatedSessions
context.setCacheTerminatedSessions(true);Note that when activated you may be vulnerable to truncation attacks. Note also that TLS 1.0 (RFC 2246) does not allow to resume incorrectly terminated sessions. However, since closing TLS sessions without correct shutdown is a common practice, TLS 1.1 (RFC 4346) does no longer require to invalidate incorrectly terminated sessions. For that reason, the default behaviour of iSaSiLk is different for TLS 1.1 (incorrectly terminated sessions are cached) and protocol versions prior TLS 1.1 where incorrectly terminated sessions cause an EOF exception and are not cached by default. You may explicitly call method
setCacheTerminatedSessions
if you want to enforce the same behaviour for all protocol versions.true
if explicitly set by the application by calling
setCacheTerminatedSessions(true)
or this context has been configured
to
support TLS 1.1 only
false
if explicitly set by the application by calling
setCacheTerminatedSessions(false)
or this context has NOT been explicitly configured
to
support TLS 1.1 only
setCacheTerminatedSessions
has not
been called explictly, the value returned by this method may differ from the
actual behaviour which depends on the version that actually has been negotiated between
client and server during the handshake. For instance, if you have decided to use
the default settings and this SSLContext supports versions SSL 3.0, TLS 1.0, TLS 1.1
this method will return false
, however, an incorrectly terminated session
will be cached by default if TLS 1.1 is negotiated as active version between client and serverpublic void setCacheTerminatedSessions(boolean value)
Unfortunately a number of SSL/TLS applications, seemingly including most or all
versions of the Microsoft IIS server and IE explorer, do not correctly shutdown
the SSL/TLS layer before closing the connection on the TCP level. Depending on
the protocol version this may cause EOFExceptions to be thrown and also may
cause iSaSiLk to invalidate the session resulting in a full handshake for each
connection and consequently lower performance.
Note that this is a bug in those client/server implementations and not in iSaSiLk!
Anyway, you can tell iSaSiLk to ignore this (i.e. no EOFException will be thrown
and the session is cached as usually) by calling:
context.setCacheTerminatedSessions(true);Note that when activated you may be vulnerable to truncation attacks. Note also that TLS 1.0 (RFC 2246) does not allow to resume incorrectly terminated sessions. However, since closing TLS sessions without correct shutdown is a common practice, TLS 1.1 (RFC 4346) does no longer require to invalidate incorrectly terminated sessions. For that reason, the default behaviour of iSaSiLk is different for TLS 1.1 (incorrectly terminated sessions are cached) and protocol versions prior TLS 1.1 where incorrectly terminated sessions cause an EOF exception and are not cached by default. You may explicitly call this
setCacheTerminatedSessions
method if you want to enforce the
same behaviour for all protocol versions.value
- true
if you want to cache incorrectly terminated sessions,
false
if you do not want to cache thempublic void setAllowedProtocolVersions(int minimumVersion, int maximumVersion) throws java.lang.IllegalArgumentException
The parameters passed should be from the VERSION_xxx list defined in this class. Per default both SSLv3 and TLS are enabled, SSLv2 is disabled.
If you want to enable e.g. SSLv3 and TLS use
setAllowedProtocolVersions(SSLContext.VERSION_SSL30, SSLContext.VERSION_TLS12);
.
throws
- IllegalArgumentException if the given protocol version
String is not supported or the
context configuration does not
comply with the versionsjava.lang.IllegalArgumentException
public void setAllowedProtocolVersions(java.lang.String minVersion, java.lang.String maxVersion) throws java.lang.IllegalArgumentException
minVersion
- the minimum protocol version as StringmaxVersion
- the maximum protocol version as Stringthrows
- IllegalArgumentException if the given protocol version
String is not supported or the
context configuration does not
comply with the versionsjava.lang.IllegalArgumentException
public int[] getAllowedProtocolVersions()
public java.lang.String[] getAllowedProtocolVersionNames()
public final void setExtensions(ExtensionList extensions) throws java.lang.IllegalArgumentException
The extensions have to be specified as
.
The ExtensionList configuration shall already be finsihed when calling
this ExtensionList
setExtensions
method to set the ExtensionList for an
SSLContext. Any modifications an application may apply to an ExtensionList
after having set it for an SSLContext are not recognized by the SSLContext.
extensions
- the TLS ExtensionList
to be used by this SSLContext,
or null
if no extensions shall be supported by
this SSLContextIllegalArgumetException
- if something is wrong with any of the
extensions to be addedjava.lang.IllegalArgumentException
public void setTLS13WaitOnPeerCloseNotify(int size)
close_notify
alert when closing the transport.
close_notify
alert before closing the write side of the
connection, unless it has already sent some error alert. Although a TLS
endpoint also may immediately close its read side, too, it may wait
doing so until having received the close_notify
alert
from the peer.
This method allows to configure the behaviour when closing
the SSL transport. By default the close method waits for the peer
close_notify
alert by reading up to 4096 bytes from the input
stream. If the close_notify
has not been received so far, the
connection is shut down and closed without further waiting. By de/increasing
the amount of bytes to be read the wait interval can be de/increased. By
setting the number of bytes to <=0, the connection is immediately shut down
and closed without waiting on the close_notify
from the peer.
Note that closing
will block until data is
received from peer.
size
- the amount of bytes to read until closing
the connection without further waiting
on the close_notify
alert
from the peer (default: 4096); or -1
for immediately shutting down / closing
the connectionpublic void setDebugStream(java.io.OutputStream out)
SSLTransport.setDebugStream()
method.public void setDebugStream(java.io.Writer out)
SSLTransport.setDebugStream()
method.public java.io.PrintWriter getDebugStream()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
public CipherSuite[] getEnabledCipherSuites()
public TrustDecider getTrustDecider()
public void setTrustDecider(TrustDecider trustDecider)
public static java.security.cert.X509Certificate[] convertCertificateChain(java.security.cert.Certificate[] certificateChain) throws java.security.cert.CertificateException
java.security.cert.CertificateException
public void setSendEmptyFragment(boolean sendEmptyFragment)
SSLContext.SEND_EMPTY_FRAGMENT
system property. If this system property is set (whatever value)
the empty fragments feature is enabled. This method overrules the system property settings.
If sending of empty fragments is enabled and SSL 3.0 / TLS 1.0 is used,
1/n-1 record splitting
is automatically
disabled. Thus, if you call this method with sendEmptyFragment
set
to true
after calling method setUseRecordSplitting
1/n-1 record splitting will not be used because empty
fragments will be sent.
sendEmptyFragment
- if true
an empty fragment will be sent.public boolean getSendEmptyFragment()
true
an empty fragment will be sent.setSendEmptyFragment(boolean)
public void setUseRecordSplitting(boolean splitRecords)
If 1/n-1 record splitting is enabled and SSL 3.0 / TLS 1.0 is used,
sending of empty fragments
is
automatically disabled. Thus, if you call this method with splitRecords
set to true
after calling method setSendEmptyFragment
no empty fragments will be sent because 1/n-1 record splitting
is used.
splitRecords
- true
(default) to use 1/n-1 record splitting,
false
to not use itpublic void setDoNotSendServerCloseNotify(boolean doNotSendServerCloseNotify)
doNotSendServerCloseNotify
- if true
the server will not send a close_notify
alert at shutdownpublic boolean getDoNotSendServerCloseNotify()
public void setRecordOverheadSize(int size)
max_fragment_length
extension
is used iSaSiLk adds an overhead size of 297 bytes only (header length
+ mac length + max padding length + max explicit IV size) to the negotiated
fragment length.
setSendRecordOverflowAlert
to tell iSaSiLk to automatically enlarge
the buffer (and not break the handshake with a record_overflow alert)
when the peer sends a record that exceeds the maximum fragment length.size
- the record overhead size to be usedpublic void setSendRecordOverflowAlert(boolean send)
record_overflow
alert shall be
sent if a record is received that exceeds the max record size.
The maximum plaintext fragment length used by the SSL/TLS protocol is 2^14 (16384) bytes. Usually a record_overflow alert has to be triggered when receiving records that exceed the allowed limit. However, some TLS protocol implementations may not take care about record size limitations. You may want to tell iSaSiLk to automatically enlarge the buffer (and not break the handshake with a record_overflow alert) when the peer sends a record that exceeds the maximum fragment length:
context.setSendRecordOverflowAlert(false);
send
- whether to send a record_overflow
alert
(default: true) if a record is received that exceeds
the max record size or to automatically resize the internal
buffer and do not send a record_overflow
alertpublic void setDoNotPackHandshakeMessages(boolean doNotPackMessages)
doNotPackMessages
- whether to pack handshake messages or not
(default: false
; messages are packed)public void setDisableRenegotiation(boolean disableRenegotation)
no_renegotatioan
warning or fatal handshake failure alert
will be triggered if the peers tries to renegotiate a session.
disableRenegotation
- whether to disable renegotation or not
(default: false
; renegotiation is allowed)public boolean getDisableRenegotiation()
no_renegotatioan
alert will be triggered if the peers tries to renegotiate a session.false
; renegotiation is allowed)setDisableRenegotiation(boolean)
public void setAllowLegacyRenegotiation(boolean allowLegacyRenegotation)
true
, renegotiation without using
the RenegotiationInfo
extension (RFC 5746) is allowed. Please note
that your application may be vulnerable to renegotiation attacks if
you allow legacy renegotiation without using the RenegotiationInfo
extension to cryptographically bind the renegotiation handshake to
the enclosing SSL/TLS connection (see RFC 5746).allowLegacyRenegotation
- whether to allow legacy renegotation or not
(default: false
; legacy renegotiation
is not allowed)public boolean getAllowLegacyRenegotiation()
allow_legacy_renegotiation
flag is set to true
, renegotiation without using
the RenegotiationInfo
extension is allowed.true
if legacy renegotation is allowed;
false
(default) if legacy renegotiation is not allowedsetAllowLegacyRenegotiation(boolean)
public void setUseNoRenegotiationWarnings(boolean useNoRenegotiationWarnings)
no_renegotiation
warnings as response
to unsupported renegotiation requests.
no_renegotiation
warning alert may be sent in any of the following
situations:
no_renegotiation
warning if renegotiation
has been disbaled
at all, but
a server sends a hello_request
message to ask the client for
initiating a renegotiation handshake.
no_renegotiation
warning if
legacy renegotiation
is
not allowed, but a server that only supports legacy renegotiation
sends a hello_request
message to ask the client for
initiating a renegotiation handshake.
no_renegotiation
warning if renegotiation
has been disbaled
at all, but
a client sends a client_hello
message to initiate a
renegotiation handshake.
no_renegotiation
warning if
legacy renegotiation
is
not allowed, but a client that only supports legacy renegotiation
sends a client_hello
message to start a renegotiation handshake.
no_renegotiation
warning alert may be
send to refuse the renegotiation request of the peer. Since no_renegotiation
alerts are not defined for SSLv3, SSLv3 client/servers immediately abort the SSL session
by sending a fatal handshake_failure
alert. Since no_renegotiation
alerts are not fatal, but only warning alerts, TLS clients/servers keep the
TLS connection opened and only send the no_renegotiation
warning
to refuse the renegotation request of the peer. It is then up to the peer to
decide whether to continue with the current session or to abort the TLS connection.
no_renegotiation
warnings. If a client
does not announce its ability to secure renegotiation within its initial ClientHello message
(by including the TLS_EMPTY_RENEGOTIATION_INFO_SCSV cipher suite value or the RenegotiationInfo
extension), an iSaSiLk server will immediately abort the handshake by sending a fatal handshake
failure alert as recommended by RFC 5746.
no_renegotiation
warning in any
of the situations described obove, configure your SSLContext to use
no_renegotiation
warnings (please note that in this case
your server maybe vulnerable to attacks where only the client notices that a renegotiation
takes place):
sslContext.setUseNoRenegotiationWarnings(true);
useNoRenegotiationWarnings
- whether to use (send) no_renegotiation
warnings on unsupported TLS renegotiation requests
(default: false
; no_renegotiation
warnings are not used)public boolean getUseNoRenegotiationWarnings()
use_no_renegotiation_warning
flag is set to true
, TLS clients/servers send a no_renegotiation
warning
to refuse a not supported renegoation request.true
if no_renegotiation
warnings shall be used;
false
(default) if no_renegotiation
warnings shall not be usedsetUseNoRenegotiationWarnings(boolean)
public void setAllowIdentityChangeDuringRenegotiation(boolean allowIdentityChange)
handshake_failure
alert if the peer tries to authenticate with a different certificate
or psk identiy, or tries to use a different ServerName extension than
used for the preceding session.allowIdentityChange
- whether to allow that the peer identity may
be changed during renegotiation (default:
false
; peer identity change is
not allowed)public boolean getAllowIdentityChangeDuringRenegotiation()
allowIdentityChange
flag is set to true
, identity change is allowed during renegotiation.false
(default) to not allow peer identity change during renegotiation
true
to allow peer identity change during renegotiation;setAllowIdentityChangeDuringRenegotiation(boolean)
public void setInputStreamAvailableMode(java.lang.String availableMode)
This method may be used to configure the SSLInputInputStream.available
behaviour for the case when the data has not been already decrypted
by a preceding read()
call. The mode may be set to
read()
call may be necessary within
method available
to read (and decrypt) the next SSL record.
This may cause method available
to block if not enough bytes
are available from the underlying stream to read a full SSL record.
availableMode
- "onebyte" to return 1 if the data has not been decrypted yet,
"encrypted" to return the number of encrypted bytes,
"decrypted" to read and decrypt the next message to return the number
of decrypted data bytespublic void setChannelBindings(ChannelBindings channelBindings)
channelBindings
- the ChannelBindingsjava.lang.IllegalArgumentException
- if any of the given ChannelBindings does
contain datapublic ChannelBindings getChannelBindings()