Auth still in progress

This commit is contained in:
Claude Brisson
2024-02-26 09:54:28 +01:00
parent 69d4a9c1e6
commit 71549f185e
27 changed files with 295 additions and 84 deletions

View File

@@ -52,6 +52,5 @@ class AESCryptograph : Cryptograph {
companion object {
private val CIPHER = "AES/ECB/PKCS5Padding"
private val ALGORITHM = "AES"
}
}

View File

@@ -0,0 +1,6 @@
package org.jeudego.pairgoth.util
object Randomizer {
private val validChars = ('a'..'z') + ('A'..'Z') + ('0'..'9')
fun randomString(length: Int) = CharArray(length) { validChars.random() }.concatToString()
}

View File

@@ -0,0 +1,18 @@
package org.jeudego.pairgoth.web
import org.jeudego.pairgoth.util.Randomizer
import java.lang.RuntimeException
// a randomly generated secret shared by the API and View webapps
val sharedSecret: String by lazy {
BaseWebappManager.properties.getProperty("auth.shared_secret") ?: when (BaseWebappManager.properties.getProperty("mode")) {
"standalone" -> Randomizer.randomString(16)
else -> when (BaseWebappManager.properties.getProperty("auth")) {
"none" -> " ".repeat(16)
else -> throw RuntimeException("missing property auth.shared_secret")
}
}.also {
if (it.length != 16) throw RuntimeException("shared secret must be 16 ascii chars long")
}
}