-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds 'TEST of KLASS3-SK 2016' certificate and organization certs support #7
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,32 +29,54 @@ | |
using System.Threading.Tasks; | ||
using Security.Challenge; | ||
using WebEid.AspNetCore.Example.Dto; | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
[Route("[controller]")] | ||
[ApiController] | ||
public class AuthController : BaseController | ||
{ | ||
private readonly IAuthTokenValidator authTokenValidator; | ||
private readonly IChallengeNonceStore challengeNonceStore; | ||
private readonly ILogger logger; | ||
|
||
public AuthController(IAuthTokenValidator authTokenValidator, IChallengeNonceStore challengeNonceStore) | ||
public AuthController(IAuthTokenValidator authTokenValidator, IChallengeNonceStore challengeNonceStore, ILogger logger) | ||
{ | ||
this.authTokenValidator = authTokenValidator; | ||
this.challengeNonceStore = challengeNonceStore; | ||
this.logger = logger; | ||
} | ||
|
||
[HttpPost] | ||
[Route("login")] | ||
public async Task Login([FromBody] AuthenticateRequestDto authToken) | ||
{ | ||
var certificate = await this.authTokenValidator.Validate(authToken.AuthToken, this.challengeNonceStore.GetAndRemove().Base64EncodedNonce); | ||
var claims = new List<Claim> | ||
var certificate = await authTokenValidator.Validate(authToken.AuthToken, challengeNonceStore.GetAndRemove().Base64EncodedNonce); | ||
|
||
Dictionary<string, Func<string>> claimDataGetters = new() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Dictionary is unordered and Claims in ClaimsIdentity are ordered, we should try to maintain that order. This would also make the code more readable and remove the necessity of creating new temporary dictionaries and loops. |
||
{ | ||
new Claim(ClaimTypes.GivenName, certificate.GetSubjectGivenName()), | ||
new Claim(ClaimTypes.Surname, certificate.GetSubjectSurname()), | ||
new Claim(ClaimTypes.NameIdentifier, certificate.GetSubjectIdCode()) | ||
{ ClaimTypes.GivenName, certificate.GetSubjectGivenName }, | ||
{ ClaimTypes.Surname, certificate.GetSubjectSurname }, | ||
{ ClaimTypes.NameIdentifier, certificate.GetSubjectIdCode }, | ||
{ ClaimTypes.Name, certificate.GetSubjectCn } | ||
}; | ||
|
||
List<Claim> claims = new(); | ||
foreach (var claimGetter in claimDataGetters) | ||
{ | ||
try | ||
{ | ||
// GivenName and Surname are not presented in case of organization certificates. | ||
// Attempt to get these throw ArgumentOutOfRangeException type exception. | ||
string claimData = claimGetter.Value.Invoke(); | ||
claims.Add(new Claim(claimGetter.Key, claimData)); | ||
} | ||
catch (ArgumentOutOfRangeException) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When creating a new Claim, the exception thrown is ArgumentNullException when either the type or value is null. |
||
{ | ||
logger.LogWarning("Claim {0} not presented", claimGetter.Key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using an organization certificate, we would not want to log missing fields which we were not expecting in the first place. |
||
} | ||
} | ||
|
||
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); | ||
|
||
var authProperties = new AuthenticationProperties | ||
|
@@ -77,8 +99,7 @@ await HttpContext.SignInAsync( | |
public async Task Logout() | ||
{ | ||
RemoveUserContainerFile(); | ||
await HttpContext.SignOutAsync( | ||
CookieAuthenticationDefaults.AuthenticationScheme); | ||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,4 @@ public ChallengeNonce GetAndRemoveImpl() | |
return null; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,14 @@ | |
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should set x64 target. For best compatibility There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the best compatibility it should be AnyCPU while in that case the architecture stays unspecified in IL and it is able to run on any target platform. x64 limits it with 64-bit platforms. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only provide x64 binaries for libdigidocpp. I cannot sign anything under arm64 windows and ubuntu |
||
<NoWarn>1701;1702;VSSpell001;VSSpell002</NoWarn> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<NoWarn>1701;1702;VSSpell001;VSSpell002</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.4" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.4" NoWarn="NU1605" /> | ||
|
@@ -29,6 +37,12 @@ | |
<None Update="Certificates\Prod\ESTEID2018.cer"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Certificates\Prod\KLASS3-SK_2016_EECCRCA_SHA384.cer"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Certificates\Dev\TEST_of_KLASS3-SK_2016.cer"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to use an organization certificate in a Development mode? Similarly to the test ID-card.