Search in sources :

Example 1 with Arc4EncryptionPluginSpi

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);
    }
}
Also used : Arc4EncryptionPluginSpi(org.firebirdsql.gds.ng.wire.crypt.arc4.Arc4EncryptionPluginSpi) SQLExceptionChainBuilder(org.firebirdsql.util.SQLExceptionChainBuilder) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) EncryptionPlugin(org.firebirdsql.gds.ng.wire.crypt.EncryptionPlugin) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) EncryptionInitInfo(org.firebirdsql.gds.ng.wire.crypt.EncryptionInitInfo) EncryptionIdentifier(org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier) EncryptionPluginSpi(org.firebirdsql.gds.ng.wire.crypt.EncryptionPluginSpi) Arc4EncryptionPluginSpi(org.firebirdsql.gds.ng.wire.crypt.arc4.Arc4EncryptionPluginSpi)

Aggregations

SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)1 EncryptionIdentifier (org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier)1 EncryptionInitInfo (org.firebirdsql.gds.ng.wire.crypt.EncryptionInitInfo)1 EncryptionPlugin (org.firebirdsql.gds.ng.wire.crypt.EncryptionPlugin)1 EncryptionPluginSpi (org.firebirdsql.gds.ng.wire.crypt.EncryptionPluginSpi)1 Arc4EncryptionPluginSpi (org.firebirdsql.gds.ng.wire.crypt.arc4.Arc4EncryptionPluginSpi)1 SQLExceptionChainBuilder (org.firebirdsql.util.SQLExceptionChainBuilder)1