Search in sources :

Example 1 with CJConnectionFeatureNotAvailableException

use of com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException in project ABC by RuiPinto96274.

the class NativeProtocol method negotiateSSLConnection.

/**
 * Negotiates the SSL communications channel used when connecting
 * to a MySQL server that understands SSL.
 */
@Override
public void negotiateSSLConnection() {
    if (!ExportControlled.enabled()) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), null);
    }
    long clientParam = this.serverSession.getClientParam();
    NativePacketPayload packet = new NativePacketPayload(SSL_REQUEST_LENGTH);
    packet.writeInteger(IntegerDataType.INT4, clientParam);
    packet.writeInteger(IntegerDataType.INT4, NativeConstants.MAX_PACKET_SIZE);
    packet.writeInteger(IntegerDataType.INT1, this.serverSession.getCharsetSettings().configurePreHandshake(false));
    // Set of bytes reserved for future use.
    packet.writeBytes(StringLengthDataType.STRING_FIXED, new byte[23]);
    send(packet, packet.getPosition());
    try {
        this.socketConnection.performTlsHandshake(this.serverSession, this.log);
        // i/o streams were replaced, build new packet sender/reader
        this.packetSender = new SimplePacketSender(this.socketConnection.getMysqlOutput());
        this.packetReader = new SimplePacketReader(this.socketConnection, this.maxAllowedPacket);
    } catch (FeatureNotAvailableException nae) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), nae);
    } catch (IOException ioEx) {
        throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, this.getPacketSentTimeHolder(), this.getPacketReceivedTimeHolder(), ioEx, getExceptionInterceptor());
    }
}
Also used : CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) IOException(java.io.IOException)

Example 2 with CJConnectionFeatureNotAvailableException

use of com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException in project ABC by RuiPinto96274.

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)

Example 3 with CJConnectionFeatureNotAvailableException

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

the class NativeProtocol method negotiateSSLConnection.

/**
 * Negotiates the SSL communications channel used when connecting
 * to a MySQL server that understands SSL.
 */
@Override
public void negotiateSSLConnection() {
    if (!ExportControlled.enabled()) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), null);
    }
    long clientParam = this.serverSession.getClientParam();
    NativePacketPayload packet = new NativePacketPayload(SSL_REQUEST_LENGTH);
    packet.writeInteger(IntegerDataType.INT4, clientParam);
    packet.writeInteger(IntegerDataType.INT4, NativeConstants.MAX_PACKET_SIZE);
    packet.writeInteger(IntegerDataType.INT1, this.serverSession.getCharsetSettings().configurePreHandshake(false));
    // Set of bytes reserved for future use.
    packet.writeBytes(StringLengthDataType.STRING_FIXED, new byte[23]);
    send(packet, packet.getPosition());
    try {
        this.socketConnection.performTlsHandshake(this.serverSession, this.log);
        // i/o streams were replaced, build new packet sender/reader
        this.packetSender = new SimplePacketSender(this.socketConnection.getMysqlOutput());
        this.packetReader = new SimplePacketReader(this.socketConnection, this.maxAllowedPacket);
    } catch (FeatureNotAvailableException nae) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), nae);
    } catch (IOException ioEx) {
        throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, this.getPacketSentTimeHolder(), this.getPacketReceivedTimeHolder(), ioEx, getExceptionInterceptor());
    }
}
Also used : CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) IOException(java.io.IOException)

Example 4 with CJConnectionFeatureNotAvailableException

use of com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException in project aws-mysql-jdbc by awslabs.

the class NativeProtocol method negotiateSSLConnection.

/**
 * Negotiates the SSL communications channel used when connecting
 * to a MySQL server that understands SSL.
 */
@Override
public void negotiateSSLConnection() {
    if (!ExportControlled.enabled()) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), null);
    }
    long clientParam = this.serverSession.getClientParam();
    NativePacketPayload packet = new NativePacketPayload(SSL_REQUEST_LENGTH);
    packet.writeInteger(IntegerDataType.INT4, clientParam);
    packet.writeInteger(IntegerDataType.INT4, NativeConstants.MAX_PACKET_SIZE);
    packet.writeInteger(IntegerDataType.INT1, this.serverSession.getCharsetSettings().configurePreHandshake(false));
    // Set of bytes reserved for future use.
    packet.writeBytes(StringLengthDataType.STRING_FIXED, new byte[23]);
    send(packet, packet.getPosition());
    try {
        this.socketConnection.performTlsHandshake(this.serverSession, this.log);
        // i/o streams were replaced, build new packet sender/reader
        this.packetSender = new SimplePacketSender(this.socketConnection.getMysqlOutput());
        this.packetReader = new SimplePacketReader(this.socketConnection, this.maxAllowedPacket);
    } catch (FeatureNotAvailableException nae) {
        throw new CJConnectionFeatureNotAvailableException(this.getPropertySet(), this.serverSession, this.getPacketSentTimeHolder(), nae);
    } catch (IOException ioEx) {
        throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, this.getPacketSentTimeHolder(), this.getPacketReceivedTimeHolder(), ioEx, getExceptionInterceptor());
    }
}
Also used : CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException) CJConnectionFeatureNotAvailableException(com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException) IOException(java.io.IOException)

Example 5 with CJConnectionFeatureNotAvailableException

use of com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException in project aws-mysql-jdbc by awslabs.

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

CJConnectionFeatureNotAvailableException (com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException)6 FeatureNotAvailableException (com.mysql.cj.exceptions.FeatureNotAvailableException)6 IOException (java.io.IOException)6 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)3 SSLParamsException (com.mysql.cj.exceptions.SSLParamsException)3 HashMap (java.util.HashMap)3