Skip to content

Commit

Permalink
dotnet format (passwordless-lib#425)
Browse files Browse the repository at this point in the history
* Added pragmas

* dotnet format

* Disabled var_elsewhere

* Adding dotnet format to pipeline

* Added command to mac/linux too

* Remove format from windows because of changes to csproj?
  • Loading branch information
abergs authored Aug 25, 2023
1 parent 2b0fe71 commit 6655af9
Show file tree
Hide file tree
Showing 83 changed files with 439 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dotnet_style_explicit_tuple_names = true:suggestion
[*.cs]
# Prefer "var" when the type is apparent on the right side of the assignment; otherwise, avoid it.
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_elsewhere = false:none

# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = false:none
Expand Down
4 changes: 2 additions & 2 deletions BlazorWasmDemo/Client/Shared/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class UserService
private const string _routeRegister = "credential";
private const string _routeAssertionOpts = "assertion-options";
private const string _routeLogin = "assertion";

private readonly JsonSerializerOptions _jsonOptions = new FidoBlazorSerializerContext().Options;
private readonly HttpClient _httpClient;
private readonly WebAuthn _webAuthn;
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task<string> RegisterAsync(string? username, string? displayName =
{
Console.WriteLine(e);
var errorMessage = e.Message;
if(options.ExcludeCredentials?.Count > 0)
if (options.ExcludeCredentials?.Count > 0)
{
errorMessage += " (You may have already registered this device)";
}
Expand Down
18 changes: 9 additions & 9 deletions BlazorWasmDemo/Server/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ public AssertionOptions MakeAssertionOptions([FromRoute] string? username, [From

var exts = new AuthenticationExtensionsClientInputs()
{
UserVerificationMethod = true,
Extensions = true,
DevicePubKey = new AuthenticationExtensionsDevicePublicKeyInputs()
UserVerificationMethod = true,
Extensions = true,
DevicePubKey = new AuthenticationExtensionsDevicePublicKeyInputs()
};

// 2. Create options (usernameless users will be prompted by their device to select a credential from their own list)
var options = _fido2.GetAssertionOptions(
existingKeys,
userVerification ?? UserVerificationRequirement.Discouraged,
exts);
// 2. Create options (usernameless users will be prompted by their device to select a credential from their own list)
var options = _fido2.GetAssertionOptions(
existingKeys,
userVerification ?? UserVerificationRequirement.Discouraged,
exts);

// 4. Temporarily store options, session/in-memory cache/redis/db
_pendingAssertions[new string(options.Challenge.Select(b => (char)b).ToArray())] = options;
Expand Down Expand Up @@ -300,7 +300,7 @@ public async Task<string> MakeAssertionAsync([FromBody] AuthenticatorAssertionRa
var token = handler.CreateEncodedJwt(
HttpContext.Request.Host.Host,
HttpContext.Request.Headers.Referer,
new ClaimsIdentity(new Claim[]{new(ClaimTypes.Actor, Encoding.UTF8.GetString(creds.UserHandle))}),
new ClaimsIdentity(new Claim[] { new(ClaimTypes.Actor, Encoding.UTF8.GetString(creds.UserHandle)) }),
DateTime.Now.Subtract(TimeSpan.FromMinutes(1)),
DateTime.Now.AddDays(1),
DateTime.Now,
Expand Down
2 changes: 1 addition & 1 deletion Demo/ConformanceTesting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Fido2Demo;

public static class ConformanceTesting
{
private static readonly object _syncRoot = new ();
private static readonly object _syncRoot = new();

private static IMetadataService _instance;

Expand Down
4 changes: 2 additions & 2 deletions Demo/Pages/_options.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -13,4 +13,4 @@ public void OnGet()
{
}
}
}
}
6 changes: 3 additions & 3 deletions Demo/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Fido2Demo;
public class TestController : Controller
{
/* CONFORMANCE TESTING ENDPOINTS */
private static readonly DevelopmentInMemoryStore _demoStorage = new ();
private static readonly DevelopmentInMemoryStore _demoStorage = new();

private readonly IFido2 _fido2;
private readonly string _origin;
Expand All @@ -31,7 +31,7 @@ public TestController(IOptions<Fido2Configuration> fido2Configuration)
ServerDomain = fido2Configuration.Value.ServerDomain,
ServerName = fido2Configuration.Value.ServerName,
Origins = fido2Configuration.Value.FullyQualifiedOrigins,
},
},
ConformanceTesting.MetadataServiceInstance(
System.IO.Path.Combine(fido2Configuration.Value.MDSCacheDirPath, @"Conformance"), _origin)
);
Expand Down Expand Up @@ -130,7 +130,7 @@ public IActionResult AssertionOptionsTest([FromBody] TEST_AssertionClientParams
uv = assertionClientParams.authenticatorSelection.UserVerification;

var exts = new AuthenticationExtensionsClientInputs
{
{
AppID = _origin,
UserVerificationMethod = true
};
Expand Down
9 changes: 5 additions & 4 deletions Src/Fido2.AspNet/DistributedCacheMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ protected virtual DateTimeOffset GetMemoryCacheAbsoluteExpiryTime(DateTimeOffset
var expiryTime = _systemClock.UtcNow.GetNextIncrement(_defaultMemoryCacheInterval);

//Ensure that memory cache expiry time never exceeds the next update time from the service
if(nextUpdateTime.HasValue && expiryTime > nextUpdateTime.Value) expiryTime = nextUpdateTime.Value;
if (nextUpdateTime.HasValue && expiryTime > nextUpdateTime.Value)
expiryTime = nextUpdateTime.Value;

return expiryTime;
}
Expand All @@ -98,7 +99,7 @@ protected virtual async Task<MetadataBLOBPayload> GetRepositoryPayloadWithErrorH
{
return await repository.GetBLOBAsync(cancellationToken);
}
catch(Exception ex)
catch (Exception ex)
{
_logger.LogError(ex, "Could not fetch metadata from {0}", repository.GetType().Name);
return null;
Expand All @@ -113,7 +114,7 @@ await _distributedCache.SetStringAsync(
new DistributedCacheEntryOptions()
{
AbsoluteExpiration = GetDistributedCacheAbsoluteExpiryTime(GetNextUpdateTimeFromPayload(payload))
},
},
cancellationToken);
}

Expand Down Expand Up @@ -165,7 +166,7 @@ protected virtual async Task<MetadataBLOBPayload> GetMemoryCachedPayload(IMetada
{
var distributedCacheBlob = await GetDistributedCachedBlob(repository, cancellationToken);

if(distributedCacheBlob != null)
if (distributedCacheBlob != null)
{
var nextUpdateTime = GetNextUpdateTimeFromPayload(distributedCacheBlob);

Expand Down
5 changes: 3 additions & 2 deletions Src/Fido2.AspNet/Fido2NetLibBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IFido2MetadataServiceBuilder AddFileSystemMetadataRepository(this

public static IFido2MetadataServiceBuilder AddConformanceMetadataRepository(
this IFido2MetadataServiceBuilder builder,
HttpClient client = null,
HttpClient client = null,
string origin = "")
{
builder.Services.AddTransient<IMetadataRepository>(provider =>
Expand All @@ -77,7 +77,8 @@ public static IFido2MetadataServiceBuilder AddFidoMetadataRepository(this IFido2
{
var httpClientBuilder = builder.Services.AddHttpClient(nameof(Fido2MetadataServiceRepository));

if(clientBuilder != null) clientBuilder(httpClientBuilder);
if (clientBuilder != null)
clientBuilder(httpClientBuilder);

builder.Services.AddTransient<IMetadataRepository, Fido2MetadataServiceRepository>();

Expand Down
5 changes: 3 additions & 2 deletions Src/Fido2.Ctap2/Commands/AuthenticatorClientPinCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public AuthenticatorClientPinCommand(
byte[]? newPinEnc = null,
byte[]? pinHashEnc = null)
{

PinProtocol = pinProtocol;
SubCommand = subCommand;
KeyAgreement = keyAgreement;
PinAuth = pinAuth;
NewPinEnc = newPinEnc;
NewPinEnc = newPinEnc;
PinHashEnc = pinHashEnc;
}

Expand Down Expand Up @@ -96,6 +96,7 @@ public AuthenticatorClientPinCommand(

public enum AuthenticatorClientPinSubCommand
{
#pragma warning disable format
GetRetries = 0x01,
GetKeyAgreement = 0x02,
SetPin = 0x03,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Fido2NetLib.Ctap2;
public sealed class AuthenticatorGetAssertionCommand : CtapCommand
{
public AuthenticatorGetAssertionCommand(
string rpId,
string rpId,
byte[] clientDataHash,
PublicKeyCredentialDescriptor[] allowList,
CborMap? extensions = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public AuthenticatorMakeCredentialCommand(
};

var pubKeyCredParams = new CborArray();

foreach (PubKeyCredParam pubKeyCredParam in PubKeyCredParams)
{
pubKeyCredParams.Add(pubKeyCredParam.ToCborObject());
Expand Down
4 changes: 2 additions & 2 deletions Src/Fido2.Ctap2/Commands/CtapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public byte[] GetPayload()
{
return new byte[] { (byte)Type };
}

var encodedObject = parameters.Encode();

var result = new byte[encodedObject.Length + 1];
Expand All @@ -25,6 +25,6 @@ public byte[] GetPayload()

encodedObject.AsSpan().CopyTo(result.AsSpan(1));

return result;
return result;
}
}
1 change: 1 addition & 0 deletions Src/Fido2.Ctap2/Commands/CtapCommandType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Fido2NetLib.Ctap2;

#pragma warning disable format
public enum CtapCommandType : byte
{
// | value | has parameters
Expand Down
36 changes: 18 additions & 18 deletions Src/Fido2.Ctap2/Devices/FidoAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async ValueTask<AuthenticatorGetInfoResponse> GetInfoAsync()

return AuthenticatorGetInfoResponse.FromCborObject(result.GetCborObject());
}


public async ValueTask<AuthenticatorClientPinResponse> ExecuteClientPinCommandAsync(AuthenticatorClientPinCommand command)
{
Expand Down Expand Up @@ -87,14 +87,14 @@ public async ValueTask SetNewPinAsync(string newPinUnicode, CredentialPublicKey
byte[] newPinEnc = CryptoHelper.AesCbcDefaultIvNoPadding(sharedSecret, CryptoHelper.ZeroPadRight(newPin, 64));

// LEFT(HMAC-SHA-256(sharedSecret, newPinEnc), 16)
var pinAuth = HMACSHA256.HashData(sharedSecret, newPinEnc).AsSpan(0, 16).ToArray();
var pinAuth = HMACSHA256.HashData(sharedSecret, newPinEnc).AsSpan(0, 16).ToArray();

var command = new AuthenticatorClientPinCommand(
pinProtocol : 0x01,
subCommand : AuthenticatorClientPinSubCommand.SetPin,
keyAgreement : platformKey,
pinAuth : pinAuth,
newPinEnc : newPinEnc
pinProtocol: 0x01,
subCommand: AuthenticatorClientPinSubCommand.SetPin,
keyAgreement: platformKey,
pinAuth: pinAuth,
newPinEnc: newPinEnc
);

_ = await ExecuteClientPinCommandAsync(command).ConfigureAwait(false);
Expand Down Expand Up @@ -122,15 +122,15 @@ public async ValueTask ChangePinAsync(string curPinUnicode, string newPinUnicode
byte[] pinAuth = HMACSHA256.HashData(sharedSecret, newPinEnc).AsSpan(0, 16).ToArray();

var command = new AuthenticatorClientPinCommand(
pinProtocol : 0x01,
subCommand : AuthenticatorClientPinSubCommand.ChangePin,
keyAgreement : platformKey,
pinAuth : pinAuth,
newPinEnc : newPinEnc,
pinHashEnc : pinHashEnc
pinProtocol: 0x01,
subCommand: AuthenticatorClientPinSubCommand.ChangePin,
keyAgreement: platformKey,
pinAuth: pinAuth,
newPinEnc: newPinEnc,
pinHashEnc: pinHashEnc
);

_= await ExecuteClientPinCommandAsync(command).ConfigureAwait(false);
_ = await ExecuteClientPinCommandAsync(command).ConfigureAwait(false);
}

public async ValueTask<byte[]> GetPinTokenAsync(string pin, CredentialPublicKey platformKey, byte[] sharedSecret)
Expand All @@ -143,10 +143,10 @@ public async ValueTask<byte[]> GetPinTokenAsync(string pin, CredentialPublicKey
byte[] pinHashEnc = CryptoHelper.AesCbcDefaultIvNoPadding(sharedSecret, SHA256.HashData(curPin).AsSpan(0, 16));

var command = new AuthenticatorClientPinCommand(
pinProtocol : 0x01,
subCommand : AuthenticatorClientPinSubCommand.GetPinToken,
keyAgreement : platformKey,
pinHashEnc : pinHashEnc
pinProtocol: 0x01,
subCommand: AuthenticatorClientPinSubCommand.GetPinToken,
keyAgreement: platformKey,
pinHashEnc: pinHashEnc
);

var result = await ExecuteClientPinCommandAsync(command).ConfigureAwait(false);
Expand Down
2 changes: 2 additions & 0 deletions Src/Fido2.Ctap2/Extensions/PubKeyCredParamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class AuthenticatorTransportExtensions
{
public static string Canonicalize(this AuthenticatorTransport value)
{
#pragma warning disable format
return value switch
{
AuthenticatorTransport.Usb => "usb",
Expand All @@ -27,5 +28,6 @@ public static string Canonicalize(this AuthenticatorTransport value)
AuthenticatorTransport.Internal => "internal",
_ => value.ToString()
};
#pragma warning restore format
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static CborMap ToCborObject(this PublicKeyCredentialRpEntity rp)
if (rp.Icon is string icon)
{
result.Add("icon", icon);
}
}

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Fido2.Ctap2/Helpers/CryptoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static byte[] AesCbcDefaultIvNoPadding(byte[] key, ReadOnlySpan<byte> d
// AES256-CBC(sharedSecret, IV = 0, data).
return aes.EncryptCbc(data, iv: DefaultIV, PaddingMode.None);
}

public static byte[] GenerateSharedSecret(CredentialPublicKey authenticatorKeyAgreementKey, out CredentialPublicKey platformKeyAgreementKey)
{
using var authenticatorKey = authenticatorKeyAgreementKey.CreateECDsa(); // public key
Expand Down
2 changes: 1 addition & 1 deletion Src/Fido2.Ctap2/Responses/AuthenticatorGetInfoResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class AuthenticatorGetInfoResponse
/// </summary>
[CborMember(0x03)]
public byte[] Aaguid { get; set; }

/// <summary>
/// List of supported options.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public static AuthenticatorMakeCredentialResponse FromCborObject(CborObject cbor
{
switch ((int)key)
{
#pragma warning disable format
case 0x01: result.Fmt = (string)value; break;
case 0x02: result.AuthData = (byte[])value; break;
case 0x03: result.AttStmt = (CborMap)value; break;
case 0x04: result.EpAtt = (bool)value; break;
case 0x05: result.LargeBlobKey = (byte[])value; break;
#pragma warning restore format
}
}

Expand Down
1 change: 1 addition & 0 deletions Src/Fido2.Ctap2/Responses/CtapStatusCode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Fido2NetLib.Ctap2;

#pragma warning disable format
public enum CtapStatusCode
{
OK = 0x00, // Indicates successful response
Expand Down
4 changes: 2 additions & 2 deletions Src/Fido2.Ctap2/Responses/NegotiateSharedSecretResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Fido2NetLib.Ctap2;
public sealed class NegotiateSharedSecretResult
{
public NegotiateSharedSecretResult(
CredentialPublicKey authenticatorKey,
CredentialPublicKey platformKey,
CredentialPublicKey authenticatorKey,
CredentialPublicKey platformKey,
byte[] sharedShared)
{
ArgumentNullException.ThrowIfNull(authenticatorKey);
Expand Down
Loading

0 comments on commit 6655af9

Please sign in to comment.