Java Code Examples for com.mysql.cj.exceptions.SSLParamsException

The following examples show how to use com.mysql.cj.exceptions.SSLParamsException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lams   Source File: XProtocol.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void negotiateSSLConnection(int packLength) {

        if (!((XServerCapabilities) this.serverSession.getCapabilities()).hasCapability("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
        ((AsyncMessageReader) this.reader).stopAfterNextMessage();
        setCapability("tls", true);

        try {
            this.socketConnection.performTlsHandshake(null);
        } catch (SSLParamsException | FeatureNotAvailableException | IOException e) {
            throw new CJCommunicationsException(e);
        }

        // resume message processing
        ((AsyncMessageSender) this.writer).setChannel(this.socketConnection.getAsynchronousSocketChannel());
        ((AsyncMessageReader) this.reader).start();
    }
 
Example 2
Source Project: quarkus   Source File: MySQLJDBCReflections.java    License: Apache License 2.0 5 votes vote down vote up
@BuildStep
void registerExceptionsForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJCommunicationsException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, CJConnectionFeatureNotAvailableException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJOperationNotSupportedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJTimeoutException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJPacketTooBigException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, AssertionFailedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJOperationNotSupportedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ClosedOnExpiredPasswordException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ConnectionIsClosedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataConversionException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataReadException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataTruncationException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DeadlockTimeoutRollbackMarker.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, FeatureNotAvailableException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, InvalidConnectionAttributeException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, NumberOutOfRange.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, OperationCancelledException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, PasswordExpiredException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, PropertyNotModifiableException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, RSAException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, SSLParamsException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StatementIsClosedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StreamingNotifiable.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, UnableToConnectException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, UnsupportedConnectionStringException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, WrongArgumentException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.mysql.cj.jdbc.MysqlXAException"));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, StandardLoadBalanceExceptionChecker.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, NdbLoadBalanceExceptionChecker.class.getName()));
}
 
Example 3
Source Project: lams   Source File: ExportControlled.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Configure the {@link SSLContext} based on the supplier property set.
 */
public static SSLContext getSSLContext(String clientCertificateKeyStoreUrl, String clientCertificateKeyStoreType, String clientCertificateKeyStorePassword,
        String trustCertificateKeyStoreUrl, String trustCertificateKeyStoreType, String trustCertificateKeyStorePassword, boolean verifyServerCert,
        String hostName, ExceptionInterceptor exceptionInterceptor) throws SSLParamsException {
    return getSSLContext(clientCertificateKeyStoreUrl, clientCertificateKeyStoreType, clientCertificateKeyStorePassword, trustCertificateKeyStoreUrl,
            trustCertificateKeyStoreType, trustCertificateKeyStorePassword, true, verifyServerCert, hostName, exceptionInterceptor);
}
 
Example 4
Source Project: FoxTelem   Source File: XProtocol.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void negotiateSSLConnection(int packLength) {

        if (!ExportControlled.enabled()) {
            throw new CJConnectionFeatureNotAvailableException();
        }

        if (!((XServerCapabilities) this.serverSession.getCapabilities()).hasCapability("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();
        setCapability("tls", true);

        try {
            this.socketConnection.performTlsHandshake(null); //(this.serverSession);
        } catch (SSLParamsException | FeatureNotAvailableException | IOException e) {
            throw new CJCommunicationsException(e);
        }

        if (this.socketConnection.isSynchronous()) {
            // i/o streams were replaced, build new packet sender/reader
            this.sender = new SyncMessageSender(this.socketConnection.getMysqlOutput());
            this.reader = new SyncMessageReader(this.socketConnection.getMysqlInput());
        } else {
            // resume message processing
            ((AsyncMessageSender) this.sender).setChannel(this.socketConnection.getAsynchronousSocketChannel());
            this.reader.start();
        }
    }
 
Example 5
Source Project: FoxTelem   Source File: ExportControlled.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts the socket being used in the given CoreIO to an SSLSocket by
 * performing the SSL/TLS handshake.
 * 
 * @param rawSocket
 *            original non-SSL socket
 * @param socketConnection
 *            the Protocol instance containing the socket to convert to an
 *            SSLSocket.
 * @param serverVersion
 *            ServerVersion object
 * @return SSL socket
 * @throws IOException
 *             if i/o exception occurs
 * @throws SSLParamsException
 *             if the handshake fails, or if this distribution of
 *             Connector/J doesn't contain the SSL crypto hooks needed to
 *             perform the handshake.
 * @throws FeatureNotAvailableException
 *             if TLS is not supported
 */
public static Socket performTlsHandshake(Socket rawSocket, SocketConnection socketConnection, ServerVersion serverVersion)
        throws IOException, SSLParamsException, FeatureNotAvailableException {

    PropertySet pset = socketConnection.getPropertySet();

    SslMode sslMode = pset.<SslMode> getEnumProperty(PropertyKey.sslMode).getValue();
    boolean verifyServerCert = sslMode == SslMode.VERIFY_CA || sslMode == SslMode.VERIFY_IDENTITY;

    KeyStoreConf trustStore = !verifyServerCert ? new KeyStoreConf() : getTrustStoreConf(pset, PropertyKey.trustCertificateKeyStoreUrl,
            PropertyKey.trustCertificateKeyStorePassword, PropertyKey.trustCertificateKeyStoreType, verifyServerCert && serverVersion == null);

    KeyStoreConf keyStore = getKeyStoreConf(pset, PropertyKey.clientCertificateKeyStoreUrl, PropertyKey.clientCertificateKeyStorePassword,
            PropertyKey.clientCertificateKeyStoreType);

    SSLSocketFactory socketFactory = getSSLContext(keyStore.keyStoreUrl, keyStore.keyStoreType, keyStore.keyStorePassword, trustStore.keyStoreUrl,
            trustStore.keyStoreType, trustStore.keyStorePassword, serverVersion != null, verifyServerCert,
            sslMode == PropertyDefinitions.SslMode.VERIFY_IDENTITY ? socketConnection.getHost() : null, socketConnection.getExceptionInterceptor())
                    .getSocketFactory();

    SSLSocket sslSocket = (SSLSocket) socketFactory.createSocket(rawSocket, socketConnection.getHost(), socketConnection.getPort(), true);

    sslSocket.setEnabledProtocols(getAllowedProtocols(pset, serverVersion, sslSocket.getSupportedProtocols()));

    String[] allowedCiphers = getAllowedCiphers(pset, serverVersion, sslSocket.getEnabledCipherSuites());
    if (allowedCiphers != null) {
        sslSocket.setEnabledCipherSuites(allowedCiphers);
    }

    sslSocket.startHandshake();

    return sslSocket;
}
 
Example 6
Source Project: lams   Source File: XAsyncSocketConnection.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException {
    this.channel = this.socketFactory.performTlsHandshake(this, serverSession);
}
 
Example 7
Source Project: lams   Source File: SQLExceptionsMapping.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static SQLException translateException(Throwable ex, ExceptionInterceptor interceptor) {
    if (ex instanceof SQLException) {
        return (SQLException) ex;

    } else if (ex.getCause() != null && ex.getCause() instanceof SQLException) {
        return (SQLException) ex.getCause();

    } else if (ex instanceof CJCommunicationsException) {
        return SQLError.createCommunicationsException(ex.getMessage(), ex, interceptor);

    } else if (ex instanceof CJConnectionFeatureNotAvailableException) {
        return new ConnectionFeatureNotAvailableException(ex.getMessage(), ex);

    } else if (ex instanceof SSLParamsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_BAD_SSL_PARAMS, 0, false, ex, interceptor);

    } else if (ex instanceof ConnectionIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN, ex, interceptor);

    } else if (ex instanceof InvalidConnectionAttributeException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, ex, interceptor);

    } else if (ex instanceof UnableToConnectException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, ex, interceptor);

    } else if (ex instanceof StatementIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof WrongArgumentException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof StringIndexOutOfBoundsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof NumberOutOfRange) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE, ex, interceptor);

    } else if (ex instanceof DataConversionException) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST, ex, interceptor);

    } else if (ex instanceof DataReadException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof DataTruncationException) {
        return new MysqlDataTruncation(((DataTruncationException) ex).getMessage(), ((DataTruncationException) ex).getIndex(),
                ((DataTruncationException) ex).isParameter(), ((DataTruncationException) ex).isRead(), ((DataTruncationException) ex).getDataSize(),
                ((DataTruncationException) ex).getTransferSize(), ((DataTruncationException) ex).getVendorCode());

    } else if (ex instanceof CJPacketTooBigException) {
        return new PacketTooBigException(ex.getMessage());

    } else if (ex instanceof OperationCancelledException) {
        return new MySQLStatementCancelledException(ex.getMessage());

    } else if (ex instanceof CJTimeoutException) {
        return new MySQLTimeoutException(ex.getMessage());

    } else if (ex instanceof CJOperationNotSupportedException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof UnsupportedOperationException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof CJException) {
        return SQLError.createSQLException(ex.getMessage(), ((CJException) ex).getSQLState(), ((CJException) ex).getVendorCode(),
                ((CJException) ex).isTransient(), interceptor);

    } else {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, ex, interceptor);
    }
}
 
Example 8
public static SQLException translateException(Throwable ex, ExceptionInterceptor interceptor) {
    if (ex instanceof SQLException) {
        return (SQLException) ex;

    } else if (ex.getCause() != null && ex.getCause() instanceof SQLException) {
        return (SQLException) ex.getCause();

    } else if (ex instanceof CJCommunicationsException) {
        return SQLError.createCommunicationsException(ex.getMessage(), ex, interceptor);

    } else if (ex instanceof CJConnectionFeatureNotAvailableException) {
        return new ConnectionFeatureNotAvailableException(ex.getMessage(), ex);

    } else if (ex instanceof SSLParamsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_BAD_SSL_PARAMS, 0, false, ex, interceptor);

    } else if (ex instanceof ConnectionIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN, ex, interceptor);

    } else if (ex instanceof InvalidConnectionAttributeException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, ex, interceptor);

    } else if (ex instanceof UnableToConnectException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, ex, interceptor);

    } else if (ex instanceof StatementIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof WrongArgumentException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof StringIndexOutOfBoundsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof NumberOutOfRange) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE, ex, interceptor);

    } else if (ex instanceof DataConversionException) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST, ex, interceptor);

    } else if (ex instanceof DataReadException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof DataTruncationException) {
        return new MysqlDataTruncation(((DataTruncationException) ex).getMessage(), ((DataTruncationException) ex).getIndex(),
                ((DataTruncationException) ex).isParameter(), ((DataTruncationException) ex).isRead(), ((DataTruncationException) ex).getDataSize(),
                ((DataTruncationException) ex).getTransferSize(), ((DataTruncationException) ex).getVendorCode());

    } else if (ex instanceof CJPacketTooBigException) {
        return new PacketTooBigException(ex.getMessage());

    } else if (ex instanceof OperationCancelledException) {
        return new MySQLStatementCancelledException(ex.getMessage());

    } else if (ex instanceof CJTimeoutException) {
        return new MySQLTimeoutException(ex.getMessage());

    } else if (ex instanceof CJOperationNotSupportedException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof UnsupportedOperationException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof CJException) {
        return SQLError.createSQLException(ex.getMessage(), ((CJException) ex).getSQLState(), ((CJException) ex).getVendorCode(),
                ((CJException) ex).isTransient(), interceptor);

    } else {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, ex, interceptor);
    }
}
 
Example 9
@Override
public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException {
    this.channel = this.socketFactory.performTlsHandshake(this, serverSession);
}
 
Example 10
@Override
public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException {
    // TODO Auto-generated method stub

}
 
Example 11
@Override
public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException {
    // TODO Auto-generated method stub

}
 
Example 12
Source Project: lams   Source File: NativeSocketConnection.java    License: GNU General Public License v2.0 3 votes vote down vote up
@Override
public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException {

    this.mysqlSocket = this.socketFactory.performTlsHandshake(this, serverSession);

    this.mysqlInput = new FullReadInputStream(this.propertySet.getBooleanReadableProperty(PropertyDefinitions.PNAME_useUnbufferedInput).getValue()
            ? getMysqlSocket().getInputStream() : new BufferedInputStream(getMysqlSocket().getInputStream(), 16384));

    this.mysqlOutput = new BufferedOutputStream(getMysqlSocket().getOutputStream(), 16384);
    this.mysqlOutput.flush();

}
 
Example 13
@Override
public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException {

    this.mysqlSocket = this.socketFactory.performTlsHandshake(this, serverSession);

    this.mysqlInput = new FullReadInputStream(this.propertySet.getBooleanProperty(PropertyKey.useUnbufferedInput).getValue()
            ? getMysqlSocket().getInputStream() : new BufferedInputStream(getMysqlSocket().getInputStream(), 16384));

    this.mysqlOutput = new BufferedOutputStream(getMysqlSocket().getOutputStream(), 16384);
    this.mysqlOutput.flush();

}
 
Example 14
Source Project: lams   Source File: SocketConnection.java    License: GNU General Public License v2.0 votes vote down vote up
void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException; 
Example 15
Source Project: FoxTelem   Source File: SocketConnection.java    License: GNU General Public License v3.0 votes vote down vote up
void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException;