Search in sources :

Example 11 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class Arc4EncryptionPlugin method createCipher.

private Cipher createCipher(int mode, byte[] key) throws SQLException {
    try {
        Cipher rc4Cipher = Cipher.getInstance(ARCFOUR_CIPHER_NAME);
        SecretKeySpec rc4Key = new SecretKeySpec(key, ARCFOUR_CIPHER_NAME);
        rc4Cipher.init(mode, rc4Key);
        return rc4Cipher;
    } catch (NoSuchPaddingException | NoSuchAlgorithmException e) {
        throw new FbExceptionBuilder().nonTransientException(jb_cryptAlgorithmNotAvailable).messageParameter(getEncryptionIdentifier().toString()).cause(e).toFlatSQLException();
    } catch (InvalidKeyException e) {
        throw new FbExceptionBuilder().nonTransientException(jb_cryptInvalidKey).messageParameter(getEncryptionIdentifier().toString()).cause(e).toFlatSQLException();
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 12 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class V13WireOperations method readCryptKeyCallback.

/**
 * Reads the database encryption callback data from the connection.
 *
 * @return Database encryption callback data received from server
 * @throws IOException
 *         For errors reading data from the socket
 * @throws SQLException
 *         For database errors
 */
protected DbCryptData readCryptKeyCallback() throws IOException, SQLException {
    final XdrInputStream xdrIn = getXdrIn();
    // p_cc_data
    final byte[] pluginData = xdrIn.readBuffer();
    try {
        return new DbCryptData(pluginData, Integer.MIN_VALUE);
    } catch (RuntimeException e) {
        throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_dbCryptDataError).cause(e).toSQLException();
    }
}
Also used : XdrInputStream(org.firebirdsql.gds.impl.wire.XdrInputStream) DbCryptData(org.firebirdsql.gds.ng.dbcrypt.DbCryptData) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder)

Example 13 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class V10OutputBlob method putSegment.

@Override
public void putSegment(byte[] segment) throws SQLException {
    try {
        if (segment.length == 0) {
            throw new FbExceptionBuilder().exception(jb_blobPutSegmentEmpty).toSQLException();
        }
        // TODO Handle by performing multiple puts?
        if (segment.length > getMaximumSegmentSize()) {
            throw new FbExceptionBuilder().exception(jb_blobPutSegmentTooLong).toSQLException();
        }
        synchronized (getSynchronizationObject()) {
            checkDatabaseAttached();
            checkTransactionActive();
            checkBlobOpen();
            final FbWireDatabase database = getDatabase();
            try {
                final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
                xdrOut.writeInt(op_put_segment);
                xdrOut.writeInt(getHandle());
                xdrOut.writeInt(segment.length);
                xdrOut.writeBuffer(segment);
                xdrOut.flush();
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
            }
            try {
                database.readResponse(null);
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
            }
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Example 14 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class V10Service method attach.

@Override
public void attach() throws SQLException {
    try {
        checkConnected();
        if (isAttached()) {
            throw new SQLException("Already attached to a service");
        }
        final ServiceParameterBuffer spb = protocolDescriptor.createAttachServiceParameterBuffer(connection);
        synchronized (getSynchronizationObject()) {
            try {
                try {
                    sendAttachToBuffer(spb);
                    getXdrOut().flush();
                } catch (IOException e) {
                    throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
                }
                try {
                    authReceiveResponse(null);
                } catch (IOException e) {
                    throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
                }
            } catch (SQLException e) {
                safelyDetach();
                throw e;
            }
            setAttached();
            afterAttachActions();
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) ServiceParameterBuffer(org.firebirdsql.gds.ServiceParameterBuffer) IOException(java.io.IOException)

Example 15 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class ClientAuthBlock method getSupportedPluginProviders.

private List<AuthenticationPluginSpi> getSupportedPluginProviders() throws SQLException {
    List<String> requestedPluginNames = getRequestedPluginNames();
    List<AuthenticationPluginSpi> pluginProviders = new ArrayList<>(requestedPluginNames.size());
    for (String pluginName : requestedPluginNames) {
        AuthenticationPluginSpi pluginSpi = PLUGIN_MAPPING.get(pluginName);
        if (pluginSpi != null) {
            pluginProviders.add(pluginSpi);
        } else {
            log.warn("No authentication plugin available with name " + pluginName);
        }
    }
    if (pluginProviders.isEmpty()) {
        throw new FbExceptionBuilder().exception(JaybirdErrorCodes.jb_noKnownAuthPlugins).messageParameter(requestedPluginNames.toString()).toFlatSQLException();
    }
    return pluginProviders;
}
Also used : FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder)

Aggregations

FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)51 SQLException (java.sql.SQLException)31 IOException (java.io.IOException)27 XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)22 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)6 GenericResponse (org.firebirdsql.gds.ng.wire.GenericResponse)6 SQLNonTransientException (java.sql.SQLNonTransientException)4 AbstractWireOperations (org.firebirdsql.gds.ng.wire.AbstractWireOperations)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)3 BigInteger (java.math.BigInteger)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)2 SQLWarning (java.sql.SQLWarning)2 Cipher (javax.crypto.Cipher)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 Encoding (org.firebirdsql.encodings.Encoding)2