1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 18:29:39 +02:00

Implement SOPs validate-userid command

This commit is contained in:
Paul Schaub 2025-04-08 16:10:38 +02:00
parent 2d1c2d2737
commit 3080e8bdd3
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 39 additions and 1 deletions

View file

@ -68,7 +68,7 @@ class SOPImpl(
override fun updateKey(): UpdateKey? = null
override fun validateUserId(): ValidateUserId? = null
override fun validateUserId(): ValidateUserId = ValidateUserIdImpl(api)
override fun version(): Version = sopv.version()!!
}

View file

@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.sop
import java.io.InputStream
import java.util.*
import org.bouncycastle.openpgp.api.OpenPGPCertificate
import org.pgpainless.PGPainless
import sop.operation.ValidateUserId
class ValidateUserIdImpl(private val api: PGPainless) : ValidateUserId {
private var addSpecOnly = false
private var userId: String? = null
private val authorities: MutableList<OpenPGPCertificate> = mutableListOf()
private var validateAt: Date = Date()
override fun addrSpecOnly(): ValidateUserId = apply { addSpecOnly = true }
override fun authorities(certs: InputStream): ValidateUserId = apply {
authorities.addAll(api.readKey().parseCertificates(certs))
}
override fun subjects(certs: InputStream): Boolean {
requireNotNull(userId) { "Missing parameter USERID" }
return api.readKey().parseCertificates(certs).all { cert ->
authorities.all { authority ->
cert.getUserId(userId)?.getCertificationBy(authority, validateAt)?.isValid == true
}
}
}
override fun userId(userId: String): ValidateUserId = apply { this.userId = userId }
override fun validateAt(date: Date): ValidateUserId = apply { validateAt = date }
}