Skip to content

Commit

Permalink
refactor: nonce issue solved for lowsecurity #2001
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Oct 9, 2023
1 parent e516e37 commit 8d4fba3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -958,17 +958,14 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
final nonce = state.uri?.queryParameters['nonce'];
final stateValue = state.uri?.queryParameters['state'];

final bool isEBSIV3 =
await isEBSIV3ForVerifier(client: client, uri: state.uri!);

final privateKey = await fetchPrivateKey(
isEBSIV3: isEBSIV3,
isEBSIV3: false,
oidc4vc: oidc4vc,
secureStorage: getSecureStorage,
);

final (did, kid) = await getDidAndKid(
isEBSIV3: isEBSIV3,
isEBSIV3: false,
privateKey: privateKey,
didKitProvider: didKitProvider,
);
Expand All @@ -979,7 +976,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
did: did,
kid: kid,
redirectUri: redirectUri,
nonce: nonce!,
nonce: nonce,
stateValue: stateValue,
);

Expand Down
9 changes: 6 additions & 3 deletions packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ class OIDC4VC {
required String did,
required String kid,
required String redirectUri,
required String nonce,
required String? nonce,
required String privateKey,
required String? stateValue,
}) async {
Expand Down Expand Up @@ -976,7 +976,7 @@ class OIDC4VC {
'holder': tokenParameters.did,
'verifiableCredential': tokenParameters.jsonIdOrJwtList,
},
'nonce': tokenParameters.nonce,
'nonce': tokenParameters.nonce!,
};

final verifierVpJwt = generateToken(
Expand Down Expand Up @@ -1037,9 +1037,12 @@ class OIDC4VC {
'exp': DateTime.now().microsecondsSinceEpoch + 1000,
'sub': tokenParameters.did,
'iss': tokenParameters.did, //'https://self-issued.me/v2',
'nonce': tokenParameters.nonce,
};

if (tokenParameters.nonce != null) {
payload['nonce'] = tokenParameters.nonce!;
}

final verifierIdJwt = generateToken(
vpTokenPayload: payload,
tokenParameters: tokenParameters,
Expand Down
4 changes: 2 additions & 2 deletions packages/oidc4vc/lib/src/verifier_token_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VerifierTokenParameters extends TokenParameters {
required super.isIdToken,
required this.audience,
required this.credentials,
required this.nonce,
this.nonce,
});

/// [audience] is is client id of the request
Expand All @@ -23,7 +23,7 @@ class VerifierTokenParameters extends TokenParameters {
final List<String> credentials;

/// [nonce] is a number given by verifier to handle request authentication
final String nonce;
final String? nonce;

/// [jsonIdOrJwtList] is list of jwt or jsonIds from the credentials
/// wich contains other credential's metadata
Expand Down

0 comments on commit 8d4fba3

Please sign in to comment.