Skip to content

Commit

Permalink
Add MalformedAuthenticatorResponse error code
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon authored and abergs committed Sep 28, 2022
1 parent e206d20 commit 31b7efc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Src/Fido2.Models/Exceptions/Fido2ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public enum Fido2ErrorCode
MalformedExtensionsDetected,
UnexpectedExtensionsDetected,
InvalidAssertionResponse,
InvalidAuthenticatorResponse,
InvalidAttestationResponse,
InvalidAuthenticatorData,
InvalidAttestedCredentialData,
InvalidAuthenticatorResponse,
MalformedAuthenticatorResponse,
MissingAuthenticatorData,
InvalidAuthenticatorData,
MissingAuthenticatorResponseChallenge,
InvalidAuthenticatorResponseChallenge,
NonUniqueCredentialId,
Expand Down
12 changes: 8 additions & 4 deletions Src/Fido2/AuthenticatorResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#pragma warning disable IDE0060 // Remove unused parameter

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
Expand All @@ -17,7 +19,7 @@ public class AuthenticatorResponse
protected AuthenticatorResponse(ReadOnlySpan<byte> utf8EncodedJson)
{
if (utf8EncodedJson.Length is 0)
throw new Fido2VerificationException("utf8EncodedJson may not be empty");
throw new Fido2VerificationException(Fido2ErrorCode.InvalidAuthenticatorResponse, "utf8EncodedJson may not be empty");

// 1. Let JSONtext be the result of running UTF-8 decode on the value of response.clientDataJSON

Expand All @@ -31,11 +33,11 @@ protected AuthenticatorResponse(ReadOnlySpan<byte> utf8EncodedJson)
}
catch (Exception e) when (e is JsonException)
{
throw new Fido2VerificationException("Malformed clientDataJson");
throw new Fido2VerificationException(Fido2ErrorCode.MalformedAuthenticatorResponse, "Malformed clientDataJson");
}

if (response is null)
throw new Fido2VerificationException("Deserialized authenticator response cannot be null");
throw new Fido2VerificationException(Fido2ErrorCode.InvalidAuthenticatorResponse, "Deserialized authenticator response cannot be null");

Type = response.Type;
Challenge = response.Challenge;
Expand Down Expand Up @@ -83,6 +85,7 @@ protected void BaseVerify(HashSet<string> fullyQualifiedExpectedOrigins, ReadOnl

}

/*
private static string FullyQualifiedOrigin(string origin)
{
var uri = new Uri(origin);
Expand All @@ -92,5 +95,6 @@ private static string FullyQualifiedOrigin(string origin)
return origin;
}
*/
}
}

0 comments on commit 31b7efc

Please sign in to comment.