import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Base64
-import java.util.UUID
- const val WebDavDomainName = "http://localhost:8180"
+ const val WebDavDomainName = "https://dav.mechyrdia.info"
private val dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME
fun ApplicationRequest.basicAuth(): Pair<String, String>? {
val auth = authorization() ?: return null
- if (!auth.startsWith(" ")) return null
+ if (!auth.startsWith("Basic ")) return null
val basic = auth.substring(6)
- return String(base64Decoder.decode(basic))
+ return String(base64Decoder.decode(basic), Utf8)
.split(':', limit = 2)
.let { (user, pass) -> user to pass }
}
suspend fun ApplicationCall.beforeWebDav() {
attributes.put(WebDavAttributeKey, true)
- val (user, token) = request.basicAuth() ?: throw WebDavAuthRequired()
- val tokenData = WebDavToken.Table.get(Id(token)) ?: throw WebDavAuthRequired()
+ response.header(HttpHeaders.DAV, "1,2")
- if (Configuration.Current.isDevMode)
- return
-
- if (tokenData.holder.id != user.toNationId() || tokenData.validUntil < Instant.now())
- throw WebDavAuthRequired()
+ val (tokenId, tokenPw) = request.basicAuth() ?: throw WebDavAuthRequired()
+ val tokenData = WebDavToken.Table.get(Id(tokenId)) ?: throw WebDavAuthRequired()
- response.header(HttpHeaders.DAV, "1,2")
+ if (tokenData.validUntil < Instant.now() || !Argon2Hasher.verifyHash(tokenData.pwHash, tokenPw))
+ throw WebDavAuthRequired()
}
suspend fun ApplicationCall.webDavOptions() {