Search in sources :

Example 6 with PropertySet

use of com.mysql.cj.conf.PropertySet in project aws-mysql-jdbc by awslabs.

the class InternalXBaseTestCase method createTestSession.

public MysqlxSession createTestSession() {
    PropertySet pset = new DefaultPropertySet();
    pset.initializeProperties(this.testProperties);
    MysqlxSession session = new MysqlxSession(this.testHostInfo, pset);
    return session;
}
Also used : DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) PropertySet(com.mysql.cj.conf.PropertySet) DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) MysqlxSession(com.mysql.cj.MysqlxSession)

Example 7 with PropertySet

use of com.mysql.cj.conf.PropertySet in project aws-mysql-jdbc by awslabs.

the class InternalXBaseTestCase method createTestProtocol.

/**
 * Create a new {@link XProtocol} instance for testing.
 *
 * @return an XProtocol instance
 */
public XProtocol createTestProtocol() {
    PropertySet ps = new DefaultPropertySet();
    ps.initializeProperties(this.testProperties);
    return new XProtocol(this.testHostInfo, ps);
}
Also used : DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) PropertySet(com.mysql.cj.conf.PropertySet) DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) XProtocol(com.mysql.cj.protocol.x.XProtocol)

Example 8 with PropertySet

use of com.mysql.cj.conf.PropertySet in project aws-mysql-jdbc by awslabs.

the class ExportControlled method performTlsHandshake.

/**
 * Converts the socket being used in the given SocketConnection 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
 * @param log
 *            Logger
 * @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, Log log) 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;
    boolean fallbackToSystemTrustStore = pset.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue();
    // (serverVersion == null) means that it was called from the X DevAPI.
    KeyStoreConf trustStore = !verifyServerCert ? new KeyStoreConf() : getTrustStoreConf(pset, serverVersion == null && verifyServerCert && !fallbackToSystemTrustStore);
    KeyStoreConf keyStore = getKeyStoreConf(pset);
    SSLSocketFactory socketFactory = getSSLContext(keyStore, trustStore, fallbackToSystemTrustStore, verifyServerCert, sslMode == PropertyDefinitions.SslMode.VERIFY_IDENTITY ? socketConnection.getHost() : null, socketConnection.getExceptionInterceptor()).getSocketFactory();
    SSLSocket sslSocket = (SSLSocket) socketFactory.createSocket(rawSocket, socketConnection.getHost(), socketConnection.getPort(), true);
    String[] allowedProtocols = getAllowedProtocols(pset, serverVersion, sslSocket.getSupportedProtocols());
    sslSocket.setEnabledProtocols(allowedProtocols);
    String[] allowedCiphers = getAllowedCiphers(pset, Arrays.asList(sslSocket.getEnabledCipherSuites()));
    if (allowedCiphers != null) {
        sslSocket.setEnabledCipherSuites(allowedCiphers);
    }
    sslSocket.startHandshake();
    return sslSocket;
}
Also used : SslMode(com.mysql.cj.conf.PropertyDefinitions.SslMode) SSLSocket(javax.net.ssl.SSLSocket) PropertySet(com.mysql.cj.conf.PropertySet) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 9 with PropertySet

use of com.mysql.cj.conf.PropertySet in project aws-mysql-jdbc by awslabs.

the class FailoverConnectionPlugin method getInitialConnectionProps.

private Map<String, String> getInitialConnectionProps(final PropertySet propertySet) {
    final Map<String, String> initialConnectionProperties = new HashMap<>();
    final Properties originalProperties = propertySet.exposeAsProperties();
    originalProperties.stringPropertyNames().stream().filter(x -> this.propertySet.getProperty(x).isExplicitlySet()).forEach(x -> initialConnectionProperties.put(x, originalProperties.getProperty(x)));
    return initialConnectionProperties;
}
Also used : MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) CJException(com.mysql.cj.exceptions.CJException) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) IConnectionProvider(com.mysql.cj.jdbc.ha.plugins.IConnectionProvider) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Matcher(java.util.regex.Matcher) Map(java.util.Map) IpAddressUtils(com.mysql.cj.util.IpAddressUtils) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) RuntimeProperty(com.mysql.cj.conf.RuntimeProperty) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) PropertySet(com.mysql.cj.conf.PropertySet) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) Messages(com.mysql.cj.Messages) Properties(java.util.Properties) Util(com.mysql.cj.util.Util) HostInfo(com.mysql.cj.conf.HostInfo) Log(com.mysql.cj.log.Log) ICurrentConnectionProvider(com.mysql.cj.jdbc.ha.plugins.ICurrentConnectionProvider) ConnectionImpl(com.mysql.cj.jdbc.ConnectionImpl) ConnectionUrl(com.mysql.cj.conf.ConnectionUrl) ConnectionUrlParser(com.mysql.cj.conf.ConnectionUrlParser) SQLExceptionsMapping(com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping) EOFException(java.io.EOFException) SQLError(com.mysql.cj.jdbc.exceptions.SQLError) Objects(java.util.Objects) List(java.util.List) SSLException(javax.net.ssl.SSLException) ConnectionUtils(com.mysql.cj.jdbc.ha.ConnectionUtils) BasicConnectionProvider(com.mysql.cj.jdbc.ha.plugins.BasicConnectionProvider) IConnectionPlugin(com.mysql.cj.jdbc.ha.plugins.IConnectionPlugin) StringUtils(com.mysql.cj.util.StringUtils) NativeSession(com.mysql.cj.NativeSession) Pattern(java.util.regex.Pattern) PropertyKey(com.mysql.cj.conf.PropertyKey) HashMap(java.util.HashMap) Properties(java.util.Properties)

Example 10 with PropertySet

use of com.mysql.cj.conf.PropertySet in project aws-mysql-jdbc by awslabs.

the class SessionImpl method getUri.

public String getUri() {
    PropertySet pset = this.session.getPropertySet();
    StringBuilder sb = new StringBuilder(ConnectionUrl.Type.XDEVAPI_SESSION.getScheme());
    sb.append("//").append(this.session.getProcessHost()).append(":").append(this.session.getPort()).append("/").append(this.defaultSchemaName).append("?");
    boolean isFirstParam = true;
    for (PropertyKey propKey : PropertyDefinitions.PROPERTY_KEY_TO_PROPERTY_DEFINITION.keySet()) {
        RuntimeProperty<?> propToGet = pset.getProperty(propKey);
        if (propToGet.isExplicitlySet()) {
            String propValue = propToGet.getStringValue();
            Object defaultValue = propToGet.getPropertyDefinition().getDefaultValue();
            if (defaultValue == null && !StringUtils.isNullOrEmpty(propValue) || defaultValue != null && propValue == null || defaultValue != null && propValue != null && !propValue.equals(defaultValue.toString())) {
                if (isFirstParam) {
                    isFirstParam = false;
                } else {
                    sb.append("&");
                }
                sb.append(propKey.getKeyName());
                sb.append("=");
                sb.append(propValue);
            }
        // TODO custom properties?
        }
    }
    return sb.toString();
}
Also used : PropertySet(com.mysql.cj.conf.PropertySet) DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) PropertyKey(com.mysql.cj.conf.PropertyKey)

Aggregations

PropertySet (com.mysql.cj.conf.PropertySet)11 DefaultPropertySet (com.mysql.cj.conf.DefaultPropertySet)8 HostInfo (com.mysql.cj.conf.HostInfo)2 PropertyKey (com.mysql.cj.conf.PropertyKey)2 Log (com.mysql.cj.log.Log)2 Properties (java.util.Properties)2 Test (org.junit.jupiter.api.Test)2 CoreSession (com.mysql.cj.CoreSession)1 Messages (com.mysql.cj.Messages)1 MysqlxSession (com.mysql.cj.MysqlxSession)1 NativeSession (com.mysql.cj.NativeSession)1 ConnectionUrl (com.mysql.cj.conf.ConnectionUrl)1 ConnectionUrlParser (com.mysql.cj.conf.ConnectionUrlParser)1 PropertyDefinitions (com.mysql.cj.conf.PropertyDefinitions)1 SslMode (com.mysql.cj.conf.PropertyDefinitions.SslMode)1 RuntimeProperty (com.mysql.cj.conf.RuntimeProperty)1 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)1 CJException (com.mysql.cj.exceptions.CJException)1 DataConversionException (com.mysql.cj.exceptions.DataConversionException)1 DataReadException (com.mysql.cj.exceptions.DataReadException)1