Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ class LoTEFilterService {
* Extracts certificates matching the requested service type identifier where
* the certificate's subject organization aligns with the trusted provider's registered names
*/
fun extractTrustedCertificates(lote: ListOfTrustedEntities, criteria: LoTEFilterCriteria): List<TrustedCertificate> {
fun extractTrustedCertificates(sourceUrl: String, lote: ListOfTrustedEntities, criteria: LoTEFilterCriteria): List<TrustedCertificate> {
val entities = lote.trustedEntitiesList ?: return emptyList()

return entities.flatMap { entity ->
val providerName = entity.trustedEntityInformation.teName

entity.trustedEntityServices
.filter { it.serviceInformation.serviceTypeIdentifier?.string == criteria.expectedServiceType }
.filter { service ->
val serviceTypeId = service.serviceInformation.serviceTypeIdentifier?.string

if (serviceTypeId != null) {
// Field is present. Check if it matches type
serviceTypeId.contains(criteria.expectedServiceType.type, ignoreCase = true)
} else {
// Field is absent. The services inherit the list's default type
sourceUrl.contains(criteria.expectedServiceType.type, ignoreCase = true)
}
}
.flatMap { service -> service.serviceInformation.serviceDigitalIdentity.x509Certificates }
.filter { cert -> cert?.hasMatchingOrganization(providerName) == true }
.map { cert -> TrustedCertificate(cert, providerName, criteria.expectedServiceType) }
Expand Down Expand Up @@ -58,9 +68,35 @@ class LoTEFilterService {
data class TrustedCertificate(
val certificate: @Serializable(with = EtsiX509CertificateSerializer::class) X509Certificate?,
val providerName: TEName,
val serviceType: String
val serviceType: LoTEServiceType
)

data class LoTEFilterCriteria(
val expectedServiceType: String,
)
val expectedServiceType: LoTEServiceType,
)

enum class LoTEServiceType(val type: String) {
PID("pid"),
MDL("mdl"),
WRPAC("wrpac"),
EAA("eaa"),
WALLET("wallet");

companion object {
/**
* Resolves a raw scheme type string into a safe Enum
*/
fun fromSchemeType(rawSchemeType: String?): LoTEServiceType? {
if (rawSchemeType.isNullOrBlank()) return null

return when {
Comment thread
nodh marked this conversation as resolved.
Outdated
rawSchemeType.contains("pid", ignoreCase = true) -> PID
rawSchemeType.contains("mdl", ignoreCase = true) -> MDL
rawSchemeType.contains("wrpac", ignoreCase = true) -> WRPAC
rawSchemeType.contains("eaa", ignoreCase = true) -> EAA
rawSchemeType.contains("wallet", ignoreCase = true) -> WALLET
else -> null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7029,21 +7029,21 @@ val LoTEFilterTest by matrixSuite {

data class TestData(
val json: String,
val expectedServiceType: String
val fetchUrl: String
)

testSuite("filter lote by type identifier") {
mapOf(
"pidProviders" to TestData(pidProvidersFixed, "http://uri.etsi.org/19602/SvcType/PID/Issuance"),
"walletProviders" to TestData(walletProvidersFixed, "http://uri.etsi.org/19602/SvcType/WalletSolution/Issuance"),
"wrpacProviders" to TestData(wrpacProvidersFixed, "http://uri.etsi.org/19602/SvcType/WRPAC/Issuance"),
"mdlProviders" to TestData(mdlProvidersFixed, "http://uri.etsi.org/19602/SvcType/mDL/Issuance"),
"pidProviders" to TestData(pidProvidersFixed, "https://acceptance.trust.tech.ec.europa.eu/lists/eudiw/pid-providers.json"),
Comment thread
StjepanovicSrdjan marked this conversation as resolved.
Outdated
"walletProviders" to TestData(walletProvidersFixed, "https://acceptance.trust.tech.ec.europa.eu/lists/eudiw/wallet-providers.json"),
"wrpacProviders" to TestData(wrpacProvidersFixed, "https://acceptance.trust.tech.ec.europa.eu/lists/eudiw/wrpac-providers.json"),
"mdlProviders" to TestData(mdlProvidersFixed, "https://acceptance.trust.tech.ec.europa.eu/lists/eudiw/mdl-providers.json"),
).asData() test{ (_, data) ->
val lote = Json.decodeFromString<ListOfTrustedEntities>(data.json)

val criteria = LoTEFilterCriteria(expectedServiceType = data.expectedServiceType)
val criteria = LoTEFilterCriteria(expectedServiceType = LoTEServiceType.fromSchemeType(data.fetchUrl)!!)

val trustedCerts = LoTEFilterService().extractTrustedCertificates(lote, criteria)
val trustedCerts = LoTEFilterService().extractTrustedCertificates(data.fetchUrl, lote, criteria)

trustedCerts.size shouldNotBe(0)
}
Expand Down