mirror of
https://github.com/corda/corda.git
synced 2025-01-17 18:29:49 +00:00
Fix for CORDA-3315 (#5580)
* Fix for CORDA-3315. Removed default implementation of partyFromKey and replaced with implementations in IdentityService sub-types. * Added test. * Added missing DB transaction to append only persistent map lookup.
This commit is contained in:
parent
c18c3aed95
commit
8a5b6ed52b
@ -80,9 +80,7 @@ interface IdentityService {
|
||||
* @param key The owning [PublicKey] of the [Party].
|
||||
* @return Returns a [Party] with a matching owningKey if known, else returns null.
|
||||
*/
|
||||
fun partyFromKey(key: PublicKey): Party? =
|
||||
@Suppress("DEPRECATION")
|
||||
certificateFromKey(key)?.party
|
||||
fun partyFromKey(key: PublicKey): Party?
|
||||
|
||||
/**
|
||||
* Resolves a party name to the well known identity [Party] instance for this name. Where possible well known identity
|
||||
|
@ -6,13 +6,10 @@ import net.corda.core.identity.Party
|
||||
import net.corda.core.identity.PartyAndCertificate
|
||||
import net.corda.core.identity.x500Matches
|
||||
import net.corda.core.internal.CertRole
|
||||
import net.corda.core.internal.hash
|
||||
import net.corda.core.node.services.IdentityService
|
||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import net.corda.core.utilities.trace
|
||||
import net.corda.node.services.api.IdentityServiceInternal
|
||||
import net.corda.node.services.persistence.WritablePublicKeyToOwningIdentityCache
|
||||
import net.corda.nodeapi.internal.crypto.X509Utilities
|
||||
import net.corda.nodeapi.internal.crypto.x509Certificates
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
@ -101,6 +98,10 @@ class InMemoryIdentityService(
|
||||
return keyToPartyAndCerts[identityCertChain[1].publicKey]
|
||||
}
|
||||
|
||||
override fun partyFromKey(key: PublicKey): Party? {
|
||||
return certificateFromKey(key)?.party ?: keyToName[key.toStringShort()]?.let { wellKnownPartyFromX500Name(it) }
|
||||
}
|
||||
|
||||
override fun certificateFromKey(owningKey: PublicKey): PartyAndCertificate? = keyToPartyAndCerts[owningKey]
|
||||
|
||||
// We give the caller a copy of the data set to avoid any locking problems
|
||||
|
@ -296,6 +296,12 @@ class PersistentIdentityService(cacheFactory: NamedCacheFactory) : SingletonSeri
|
||||
keyToPartyAndCert[owningKey.toStringShort()]
|
||||
}
|
||||
|
||||
override fun partyFromKey(key: PublicKey): Party? {
|
||||
return certificateFromKey(key)?.party ?: database.transaction {
|
||||
keyToName[key.toStringShort()]
|
||||
}?.let { wellKnownPartyFromX500Name(it) }
|
||||
}
|
||||
|
||||
private fun certificateFromCordaX500Name(name: CordaX500Name): PartyAndCertificate? {
|
||||
return database.transaction {
|
||||
val partyId = nameToKey[name]
|
||||
|
@ -261,6 +261,17 @@ class PersistentIdentityServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve key to party for key without certificate`() {
|
||||
// Register Alice's PartyAndCert as if it was done so via the network map cache.
|
||||
identityService.verifyAndRegisterIdentity(alice.identity)
|
||||
// Use a key which is not tied to a cert.
|
||||
val publicKey = Crypto.generateKeyPair().public
|
||||
// Register the PublicKey to Alice's CordaX500Name.
|
||||
identityService.registerKey(publicKey, alice.party)
|
||||
assertEquals(alice.party, identityService.partyFromKey(publicKey))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `register incorrect party to public key `(){
|
||||
database.transaction { identityService.verifyAndRegisterIdentity(ALICE_IDENTITY) }
|
||||
|
Loading…
Reference in New Issue
Block a user