CORDA-4028 Forcibly register security providers (#6702)

Forcibly register security providers before starting Jimfs, to resolve a sequencing problem where Jimfs triggers loading of the SFTP filesystem provider, which in turn registers the standard BouncyCastle provider rather than the patched version Corda needs.
This commit is contained in:
Ross Nicoll 2020-09-12 23:52:52 +01:00 committed by GitHub
parent df7b1bccd6
commit ba802c6619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package net.corda.coretests.indentity
import com.google.common.jimfs.Configuration.unix
import com.google.common.jimfs.Jimfs
import net.corda.core.crypto.Crypto
import net.corda.core.crypto.entropyToKeyPair
import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.Party
@ -14,6 +15,7 @@ import net.corda.testing.core.SerializationEnvironmentRule
import net.corda.testing.core.getTestPartyAndCertificate
import net.corda.testing.internal.DEV_ROOT_CA
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.math.BigInteger
@ -24,6 +26,13 @@ class PartyAndCertificateTest {
@JvmField
val testSerialization = SerializationEnvironmentRule()
@Before
fun setUp() {
// Register providers before creating Jimfs filesystem. JimFs creates an SSHD instance which
// register BouncyCastle and EdDSA provider separately, which wrecks havoc.
Crypto.registerProviders()
}
@Test
fun `reject a path with no roles`() {
val path = X509Utilities.buildCertPath(DEV_ROOT_CA.certificate)

View File

@ -76,6 +76,10 @@ class NetworkMapUpdaterTest {
@Before
fun setUp() {
// Register providers before creating Jimfs filesystem. JimFs creates an SSHD instance which
// register BouncyCastle and EdDSA provider separately, which wrecks havoc.
Crypto.registerProviders()
ourKeyPair = Crypto.generateKeyPair(X509Utilities.DEFAULT_TLS_SIGNATURE_SCHEME)
ourNodeInfo = createNodeInfoAndSigned("Our info", ourKeyPair).signed
server = NetworkMapServer(cacheExpiryMs.millis)

View File

@ -2,6 +2,7 @@ package net.corda.node.services.network
import com.google.common.jimfs.Configuration
import com.google.common.jimfs.Jimfs
import net.corda.core.crypto.Crypto
import net.corda.core.internal.*
import net.corda.core.serialization.deserialize
import net.corda.core.utilities.days
@ -20,6 +21,7 @@ import org.junit.Rule
import org.junit.Test
import java.net.URL
import java.nio.file.FileSystem
import java.security.Security
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
@ -29,7 +31,7 @@ class NetworkParametersReaderTest {
@JvmField
val testSerialization = SerializationEnvironmentRule(true)
private val fs: FileSystem = Jimfs.newFileSystem(Configuration.unix())
private lateinit var fs: FileSystem
private val cacheTimeout = 100000.seconds
private lateinit var server: NetworkMapServer
@ -37,6 +39,11 @@ class NetworkParametersReaderTest {
@Before
fun setUp() {
// Register providers before creating Jimfs filesystem. JimFs creates an SSHD instance which
// register BouncyCastle and EdDSA provider separately, which wrecks havoc.
Crypto.registerProviders()
fs = Jimfs.newFileSystem(Configuration.unix())
server = NetworkMapServer(cacheTimeout)
val address = server.start()
networkMapClient = NetworkMapClient(URL("http://$address"), VersionInfo(1, "TEST", "TEST", "TEST"))

View File

@ -2,6 +2,7 @@ package net.corda.node.services.network
import com.google.common.jimfs.Configuration
import com.google.common.jimfs.Jimfs
import net.corda.core.crypto.Crypto
import net.corda.core.internal.NODE_INFO_DIRECTORY
import net.corda.core.internal.createDirectories
import net.corda.core.internal.div
@ -48,6 +49,10 @@ class NodeInfoWatcherTest {
@Before
fun start() {
// Register providers before creating Jimfs filesystem. JimFs creates an SSHD instance which
// register BouncyCastle and EdDSA provider separately, which wrecks havoc.
Crypto.registerProviders()
nodeInfoAndSigned = createNodeInfoAndSigned(ALICE_NAME)
val identityService = makeTestIdentityService()
keyManagementService = MockKeyManagementService(identityService)

View File

@ -7,6 +7,7 @@ import com.google.common.jimfs.Jimfs
import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.whenever
import net.corda.core.contracts.ContractAttachment
import net.corda.core.crypto.Crypto
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.sha256
import net.corda.core.flows.FlowLogic
@ -68,6 +69,10 @@ class NodeAttachmentServiceTest {
@Before
fun setUp() {
// Register providers before creating Jimfs filesystem. JimFs creates an SSHD instance which
// register BouncyCastle and EdDSA provider separately, which wrecks havoc.
Crypto.registerProviders()
LogHelper.setLevel(PersistentUniquenessProvider::class)
val dataSourceProperties = makeTestDataSourceProperties()

View File

@ -36,6 +36,7 @@ import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.nio.file.FileSystem
import java.security.PublicKey
import java.security.cert.CertPathValidatorException
import java.security.cert.X509Certificate
@ -45,7 +46,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue
class NetworkRegistrationHelperTest {
private val fs = Jimfs.newFileSystem(unix())
private lateinit var fs: FileSystem
private val nodeLegalName = ALICE_NAME
private lateinit var config: NodeConfiguration
@ -54,6 +55,11 @@ class NetworkRegistrationHelperTest {
@Before
fun init() {
// Register providers before creating Jimfs filesystem. JimFs creates an SSHD instance which
// register BouncyCastle and EdDSA provider separately, which wrecks havoc.
Crypto.registerProviders()
fs = Jimfs.newFileSystem(unix())
val baseDirectory = fs.getPath("/baseDir").createDirectories()
abstract class AbstractNodeConfiguration : NodeConfiguration