|
15 | 15 | */ |
16 | 16 | package eu.europa.ec.eudi.openid4vci |
17 | 17 |
|
| 18 | +import com.nimbusds.jose.JWSAlgorithm |
18 | 19 | import com.nimbusds.jose.JWSObject |
19 | 20 | import com.nimbusds.jose.jwk.Curve |
20 | 21 | import com.nimbusds.jose.jwk.gen.ECKeyGenerator |
@@ -995,4 +996,141 @@ class IssuanceSingleRequestTest { |
995 | 996 | authorizedRequest.request(requestPayload, attestationProofSpec()).getOrThrow() |
996 | 997 | } |
997 | 998 | } |
| 999 | + |
| 1000 | + @Test |
| 1001 | + fun `when wallet does not support non device bound attestation, issuance fails`() = |
| 1002 | + runTest { |
| 1003 | + val mockedHttpClient = mockedHttpClient( |
| 1004 | + credentialIssuerMetadataWellKnownMocker(), |
| 1005 | + authServerWellKnownMocker(), |
| 1006 | + parPostMocker(), |
| 1007 | + tokenPostMocker(), |
| 1008 | + ) |
| 1009 | + val (authorizedRequest, issuer) = authorizeRequestForCredentialOffer( |
| 1010 | + config = OpenId4VCIConfiguration.copy(proofs = ProofsConfig.None), |
| 1011 | + credentialOfferStr = CredentialOfferWithMDLMdoc_NO_GRANTS, |
| 1012 | + httpClient = mockedHttpClient, |
| 1013 | + ) |
| 1014 | + |
| 1015 | + val credentialConfigurationId = issuer.credentialOffer.credentialConfigurationIdentifiers[0] |
| 1016 | + with(issuer) { |
| 1017 | + val requestPayload = IssuanceRequestPayload.ConfigurationBased(credentialConfigurationId) |
| 1018 | + val exception = assertFailsWith<IllegalArgumentException> { |
| 1019 | + authorizedRequest.request(requestPayload, ProofsSpecification.NoProofs).getOrThrow() |
| 1020 | + } |
| 1021 | + assertEquals("Wallet doesn't support non-device-bound attestations", exception.message) |
| 1022 | + } |
| 1023 | + } |
| 1024 | + |
| 1025 | + @Test |
| 1026 | + fun `when wallet does not support device bound attestation, issuance fails`() = |
| 1027 | + runTest { |
| 1028 | + val mockedHttpClient = mockedHttpClient( |
| 1029 | + credentialIssuerMetadataWellKnownMocker(), |
| 1030 | + authServerWellKnownMocker(), |
| 1031 | + parPostMocker(), |
| 1032 | + tokenPostMocker(), |
| 1033 | + ) |
| 1034 | + val (authorizedRequest, issuer) = authorizeRequestForCredentialOffer( |
| 1035 | + config = OpenId4VCIConfiguration.copy(proofs = ProofsConfig.None), |
| 1036 | + credentialOfferStr = CredentialOfferWithSdJwtVc_NO_GRANTS, |
| 1037 | + httpClient = mockedHttpClient, |
| 1038 | + ) |
| 1039 | + |
| 1040 | + val credentialConfigurationId = issuer.credentialOffer.credentialConfigurationIdentifiers[0] |
| 1041 | + with(issuer) { |
| 1042 | + val requestPayload = IssuanceRequestPayload.ConfigurationBased(credentialConfigurationId) |
| 1043 | + val exception = assertFailsWith<IllegalArgumentException> { |
| 1044 | + authorizedRequest.request(requestPayload, noKeyAttestationJwtProofsSpec()).getOrThrow() |
| 1045 | + } |
| 1046 | + assertEquals("Wallet doesn't support device-bound attestations", exception.message) |
| 1047 | + } |
| 1048 | + } |
| 1049 | + |
| 1050 | + @Test |
| 1051 | + fun `when wallet does supports device bound attestation, but none of the advertised algorithms, issuance fails`() = |
| 1052 | + runTest { |
| 1053 | + val mockedHttpClient = mockedHttpClient( |
| 1054 | + credentialIssuerMetadataWellKnownMocker(), |
| 1055 | + authServerWellKnownMocker(), |
| 1056 | + parPostMocker(), |
| 1057 | + tokenPostMocker(), |
| 1058 | + ) |
| 1059 | + val (authorizedRequest, issuer) = authorizeRequestForCredentialOffer( |
| 1060 | + config = OpenId4VCIConfiguration.copy( |
| 1061 | + proofs = ProofsConfig( |
| 1062 | + supportsNonDeviceBound = false, |
| 1063 | + deviceBound = ProofsConfig.DeviceBound( |
| 1064 | + algorithms = setOf( |
| 1065 | + JWSAlgorithm.ES512, |
| 1066 | + ), |
| 1067 | + proofs = setOf(ProofsConfig.DeviceBound.Proof.JwtProofWithoutKeyAttestation), |
| 1068 | + ), |
| 1069 | + ), |
| 1070 | + ), |
| 1071 | + credentialOfferStr = CredentialOfferWithSdJwtVc_NO_GRANTS, |
| 1072 | + httpClient = mockedHttpClient, |
| 1073 | + ) |
| 1074 | + |
| 1075 | + val credentialConfigurationId = issuer.credentialOffer.credentialConfigurationIdentifiers[0] |
| 1076 | + with(issuer) { |
| 1077 | + val requestPayload = IssuanceRequestPayload.ConfigurationBased(credentialConfigurationId) |
| 1078 | + val exception = assertFailsWith<IllegalArgumentException> { |
| 1079 | + authorizedRequest.request(requestPayload, noKeyAttestationJwtProofsSpec()).getOrThrow() |
| 1080 | + } |
| 1081 | + assertEquals("Wallet doesn't support any of the advertised Proofs", exception.message) |
| 1082 | + } |
| 1083 | + } |
| 1084 | + |
| 1085 | + @Test |
| 1086 | + fun `when wallet does not support the required device bound attestation proof, issuance fails`() = |
| 1087 | + runTest { |
| 1088 | + suspend fun test( |
| 1089 | + supportedProofType: ProofsConfig.DeviceBound.Proof, |
| 1090 | + credentialOffer: String, |
| 1091 | + proofsSpecification: ProofsSpecification, |
| 1092 | + ) { |
| 1093 | + val mockedHttpClient = mockedHttpClient( |
| 1094 | + credentialIssuerMetadataWellKnownMocker(IssuerMetadataVersion.ATTESTATION_PROOF_SUPPORTED), |
| 1095 | + authServerWellKnownMocker(), |
| 1096 | + parPostMocker(), |
| 1097 | + tokenPostMocker(), |
| 1098 | + ) |
| 1099 | + val (authorizedRequest, issuer) = authorizeRequestForCredentialOffer( |
| 1100 | + config = OpenId4VCIConfiguration.copy( |
| 1101 | + proofs = ProofsConfig( |
| 1102 | + supportsNonDeviceBound = false, |
| 1103 | + deviceBound = ProofsConfig.DeviceBound( |
| 1104 | + algorithms = null, |
| 1105 | + proofs = setOf(supportedProofType), |
| 1106 | + ), |
| 1107 | + ), |
| 1108 | + ), |
| 1109 | + credentialOfferStr = credentialOffer, |
| 1110 | + httpClient = mockedHttpClient, |
| 1111 | + ) |
| 1112 | + |
| 1113 | + val credentialConfigurationId = issuer.credentialOffer.credentialConfigurationIdentifiers[0] |
| 1114 | + with(issuer) { |
| 1115 | + val requestPayload = IssuanceRequestPayload.ConfigurationBased(credentialConfigurationId) |
| 1116 | + val exception = assertFailsWith<IllegalArgumentException> { |
| 1117 | + authorizedRequest.request(requestPayload, proofsSpecification).getOrThrow() |
| 1118 | + } |
| 1119 | + assertEquals("Wallet doesn't support any of the advertised Proofs", exception.message) |
| 1120 | + } |
| 1121 | + } |
| 1122 | + |
| 1123 | + // Wallet supports Jwt Proofs without Key Attestations, but Credential Issuer requires Jwt Proofs with Key Attestations |
| 1124 | + test( |
| 1125 | + ProofsConfig.DeviceBound.Proof.JwtProofWithoutKeyAttestation, |
| 1126 | + CredentialOfferWithSdJwtVc_NO_GRANTS, |
| 1127 | + noKeyAttestationJwtProofsSpec(), |
| 1128 | + ) |
| 1129 | + |
| 1130 | + // Wallet supports Jwt Proofs with Key Attestations, but Credential Issuer requires Jwt Proofs without Key Attestations |
| 1131 | + test(ProofsConfig.DeviceBound.Proof.JwtProofWithKeyAttestation, CredentialOfferMsoMdoc_NO_GRANTS, keyAttestationJwtProofsSpec()) |
| 1132 | + |
| 1133 | + // Wallet supports Attestation Proofs, but Credential Issuer requires Jwt Proofs without Key Attestations |
| 1134 | + test(ProofsConfig.DeviceBound.Proof.AttestationProof, CredentialOfferMsoMdoc_NO_GRANTS, attestationProofSpec()) |
| 1135 | + } |
998 | 1136 | } |
0 commit comments