Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d802ffc

Browse files
committed
Make byte order for X509Certificate2::GetSerialNumber on Unix match Windows.
PropsTests::TestSerial caught that the byte ordering for GetSerialNumber was big-endian on Unix systems, and little-endian on Windows.
1 parent 0908b1c commit d802ffc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509CertificateReader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ public byte[] SerialNumber
140140
get
141141
{
142142
IntPtr serialNumberPtr = Interop.libcrypto.X509_get_serialNumber(_cert);
143-
return Interop.NativeCrypto.GetAsn1StringBytes(serialNumberPtr);
143+
byte[] serial = Interop.NativeCrypto.GetAsn1StringBytes(serialNumberPtr);
144+
145+
// Windows returns this in BigInteger Little-Endian,
146+
// OpenSSL returns this in BigInteger Big-Endian.
147+
Array.Reverse(serial);
148+
return serial;
144149
}
145150
}
146151

0 commit comments

Comments
 (0)