use of org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback in project jaybird by FirebirdSQL.
the class WireConnection method identify.
/**
* Performs the connection identification phase of the Wire protocol and
* returns the FbWireDatabase implementation for the agreed protocol.
*
* @return FbWireDatabase
* @throws SQLTimeoutException
* @throws SQLException
*/
@Override
public final C identify() throws SQLException {
try {
xdrIn = new XdrInputStream(socket.getInputStream());
xdrOut = new XdrOutputStream(socket.getOutputStream());
xdrOut.writeInt(op_connect);
xdrOut.writeInt(op_attach);
xdrOut.writeInt(CONNECT_VERSION3);
xdrOut.writeInt(arch_generic);
xdrOut.writeString(getAttachObjectName(), getEncoding());
// Count of protocols understood
xdrOut.writeInt(protocols.getProtocolCount());
xdrOut.writeBuffer(createUserIdentificationBlock());
for (ProtocolDescriptor protocol : protocols) {
// Protocol version
xdrOut.writeInt(protocol.getVersion());
// Architecture of client
xdrOut.writeInt(protocol.getArchitecture());
// Minimum type
xdrOut.writeInt(protocol.getMinimumType());
if (protocol.supportsWireCompression() && attachProperties.isWireCompression()) {
xdrOut.writeInt(protocol.getMaximumType() | pflag_compress);
} else {
// Maximum type
xdrOut.writeInt(protocol.getMaximumType());
}
// Preference weight
xdrOut.writeInt(protocol.getWeight());
}
xdrOut.flush();
FbWireOperations cryptKeyCallbackWireOperations = null;
DbCryptCallback dbCryptCallback = null;
int operation = readNextOperation();
while (operation == op_crypt_key_callback) {
if (cryptKeyCallbackWireOperations == null) {
cryptKeyCallbackWireOperations = getCryptKeyCallbackWireOperations();
}
if (dbCryptCallback == null) {
dbCryptCallback = createDbCryptCallback();
}
cryptKeyCallbackWireOperations.handleCryptKeyCallback(dbCryptCallback);
operation = readNextOperation();
}
if (operation == op_accept || operation == op_cond_accept || operation == op_accept_data) {
FbWireAttachment.AcceptPacket acceptPacket = new FbWireAttachment.AcceptPacket();
acceptPacket.operation = operation;
// p_acpt_version - Protocol version
protocolVersion = xdrIn.readInt();
// p_acpt_architecture - Architecture for protocol
protocolArchitecture = xdrIn.readInt();
// p_acpt_type - Minimum type
int acceptType = xdrIn.readInt();
protocolMinimumType = acceptType & ptype_MASK;
final boolean compress = (acceptType & pflag_compress) != 0;
if (protocolVersion < 0) {
protocolVersion = (protocolVersion & FB_PROTOCOL_MASK) | FB_PROTOCOL_FLAG;
}
if (operation == op_cond_accept || operation == op_accept_data) {
byte[] data = acceptPacket.p_acpt_data = xdrIn.readBuffer();
acceptPacket.p_acpt_plugin = xdrIn.readString(getEncoding());
final int isAuthenticated = xdrIn.readInt();
byte[] serverKeys = acceptPacket.p_acpt_keys = xdrIn.readBuffer();
clientAuthBlock.setServerData(data);
clientAuthBlock.setAuthComplete(isAuthenticated == 1);
addServerKeys(serverKeys);
clientAuthBlock.resetClient(serverKeys);
clientAuthBlock.switchPlugin(acceptPacket.p_acpt_plugin);
} else {
clientAuthBlock.resetClient(null);
}
if (compress) {
xdrOut.enableCompression();
xdrIn.enableDecompression();
}
ProtocolDescriptor descriptor = protocols.getProtocolDescriptor(protocolVersion);
if (descriptor == null) {
throw new SQLException(String.format("Unsupported or unexpected protocol version %d connecting to database %s. Supported version(s): %s", protocolVersion, getServerName(), protocols.getProtocolVersions()));
}
C connectionHandle = createConnectionHandle(descriptor);
if (operation == op_cond_accept) {
connectionHandle.authReceiveResponse(acceptPacket);
}
return connectionHandle;
} else {
try {
if (operation == op_response) {
// Handle exception from response
AbstractWireOperations wireOperations = getDefaultWireOperations();
wireOperations.processResponse(wireOperations.processOperation(operation));
}
} finally {
try {
close();
} catch (Exception ex) {
log.debug("Ignoring exception on disconnect in connect phase of protocol", ex);
}
}
throw new FbExceptionBuilder().exception(ISCConstants.isc_connect_reject).toFlatSQLException();
}
} catch (SocketTimeoutException ste) {
throw new FbExceptionBuilder().timeoutException(ISCConstants.isc_network_error).messageParameter(getServerName()).cause(ste).toSQLException();
} catch (IOException ioex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_network_error).messageParameter(getServerName()).cause(ioex).toSQLException();
}
}
use of org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback in project jaybird by FirebirdSQL.
the class StaticValueDbCryptCallbackTest method returnsReplyWithFixedResponseValue_null.
@Test
public void returnsReplyWithFixedResponseValue_null() {
DbCryptCallback callback = new StaticValueDbCryptCallback(null);
DbCryptData dbCryptData = callback.handleCallback(DbCryptData.EMPTY_DATA);
assertNull("pluginData", dbCryptData.getPluginData());
assertEquals("replySize", 0, dbCryptData.getReplySize());
}
use of org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback in project jaybird by FirebirdSQL.
the class StaticValueDbCryptCallbackSpiTest method fixedResponseWithBase64urlConfig.
@Test
public void fixedResponseWithBase64urlConfig() {
final DbCryptCallback dbCryptCallback = new StaticValueDbCryptCallbackSpi().createDbCryptCallback("base64url:PDw_Pz8-Pg==");
DbCryptData dbCryptData = dbCryptCallback.handleCallback(DbCryptData.EMPTY_DATA);
assertArrayEquals("<<???>>".getBytes(StandardCharsets.US_ASCII), dbCryptData.getPluginData());
}
use of org.firebirdsql.gds.ng.dbcrypt.DbCryptCallback in project jaybird by FirebirdSQL.
the class StaticValueDbCryptCallbackSpiTest method fixedResponseWithNullConfig.
@Test
public void fixedResponseWithNullConfig() {
final DbCryptCallback dbCryptCallback = new StaticValueDbCryptCallbackSpi().createDbCryptCallback(null);
DbCryptData dbCryptData = dbCryptCallback.handleCallback(DbCryptData.EMPTY_DATA);
assertNull(dbCryptData.getPluginData());
}
Aggregations