Skip to content

Commit

Permalink
Fix issue where delegate would be GCed.
Browse files Browse the repository at this point in the history
The problem here was we were creating a method group which implicitly
creates a delegate instance. This delegate instance didn't live long
enough, so set it's lifetime to the duration of the owning object.
  • Loading branch information
vcsjones committed Dec 22, 2017
1 parent 1838909 commit c2c9363
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions AzureSignTool/AuthenticodeKeyVaultSigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AuthenticodeKeyVaultSigner : IDisposable
private readonly MemoryCertificateStore _certificateStore;
private readonly X509Chain _chain;
private readonly ILogger _logger;
private readonly SignCallback _signCallback;

public AuthenticodeKeyVaultSigner(AzureKeyVaultMaterializedConfiguration configuration, TimeStampConfiguration timeStampConfiguration, X509Certificate2Collection additionalCertificates,
ILogger logger)
Expand All @@ -34,6 +35,7 @@ public AuthenticodeKeyVaultSigner(AzureKeyVaultMaterializedConfiguration configu
{
_certificateStore.Add(_chain.ChainElements[i].Certificate);
}
_signCallback = SignCallback;
}

public int SignFile(string path, string description, string descriptionUrl, bool? pageHashing)
Expand Down Expand Up @@ -74,10 +76,9 @@ public int SignFile(string path, string description, string descriptionUrl, bool
timestampUrl = null;
break;
}

_logger.Log("Getting SIP Data", LogLevel.Verbose);
using (var data = SipExtensionFactory.GetSipData(path, flags, contextReceiver, timeStampFlags, storeInfo, timestampUrl,
timestampAlgorithmOid, SignCallback, _configuration.FileDigestAlgorithm, fileInfo, attributes))
timestampAlgorithmOid, _signCallback, _configuration.FileDigestAlgorithm, fileInfo, attributes))
{
_logger.Log("Calling SignerSignEx3", LogLevel.Verbose);
return mssign32.SignerSignEx3
Expand Down Expand Up @@ -113,7 +114,7 @@ private int SignCallback(
uint algId,
byte[] pDigestToSign,
uint dwDigestToSign,
out CRYPTOAPI_BLOB blob
ref CRYPTOAPI_BLOB blob
)
{
_logger.Log("SignCallback", LogLevel.Verbose);
Expand Down
2 changes: 1 addition & 1 deletion AzureSignTool/Interop/mssign32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,6 @@ internal delegate int SignCallback(
[param: In, MarshalAs(UnmanagedType.U4)] uint algId,
[param: In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 4)] byte[] pDigestToSign,
[param: In, MarshalAs(UnmanagedType.U4)] uint dwDigestToSign,
[param: Out] out CRYPTOAPI_BLOB blob
[param: In, Out] ref CRYPTOAPI_BLOB blob
);
}

0 comments on commit c2c9363

Please sign in to comment.