From 72ba01669a0f9f70d2a40367d6a7aa2551644654 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 30 Apr 2018 13:45:46 +0100 Subject: [PATCH] Move platformSecureRandom property into a separate class. (#790) This allows it to be deleted completely from core-deterministic. --- .../crypto/internal/PlatformSecureRandom.kt | 27 +++++++++++++++++++ .../corda/core/crypto/internal/ProviderMap.kt | 19 +++++++------ 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 core/src/main/kotlin/net/corda/core/crypto/internal/PlatformSecureRandom.kt diff --git a/core/src/main/kotlin/net/corda/core/crypto/internal/PlatformSecureRandom.kt b/core/src/main/kotlin/net/corda/core/crypto/internal/PlatformSecureRandom.kt new file mode 100644 index 0000000000..bc66484f4b --- /dev/null +++ b/core/src/main/kotlin/net/corda/core/crypto/internal/PlatformSecureRandom.kt @@ -0,0 +1,27 @@ +/* + * R3 Proprietary and Confidential + * + * Copyright (c) 2018 R3 Limited. All rights reserved. + * + * The intellectual and technical concepts contained herein are proprietary to R3 and its suppliers and are protected by trade secret law. + * + * Distribution of this file or any portion thereof via any medium without the express permission of R3 is strictly prohibited. + */ +@file:JvmName("PlatformSecureRandom") +package net.corda.core.crypto.internal + +import net.corda.core.crypto.CORDA_SECURE_RANDOM_ALGORITHM +import net.corda.core.crypto.DummySecureRandom +import net.corda.core.internal.VisibleForTesting +import net.corda.core.utilities.SgxSupport +import java.security.SecureRandom + +/** + * This has been migrated into a separate class so that it + * is easier to delete from the core-deterministic module. + */ +@VisibleForTesting +internal val platformSecureRandom = when { + SgxSupport.isInsideEnclave -> DummySecureRandom + else -> SecureRandom.getInstance(CORDA_SECURE_RANDOM_ALGORITHM) +} diff --git a/core/src/main/kotlin/net/corda/core/crypto/internal/ProviderMap.kt b/core/src/main/kotlin/net/corda/core/crypto/internal/ProviderMap.kt index 4661b1ecd5..6a01370629 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/internal/ProviderMap.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/internal/ProviderMap.kt @@ -1,14 +1,19 @@ +/* + * R3 Proprietary and Confidential + * + * Copyright (c) 2018 R3 Limited. All rights reserved. + * + * The intellectual and technical concepts contained herein are proprietary to R3 and its suppliers and are protected by trade secret law. + * + * Distribution of this file or any portion thereof via any medium without the express permission of R3 is strictly prohibited. + */ package net.corda.core.crypto.internal -import net.corda.core.crypto.CORDA_SECURE_RANDOM_ALGORITHM import net.corda.core.crypto.CordaSecurityProvider import net.corda.core.crypto.Crypto.EDDSA_ED25519_SHA512 import net.corda.core.crypto.Crypto.decodePrivateKey import net.corda.core.crypto.Crypto.decodePublicKey -import net.corda.core.crypto.DummySecureRandom -import net.corda.core.internal.VisibleForTesting import net.corda.core.internal.X509EdDSAEngine -import net.corda.core.utilities.SgxSupport import net.i2p.crypto.eddsa.EdDSAEngine import net.i2p.crypto.eddsa.EdDSASecurityProvider import org.bouncycastle.asn1.ASN1ObjectIdentifier @@ -17,7 +22,6 @@ import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo import org.bouncycastle.jcajce.provider.util.AsymmetricKeyInfoConverter import org.bouncycastle.jce.provider.BouncyCastleProvider import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider -import java.security.SecureRandom import java.security.Security internal val cordaSecurityProvider = CordaSecurityProvider().also { @@ -48,10 +52,5 @@ internal val bouncyCastlePQCProvider = BouncyCastlePQCProvider().apply { // i.e. if someone removes a Provider and then he/she adds a new one with the same name. // The val is private to avoid any harmful state changes. internal val providerMap = listOf(cordaBouncyCastleProvider, cordaSecurityProvider, bouncyCastlePQCProvider).map { it.name to it }.toMap() -@VisibleForTesting -internal val platformSecureRandom = when { - SgxSupport.isInsideEnclave -> DummySecureRandom - else -> SecureRandom.getInstance(CORDA_SECURE_RANDOM_ALGORITHM) -} internal fun platformSecureRandomFactory() = platformSecureRandom // To minimise diff of CryptoUtils against open-source.