Search in sources :

Example 6 with Encoding

use of org.firebirdsql.encodings.Encoding in project jaybird by FirebirdSQL.

the class V12ParameterConverter method createServiceParameterBuffer.

protected ServiceParameterBuffer createServiceParameterBuffer(WireServiceConnection connection) {
    final Encoding stringEncoding = connection.getEncodingFactory().getEncodingForFirebirdName("UTF8");
    ServiceParameterBuffer spb = new ServiceParameterBufferImp(ServiceParameterBufferImp.SpbMetaData.SPB_VERSION_2_ATTACH, stringEncoding);
    spb.addArgument(SpbItems.isc_spb_utf8_filename);
    return spb;
}
Also used : Encoding(org.firebirdsql.encodings.Encoding) ServiceParameterBuffer(org.firebirdsql.gds.ServiceParameterBuffer) ServiceParameterBufferImp(org.firebirdsql.gds.impl.ServiceParameterBufferImp)

Example 7 with Encoding

use of org.firebirdsql.encodings.Encoding in project jaybird by FirebirdSQL.

the class V12ParameterConverter method createDatabaseParameterBuffer.

protected DatabaseParameterBuffer createDatabaseParameterBuffer(WireDatabaseConnection connection) {
    final Encoding stringEncoding = connection.getEncodingFactory().getEncodingForFirebirdName("UTF8");
    DatabaseParameterBuffer dpb = new DatabaseParameterBufferImp(DatabaseParameterBufferImp.DpbMetaData.DPB_VERSION_1, stringEncoding);
    dpb.addArgument(DpbItems.isc_dpb_utf8_filename);
    return dpb;
}
Also used : DatabaseParameterBufferImp(org.firebirdsql.gds.impl.DatabaseParameterBufferImp) Encoding(org.firebirdsql.encodings.Encoding) DatabaseParameterBuffer(org.firebirdsql.gds.DatabaseParameterBuffer)

Example 8 with Encoding

use of org.firebirdsql.encodings.Encoding in project jaybird by FirebirdSQL.

the class V13WireOperations method authReceiveResponse.

@Override
public void authReceiveResponse(FbWireAttachment.AcceptPacket acceptPacket, DbCryptCallback dbCryptCallback, FbWireOperations.ProcessAttachCallback processAttachCallback) throws SQLException, IOException {
    assert acceptPacket == null || acceptPacket.operation == op_cond_accept : "Unexpected operation in AcceptPacket";
    final XdrInputStream xdrIn = getXdrIn();
    final XdrOutputStream xdrOut = getXdrOut();
    final ClientAuthBlock clientAuthBlock = getClientAuthBlock();
    final Encoding encoding = getEncoding();
    while (true) {
        String pluginName;
        byte[] data;
        if (acceptPacket != null) {
            data = acceptPacket.p_acpt_data;
            pluginName = acceptPacket.p_acpt_plugin;
            addServerKeys(acceptPacket.p_acpt_keys);
            log.debug(String.format("authReceiveResponse: cond_accept data=%d pluginName=%d '%s'", data.length, pluginName != null ? pluginName.length() : null, pluginName));
            // TODO handle compression
            acceptPacket = null;
        } else {
            int operation = readNextOperation();
            switch(operation) {
                case op_trusted_auth:
                    // p_trau_data
                    xdrIn.readBuffer();
                    throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_receiveTrustedAuth_NotSupported).toFlatSQLException();
                case op_cont_auth:
                    // p_data
                    data = xdrIn.readBuffer();
                    // p_name
                    pluginName = xdrIn.readString(encoding);
                    // p_list (ignore?)
                    xdrIn.readBuffer();
                    // p_keys
                    addServerKeys(xdrIn.readBuffer());
                    log.debug(String.format("authReceiveResponse: cont_auth data=%d pluginName=%d '%s'", data.length, pluginName.length(), pluginName));
                    break;
                case op_crypt_key_callback:
                    log.debug("Handling db crypt callback using plugin " + dbCryptCallback.getDbCryptCallbackName());
                    handleCryptKeyCallback(dbCryptCallback);
                    continue;
                case op_cond_accept:
                    // Note this is the equivalent of handling the acceptPacket != null above
                    // p_acpt_version
                    xdrIn.readInt();
                    // p_acpt_architecture
                    xdrIn.readInt();
                    // p_acpt_type
                    xdrIn.readInt();
                    // p_acpt_data
                    data = xdrIn.readBuffer();
                    // p_acpt_plugin
                    pluginName = xdrIn.readString(encoding);
                    // p_acpt_authenticated
                    xdrIn.readInt();
                    // p_acpt_keys
                    addServerKeys(xdrIn.readBuffer());
                    log.debug(String.format("authReceiveResponse: cond_accept data=%d pluginName=%d '%s'", data.length, pluginName.length(), pluginName));
                    // TODO handle compression
                    break;
                case op_response:
                    GenericResponse response = (GenericResponse) readOperationResponse(operation, null);
                    boolean wasAuthComplete = clientAuthBlock.isAuthComplete();
                    clientAuthBlock.setAuthComplete(true);
                    processAttachCallback.processAttachResponse(response);
                    addServerKeys(response.getData());
                    WireCrypt wireCrypt = getAttachProperties().getWireCryptAsEnum();
                    if (!wasAuthComplete && wireCrypt != WireCrypt.DISABLED) {
                        tryKnownServerKeys();
                    }
                    return;
                default:
                    throw new SQLException(String.format("Unsupported operation code: %d", operation));
            }
        }
        if (pluginName != null && pluginName.length() > 0 && Objects.equals(pluginName, clientAuthBlock.getCurrentPluginName())) {
            pluginName = null;
        }
        if (pluginName != null && pluginName.length() > 0) {
            if (!clientAuthBlock.switchPlugin(pluginName)) {
                break;
            }
        }
        if (!clientAuthBlock.hasPlugin()) {
            break;
        }
        clientAuthBlock.setServerData(data);
        log.debug(String.format("receiveResponse: authenticate(%s)", clientAuthBlock.getCurrentPluginName()));
        clientAuthBlock.authenticate();
        xdrOut.writeInt(op_cont_auth);
        // TODO Move to ClientAuthBlock?
        // p_data
        xdrOut.writeBuffer(clientAuthBlock.getClientData());
        // p_name
        xdrOut.writeString(clientAuthBlock.getCurrentPluginName(), encoding);
        if (clientAuthBlock.isFirstTime()) {
            // p_list
            xdrOut.writeString(clientAuthBlock.getPluginNames(), encoding);
            clientAuthBlock.setFirstTime(false);
        } else {
            // p_list
            xdrOut.writeBuffer(null);
        }
        // p_keys
        xdrOut.writeBuffer(null);
        xdrOut.flush();
    }
    // If we have exited from the cycle, this mean auth failed
    throw new FbExceptionBuilder().exception(ISCConstants.isc_login).toFlatSQLException();
}
Also used : XdrInputStream(org.firebirdsql.gds.impl.wire.XdrInputStream) GenericResponse(org.firebirdsql.gds.ng.wire.GenericResponse) SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) Encoding(org.firebirdsql.encodings.Encoding) WireCrypt(org.firebirdsql.gds.ng.WireCrypt) ClientAuthBlock(org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock)

Example 9 with Encoding

use of org.firebirdsql.encodings.Encoding in project jaybird by FirebirdSQL.

the class V13ParameterConverter method createDatabaseParameterBuffer.

protected DatabaseParameterBuffer createDatabaseParameterBuffer(WireDatabaseConnection connection) {
    final Encoding stringEncoding = connection.getEncodingFactory().getEncodingForFirebirdName("UTF8");
    DatabaseParameterBuffer dpb = new DatabaseParameterBufferImp(DatabaseParameterBufferImp.DpbMetaData.DPB_VERSION_2, stringEncoding);
    dpb.addArgument(DpbItems.isc_dpb_utf8_filename);
    return dpb;
}
Also used : DatabaseParameterBufferImp(org.firebirdsql.gds.impl.DatabaseParameterBufferImp) Encoding(org.firebirdsql.encodings.Encoding)

Example 10 with Encoding

use of org.firebirdsql.encodings.Encoding in project jaybird by FirebirdSQL.

the class V10Database method sendAttachOrCreateToBuffer.

/**
 * Sends the buffer for op_attach or op_create
 *
 * @param dpb
 *         Database parameter buffer
 * @param create
 *         <code>true</code> create database, <code>false</code> only
 *         attach
 * @throws SQLException
 *         If the connection is not open
 * @throws IOException
 *         For errors writing to the connection
 */
protected final void sendAttachOrCreateToBuffer(DatabaseParameterBuffer dpb, boolean create) throws SQLException, IOException {
    final int operation = create ? op_create : op_attach;
    final XdrOutputStream xdrOut = getXdrOut();
    final Encoding filenameEncoding = getFilenameEncoding(dpb);
    xdrOut.writeInt(operation);
    // Database object ID
    xdrOut.writeInt(0);
    xdrOut.writeString(connection.getAttachObjectName(), filenameEncoding);
    xdrOut.writeTyped(dpb);
}
Also used : XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) Encoding(org.firebirdsql.encodings.Encoding)

Aggregations

Encoding (org.firebirdsql.encodings.Encoding)10 XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)4 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)3 SQLException (java.sql.SQLException)2 DatabaseParameterBufferImp (org.firebirdsql.gds.impl.DatabaseParameterBufferImp)2 ServiceParameterBufferImp (org.firebirdsql.gds.impl.ServiceParameterBufferImp)2 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)2 WireCrypt (org.firebirdsql.gds.ng.WireCrypt)2 GenericResponse (org.firebirdsql.gds.ng.wire.GenericResponse)2 ClientAuthBlock (org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock)2 DatabaseParameterBuffer (org.firebirdsql.gds.DatabaseParameterBuffer)1 ServiceParameterBuffer (org.firebirdsql.gds.ServiceParameterBuffer)1 RowDescriptor (org.firebirdsql.gds.ng.fields.RowDescriptor)1 RowValue (org.firebirdsql.gds.ng.fields.RowValue)1 SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)1 EncryptionIdentifier (org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier)1 FBBlob (org.firebirdsql.jdbc.FBBlob)1 Test (org.junit.Test)1