mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 12:27:58 +01:00
Implement authenticate command
This commit is contained in:
parent
9d4b294965
commit
38cc67f8e7
2 changed files with 19 additions and 11 deletions
|
@ -13,6 +13,8 @@ import org.pgpainless.wot.api.WoTAPI
|
||||||
import org.pgpainless.wot.cli.subcommands.*
|
import org.pgpainless.wot.cli.subcommands.*
|
||||||
import org.pgpainless.wot.network.Fingerprint
|
import org.pgpainless.wot.network.Fingerprint
|
||||||
import org.pgpainless.wot.network.ReferenceTime
|
import org.pgpainless.wot.network.ReferenceTime
|
||||||
|
import org.pgpainless.wot.network.Root
|
||||||
|
import org.pgpainless.wot.network.Roots
|
||||||
import pgp.cert_d.PGPCertificateStoreAdapter
|
import pgp.cert_d.PGPCertificateStoreAdapter
|
||||||
import pgp.cert_d.subkey_lookup.InMemorySubkeyLookupFactory
|
import pgp.cert_d.subkey_lookup.InMemorySubkeyLookupFactory
|
||||||
import pgp.certificate_store.PGPCertificateStore
|
import pgp.certificate_store.PGPCertificateStore
|
||||||
|
@ -39,7 +41,7 @@ import kotlin.system.exitProcess
|
||||||
)
|
)
|
||||||
class WotCLI: Callable<Int> {
|
class WotCLI: Callable<Int> {
|
||||||
|
|
||||||
@Option(names = ["--trust-root", "-r"], required = true)
|
@Option(names = ["--trust-root", "-r"])
|
||||||
var mTrustRoot: Array<String> = arrayOf()
|
var mTrustRoot: Array<String> = arrayOf()
|
||||||
|
|
||||||
@ArgGroup(exclusive = true, multiplicity = "1")
|
@ArgGroup(exclusive = true, multiplicity = "1")
|
||||||
|
@ -62,10 +64,10 @@ class WotCLI: Callable<Int> {
|
||||||
|
|
||||||
@Option(names = ["--keyserver"], description=["Change the default keyserver"])
|
@Option(names = ["--keyserver"], description=["Change the default keyserver"])
|
||||||
var keyServer: String = "hkps://keyserver.ubuntu.com"
|
var keyServer: String = "hkps://keyserver.ubuntu.com"
|
||||||
|
*/
|
||||||
|
|
||||||
@Option(names = ["--gpg-ownertrust"])
|
@Option(names = ["--gpg-ownertrust"])
|
||||||
var gpgOwnertrust: Boolean = false
|
var gpgOwnertrust: Boolean = false
|
||||||
*/
|
|
||||||
|
|
||||||
@Option(names = ["--certification-network"], description = ["Treat the web of trust as a certification network instead of an authentication network."])
|
@Option(names = ["--certification-network"], description = ["Treat the web of trust as a certification network instead of an authentication network."])
|
||||||
var certificationNetwork = false
|
var certificationNetwork = false
|
||||||
|
@ -73,8 +75,8 @@ class WotCLI: Callable<Int> {
|
||||||
@Option(names = ["--gossip"], description = ["Find arbitrary paths by treating all certificates as trust-roots with zero trust."])
|
@Option(names = ["--gossip"], description = ["Find arbitrary paths by treating all certificates as trust-roots with zero trust."])
|
||||||
var gossip = false
|
var gossip = false
|
||||||
|
|
||||||
@ArgGroup(exclusive = true, multiplicity = "1")
|
@ArgGroup(exclusive = true)
|
||||||
lateinit var mTrustAmount: TrustAmount
|
var mTrustAmount: TrustAmount = TrustAmount()
|
||||||
|
|
||||||
class TrustAmount {
|
class TrustAmount {
|
||||||
@Option(names = ["--trust-amount", "-a"], description = ["The required amount of trust."])
|
@Option(names = ["--trust-amount", "-a"], description = ["The required amount of trust."])
|
||||||
|
@ -104,13 +106,15 @@ class WotCLI: Callable<Int> {
|
||||||
} ?: ReferenceTime.now()
|
} ?: ReferenceTime.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val trustRoots: List<Fingerprint>
|
private val trustRoots: Roots
|
||||||
get() {
|
get() {
|
||||||
if (mCertificateSource.gpg) {
|
val trustRootFingerprints = if (mCertificateSource.gpg || gpgOwnertrust) {
|
||||||
return readGpgOwnertrust().plus(mTrustRoot.map { Fingerprint(it) })
|
readGpgOwnertrust().plus(mTrustRoot.map { Fingerprint(it) })
|
||||||
|
} else {
|
||||||
|
mTrustRoot.map { Fingerprint(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
return mTrustRoot.map { Fingerprint(it) }
|
return Roots(trustRootFingerprints.map { Root(it) })
|
||||||
}
|
}
|
||||||
|
|
||||||
private val amount: Int
|
private val amount: Int
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
package org.pgpainless.wot.api
|
package org.pgpainless.wot.api
|
||||||
|
|
||||||
|
import org.pgpainless.wot.dijkstra.Query
|
||||||
import org.pgpainless.wot.network.Fingerprint
|
import org.pgpainless.wot.network.Fingerprint
|
||||||
import org.pgpainless.wot.network.Network
|
import org.pgpainless.wot.network.Network
|
||||||
import org.pgpainless.wot.network.ReferenceTime
|
import org.pgpainless.wot.network.ReferenceTime
|
||||||
|
import org.pgpainless.wot.network.Roots
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web of Trust API, offering different operations.
|
* Web of Trust API, offering different operations.
|
||||||
|
@ -21,7 +23,7 @@ import org.pgpainless.wot.network.ReferenceTime
|
||||||
*/
|
*/
|
||||||
class WoTAPI(
|
class WoTAPI(
|
||||||
val network: Network,
|
val network: Network,
|
||||||
val trustRoots: List<Fingerprint>,
|
val trustRoots: Roots,
|
||||||
val gossip: Boolean = false,
|
val gossip: Boolean = false,
|
||||||
val certificationNetwork: Boolean = false,
|
val certificationNetwork: Boolean = false,
|
||||||
val trustAmount: Int = AuthenticationLevel.Fully.amount,
|
val trustAmount: Int = AuthenticationLevel.Fully.amount,
|
||||||
|
@ -32,7 +34,7 @@ class WoTAPI(
|
||||||
* Secondary constructor, taking an [AuthenticationLevel] instead of an [Int].
|
* Secondary constructor, taking an [AuthenticationLevel] instead of an [Int].
|
||||||
*/
|
*/
|
||||||
constructor(network: Network,
|
constructor(network: Network,
|
||||||
trustRoots: List<Fingerprint>,
|
trustRoots: Roots,
|
||||||
gossip: Boolean = false,
|
gossip: Boolean = false,
|
||||||
certificationNetwork: Boolean = false,
|
certificationNetwork: Boolean = false,
|
||||||
trustAmount: AuthenticationLevel = AuthenticationLevel.Fully,
|
trustAmount: AuthenticationLevel = AuthenticationLevel.Fully,
|
||||||
|
@ -40,7 +42,9 @@ class WoTAPI(
|
||||||
this(network,trustRoots, gossip,certificationNetwork, trustAmount.amount, referenceTime)
|
this(network,trustRoots, gossip,certificationNetwork, trustAmount.amount, referenceTime)
|
||||||
|
|
||||||
override fun authenticate(arguments: AuthenticateAPI.Arguments): AuthenticateAPI.Result {
|
override fun authenticate(arguments: AuthenticateAPI.Arguments): AuthenticateAPI.Result {
|
||||||
TODO("Not yet implemented")
|
val query = Query(network, trustRoots, certificationNetwork)
|
||||||
|
val paths = query.authenticate(arguments.fingerprint, arguments.userId, trustAmount)
|
||||||
|
return AuthenticateAPI.Result(arguments.fingerprint, arguments.userId, trustAmount, paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun identify(arguments: IdentifyAPI.Arguments): IdentifyAPI.Result {
|
override fun identify(arguments: IdentifyAPI.Arguments): IdentifyAPI.Result {
|
||||||
|
|
Loading…
Reference in a new issue