Skip to content

Commit

Permalink
If SN and/or G are missing in the Subject, then set to "Unknown"
Browse files Browse the repository at this point in the history
  • Loading branch information
fume committed Jul 7, 2024
1 parent 02fa0f6 commit c535290
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions WebApps/CNS.Auth.Web/Services/CNSCertificateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,26 @@ public Task<ClaimsPrincipal> GetClaimsPrincipal(X509Certificate2 cert, Cancellat
Claim commonName = new Claim("commonName", CN);
var subjectRawData = cert.SubjectName.RawData;

var SN = new AsnEncodedData("SN", subjectRawData).Format(false);
var G = new AsnEncodedData("G", subjectRawData).Format(false);
string SN, G;

if (!cert.Subject.Contains("SN="))
{
SN = "Unknown";
}
else
{
SN = new AsnEncodedData("SN", subjectRawData).Format(false);
}

if (!cert.Subject.Contains("G="))
{
G = "Unknown";
}
else
{
G = new AsnEncodedData("G", subjectRawData).Format(false);
}

var OU = new AsnEncodedData("OU", subjectRawData).Format(false);
var O = new AsnEncodedData("O", subjectRawData).Format(false);
var C = new AsnEncodedData("C", subjectRawData).Format(false);
Expand Down

0 comments on commit c535290

Please sign in to comment.