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;
}
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);
}
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;
}
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;
}
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();
}
Aggregations