Skip to content

Commit 2a3ed21

Browse files
aw0lidAhmed
authored andcommitted
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
1 parent 01bad01 commit 2a3ed21

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

docs/release-notes/.FSharp.Compiler.Service/10.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Fixed
22

3+
* Fix strong name signature size to align with Roslyn for public signing ([PR #19242](https://github.com/dotnet/fsharp/pull/19242))
34
* 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))
45
* 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))
56
* 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))

src/Compiler/AbstractIL/ilsign.fs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
22

33
module internal FSharp.Compiler.AbstractIL.StrongNameSign
44

@@ -301,19 +301,30 @@ let signStream stream keyBlob =
301301
patchSignature stream peReader signature
302302

303303
let signatureSize (pk: byte array) =
304-
if pk.Length < 25 then
305-
raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ())))
306-
307-
let mutable reader = BlobReader pk
308-
reader.ReadBigInteger 12 |> ignore // Skip CLRHeader
309-
reader.ReadBigInteger 8 |> ignore // Skip BlobHeader
310-
let magic = reader.ReadInt32() // Read magic
311-
312-
if not (magic = RSA_PRIV_MAGIC || magic = RSA_PUB_MAGIC) then // RSAPubKey.magic
313-
raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ())))
314-
315-
let x = reader.ReadInt32() / 8
316-
x
304+
if isNull (box pk) || pk.Length < 16 then
305+
0
306+
else
307+
let reader = BlobReader pk
308+
309+
let tryReadBitLen (offset: int) =
310+
if pk.Length >= offset + 12 then
311+
reader._offset <- offset
312+
let magic = reader.ReadInt32()
313+
314+
if magic = RSA_PUB_MAGIC || magic = RSA_PRIV_MAGIC then
315+
let bitLen = reader.ReadInt32()
316+
Some bitLen
317+
else
318+
None
319+
else
320+
None
321+
322+
match tryReadBitLen 8 with
323+
| Some bitLen -> (bitLen / 8 + 7) &&& ~~~7
324+
| None ->
325+
match tryReadBitLen 20 with
326+
| Some bitLen -> (bitLen / 8 + 7) &&& ~~~7
327+
| None -> 128
317328

318329
// Returns a CLR Format Blob public key
319330
let getPublicKeyForKeyPair keyBlob =

0 commit comments

Comments
 (0)