use of org.firebirdsql.gds.ng.wire.crypt.arc4.Arc4EncryptionPluginSpi in project jaybird by FirebirdSQL.
the class V13WireOperations method tryKnownServerKeys.
private void tryKnownServerKeys() throws IOException, SQLException {
boolean initializedEncryption = false;
SQLExceptionChainBuilder<SQLException> chainBuilder = new SQLExceptionChainBuilder<>();
// TODO Define separately and make configurable
Map<EncryptionIdentifier, EncryptionPluginSpi> supportedEncryptionPlugins = new HashMap<>();
EncryptionPluginSpi encryptionPluginSpi = new Arc4EncryptionPluginSpi();
supportedEncryptionPlugins.put(encryptionPluginSpi.getEncryptionIdentifier(), encryptionPluginSpi);
for (EncryptionIdentifier encryptionIdentifier : getEncryptionIdentifiers()) {
EncryptionPluginSpi currentEncryptionSpi = supportedEncryptionPlugins.get(encryptionIdentifier);
if (currentEncryptionSpi == null) {
continue;
}
EncryptionPlugin encryptionPlugin = currentEncryptionSpi.createEncryptionPlugin(getConnection());
EncryptionInitInfo encryptionInitInfo = encryptionPlugin.initializeEncryption();
if (encryptionInitInfo.isSuccess()) {
enableEncryption(encryptionInitInfo);
clearServerKeys();
initializedEncryption = true;
log.debug("Wire encryption established with " + encryptionIdentifier);
break;
} else {
chainBuilder.append(encryptionInitInfo.getException());
}
}
if (!initializedEncryption && getAttachProperties().getWireCrypt() == WireCrypt.REQUIRED) {
SQLException exception = new FbExceptionBuilder().nonTransientException(ISCConstants.isc_wirecrypt_incompatible).toFlatSQLException();
if (chainBuilder.hasException()) {
exception.setNextException(chainBuilder.getException());
}
throw exception;
}
if (chainBuilder.hasException()) {
log.warn(initializedEncryption ? "No wire encryption established because of errors" : "Wire encryption established, but some plugins failed; see other loglines for details");
SQLException current = chainBuilder.getException();
do {
log.warn("Encryption plugin failed", current);
} while ((current = current.getNextException()) != null);
}
}
Aggregations