use of org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier in project jaybird by FirebirdSQL.
the class V13WireOperations method enableEncryption.
protected void enableEncryption(EncryptionInitInfo encryptionInitInfo) throws SQLException, IOException {
final XdrInputStream xdrIn = getXdrIn();
final XdrOutputStream xdrOut = getXdrOut();
final Encoding encoding = getEncoding();
final EncryptionIdentifier encryptionIdentifier = encryptionInitInfo.getEncryptionIdentifier();
xdrOut.writeInt(op_crypt);
xdrOut.writeString(encryptionIdentifier.getPluginName(), encoding);
xdrOut.writeString(encryptionIdentifier.getType(), encoding);
xdrOut.flush();
xdrIn.setCipher(encryptionInitInfo.getDecryptionCipher());
xdrOut.setCipher(encryptionInitInfo.getEncryptionCipher());
readOperationResponse(readNextOperation(), null);
}
use of org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier 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