[NOTICK] Expose type in CryptoService (#5416)

This commit is contained in:
Dimos Raptis 2019-08-30 09:22:15 +01:00 committed by Shams Asari
parent 07b96aea18
commit 3023e3ab87
4 changed files with 13 additions and 5 deletions

View File

@ -59,6 +59,11 @@ interface CryptoService : SignOnlyCryptoService {
* Returns the [PublicKey] of the generated [KeyPair].
*/
fun generateKeyPair(alias: String, scheme: SignatureScheme): PublicKey
/**
* Returns the type of the service.
*/
fun getType(): SupportedCryptoServices
}
open class CryptoServiceException(message: String?, cause: Throwable? = null) : Exception(message, cause)

View File

@ -1,9 +1,6 @@
package net.corda.nodeapi.internal.cryptoservice
enum class SupportedCryptoServices {
enum class SupportedCryptoServices(val userFriendlyName: String) {
/** Identifier for [BCCryptoService]. */
BC_SIMPLE
// UTIMACO, // Utimaco HSM.
// GEMALTO_LUNA, // Gemalto Luna HSM.
// AZURE_KV // Azure key Vault.
BC_SIMPLE("file-based keystore")
}

View File

@ -11,6 +11,7 @@ import net.corda.nodeapi.internal.crypto.ContentSignerBuilder
import net.corda.nodeapi.internal.crypto.X509Utilities
import net.corda.nodeapi.internal.cryptoservice.CryptoService
import net.corda.nodeapi.internal.cryptoservice.CryptoServiceException
import net.corda.nodeapi.internal.cryptoservice.SupportedCryptoServices
import org.bouncycastle.operator.ContentSigner
import java.security.KeyPair
import java.security.KeyStore
@ -25,6 +26,8 @@ import javax.security.auth.x500.X500Principal
*/
class BCCryptoService(private val legalName: X500Principal, private val certificateStoreSupplier: CertificateStoreSupplier) : CryptoService {
override fun getType(): SupportedCryptoServices = SupportedCryptoServices.BC_SIMPLE
// TODO check if keyStore exists.
// TODO make it private when E2ETestKeyManagementService does not require direct access to the private key.
var certificateStore: CertificateStore = certificateStoreSupplier.get(true)

View File

@ -8,6 +8,7 @@ import net.corda.core.crypto.sha256
import net.corda.nodeapi.internal.crypto.ContentSignerBuilder
import net.corda.nodeapi.internal.cryptoservice.CryptoService
import net.corda.nodeapi.internal.cryptoservice.CryptoServiceException
import net.corda.nodeapi.internal.cryptoservice.SupportedCryptoServices
import org.bouncycastle.operator.ContentSigner
import java.security.KeyPair
import java.security.PublicKey
@ -15,6 +16,8 @@ import java.security.Signature
class MockCryptoService(initialKeyPairs: Map<String, KeyPair>) : CryptoService {
override fun getType(): SupportedCryptoServices = SupportedCryptoServices.BC_SIMPLE
private val aliasToKey: MutableMap<String, KeyPair> = mutableMapOf()
init {