mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
Standardise Public Key hash size as per discussions with KC.
This commit is contained in:
parent
cda3ecbc0a
commit
b861f4b7cb
@ -12,6 +12,7 @@ import net.corda.core.serialization.SingletonSerializeAsToken
|
||||
import net.corda.core.utilities.debug
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.node.utilities.AppendOnlyPersistentMap
|
||||
import net.corda.node.utilities.MAX_HASH_HEX_SIZE
|
||||
import net.corda.node.utilities.NODE_DATABASE_PREFIX
|
||||
import org.bouncycastle.cert.X509CertificateHolder
|
||||
import java.io.ByteArrayInputStream
|
||||
@ -72,8 +73,8 @@ class PersistentIdentityService(identities: Iterable<PartyAndCertificate> = empt
|
||||
@javax.persistence.Table(name = "${NODE_DATABASE_PREFIX}identities")
|
||||
class PersistentIdentity(
|
||||
@Id
|
||||
@Column(name = "pk_hash", length = 64)
|
||||
var publicKeyHash: String = "",
|
||||
@Column(name = "pk_hash", length = MAX_HASH_HEX_SIZE)
|
||||
var publicKeyHash: String,
|
||||
|
||||
@Lob
|
||||
@Column
|
||||
@ -87,7 +88,7 @@ class PersistentIdentityService(identities: Iterable<PartyAndCertificate> = empt
|
||||
@Column(name = "name", length = 128)
|
||||
var name: String = "",
|
||||
|
||||
@Column(name = "pk_hash", length = 64)
|
||||
@Column(name = "pk_hash", length = MAX_HASH_HEX_SIZE)
|
||||
var publicKeyHash: String = ""
|
||||
)
|
||||
|
||||
|
@ -8,10 +8,8 @@ import net.corda.core.serialization.SerializationDefaults
|
||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.core.utilities.hexToBase58
|
||||
import net.corda.core.utilities.parsePublicKeyBase58
|
||||
import net.corda.core.utilities.toBase58String
|
||||
import net.corda.node.utilities.AppendOnlyPersistentMap
|
||||
import net.corda.node.utilities.MAX_HASH_HEX_SIZE
|
||||
import net.corda.node.utilities.NODE_DATABASE_PREFIX
|
||||
import org.bouncycastle.operator.ContentSigner
|
||||
import java.security.KeyPair
|
||||
@ -36,27 +34,31 @@ class PersistentKeyManagementService(val identityService: IdentityService,
|
||||
@javax.persistence.Table(name = "${NODE_DATABASE_PREFIX}our_key_pairs")
|
||||
class PersistentKey(
|
||||
@Id
|
||||
@Column(name = "public_key_hash", length = 64)
|
||||
@Column(name = "public_key_hash", length = MAX_HASH_HEX_SIZE)
|
||||
var publicKeyHash: String,
|
||||
|
||||
@Lob
|
||||
@Column(name = "public_key")
|
||||
var publicKey: ByteArray = ByteArray(0),
|
||||
|
||||
@Lob
|
||||
@Column(name = "private_key")
|
||||
var privateKey: ByteArray = ByteArray(0)
|
||||
) {
|
||||
constructor(publicKey: PublicKey, privateKey: ByteArray)
|
||||
: this(publicKey.encoded.sha256().toString(), privateKey)
|
||||
constructor(publicKey: PublicKey, privateKey: PrivateKey)
|
||||
: this(publicKey.toStringShort(),
|
||||
publicKey.serialize(context = SerializationDefaults.STORAGE_CONTEXT).bytes,
|
||||
privateKey.serialize(context = SerializationDefaults.STORAGE_CONTEXT).bytes)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
fun createKeyMap(): AppendOnlyPersistentMap<PublicKey, PrivateKey, PersistentKey, String> {
|
||||
return AppendOnlyPersistentMap(
|
||||
toPersistentEntityKey = { it.toBase58String() },
|
||||
fromPersistentEntity = {
|
||||
Pair(parsePublicKeyBase58(it.publicKeyHash.hexToBase58()),
|
||||
it.privateKey.deserialize(context = SerializationDefaults.STORAGE_CONTEXT))
|
||||
},
|
||||
toPersistentEntityKey = { it.toStringShort() },
|
||||
fromPersistentEntity = { Pair(it.publicKey.deserialize(context = SerializationDefaults.STORAGE_CONTEXT),
|
||||
it.privateKey.deserialize(context = SerializationDefaults.STORAGE_CONTEXT)) },
|
||||
toPersistentEntity = { key: PublicKey, value: PrivateKey ->
|
||||
PersistentKey(key, value.serialize(context = SerializationDefaults.STORAGE_CONTEXT).bytes)
|
||||
PersistentKey(key, value)
|
||||
},
|
||||
persistentEntityClass = PersistentKey::class.java
|
||||
)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.corda.node.services.network
|
||||
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.sha256
|
||||
import net.corda.core.crypto.toStringShort
|
||||
import net.corda.core.identity.PartyAndCertificate
|
||||
import net.corda.core.internal.ThreadBox
|
||||
import net.corda.core.messaging.SingleMessageRecipient
|
||||
@ -10,6 +9,7 @@ import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.node.services.api.NetworkMapCacheInternal
|
||||
import net.corda.node.services.messaging.MessagingService
|
||||
import net.corda.node.utilities.MAX_HASH_HEX_SIZE
|
||||
import net.corda.node.utilities.NODE_DATABASE_PREFIX
|
||||
import net.corda.node.utilities.PersistentMap
|
||||
import net.corda.nodeapi.ArtemisMessagingComponent
|
||||
@ -34,7 +34,7 @@ class PersistentNetworkMapService(network: MessagingService, networkMapCache: Ne
|
||||
@Table(name = "${NODE_DATABASE_PREFIX}network_map_nodes")
|
||||
class NetworkNode(
|
||||
@Id
|
||||
@Column(name = "node_party_key_hash", length = 64)
|
||||
@Column(name = "node_party_key_hash", length = MAX_HASH_HEX_SIZE)
|
||||
var publicKeyHash: String,
|
||||
|
||||
@Column
|
||||
@ -61,14 +61,14 @@ class PersistentNetworkMapService(network: MessagingService, networkMapCache: Ne
|
||||
|
||||
fun createNetworkNodesMap(): PersistentMap<PartyAndCertificate, NodeRegistrationInfo, NetworkNode, String> {
|
||||
return PersistentMap(
|
||||
toPersistentEntityKey = { SecureHash.sha256(it.owningKey.encoded).toString() },
|
||||
toPersistentEntityKey = { it.owningKey.toStringShort() },
|
||||
fromPersistentEntity = {
|
||||
Pair(PartyAndCertificate(factory.generateCertPath(ByteArrayInputStream(it.nodeParty.certPath))),
|
||||
it.registrationInfo.deserialize(context = SerializationDefaults.STORAGE_CONTEXT))
|
||||
},
|
||||
toPersistentEntity = { key: PartyAndCertificate, value: NodeRegistrationInfo ->
|
||||
NetworkNode(
|
||||
publicKeyHash = key.owningKey.encoded.sha256().toString(),
|
||||
publicKeyHash = key.owningKey.toStringShort(),
|
||||
nodeParty = NodeParty(
|
||||
key.name.toString(),
|
||||
key.certificate.encoded,
|
||||
|
@ -20,6 +20,14 @@ import java.util.concurrent.CopyOnWriteArrayList
|
||||
*/
|
||||
const val NODE_DATABASE_PREFIX = "node_"
|
||||
|
||||
/**
|
||||
* The maximum supported field-size for hash HEX-encoded outputs (e.g. database fields).
|
||||
* This value is enough to support hash functions with outputs up to 512 bits (e.g. SHA3-512), in which
|
||||
* case 128 HEX characters are required.
|
||||
* 130 was selected instead of 128, to allow for 2 extra characters that will be used as hash-scheme identifiers.
|
||||
*/
|
||||
const val MAX_HASH_HEX_SIZE = 130
|
||||
|
||||
//HikariDataSource implements Closeable which allows CordaPersistence to be Closeable
|
||||
class CordaPersistence(var dataSource: HikariDataSource, private val schemaService: SchemaService,
|
||||
private val createIdentityService: () -> IdentityService, databaseProperties: Properties) : Closeable {
|
||||
|
Loading…
Reference in New Issue
Block a user