Remove data signing

This commit is contained in:
ChronosX88 2019-04-10 15:35:31 +04:00
parent 2185285c11
commit bd3a141e68
3 changed files with 2 additions and 103 deletions

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel>
<module name="io.github.chronosx88.influence-bootstrap-node.test" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

View File

@ -13,8 +13,7 @@ import java.security.InvalidKeyException
import java.security.SignatureException import java.security.SignatureException
class DataSerializer(private val signatureFactory: SignatureFactory) : EntryBinding<Data>, Serializable { class DataSerializer(private val signatureFactory: SignatureFactory) : EntryBinding<Data>, Serializable {
private val LOG_TAG = "DataSerializer" private val log = LoggerFactory.getLogger(DataSerializer::class.java)
private val LOG = LoggerFactory.getLogger(DataSerializer::class.java)
override fun entryToObject(databaseEntry: DatabaseEntry): Data? { override fun entryToObject(databaseEntry: DatabaseEntry): Data? {
if (databaseEntry.data == null) { if (databaseEntry.data == null) {
@ -38,18 +37,12 @@ class DataSerializer(private val signatureFactory: SignatureFactory) : EntryBind
buf = Unpooled.wrappedBuffer(me) buf = Unpooled.wrappedBuffer(me)
var retVal = data.decodeBuffer(buf) var retVal = data.decodeBuffer(buf)
if (!retVal) { if (!retVal) {
LOG.error("# ERROR: Data could not be deserialized!") log.error("# ERROR: Data could not be deserialized!")
} }
/*retVal = data.decodeDone(buf, signatureFactory)
if (!retVal) {
LOG.error("# ERROR: Signature could not be read!")
}*/
return data return data
} }
override fun objectToEntry(data: Data, databaseEntry: DatabaseEntry) { override fun objectToEntry(data: Data, databaseEntry: DatabaseEntry) {
val forSigningKP = keyPairManager.getKeyPair("mainSigningKeyPair")
data.sign(forSigningKP)
val out = ByteArrayOutputStream() val out = ByteArrayOutputStream()
val acb = AlternativeCompositeByteBuf.compBuffer(AlternativeCompositeByteBuf.UNPOOLED_HEAP) val acb = AlternativeCompositeByteBuf.compBuffer(AlternativeCompositeByteBuf.UNPOOLED_HEAP)
try { try {
@ -91,6 +84,5 @@ class DataSerializer(private val signatureFactory: SignatureFactory) : EntryBind
companion object { companion object {
private const val serialVersionUID = 1428836065493792295L private const val serialVersionUID = 1428836065493792295L
private val keyPairManager = KeyPairManager()
} }
} }

View File

@ -1,85 +0,0 @@
package io.github.chronosx88.dhtBootstrap
import java.io.IOException
import java.io.FileOutputStream
import java.io.File
import java.security.KeyPair
import java.security.NoSuchAlgorithmException
import java.security.KeyPairGenerator
import java.io.FileInputStream
class KeyPairManager {
private val keyPairDir: File
private val serializer: Serializer<KeyPair>
init {
this.keyPairDir = File(DATA_DIR_PATH, "keyPairs")
if (!this.keyPairDir.exists()) {
this.keyPairDir.mkdir()
}
this.serializer = Serializer()
}
fun openMainKeyPair(): KeyPair? {
return getKeyPair("mainKeyPair")
}
fun getKeyPair(keyPairName: String): KeyPair? {
var keyPairName = keyPairName
keyPairName = "$keyPairName.kp"
val keyPairFile = File(keyPairDir, keyPairName)
return if (!keyPairFile.exists()) {
createKeyPairFile(keyPairFile)
} else openKeyPairFile(keyPairFile)
}
@Synchronized
private fun openKeyPairFile(keyPairFile: File): KeyPair? {
var keyPair: KeyPair? = null
try {
val inputStream = FileInputStream(keyPairFile)
val serializedKeyPair = ByteArray(keyPairFile.length().toInt())
inputStream.read(serializedKeyPair)
inputStream.close()
keyPair = serializer.deserialize(serializedKeyPair)
} catch (e: IOException) {
e.printStackTrace()
}
return keyPair
}
@Synchronized
private fun createKeyPairFile(keyPairFile: File): KeyPair? {
var keyPair: KeyPair? = null
try {
keyPairFile.createNewFile()
keyPair = KeyPairGenerator.getInstance("DSA").generateKeyPair()
val outputStream = FileOutputStream(keyPairFile)
outputStream.write(serializer.serialize(keyPair))
outputStream.close()
} catch (e: IOException) {
e.printStackTrace()
} catch (e: NoSuchAlgorithmException) {
e.printStackTrace()
}
return keyPair
}
@Synchronized
fun saveKeyPair(keyPairID: String, keyPair: KeyPair) {
val keyPairFile = File(keyPairDir, "$keyPairID.kp")
if (!keyPairFile.exists()) {
try {
val outputStream = FileOutputStream(keyPairFile)
outputStream.write(serializer.serialize(keyPair))
outputStream.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
}