mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
Updated DB schemas from using string'ified key to use hash of key.
This commit is contained in:
parent
20e0e63eed
commit
0e5346caa1
@ -1,11 +1,11 @@
|
||||
package net.corda.core.schemas
|
||||
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.identity.PartyAndCertificate
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.toBase58String
|
||||
import java.io.Serializable
|
||||
import javax.persistence.*
|
||||
|
||||
@ -85,8 +85,8 @@ object NodeInfoSchemaV1 : MappedSchema(
|
||||
@Table(name = "node_info_party_cert")
|
||||
data class DBPartyAndCertificate(
|
||||
@Id
|
||||
@Column(name = "owning_key", length = 65535, nullable = false)
|
||||
val owningKey: String,
|
||||
@Column(name = "owning_key_hash")
|
||||
val owningKeyHash: String,
|
||||
|
||||
//@Id // TODO Do we assume that names are unique? Note: We can't have it as Id, because our toString on X500 is inconsistent.
|
||||
@Column(name = "party_name", nullable = false)
|
||||
@ -102,10 +102,10 @@ object NodeInfoSchemaV1 : MappedSchema(
|
||||
private val persistentNodeInfos: Set<PersistentNodeInfo> = emptySet()
|
||||
) {
|
||||
constructor(partyAndCert: PartyAndCertificate, isMain: Boolean = false)
|
||||
: this(partyAndCert.party.owningKey.toBase58String(), partyAndCert.party.name.toString(), partyAndCert.serialize().bytes, isMain)
|
||||
: this(SecureHash.sha256(partyAndCert.owningKey.encoded).toString(), partyAndCert.party.name.toString(), partyAndCert.serialize().bytes, isMain)
|
||||
|
||||
fun toLegalIdentityAndCert(): PartyAndCertificate {
|
||||
return partyCertBinary.deserialize<PartyAndCertificate>()
|
||||
return partyCertBinary.deserialize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ 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
|
||||
@ -34,29 +35,28 @@ class PersistentKeyManagementService(val identityService: IdentityService,
|
||||
@Entity
|
||||
@javax.persistence.Table(name = "${NODE_DATABASE_PREFIX}our_key_pairs")
|
||||
class PersistentKey(
|
||||
|
||||
@Id
|
||||
@Column(length = 6000, name = "public_key")
|
||||
var publicKey: String = "",
|
||||
@Column(name = "public_key_hash")
|
||||
var publicKeyHash: String,
|
||||
|
||||
@Lob
|
||||
@Column(name = "private_key")
|
||||
var privateKey: ByteArray = ByteArray(0)
|
||||
)
|
||||
) {
|
||||
constructor(publicKey: PublicKey, privateKey: ByteArray)
|
||||
: this(SecureHash.sha256(publicKey.encoded).toString(), privateKey)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
fun createKeyMap(): AppendOnlyPersistentMap<PublicKey, PrivateKey, PersistentKey, String> {
|
||||
return AppendOnlyPersistentMap(
|
||||
toPersistentEntityKey = { it.toBase58String() },
|
||||
fromPersistentEntity = {
|
||||
Pair(parsePublicKeyBase58(it.publicKey),
|
||||
it.privateKey.deserialize<PrivateKey>(context = SerializationDefaults.STORAGE_CONTEXT))
|
||||
Pair(parsePublicKeyBase58(it.publicKeyHash.hexToBase58()),
|
||||
it.privateKey.deserialize(context = SerializationDefaults.STORAGE_CONTEXT))
|
||||
},
|
||||
toPersistentEntity = { key: PublicKey, value: PrivateKey ->
|
||||
PersistentKey().apply {
|
||||
publicKey = key.toBase58String()
|
||||
privateKey = value.serialize(context = SerializationDefaults.STORAGE_CONTEXT).bytes
|
||||
}
|
||||
PersistentKey(key, value.serialize(context = SerializationDefaults.STORAGE_CONTEXT).bytes)
|
||||
},
|
||||
persistentEntityClass = PersistentKey::class.java
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.corda.node.services.network
|
||||
|
||||
import net.corda.core.concurrent.CordaFuture
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.identity.Party
|
||||
@ -21,7 +22,6 @@ import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.core.utilities.toBase58String
|
||||
import net.corda.node.services.api.NetworkCacheException
|
||||
import net.corda.node.services.api.NetworkMapCacheInternal
|
||||
import net.corda.node.services.api.ServiceHubInternal
|
||||
@ -310,9 +310,9 @@ open class PersistentNetworkMapCache(private val serviceHub: ServiceHubInternal)
|
||||
|
||||
private fun findByIdentityKey(session: Session, identityKey: PublicKey): List<NodeInfoSchemaV1.PersistentNodeInfo> {
|
||||
val query = session.createQuery(
|
||||
"SELECT n FROM ${NodeInfoSchemaV1.PersistentNodeInfo::class.java.name} n JOIN n.legalIdentitiesAndCerts l WHERE l.owningKey = :owningKey",
|
||||
"SELECT n FROM ${NodeInfoSchemaV1.PersistentNodeInfo::class.java.name} n JOIN n.legalIdentitiesAndCerts l WHERE l.owningKeyHash = :owningKeyHash",
|
||||
NodeInfoSchemaV1.PersistentNodeInfo::class.java)
|
||||
query.setParameter("owningKey", identityKey.toBase58String())
|
||||
query.setParameter("owningKeyHash", SecureHash.sha256(identityKey.encoded).toString())
|
||||
return query.resultList
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,9 @@ class PersistentNetworkMapService(network: MessagingService, networkMapCache: Ne
|
||||
@Entity
|
||||
@Table(name = "${NODE_DATABASE_PREFIX}network_map_nodes")
|
||||
class NetworkNode(
|
||||
@Id @Column(name = "node_party_key_hash")
|
||||
var publicKeyHash: String = "",
|
||||
@Id
|
||||
@Column(name = "node_party_key_hash")
|
||||
var publicKeyHash: String,
|
||||
|
||||
@Column
|
||||
var nodeParty: NodeParty = NodeParty(),
|
||||
|
Loading…
Reference in New Issue
Block a user