Skip to content

Commit

Permalink
feat: Added OIDC4VP logic for client_id_scheme = verifier_attestation #…
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Apr 4, 2024
1 parent f7363dc commit ff48091
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
43 changes: 40 additions & 3 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1802,10 +1802,8 @@ Future<Map<String, dynamic>?> checkX509({
required String encodedData,
required String clientId,
required JWTDecode jwtDecode,
required Map<String, dynamic> header,
}) async {
final Map<String, dynamic> header =
decodeHeader(jwtDecode: jwtDecode, token: encodedData);

final x5c = header['x5c'];

if (x5c != null) {
Expand Down Expand Up @@ -1881,3 +1879,42 @@ Future<Map<String, dynamic>?> checkX509({
}
return null;
}

Future<Map<String, dynamic>?> checkVerifierAttestation({
required String clientId,
required JWTDecode jwtDecode,
required Map<String, dynamic> header,
}) async {
final jwt = header['jwt'];

if (jwt == null) {
throw ResponseMessage(
data: {
'error': 'invalid_format',
'error_description': 'verifier_attestation scheme error',
},
);
}

final Map<String, dynamic> verifierAttestationPayload =
decodePayload(jwtDecode: jwtDecode, token: jwt.toString());

final sub = verifierAttestationPayload['sub'];
final cnf = verifierAttestationPayload['cnf'];

if (sub == null ||
sub != clientId ||
cnf == null ||
cnf is! Map<String, dynamic> ||
!cnf.containsKey('jwk') ||
cnf['jwk'] is! Map<String, dynamic>) {
throw ResponseMessage(
data: {
'error': 'invalid_format',
'error_description': 'verifier_attestation scheme error',
},
);
}

return cnf['jwk'] as Map<String, dynamic>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1089,11 +1089,20 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
final clientIdScheme = payload['client_id_scheme'];

if (clientIdScheme != null) {
final Map<String, dynamic> header =
decodeHeader(jwtDecode: jwtDecode, token: encodedData);
if (clientIdScheme == 'x509_san_dns') {
publicKeyJwk = await checkX509(
clientId: clientId,
encodedData: encodedData,
jwtDecode: jwtDecode,
header: header,
);
} else if (clientIdScheme == 'verifier_attestation') {
publicKeyJwk = await checkVerifierAttestation(
clientId: clientId,
jwtDecode: jwtDecode,
header: header,
);
}
}
Expand Down

0 comments on commit ff48091

Please sign in to comment.