Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
n0900 committed Dec 18, 2023
1 parent 94d7bec commit 450cabb
Show file tree
Hide file tree
Showing 25 changed files with 109 additions and 254 deletions.
2 changes: 1 addition & 1 deletion kmp-crypto
9 changes: 1 addition & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ includeBuild("kmp-crypto") {
substitute(module("at.asitplus.crypto:datatypes-jws")).using(project(":datatypes-jws"))
substitute(module("at.asitplus.crypto:datatypes-cose")).using(project(":datatypes-cose"))
}
}

startParameter.excludedTaskNames+="transformNativeMainCInteropDependenciesMetadataForIde" //disable broken import on non-macOS
startParameter.excludedTaskNames+="transformAppleMainCInteropDependenciesMetadataForIde" //disable broken import on non-macOS
startParameter.excludedTaskNames+="transformIosMainCInteropDependenciesMetadataForIde" //disable broken import on non-macOS
startParameter.excludedTaskNames+="transformNativeTestCInteropDependenciesMetadataForIde" //disable broken import on non-macOS
startParameter.excludedTaskNames+="transformAppleTestCInteropDependenciesMetadataForIde" //disable broken import on non-macOS
startParameter.excludedTaskNames+="transformIosTestCInteropDependenciesMetadataForIde" //disable broken import on non-macOS
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
package at.asitplus.wallet.lib.aries

import at.asitplus.wallet.lib.agent.CryptoService
import at.asitplus.wallet.lib.agent.DefaultCryptoService
import at.asitplus.wallet.lib.agent.Holder
import at.asitplus.wallet.lib.agent.HolderAgent
import at.asitplus.wallet.lib.agent.Issuer
import at.asitplus.wallet.lib.agent.IssuerAgent
import at.asitplus.wallet.lib.agent.*
import at.asitplus.wallet.lib.data.AriesGoalCodeParser
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.msg.AttachmentFormatReference
import at.asitplus.wallet.lib.msg.IssueCredential
import at.asitplus.wallet.lib.msg.JwmAttachment
import at.asitplus.wallet.lib.msg.JwmAttachmentData
import at.asitplus.wallet.lib.msg.Presentation
import at.asitplus.wallet.lib.msg.PresentationBody
import at.asitplus.wallet.lib.msg.RequestCredential
import at.asitplus.wallet.lib.msg.RequestCredentialBody
import at.asitplus.wallet.lib.msg.*
import com.benasher44.uuid.uuid4
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldNotBe
Expand Down Expand Up @@ -128,4 +116,4 @@ class IssueCredentialProtocolTest : FreeSpec({

problemReport.parentThreadId shouldNotBe null
}
})
})
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
package at.asitplus.wallet.lib.aries

import at.asitplus.wallet.lib.agent.CredentialToBeIssued
import at.asitplus.wallet.lib.agent.CryptoService
import at.asitplus.wallet.lib.agent.DefaultCryptoService
import at.asitplus.wallet.lib.agent.Holder
import at.asitplus.wallet.lib.agent.HolderAgent
import at.asitplus.wallet.lib.agent.InMemorySubjectCredentialStore
import at.asitplus.wallet.lib.agent.Issuer
import at.asitplus.wallet.lib.agent.IssuerAgent
import at.asitplus.wallet.lib.agent.SubjectCredentialStore
import at.asitplus.wallet.lib.agent.Verifier
import at.asitplus.wallet.lib.agent.VerifierAgent
import at.asitplus.wallet.lib.agent.*
import at.asitplus.wallet.lib.data.AtomicAttribute2023
import at.asitplus.wallet.lib.data.ConstantIndex
import com.benasher44.uuid.uuid4
Expand Down Expand Up @@ -45,7 +35,7 @@ class PresentProofMessengerTest : FreeSpec() {
issuerCryptoService = DefaultCryptoService()
holderCredentialStore = InMemorySubjectCredentialStore()
holder = HolderAgent.newDefaultInstance(holderCryptoService, subjectCredentialStore = holderCredentialStore)
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.publicKey.keyId)
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.jsonWebKey.identifier)
issuer = IssuerAgent.newDefaultInstance(issuerCryptoService, dataProvider = DummyCredentialDataProvider())
verifierChallenge = uuid4().toString()
holderServiceEndpoint = "https://example.com/present-proof?${uuid4()}"
Expand Down Expand Up @@ -160,4 +150,4 @@ class PresentProofMessengerTest : FreeSpec() {
expiration = Clock.System.now() + attributeLifetime,
)

}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
package at.asitplus.wallet.lib.aries

import at.asitplus.wallet.lib.agent.CryptoService
import at.asitplus.wallet.lib.agent.DefaultCryptoService
import at.asitplus.wallet.lib.agent.Holder
import at.asitplus.wallet.lib.agent.HolderAgent
import at.asitplus.wallet.lib.agent.IssuerAgent
import at.asitplus.wallet.lib.agent.Verifier
import at.asitplus.wallet.lib.agent.VerifierAgent
import at.asitplus.wallet.lib.agent.*
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.msg.JwmAttachment
import at.asitplus.wallet.lib.msg.JwmAttachmentData
import at.asitplus.wallet.lib.msg.Presentation
import at.asitplus.wallet.lib.msg.RequestCredential
import at.asitplus.wallet.lib.msg.RequestCredentialBody
import at.asitplus.wallet.lib.msg.*
import com.benasher44.uuid.uuid4
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe
Expand All @@ -31,7 +21,7 @@ class PresentProofProtocolTest : FreeSpec({
holderCryptoService = DefaultCryptoService()
verifierCryptoService = DefaultCryptoService()
holder = HolderAgent.newDefaultInstance(holderCryptoService)
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.publicKey.keyId)
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.jsonWebKey.identifier)
holderProtocol = PresentProofProtocol.newHolderInstance(
holder = holder,
serviceEndpoint = "https://example.com/",
Expand Down Expand Up @@ -135,4 +125,4 @@ class PresentProofProtocolTest : FreeSpec({
requestPresentation.threadId shouldBe problemReport.parentThreadId
}

})
})
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class RelyingPartyMetadata(
@SerialName("client_id_scheme")
val clientIdScheme: String? = "pre-registered",

) {
) {

fun serialize() = jsonSerializer.encodeToString(this)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package at.asitplus.wallet.lib.oidvci

import at.asitplus.crypto.datatypes.jws.JwsAlgorithm
import at.asitplus.crypto.datatypes.io.Base64UrlStrict
import at.asitplus.crypto.datatypes.jws.JsonWebToken
import at.asitplus.crypto.datatypes.jws.JwsAlgorithm
import at.asitplus.crypto.datatypes.jws.JwsSigned
import at.asitplus.wallet.lib.agent.Issuer
import at.asitplus.wallet.lib.data.ConstantIndex
Expand All @@ -17,7 +17,7 @@ import at.asitplus.wallet.lib.oidc.OpenIdConstants.TOKEN_PREFIX_BEARER
import at.asitplus.wallet.lib.oidc.OpenIdConstants.TOKEN_TYPE_BEARER
import at.asitplus.wallet.lib.oidc.OpenIdConstants.URN_TYPE_JWK_THUMBPRINT
import at.asitplus.wallet.lib.oidvci.mdl.RequestedCredentialClaimSpecification
import io.ktor.http.URLBuilder
import io.ktor.http.*
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlin.coroutines.cancellation.CancellationException

Expand Down Expand Up @@ -218,4 +218,4 @@ private fun CredentialFormatEnum.toRepresentation() = when (this) {

class OAuth2Exception(val error: String, val errorDescription: String? = null) : Throwable(error) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DummyCredentialDataProvider(
val expiration = clock.now() + defaultLifetime
val credentials = mutableListOf<CredentialToBeIssued>()
if (credentialScheme == ConstantIndex.AtomicAttribute2023) {
val subjectId = subjectPublicKey.keyId
val subjectId = subjectPublicKey.toJsonWebKey().getOrNull()!!.identifier
val claims = listOfNotNull(
optionalClaim(claimNames, "given-name", "Susanne"),
optionalClaim(claimNames, "family-name", "Meier"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package at.asitplus.wallet.lib.oidc

import at.asitplus.wallet.lib.agent.CryptoService
import at.asitplus.wallet.lib.agent.DefaultCryptoService
import at.asitplus.wallet.lib.agent.Holder
import at.asitplus.wallet.lib.agent.HolderAgent
import at.asitplus.wallet.lib.agent.IssuerAgent
import at.asitplus.wallet.lib.agent.Verifier
import at.asitplus.wallet.lib.agent.VerifierAgent
import at.asitplus.wallet.lib.agent.*
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.data.IsoDocumentParsed
import at.asitplus.wallet.lib.iso.MobileDrivingLicenceDataElements
Expand Down Expand Up @@ -43,7 +37,7 @@ class OidcSiopIsoProtocolTest : FreeSpec({
relyingPartyUrl = "https://example.com/rp/${uuid4()}"
walletUrl = "https://example.com/wallet/${uuid4()}"
holderAgent = HolderAgent.newDefaultInstance(holderCryptoService)
verifierAgent = VerifierAgent.newDefaultInstance(verifierCryptoService.publicKey.keyId)
verifierAgent = VerifierAgent.newDefaultInstance(verifierCryptoService.jsonWebKey.identifier)
runBlocking {
val issuerAgent = IssuerAgent.newDefaultInstance(
DefaultCryptoService(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package at.asitplus.wallet.lib.oidc

import at.asitplus.wallet.lib.agent.CryptoService
import at.asitplus.wallet.lib.agent.DefaultCryptoService
import at.asitplus.wallet.lib.agent.Holder
import at.asitplus.wallet.lib.agent.HolderAgent
import at.asitplus.wallet.lib.agent.IssuerAgent
import at.asitplus.wallet.lib.agent.Verifier
import at.asitplus.wallet.lib.agent.VerifierAgent
import at.asitplus.wallet.lib.agent.*
import at.asitplus.wallet.lib.data.AtomicAttribute2023
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.oidvci.decodeFromPostBody
Expand Down Expand Up @@ -43,7 +37,7 @@ class OidcSiopProtocolTest : FreeSpec({
relyingPartyUrl = "https://example.com/rp/${uuid4()}"
walletUrl = "https://example.com/wallet/${uuid4()}"
holderAgent = HolderAgent.newDefaultInstance(holderCryptoService)
verifierAgent = VerifierAgent.newDefaultInstance(verifierCryptoService.publicKey.keyId)
verifierAgent = VerifierAgent.newDefaultInstance(verifierCryptoService.jsonWebKey.identifier)
runBlocking {
holderAgent.storeCredentials(
IssuerAgent.newDefaultInstance(
Expand Down Expand Up @@ -170,4 +164,4 @@ class OidcSiopProtocolTest : FreeSpec({
it.vc.credentialSubject.shouldBeInstanceOf<AtomicAttribute2023>()
}
}
})
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package at.asitplus.wallet.lib.oidc

import at.asitplus.wallet.lib.agent.CryptoService
import at.asitplus.wallet.lib.agent.DefaultCryptoService
import at.asitplus.wallet.lib.agent.Holder
import at.asitplus.wallet.lib.agent.HolderAgent
import at.asitplus.wallet.lib.agent.IssuerAgent
import at.asitplus.wallet.lib.agent.Verifier
import at.asitplus.wallet.lib.agent.VerifierAgent
import at.asitplus.wallet.lib.agent.*
import at.asitplus.wallet.lib.data.ConstantIndex
import com.benasher44.uuid.uuid4
import io.kotest.core.spec.style.FreeSpec
Expand Down Expand Up @@ -36,7 +30,7 @@ class OidcSiopSdJwtProtocolTest : FreeSpec({
relyingPartyUrl = "https://example.com/rp/${uuid4()}"
walletUrl = "https://example.com/wallet/${uuid4()}"
holderAgent = HolderAgent.newDefaultInstance(holderCryptoService)
verifierAgent = VerifierAgent.newDefaultInstance(verifierCryptoService.publicKey.keyId)
verifierAgent = VerifierAgent.newDefaultInstance(verifierCryptoService.jsonWebKey.identifier)
runBlocking {
holderAgent.storeCredentials(
IssuerAgent.newDefaultInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ interface CryptoService {

val jsonWebKey: JsonWebKey

val coseKey: CoseKey //get() = this.publicKey.toCoseKey(this.algorithm.toCoseAlgorithm()).getOrNull()

val coseKey: CoseKey
/**
* May be used in [at.asitplus.wallet.lib.cbor.CoseService] to transport the signing key for a COSE structure.
* a `null` value signifies that raw public keys are used and no certificate is present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ object EmptyCredentialDataProvider : IssuerCredentialDataProvider {
claimNames: Collection<String>?
): KmmResult<List<CredentialToBeIssued>> = KmmResult.failure(NotImplementedError())

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ class HolderAgent(
Document(
docType = credential.scheme.isoDocType,
issuerSigned = IssuerSigned(
namespaces = mapOf(
credential.scheme.isoNamespace to
IssuerSignedList(attributes.entries.filter { it.discloseItem(requestedClaims) })
namespaces = mapOf(credential.scheme.isoNamespace to
IssuerSignedList(attributes.entries.filter { it.discloseItem(requestedClaims) })
),
issuerAuth = credential.issuerSigned.issuerAuth
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ sealed class CredentialToBeIssued {
) : CredentialToBeIssued()
}

data class ClaimToBeIssued(val name: String, val value: Any)
data class ClaimToBeIssued(val name: String, val value: Any)
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ class DefaultCoseService(private val cryptoService: CryptoService) : CoseService
return KmmResult.failure(it)
}

// val rawSignature: ByteArray = when (cryptoService.algorithm.toCoseAlgorithm()) {
// CoseAlgorithm.ES256, CoseAlgorithm.ES384, CoseAlgorithm.ES512 -> signature.extractSignatureValues(
// (cryptoService.publicKey as CryptoPublicKey.Ec).curve.signatureLengthBytes / 2u)
//
// else -> signature
// }
return KmmResult.success(
CoseSigned(
ByteStringWrapper(copyProtectedHeader),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package at.asitplus.wallet.lib.data

import io.matthewnelson.encoding.base64.Base64
import io.matthewnelson.encoding.base64.Base64ConfigBuilder
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import io.matthewnelson.component.base64.decodeBase64ToArray
import io.matthewnelson.encoding.base64.Base64
import io.matthewnelson.encoding.core.Decoder.Companion.decodeToByteArrayOrNull
import kotlinx.datetime.Clock
import kotlin.random.Random
import kotlin.time.Duration.Companion.seconds
Expand All @@ -36,7 +34,7 @@ class AgentRevocationTest : FreeSpec({
dataProvider = DummyCredentialDataProvider()
)
verifierCryptoService = DefaultCryptoService()
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.publicKey.keyId)
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.jsonWebKey.identifier)
expectedRevokedIndexes = issuerCredentialStore.revokeRandomCredentials()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DummyCredentialDataProvider(
ClaimToBeIssued("family-name", "Meier"),
ClaimToBeIssued("date-of-birth", "1990-01-01"),
)
val subjectId = subjectPublicKey.keyId
val subjectId = subjectPublicKey.toJsonWebKey().getOrNull()!!.identifier
val credentials = when (representation) {
ConstantIndex.CredentialRepresentation.SD_JWT -> listOf(
CredentialToBeIssued.VcSd(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ValidatorVcTest : FreeSpec() {
)
issuerJwsService = DefaultJwsService(issuerCryptoService)
verifierCryptoService = DefaultCryptoService()
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.publicKey.keyId)
verifier = VerifierAgent.newDefaultInstance(verifierCryptoService.jsonWebKey.identifier)
}

"credentials are valid for" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CoseServiceTest : FreeSpec({
parsed.shouldNotBeNull()

cryptoService.coseKey shouldNotBe null
val result = verifierCoseService.verifyCose(parsed, cryptoService.coseKey!!).getOrNull()
val result = verifierCoseService.verifyCose(parsed, cryptoService.coseKey).getOrThrow()
result shouldBe true
}

Expand All @@ -65,7 +65,7 @@ class CoseServiceTest : FreeSpec({
parsed.shouldNotBeNull()

cryptoService.coseKey shouldNotBe null
val result = verifierCoseService.verifyCose(parsed, cryptoService.coseKey!!).getOrNull()
val result = verifierCoseService.verifyCose(parsed, cryptoService.coseKey).getOrThrow()
result shouldBe true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IsoMdocTest : FreeSpec({
val verifierRequest = verifier.buildDeviceRequest()
val walletResponse = wallet.buildDeviceResponse(verifierRequest)
issuer.cryptoService.coseKey shouldNotBe null
verifier.verifyResponse(walletResponse, issuer.cryptoService.coseKey!!)
verifier.verifyResponse(walletResponse, issuer.cryptoService.coseKey)
}

})
Expand All @@ -58,7 +58,7 @@ class Wallet {
val coseService = DefaultCoseService(cryptoService)

val deviceKeyInfo = DeviceKeyInfo(
deviceKey = cryptoService.coseKey ?: throw IllegalArgumentException("Missing Cose Key"),
deviceKey = cryptoService.coseKey
)

var storedMdl: MobileDrivingLicence? = null
Expand Down
Loading

0 comments on commit 450cabb

Please sign in to comment.