-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbc282f
commit 594bd72
Showing
6 changed files
with
495 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using Guard.Core.Security.WebAuthn.entities; | ||
using NeoSmart.Utils; | ||
|
||
namespace Guard.Core.Security.WebAuthn | ||
{ | ||
internal class WebAuthnSettings | ||
{ | ||
public static string Origin = "2faguard.app"; | ||
|
||
public static RelayingPartyInfo RelayingPartyInfo | ||
{ | ||
get => new() { Id = Origin, Name = "2FAGuard", }; | ||
} | ||
|
||
public static UserInfo UserInfo | ||
{ | ||
get => | ||
new() | ||
{ | ||
UserId = Encoding.UTF8.GetBytes(Auth.GetInstallationID()), | ||
Name = "2FAGuard User", | ||
DisplayName = "2FAGuard User" | ||
}; | ||
} | ||
|
||
public static List<CoseCredentialParameter> CoseCredentialParameters | ||
{ | ||
get => | ||
new() | ||
{ | ||
new CoseCredentialParameter | ||
{ | ||
Algorithm = CoseAlgorithm.ECDSA_P521_WITH_SHA512 | ||
}, | ||
new CoseCredentialParameter | ||
{ | ||
Algorithm = CoseAlgorithm.ECDSA_P384_WITH_SHA384 | ||
}, | ||
new CoseCredentialParameter { Algorithm = CoseAlgorithm.EDDSA }, | ||
new CoseCredentialParameter | ||
{ | ||
Algorithm = CoseAlgorithm.ECDSA_P256_WITH_SHA256 | ||
}, | ||
new CoseCredentialParameter | ||
{ | ||
Algorithm = CoseAlgorithm.RSASSA_PKCS1_V1_5_WITH_SHA512, | ||
}, | ||
new CoseCredentialParameter { Algorithm = CoseAlgorithm.RSA_PSS_WITH_SHA512 }, | ||
}; | ||
} | ||
|
||
public enum ClientDataType | ||
{ | ||
Create, | ||
Get | ||
} | ||
|
||
public static ClientData GetClientData(byte[] challenge, ClientDataType type) | ||
{ | ||
string typeString = type switch | ||
{ | ||
ClientDataType.Create => "webauthn.create", | ||
ClientDataType.Get => "webauthn.get", | ||
_ => throw new ArgumentOutOfRangeException(nameof(type)) | ||
}; | ||
return new ClientData() | ||
{ | ||
ClientDataJSON = JsonSerializer.SerializeToUtf8Bytes( | ||
new | ||
{ | ||
type = typeString, | ||
challenge = UrlBase64.Encode(challenge), | ||
origin = Origin | ||
} | ||
), | ||
HashAlgorithm = HashAlgorithm.Sha512 | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.