You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
X509Certificate2 class unable to read Subject data from some certificates on WSL/Docker containers/Linux #88037
After upgrading our company projects from .net core 3.1 to .net 6, X509Certificate2 class is unable to read data from certificates issued by two different polish electronic signature providers (KIR and Cencert). On windows everything works fine but on linux-based environments (so far tested on docker containers and WSL), Subject property always contains empty string.
postalAddress ATTRIBUTE ::= {
WITH SYNTAX PostalAddress
EQUALITY MATCHING RULE caseIgnoreListMatch
SUBSTRINGS MATCHING RULE caseIgnoreListSubstringsMatch
LDAP-SYNTAX postalAddr.&id
LDAP-NAME {"postalAddress"}
ID id-at-postalAddress }
PostalAddress ::= SEQUENCE SIZE (1..MAX) OF UnboundedDirectoryString
So, this is "correct". The certificate is not malformed, it just uses a directory type that the managed decoder doesn't handle at all.
That we haven't run in to this yet so far indicates that most applications expect the AttributeValue to be a directory string. MacOS, for example, is completely unwilling to parse this certificate.
Windows on the other hand fairs a bit better, it just shows it as hex-encoded.
I think it's sensible to do what Windows is doing here and display it as hex when we encounter a non-string AttributeValue.
The next logical question is: "Why did this used to work in .NET Core 3.1?"
In .NET 5, the distinguished name decoder was changed from using OpenSSL's APIs to a managed implementation.
Reacted by David Cantú, Jeremy Barton and afdsa213
ghost added
in-prThere is an active PR which will close this issue when it is merged
Activity
vcsjones commentedon Jun 26, 2023
I can reproduce it on .NET 8 nightly, and nothing jumps out at me as "invalid text according to the ASN.1 tag"
I'll dig in.
vcsjones commentedon Jun 26, 2023
The issue is due to the postalAddress in the distinguished name as seen here:
Sequence: Length: 38 Offset: 0 ObjectIdentifier: 2.5.4.16, Length: 5 Offset: 2 Sequence: Length: 31 Offset: 7 UTF8String: Kolska 12, Length: 11 Offset: 9 UTF8String: 01-045, Length: 8 Offset: 20 UTF8String: Warszawa, Length: 10 Offset: 28Our managed decoder more or less requires the
AttributeValueof a certificate to be a DirectoryString:https://github.com/dotnet/runtime/blob/main/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.ManagedDecode.cs#L94-L95
Now, X.520 defines postalAddress as
postalAddress ATTRIBUTE ::= { WITH SYNTAX PostalAddress EQUALITY MATCHING RULE caseIgnoreListMatch SUBSTRINGS MATCHING RULE caseIgnoreListSubstringsMatch LDAP-SYNTAX postalAddr.&id LDAP-NAME {"postalAddress"} ID id-at-postalAddress } PostalAddress ::= SEQUENCE SIZE (1..MAX) OF UnboundedDirectoryStringSo, this is "correct". The certificate is not malformed, it just uses a directory type that the managed decoder doesn't handle at all.
That we haven't run in to this yet so far indicates that most applications expect the AttributeValue to be a directory string. MacOS, for example, is completely unwilling to parse this certificate.
Windows on the other hand fairs a bit better, it just shows it as hex-encoded.
I think it's sensible to do what Windows is doing here and display it as hex when we encounter a non-string AttributeValue.
The next logical question is: "Why did this used to work in .NET Core 3.1?"
In .NET 5, the distinguished name decoder was changed from using OpenSSL's APIs to a managed implementation.