From 0508fdf6dec7e711af66ae3295906c9fe99b573e Mon Sep 17 00:00:00 2001 From: Ahmed Walid Date: Thu, 22 Jan 2026 23:33:02 +0200 Subject: [PATCH] Fix strong name signature size to align with Roslyn for public signing (#11887) Fix StrongNameSignatureSize failure on Linux This fix handles full RSA key pairs on non-Windows platforms by attempting both Public and KeyPair imports, mirroring Roslyn's behavior. Final code formatting fix for signatureSize Align signature size logic with Roslyn and fix cross-platform key import Fix cross-platform strong name signing by manually parsing RSA key blobs fix: move release notes to 300 --- .../.FSharp.Compiler.Service/10.0.300.md | 1 + src/Compiler/AbstractIL/ilsign.fs | 39 ++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index 471abbfb982..fe5b4f1d83a 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -1,5 +1,6 @@ ### Fixed +* Fix strong name signature size to align with Roslyn for public signing ([Issue #17451](https://github.com/dotnet/fsharp/issues/17451), [PR #19242](https://github.com/dotnet/fsharp/pull/19242)) * Fixed Find All References not correctly finding active pattern cases in signature files. ([Issue #19173](https://github.com/dotnet/fsharp/issues/19173), [Issue #14969](https://github.com/dotnet/fsharp/issues/14969), [PR #19252](https://github.com/dotnet/fsharp/pull/19252)) * Fixed Rename not correctly handling operators containing `.` (e.g., `-.-`). ([Issue #17221](https://github.com/dotnet/fsharp/issues/17221), [Issue #14057](https://github.com/dotnet/fsharp/issues/14057), [PR #19252](https://github.com/dotnet/fsharp/pull/19252)) * Fixed Find All References not correctly applying `#line` directive remapping. ([Issue #9928](https://github.com/dotnet/fsharp/issues/9928), [PR #19252](https://github.com/dotnet/fsharp/pull/19252)) diff --git a/src/Compiler/AbstractIL/ilsign.fs b/src/Compiler/AbstractIL/ilsign.fs index e03f614244c..80ba7152a99 100644 --- a/src/Compiler/AbstractIL/ilsign.fs +++ b/src/Compiler/AbstractIL/ilsign.fs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. module internal FSharp.Compiler.AbstractIL.StrongNameSign @@ -301,19 +301,32 @@ let signStream stream keyBlob = patchSignature stream peReader signature let signatureSize (pk: byte array) = - if pk.Length < 25 then + if isNull (box pk) || pk.Length < 16 then raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ()))) - - let mutable reader = BlobReader pk - reader.ReadBigInteger 12 |> ignore // Skip CLRHeader - reader.ReadBigInteger 8 |> ignore // Skip BlobHeader - let magic = reader.ReadInt32() // Read magic - - if not (magic = RSA_PRIV_MAGIC || magic = RSA_PUB_MAGIC) then // RSAPubKey.magic - raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ()))) - - let x = reader.ReadInt32() / 8 - x + else + let mutable reader = BlobReader pk + + let tryReadBitLen (offset: int) = + if pk.Length >= offset + 12 then + reader._offset <- offset + let magic = reader.ReadInt32() + + if magic = RSA_PUB_MAGIC || magic = RSA_PRIV_MAGIC then + let bitLen = reader.ReadInt32() + Some bitLen + else + None + else + None + + // Try offset 8: RSAPUBKEY header in a raw key blob (no CLR header) + match tryReadBitLen 8 with + | Some bitLen -> (bitLen / 8 + 7) &&& ~~~7 + | None -> + // Try offset 20: RSAPUBKEY header in a CLR key blob (12-byte CLR header + 8-byte BLOBHEADER) + match tryReadBitLen 20 with + | Some bitLen -> (bitLen / 8 + 7) &&& ~~~7 + | None -> 128 // Returns a CLR Format Blob public key let getPublicKeyForKeyPair keyBlob =