Search in sources :

Example 1 with DbCryptData

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

the class V15WireOperations method readCryptKeyCallback.

@Override
protected DbCryptData readCryptKeyCallback() throws IOException, SQLException {
    final XdrInputStream xdrIn = getXdrIn();
    // p_cc_data
    final byte[] pluginData = xdrIn.readBuffer();
    // p_cc_reply
    final int replySize = xdrIn.readInt();
    try {
        return new DbCryptData(pluginData, replySize);
    } 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 2 with DbCryptData

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

the class StaticValueDbCryptCallbackSpiTest method fixedResponseWithBase64Config.

@Test
public void fixedResponseWithBase64Config() {
    final DbCryptCallback dbCryptCallback = new StaticValueDbCryptCallbackSpi().createDbCryptCallback("base64:ZWFzdXJlLg==");
    DbCryptData dbCryptData = dbCryptCallback.handleCallback(DbCryptData.EMPTY_DATA);
    assertArrayEquals("easure.".getBytes(StandardCharsets.US_ASCII), dbCryptData.getPluginData());
}
Also used : DbCryptData(org.firebirdsql.gds.ng.dbcrypt.DbCryptData) DbCryptCallback(org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback) Test(org.junit.Test)

Example 3 with DbCryptData

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

the class StaticValueDbCryptCallbackSpiTest method fixedResponseWithStringConfig.

@Test
public void fixedResponseWithStringConfig() {
    final String dbCryptConfig = "abc\u02a5\u0b2c\u1d38\u213b";
    final DbCryptCallback dbCryptCallback = new StaticValueDbCryptCallbackSpi().createDbCryptCallback(dbCryptConfig);
    DbCryptData dbCryptData = dbCryptCallback.handleCallback(DbCryptData.EMPTY_DATA);
    assertArrayEquals(dbCryptConfig.getBytes(StandardCharsets.UTF_8), dbCryptData.getPluginData());
}
Also used : DbCryptData(org.firebirdsql.gds.ng.dbcrypt.DbCryptData) DbCryptCallback(org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback) Test(org.junit.Test)

Example 4 with DbCryptData

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

the class StaticValueDbCryptCallbackTest method returnsReplyWithFixedResponseValue_nonNull.

@Test
public void returnsReplyWithFixedResponseValue_nonNull() {
    final byte[] responseData = { 2, 3, 4, 5, 6 };
    DbCryptCallback callback = new StaticValueDbCryptCallback(responseData);
    DbCryptData dbCryptData = callback.handleCallback(DbCryptData.EMPTY_DATA);
    assertSame("pluginData", responseData, dbCryptData.getPluginData());
    assertEquals("replySize", 0, dbCryptData.getReplySize());
}
Also used : DbCryptData(org.firebirdsql.gds.ng.dbcrypt.DbCryptData) DbCryptCallback(org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback) Test(org.junit.Test)

Example 5 with DbCryptData

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

the class V13WireOperations method handleCryptKeyCallback.

@Override
public final void handleCryptKeyCallback(DbCryptCallback dbCryptCallback) throws IOException, SQLException {
    final DbCryptData serverPluginData = readCryptKeyCallback();
    DbCryptData clientPluginResponse;
    try {
        clientPluginResponse = dbCryptCallback.handleCallback(serverPluginData);
    } catch (Exception e) {
        log.error("Error during database encryption callback, using default empty response", e);
        clientPluginResponse = DbCryptData.EMPTY_DATA;
    }
    writeCryptKeyCallback(clientPluginResponse);
}
Also used : DbCryptData(org.firebirdsql.gds.ng.dbcrypt.DbCryptData) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

DbCryptData (org.firebirdsql.gds.ng.dbcrypt.DbCryptData)9 DbCryptCallback (org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback)6 Test (org.junit.Test)6 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)2 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1