Search in sources :

Example 6 with SSLParamsException

use of com.mysql.cj.exceptions.SSLParamsException in project JavaSegundasQuintas by ecteruel.

the class XProtocol method negotiateSSLConnection.

public void negotiateSSLConnection() {
    if (!ExportControlled.enabled()) {
        throw new CJConnectionFeatureNotAvailableException();
    }
    if (!((XServerCapabilities) this.serverSession.getCapabilities()).hasCapability(XServerCapabilities.KEY_TLS)) {
        throw new CJCommunicationsException("A secure connection is required but the server is not configured with SSL.");
    }
    // the message reader is async and is always "reading". we need to stop it to use the socket for the TLS handshake
    this.reader.stopAfterNextMessage();
    Map<String, Object> tlsCapabilities = new HashMap<>();
    tlsCapabilities.put(XServerCapabilities.KEY_TLS, true);
    sendCapabilities(tlsCapabilities);
    try {
        this.socketConnection.performTlsHandshake(null, this.log);
    } catch (SSLParamsException | FeatureNotAvailableException | IOException e) {
        throw new CJCommunicationsException(e);
    }
    try {
        this.sender = new SyncMessageSender(this.socketConnection.getMysqlOutput());
        this.reader = new SyncMessageReader(this.socketConnection.getMysqlInput(), this);
    } catch (IOException e) {
        throw new XProtocolError(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) IOException(java.io.IOException) SSLParamsException(com.mysql.cj.exceptions.SSLParamsException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException)

Aggregations

SSLParamsException (com.mysql.cj.exceptions.SSLParamsException)6 IOException (java.io.IOException)6 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)3 CJConnectionFeatureNotAvailableException (com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException)3 FeatureNotAvailableException (com.mysql.cj.exceptions.FeatureNotAvailableException)3 InputStream (java.io.InputStream)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 KeyManagementException (java.security.KeyManagementException)3 KeyStore (java.security.KeyStore)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UnrecoverableKeyException (java.security.UnrecoverableKeyException)3 CertificateException (java.security.cert.CertificateException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 KeyManager (javax.net.ssl.KeyManager)3 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)3 SSLContext (javax.net.ssl.SSLContext)3 TrustManager (javax.net.ssl.TrustManager)3