-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathAuthenticatorClientPinCommand.cs
94 lines (79 loc) · 2.51 KB
/
AuthenticatorClientPinCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using Fido2NetLib.Cbor;
using Fido2NetLib.Objects;
namespace Fido2NetLib.Ctap2;
public sealed class AuthenticatorClientPinCommand(
uint pinProtocol,
AuthenticatorClientPinSubCommand subCommand,
CredentialPublicKey? keyAgreement = null,
byte[]? pinAuth = null,
byte[]? newPinEnc = null,
byte[]? pinHashEnc = null) : CtapCommand
{
/// <summary>
/// Required PIN protocol version chosen by the client.
/// </summary>
[CborMember(0x01)]
public uint PinProtocol { get; } = pinProtocol;
/// <summary>
/// The authenticator Client PIN sub command currently being requested.
/// </summary>
[CborMember(0x02)]
public AuthenticatorClientPinSubCommand SubCommand { get; } = subCommand;
/// <summary>
/// Public key of platformKeyAgreementKey.
/// The COSE_Key-encoded public key MUST contain the optional "alg" parameter and MUST NOT contain any other optional parameters.
/// The "alg" parameter MUST contain a COSEAlgorithmIdentifier value.
/// </summary>
[CborMember(0x03)]
public CredentialPublicKey? KeyAgreement { get; } = keyAgreement;
/// <summary>
/// First 16 bytes of HMAC-SHA-256 of encrypted contents using sharedSecret.
/// </summary>
[CborMember(0x04)]
public byte[]? PinAuth { get; } = pinAuth;
/// <summary>
/// Encrypted new PIN using sharedSecret.
/// </summary>
[CborMember(0x05)]
public byte[]? NewPinEnc { get; } = newPinEnc;
/// <summary>
/// Encrypted first 16 bytes of SHA-256 of PIN using sharedSecret.
/// </summary>
[CborMember(0x06)]
public byte[]? PinHashEnc { get; } = pinHashEnc;
public override CtapCommandType Type => CtapCommandType.AuthenticatorClientPin;
protected override CborObject? GetParameters()
{
var cbor = new CborMap
{
{ 0x01, PinProtocol },
{ 0x02, (int)SubCommand }
};
if (KeyAgreement != null)
{
cbor.Add(0x03, KeyAgreement.GetCborObject());
}
if (PinAuth != null)
{
cbor.Add(0x04, PinAuth);
}
if (NewPinEnc != null)
{
cbor.Add(0x05, NewPinEnc);
}
if (PinHashEnc != null)
{
cbor.Add(0x06, PinHashEnc);
}
return cbor;
}
}
public enum AuthenticatorClientPinSubCommand
{
#pragma warning disable format
GetRetries = 0x01,
GetKeyAgreement = 0x02,
SetPin = 0x03,
ChangePin = 0x04,
GetPinToken = 0x05,
}