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