Cleaned up how pub/priv key are initialized/used
This commit is contained in:
parent
e85025c199
commit
2a52c2b4d5
@ -80,7 +80,7 @@ internal class EventPoller {
|
||||
fun configure(logger: KLogger, config: Configuration, endPoint: EndPoint<*>) = runBlocking {
|
||||
mutex.withLock {
|
||||
logger.debug { "Initializing the Network Event Poller..." }
|
||||
configureEventsEndpoints.add(ByteArrayWrapper.wrap(endPoint.storage.publicKey)!!)
|
||||
configureEventsEndpoints.add(ByteArrayWrapper.wrap(endPoint.storage.publicKey))
|
||||
|
||||
if (!configured) {
|
||||
logger.trace { "Configuring the Network Event Poller..." }
|
||||
|
@ -82,10 +82,13 @@ internal class CryptoManagement(val logger: KLogger,
|
||||
|
||||
// initialize the private/public keys used for negotiating ECC handshakes
|
||||
// these are ONLY used for IP connections. LOCAL connections do not need a handshake!
|
||||
var privateKeyBytes = settingsStore.privateKey
|
||||
var publicKeyBytes = settingsStore.publicKey
|
||||
val privateKeyBytes: ByteArray
|
||||
val publicKeyBytes: ByteArray
|
||||
|
||||
if (privateKeyBytes == null || publicKeyBytes == null) {
|
||||
if (settingsStore.validKeys()) {
|
||||
privateKeyBytes = settingsStore.privateKey
|
||||
publicKeyBytes = settingsStore.publicKey
|
||||
} else {
|
||||
try {
|
||||
// seed our RNG based off of this and create our ECC keys
|
||||
val seedBytes = Entropy["There are no ECC keys for the ${type.simpleName} yet"]
|
||||
@ -109,8 +112,6 @@ internal class CryptoManagement(val logger: KLogger,
|
||||
}
|
||||
}
|
||||
|
||||
publicKeyBytes!!
|
||||
|
||||
logger.info("ECC public key: ${publicKeyBytes.toHexString()}")
|
||||
|
||||
this.publicKey = keyFactory.generatePublic(XECPublicKeySpec(X25519KeySpec, BigInteger(publicKeyBytes))) as XECPublicKey
|
||||
|
@ -124,16 +124,24 @@ class SettingsStore(storageBuilder: Storage.Builder, val logger: KLogger) : Auto
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if both the private and public keys are non-null
|
||||
*/
|
||||
fun validKeys(): Boolean {
|
||||
val pubKey = store.get(local4Buffer) as ByteArray?
|
||||
val privKey = store.get(privateKey_) as ByteArray?
|
||||
return pubKey != null && privKey != null
|
||||
}
|
||||
|
||||
/**
|
||||
* the private key of the server
|
||||
*
|
||||
* @throws SecurityException
|
||||
*/
|
||||
var privateKey: ByteArray?
|
||||
var privateKey: ByteArray
|
||||
get() {
|
||||
checkAccess(CryptoManagement::class.java)
|
||||
return store[privateKey_]
|
||||
return store[privateKey_]!!
|
||||
}
|
||||
set(value) {
|
||||
store[privateKey_] = value
|
||||
@ -144,8 +152,8 @@ class SettingsStore(storageBuilder: Storage.Builder, val logger: KLogger) : Auto
|
||||
*
|
||||
* @throws SecurityException
|
||||
*/
|
||||
var publicKey: ByteArray?
|
||||
get() { return store[local4Buffer] }
|
||||
var publicKey: ByteArray
|
||||
get() { return store[local4Buffer]!! }
|
||||
set(value) {
|
||||
store[local4Buffer] = value
|
||||
store[local6Buffer] = value
|
||||
@ -411,4 +419,6 @@ class SettingsStore(storageBuilder: Storage.Builder, val logger: KLogger) : Auto
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user