Search in sources :

Example 1 with EncryptionIdentifier

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);
}
Also used : XdrInputStream(org.firebirdsql.gds.impl.wire.XdrInputStream) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) Encoding(org.firebirdsql.encodings.Encoding) EncryptionIdentifier(org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier)

Example 2 with EncryptionIdentifier

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

EncryptionIdentifier (org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier)2 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Encoding (org.firebirdsql.encodings.Encoding)1 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)1 XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)1 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)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