diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index e033963..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/main/kotlin/io/github/chronosx88/dhtBootstrap/DataSerializer.kt b/src/main/kotlin/io/github/chronosx88/dhtBootstrap/DataSerializer.kt index 9d02ebc..4598970 100644 --- a/src/main/kotlin/io/github/chronosx88/dhtBootstrap/DataSerializer.kt +++ b/src/main/kotlin/io/github/chronosx88/dhtBootstrap/DataSerializer.kt @@ -13,8 +13,7 @@ import java.security.InvalidKeyException import java.security.SignatureException class DataSerializer(private val signatureFactory: SignatureFactory) : EntryBinding, 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? { if (databaseEntry.data == null) { @@ -38,18 +37,12 @@ class DataSerializer(private val signatureFactory: SignatureFactory) : EntryBind buf = Unpooled.wrappedBuffer(me) var retVal = data.decodeBuffer(buf) 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 } override fun objectToEntry(data: Data, databaseEntry: DatabaseEntry) { - val forSigningKP = keyPairManager.getKeyPair("mainSigningKeyPair") - data.sign(forSigningKP) val out = ByteArrayOutputStream() val acb = AlternativeCompositeByteBuf.compBuffer(AlternativeCompositeByteBuf.UNPOOLED_HEAP) try { @@ -91,6 +84,5 @@ class DataSerializer(private val signatureFactory: SignatureFactory) : EntryBind companion object { private const val serialVersionUID = 1428836065493792295L - private val keyPairManager = KeyPairManager() } } \ No newline at end of file diff --git a/src/main/kotlin/io/github/chronosx88/dhtBootstrap/KeyPairManager.kt b/src/main/kotlin/io/github/chronosx88/dhtBootstrap/KeyPairManager.kt deleted file mode 100644 index 984c7ad..0000000 --- a/src/main/kotlin/io/github/chronosx88/dhtBootstrap/KeyPairManager.kt +++ /dev/null @@ -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 - - 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() - } - - } - } -}