mirror of
https://github.com/corda/corda.git
synced 2025-06-12 20:28:18 +00:00
[CORDA-1264}: Complete obfuscation of exceptions to client side. (#3155)
This commit is contained in:
committed by
GitHub
parent
b0b36b5b7d
commit
5de2c2aa4b
@ -1,37 +0,0 @@
|
||||
package net.corda.nodeapi.exceptions
|
||||
|
||||
import net.corda.core.CordaRuntimeException
|
||||
import net.corda.core.contracts.TransactionVerificationException
|
||||
import net.corda.core.flows.FlowException
|
||||
import java.io.InvalidClassException
|
||||
|
||||
// could change to use package name matching but trying to avoid reflection for now
|
||||
private val whitelisted = setOf(
|
||||
FlowException::class,
|
||||
InvalidClassException::class,
|
||||
RpcSerializableError::class,
|
||||
TransactionVerificationException::class
|
||||
)
|
||||
|
||||
/**
|
||||
* An [Exception] to signal RPC clients that something went wrong within a Corda node.
|
||||
*/
|
||||
class InternalNodeException(message: String) : CordaRuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
|
||||
private const val DEFAULT_MESSAGE = "Something went wrong within the Corda node."
|
||||
|
||||
fun defaultMessage(): String = DEFAULT_MESSAGE
|
||||
|
||||
fun obfuscateIfInternal(wrapped: Throwable): Throwable {
|
||||
(wrapped as? CordaRuntimeException)?.setCause(null)
|
||||
return when {
|
||||
whitelisted.any { it.isInstance(wrapped) } -> wrapped
|
||||
else -> InternalNodeException(DEFAULT_MESSAGE).apply {
|
||||
stackTrace = emptyArray()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package net.corda.nodeapi.exceptions
|
||||
|
||||
import net.corda.core.CordaRuntimeException
|
||||
import net.corda.core.crypto.SecureHash
|
||||
|
||||
class OutdatedNetworkParameterHashException(old: SecureHash, new: SecureHash) : CordaRuntimeException(TEMPLATE.format(old, new)), RpcSerializableError {
|
||||
|
||||
private companion object {
|
||||
private const val TEMPLATE = "Refused to accept parameters with hash %s because network map advertises update with hash %s. Please check newest version"
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package net.corda.nodeapi.exceptions
|
||||
|
||||
import net.corda.core.CordaRuntimeException
|
||||
|
||||
/**
|
||||
* Thrown to indicate that the command was rejected by the node, typically due to a special temporary mode.
|
||||
*/
|
||||
class RejectedCommandException(message: String) : CordaRuntimeException(message), RpcSerializableError
|
@ -0,0 +1,49 @@
|
||||
package net.corda.nodeapi.exceptions
|
||||
|
||||
import net.corda.core.CordaRuntimeException
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.ClientRelevantError
|
||||
import net.corda.core.flows.IdentifiableException
|
||||
|
||||
/**
|
||||
* Thrown to indicate that an attachment was already uploaded to a Corda node.
|
||||
*/
|
||||
class DuplicateAttachmentException(attachmentHash: String) : java.nio.file.FileAlreadyExistsException(attachmentHash), ClientRelevantError
|
||||
|
||||
/**
|
||||
* Thrown to indicate that a flow was not designed for RPC and should be started from an RPC client.
|
||||
*/
|
||||
class NonRpcFlowException(logicType: Class<*>) : IllegalArgumentException("${logicType.name} was not designed for RPC"), ClientRelevantError
|
||||
|
||||
/**
|
||||
* An [Exception] to signal RPC clients that something went wrong within a Corda node.
|
||||
* The message is generic on purpose, as this prevents internal information from reaching RPC clients.
|
||||
* Leaking internal information outside can compromise privacy e.g., party names and security e.g., passwords, stacktraces, etc.
|
||||
*
|
||||
* @param errorIdentifier an optional identifier for tracing problems across parties.
|
||||
*/
|
||||
class InternalNodeException(private val errorIdentifier: Long? = null) : CordaRuntimeException(message), ClientRelevantError, IdentifiableException {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Message for the exception.
|
||||
*/
|
||||
const val message = "Something went wrong within the Corda node."
|
||||
}
|
||||
|
||||
override fun getErrorId(): Long? {
|
||||
return errorIdentifier
|
||||
}
|
||||
}
|
||||
|
||||
class OutdatedNetworkParameterHashException(old: SecureHash, new: SecureHash) : CordaRuntimeException(TEMPLATE.format(old, new)), ClientRelevantError {
|
||||
|
||||
private companion object {
|
||||
private const val TEMPLATE = "Refused to accept parameters with hash %s because network map advertises update with hash %s. Please check newest version"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown to indicate that the command was rejected by the node, typically due to a special temporary mode.
|
||||
*/
|
||||
class RejectedCommandException(message: String) : CordaRuntimeException(message), ClientRelevantError
|
@ -1,9 +0,0 @@
|
||||
package net.corda.nodeapi.exceptions
|
||||
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
|
||||
/**
|
||||
* Allows an implementing [Throwable] to be propagated to RPC clients.
|
||||
*/
|
||||
@CordaSerializable
|
||||
interface RpcSerializableError
|
@ -1,15 +0,0 @@
|
||||
package net.corda.nodeapi.exceptions.adapters
|
||||
|
||||
import net.corda.core.internal.concurrent.mapError
|
||||
import net.corda.core.messaging.FlowHandle
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.nodeapi.exceptions.InternalNodeException
|
||||
|
||||
/**
|
||||
* Adapter able to mask errors within a Corda node for RPC clients.
|
||||
*/
|
||||
@CordaSerializable
|
||||
data class InternalObfuscatingFlowHandle<RESULT>(val wrapped: FlowHandle<RESULT>) : FlowHandle<RESULT> by wrapped {
|
||||
|
||||
override val returnValue = wrapped.returnValue.mapError(InternalNodeException.Companion::obfuscateIfInternal)
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package net.corda.nodeapi.exceptions.adapters
|
||||
|
||||
import net.corda.core.internal.concurrent.mapError
|
||||
import net.corda.core.mapErrors
|
||||
import net.corda.core.messaging.FlowProgressHandle
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.nodeapi.exceptions.InternalNodeException
|
||||
|
||||
/**
|
||||
* Adapter able to mask errors within a Corda node for RPC clients.
|
||||
*/
|
||||
@CordaSerializable
|
||||
class InternalObfuscatingFlowProgressHandle<RESULT>(val wrapped: FlowProgressHandle<RESULT>) : FlowProgressHandle<RESULT> by wrapped {
|
||||
|
||||
override val returnValue = wrapped.returnValue.mapError(InternalNodeException.Companion::obfuscateIfInternal)
|
||||
|
||||
override val progress = wrapped.progress.mapErrors(InternalNodeException.Companion::obfuscateIfInternal)
|
||||
|
||||
override val stepsTreeIndexFeed = wrapped.stepsTreeIndexFeed?.mapErrors(InternalNodeException.Companion::obfuscateIfInternal)
|
||||
|
||||
override val stepsTreeFeed = wrapped.stepsTreeFeed?.mapErrors(InternalNodeException.Companion::obfuscateIfInternal)
|
||||
}
|
Reference in New Issue
Block a user