Skip to content

Commit df24e79

Browse files
committed
Merge branch 'main' into develop
2 parents f65ae7d + eb87aed commit df24e79

23 files changed

+354
-181
lines changed

.github/workflows/build-nativeshims.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ jobs:
3939
echo 'Running build script: Windows'
4040
cd Yubico.NativeShims
4141
if ("${{ github.event.inputs.version }}" -ne "") {
42-
$baseVersion = "${{ github.event.inputs.version }}".Split('-')[0]
42+
$versionInput = "${{ github.event.inputs.version }}"
43+
if ($versionInput -like "*-*") {
44+
$baseVersion = $versionInput.Split('-')[0]
45+
} else {
46+
Write-Warning "Version input does not contain a hyphen ('-'). Using the full version string as base version."
47+
$baseVersion = $versionInput
48+
}
4349
& ./build-windows.ps1 -Version $baseVersion
4450
} else {
4551
& ./build-windows.ps1

Yubico.Core/src/Yubico/PlatformInterop/Libraries.Net47.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#if NET47
15+
#if NETFRAMEWORK
1616

1717
using System;
1818
using System.IO;

Yubico.Core/src/Yubico/PlatformInterop/Libraries.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// As long as we have the Libraries.Net47.cs class which holds the opposite preprocessor directive check,
1616
// this check is required - as having both at the same time is not possible.
17-
#if !NET47
17+
#if !NETFRAMEWORK
1818

1919
namespace Yubico.PlatformInterop
2020
{

Yubico.YubiKey/src/Yubico/YubiKey/ApplicationSession.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ public abstract class ApplicationSession : IDisposable
3030
{
3131
/// <summary>
3232
/// The object that represents the connection to the YubiKey. Most
33-
/// applications will ignore this, but it can be used to call Commands
33+
/// applications will ignore this, but it can be used to issue commands
3434
/// directly.
3535
/// </summary>
36+
/// <remarks> This property gives you direct access to the existing connection to the YubiKey using the
37+
/// <see cref="IYubiKeyConnection"/> interface. To send your own commands, call the
38+
/// <see cref="IYubiKeyConnection.SendCommand{TResponse}"/>
39+
/// </remarks>
3640
public IYubiKeyConnection Connection { get; protected set; }
3741

3842
/// <summary>

Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Commands/CredentialManagementCommand.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,11 @@ protected CredentialManagementCommand()
159159
/// <param name="authProtocol">
160160
/// The Auth Protocol used to build the Auth Token.
161161
/// </param>
162-
/// <param name="decryptAuthToken">If true, the <c>pinUvAuthToken</c> is assumed encrypted,
163-
/// and thus the SDK will attempt to decrypt it before passing it to the YubiKey.
164-
/// If false, no decryption will be attempted.</param>
165162
public CredentialManagementCommand(
166163
int subCommand,
167164
byte[]? subCommandParams,
168165
ReadOnlyMemory<byte> pinUvAuthToken,
169-
PinUvAuthProtocolBase authProtocol,
170-
bool decryptAuthToken = true)
166+
PinUvAuthProtocolBase authProtocol)
171167
{
172168
if (authProtocol is null)
173169
{
@@ -189,9 +185,7 @@ public CredentialManagementCommand(
189185

190186
// The pinUvAuthToken is an encrypted value, so there's no need to
191187
// overwrite the array.
192-
byte[] authParam = decryptAuthToken
193-
? authProtocol.AuthenticateUsingPinToken(pinUvAuthToken.ToArray(), message)
194-
: authProtocol.Authenticate(pinUvAuthToken.ToArray(), message);
188+
byte[] authParam = authProtocol.AuthenticateUsingPinToken(pinUvAuthToken, message);
195189

196190
PinUvAuthParam = authParam;
197191
PinUvAuthProtocol = authProtocol.Protocol;
@@ -215,6 +209,35 @@ public CredentialManagementCommand(
215209
PinUvAuthParam = null;
216210
}
217211

212+
/// <summary>
213+
/// Constructs a new instance of <see cref="CredentialManagementCommand"/> with a pre-computed PIN/UV auth param.
214+
/// </summary>
215+
/// <param name="subCommand">
216+
/// The byte representing the subcommand to execute.
217+
/// </param>
218+
/// <param name="subCommandParams">
219+
/// The parameters needed in order to execute the subcommand. Not all
220+
/// subcommands have parameters, so this can be null.
221+
/// </param>
222+
/// <param name="pinUvAuthParam">
223+
/// The pre-computed PIN/UV auth param for this command.
224+
/// </param>
225+
/// <param name="protocol">
226+
/// The PIN/UV protocol version used to compute the auth param.
227+
/// </param>
228+
public CredentialManagementCommand(
229+
int subCommand,
230+
byte[]? subCommandParams,
231+
ReadOnlyMemory<byte> pinUvAuthParam,
232+
PinUvAuthProtocol protocol)
233+
{
234+
SubCommand = subCommand;
235+
_encodedParams = subCommandParams;
236+
_protocol = (int)protocol;
237+
PinUvAuthParam = pinUvAuthParam;
238+
PinUvAuthProtocol = protocol;
239+
}
240+
218241
/// <summary>
219242
/// Creates a well-formed CommandApdu to send to the YubiKey.
220243
/// </summary>

Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Commands/EnumerateCredentialsBeginCommand.cs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,58 @@ private EnumerateCredentialsBeginCommand()
6969
/// <param name="authProtocol">
7070
/// The Auth Protocol used to build the Auth Token.
7171
/// </param>
72-
/// <param name="decryptAuthToken">If true, the <c>pinUvAuthToken</c> is assumed encrypted,
73-
/// and thus the SDK will attempt to decrypt it before passing it to the YubiKey.
74-
/// If false, no decryption will be attempted.</param>
7572
public EnumerateCredentialsBeginCommand(
7673
RelyingParty relyingParty,
7774
ReadOnlyMemory<byte> pinUvAuthToken,
78-
PinUvAuthProtocolBase authProtocol,
79-
bool decryptAuthToken = true)
75+
PinUvAuthProtocolBase authProtocol)
8076
: base(new CredentialManagementCommand(
81-
SubCmdEnumerateCredsBegin, EncodeParams(relyingParty), pinUvAuthToken, authProtocol, decryptAuthToken))
77+
SubCmdEnumerateCredsBegin, EncodeParams(relyingParty), pinUvAuthToken, authProtocol))
78+
{
79+
}
80+
81+
/// <summary>
82+
/// Constructs a new instance of <see cref="EnumerateCredentialsBeginCommand"/> with a pre-computed PIN/UV auth param.
83+
/// </summary>
84+
/// <param name="relyingParty">
85+
/// The relying party for which the credential enumeration is requested.
86+
/// </param>
87+
/// <param name="pinUvAuthParam">
88+
/// The pre-computed PIN/UV auth param for this command.
89+
/// </param>
90+
/// <param name="protocol">
91+
/// The PIN/UV protocol version used to compute the auth param.
92+
/// </param>
93+
public EnumerateCredentialsBeginCommand(
94+
RelyingParty relyingParty,
95+
ReadOnlyMemory<byte> pinUvAuthParam,
96+
PinUvAuthProtocol protocol)
97+
: base(new CredentialManagementCommand(
98+
SubCmdEnumerateCredsBegin, EncodeParams(relyingParty), pinUvAuthParam, protocol))
8299
{
83100
}
84101

85102
/// <inheritdoc />
86103
public EnumerateCredentialsBeginResponse CreateResponseForApdu(ResponseApdu responseApdu) =>
87104
new EnumerateCredentialsBeginResponse(responseApdu);
88105

106+
/// <summary>
107+
/// Creates the authentication message for this command, consisting of the subcommand byte plus encoded parameters.
108+
/// </summary>
109+
/// <param name="relyingParty">
110+
/// The relying party for which the credential enumeration is requested.
111+
/// </param>
112+
/// <returns>
113+
/// The message to be used for PIN/UV authentication.
114+
/// </returns>
115+
public static byte[] GetAuthenticationMessage(RelyingParty relyingParty)
116+
{
117+
byte[] encodedParams = EncodeParams(relyingParty);
118+
byte[] message = new byte[1 + encodedParams.Length];
119+
message[0] = SubCmdEnumerateCredsBegin;
120+
encodedParams.CopyTo(message, 1);
121+
return message;
122+
}
123+
89124
// This method encodes the parameters. For
90125
// EnumerateCredentialsBeginCommand, the parameters consist of only the
91126
// rpIdHash, and it is encoded as

Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Commands/EnumerateCredentialsGetNextCommand.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System;
1516
using Yubico.Core.Iso7816;
17+
using Yubico.YubiKey.Fido2.PinProtocols;
1618

1719
namespace Yubico.YubiKey.Fido2.Commands
1820
{
@@ -56,6 +58,22 @@ public EnumerateCredentialsGetNextCommand()
5658
{
5759
}
5860

61+
/// <summary>
62+
/// Constructs a new instance of <see cref="EnumerateCredentialsGetNextCommand"/> with a pre-computed PIN/UV auth param.
63+
/// </summary>
64+
/// <param name="pinUvAuthParam">
65+
/// The pre-computed PIN/UV auth param for this command.
66+
/// </param>
67+
/// <param name="protocol">
68+
/// The PIN/UV protocol version used to compute the auth param.
69+
/// </param>
70+
public EnumerateCredentialsGetNextCommand(
71+
ReadOnlyMemory<byte> pinUvAuthParam,
72+
PinUvAuthProtocol protocol)
73+
: base(new CredentialManagementCommand(SubCmdGetEnumerateCredsGetNext, null, pinUvAuthParam, protocol))
74+
{
75+
}
76+
5977
/// <inheritdoc />
6078
public EnumerateCredentialsGetNextResponse CreateResponseForApdu(ResponseApdu responseApdu) =>
6179
new EnumerateCredentialsGetNextResponse(responseApdu);

Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Commands/EnumerateRpsBeginCommand.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,42 @@ private EnumerateRpsBeginCommand()
6060
/// <param name="authProtocol">
6161
/// The Auth Protocol used to build the Auth Token.
6262
/// </param>
63-
/// <param name="decryptAuthToken">If true, the <c>pinUvAuthToken</c> is assumed encrypted,
64-
/// and thus the SDK will attempt to decrypt it before passing it to the YubiKey.
65-
/// If false, no decryption will be attempted.</param>
6663
public EnumerateRpsBeginCommand(
6764
ReadOnlyMemory<byte> pinUvAuthToken,
68-
PinUvAuthProtocolBase authProtocol,
69-
bool decryptAuthToken = true)
70-
: base(new CredentialManagementCommand(SubCmdEnumerateRpsBegin, null, pinUvAuthToken, authProtocol, decryptAuthToken))
65+
PinUvAuthProtocolBase authProtocol)
66+
: base(new CredentialManagementCommand(SubCmdEnumerateRpsBegin, null, pinUvAuthToken, authProtocol))
67+
{
68+
}
69+
70+
/// <summary>
71+
/// Constructs a new instance of <see cref="EnumerateRpsBeginCommand"/> with a pre-computed PIN/UV auth param.
72+
/// </summary>
73+
/// <param name="pinUvAuthParam">
74+
/// The pre-computed PIN/UV auth param for this command.
75+
/// </param>
76+
/// <param name="protocol">
77+
/// The PIN/UV protocol version used to compute the auth param.
78+
/// </param>
79+
public EnumerateRpsBeginCommand(
80+
ReadOnlyMemory<byte> pinUvAuthParam,
81+
PinUvAuthProtocol protocol)
82+
: base(new CredentialManagementCommand(SubCmdEnumerateRpsBegin, null, pinUvAuthParam, protocol))
7183
{
7284
}
7385

7486
/// <inheritdoc />
7587
public EnumerateRpsBeginResponse CreateResponseForApdu(ResponseApdu responseApdu) =>
7688
new EnumerateRpsBeginResponse(responseApdu);
89+
90+
/// <summary>
91+
/// Creates the authentication message for this command, consisting of only the subcommand byte.
92+
/// </summary>
93+
/// <returns>
94+
/// The message to be used for PIN/UV authentication.
95+
/// </returns>
96+
public static byte[] GetAuthenticationMessage()
97+
{
98+
return new byte[] { SubCmdEnumerateRpsBegin };
99+
}
77100
}
78101
}

Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Commands/EnumerateRpsBeginResponse.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public EnumerateRpsBeginResponse(ResponseApdu responseApdu)
7272
{
7373
var credentialManagementData = _response.GetData();
7474

75-
if (!(credentialManagementData.RelyingParty is null)
76-
&& !(credentialManagementData.RelyingPartyIdHash is null)
77-
&& !(credentialManagementData.TotalRelyingPartyCount is null))
75+
if (credentialManagementData.RelyingParty is not null
76+
&& credentialManagementData.RelyingPartyIdHash is not null
77+
&& credentialManagementData.TotalRelyingPartyCount is not null)
7878
{
7979
if (credentialManagementData.RelyingParty.IsMatchingRelyingPartyId(credentialManagementData.RelyingPartyIdHash.Value))
8080
{

Yubico.YubiKey/src/Yubico/YubiKey/Fido2/Commands/GetCredentialMetadataCommand.cs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,48 @@ private GetCredentialMetadataCommand()
5151
/// <param name="authProtocol">
5252
/// The Auth Protocol used to build the Auth Token.
5353
/// </param>
54-
/// <param name="decryptAuthToken">If true, the <c>pinUvAuthToken</c> is assumed encrypted,
55-
/// and thus the SDK will attempt to decrypt it before passing it to the YubiKey.
56-
/// If false, no decryption will be attempted.</param>
5754
public GetCredentialMetadataCommand(
5855
ReadOnlyMemory<byte> pinUvAuthToken,
59-
PinUvAuthProtocolBase authProtocol,
60-
bool decryptAuthToken = true)
56+
PinUvAuthProtocolBase authProtocol)
6157
: base(
6258
new CredentialManagementCommand(
6359
SubCmdGetMetadata,
6460
null,
6561
pinUvAuthToken,
66-
authProtocol,
67-
decryptAuthToken))
62+
authProtocol))
63+
{
64+
65+
}
66+
67+
/// <summary>
68+
/// Constructs a new instance of <see cref="GetCredentialMetadataCommand"/> with a pre-computed PIN/UV auth param.
69+
/// </summary>
70+
/// <param name="pinUvAuthParam">
71+
/// The pre-computed PIN/UV auth param for this command.
72+
/// </param>
73+
/// <param name="protocol">
74+
/// The PIN/UV protocol version used to compute the auth param.
75+
/// </param>
76+
public GetCredentialMetadataCommand(
77+
ReadOnlyMemory<byte> pinUvAuthParam,
78+
PinUvAuthProtocol protocol)
79+
: base(new CredentialManagementCommand(SubCmdGetMetadata, null, pinUvAuthParam, protocol))
6880
{
69-
7081
}
7182

7283
/// <inheritdoc />
7384
public GetCredentialMetadataResponse CreateResponseForApdu(ResponseApdu responseApdu) =>
7485
new GetCredentialMetadataResponse(responseApdu);
86+
87+
/// <summary>
88+
/// Creates the authentication message for this command, consisting of only the subcommand byte.
89+
/// </summary>
90+
/// <returns>
91+
/// The message to be used for PIN/UV authentication.
92+
/// </returns>
93+
public static byte[] GetAuthenticationMessage()
94+
{
95+
return new byte[] { SubCmdGetMetadata };
96+
}
7597
}
7698
}

0 commit comments

Comments
 (0)