Skip to content

Commit

Permalink
Remove NetFramework-only files from netcore compile sources
Browse files Browse the repository at this point in the history
  • Loading branch information
ellahathaway committed Feb 4, 2025
1 parent b325256 commit d098c84
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 53 deletions.
3 changes: 0 additions & 3 deletions src/SignCheck/Microsoft.SignCheck/Interop/Ole32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System;
using System.Runtime.InteropServices;

#if NETFRAMEWORK
using Microsoft.VisualStudio.OLE.Interop;

namespace Microsoft.SignCheck.Interop
Expand All @@ -29,4 +27,3 @@ public static extern int StgCreateDocfile(
out IStorage ppstgOpen);
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Deployment.WindowsInstaller;

#if NETFRAMEWORK
using Microsoft.VisualStudio.OLE.Interop;
using STATSTG = Microsoft.VisualStudio.OLE.Interop.STATSTG;
#endif

namespace Microsoft.SignCheck.Interop
{
Expand All @@ -23,7 +20,6 @@ public class StructuredStorage

public const int S_OK = 0;

#if NETFRAMEWORK
/// <summary>
/// Returns true if the storage represents a patch (MSP)
/// </summary>
Expand Down Expand Up @@ -134,7 +130,6 @@ public static void SaveStorage(IStorage rootStorage, string storageDir, string s
Marshal.ReleaseComObject(stg);
}
}
#endif

public static void SaveStream(Record record, string dir)
{
Expand Down
4 changes: 0 additions & 4 deletions src/SignCheck/Microsoft.SignCheck/Interop/WinCrypt.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETFRAMEWORK

using System;
using System.Runtime.InteropServices;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
Expand Down Expand Up @@ -317,5 +315,3 @@ public struct CRYPT_TIMESTAMP_INFO
public IntPtr rgExtension;
}
}

#endif
2 changes: 0 additions & 2 deletions src/SignCheck/Microsoft.SignCheck/Interop/WinTrust.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETFRAMEWORK
using System;
using System.Runtime.InteropServices;

Expand All @@ -16,4 +15,3 @@ public static class WinTrust {
public static extern uint WinVerifyTrust(IntPtr hWnd, IntPtr pgActionID, IntPtr pWinTrustData);
}
}
#endif
4 changes: 0 additions & 4 deletions src/SignCheck/Microsoft.SignCheck/Interop/WinTrustData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETFRAMEWORK

using System;
using System.Runtime.InteropServices;

Expand All @@ -25,5 +23,3 @@ public struct WinTrustData
public uint dwUIContext;
}
}

#endif
3 changes: 0 additions & 3 deletions src/SignCheck/Microsoft.SignCheck/Interop/WinTrustFileInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETFRAMEWORK
using System;
using System.Runtime.InteropServices;

Expand All @@ -17,5 +16,3 @@ public struct WinTrustFileInfo
public IntPtr pgKnownSubject;
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == '$(NetToolCurrent)'">
<!-- Interop -->
<Compile Remove="Interop\**" />
<EmbeddedResource Remove="Interop\**" />

<!-- Unsupported file types -->
<Compile Remove="Verification\AuthentiCode.cs" />
<Compile Remove="Verification\AuthentiCodeVerifier.cs" />
<Compile Remove="Verification\CabVerifier.cs" />
<Compile Remove="Verification\ExeVerifier.cs" />
<Compile Remove="Verification\JarVerifier.cs" />
<Compile Remove="Verification\MsiVerifier.cs" />
<Compile Remove="Verification\MspVerifier.cs" />
<Compile Remove="Verification\MsuVerifier.cs" />
<Compile Remove="Verification\PortableExecutableVerifier.cs" />
<Compile Remove="Verification\StrongName.cs" />
<Compile Remove="Verification\VsixVerifier.cs" />
<Compile Remove="Verification\Jar\JarFile.cs" />
<Compile Remove="Verification\Jar\JarSignatureFile.cs" />
</ItemGroup>

<ItemGroup>
<Compile Update="SignCheckResources.Designer.cs"
DesignTime="True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Pkcs;
using Microsoft.SignCheck.Logging;

namespace Microsoft.SignCheck.Verification
{
public static class AuthentiCode
{
public static uint IsSigned(string path)
{
#if NETFRAMEWORK
WinTrustFileInfo fileInfo = new WinTrustFileInfo()
{
cbStruct = (uint)Marshal.SizeOf(typeof(WinTrustFileInfo)),
Expand Down Expand Up @@ -58,12 +56,8 @@ public static uint IsSigned(string path)
Marshal.FreeHGlobal(pData);

return result;
#else
throw new PlatformNotSupportedException();
#endif
}

#if NETFRAMEWORK
/// <summary>
/// Searches the unsigned attributes in the counter signature for a timestamp token.
/// </summary>
Expand Down Expand Up @@ -206,6 +200,6 @@ public static IEnumerable<Timestamp> GetTimestamps(string path)

return timestamps;
}
#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ public AuthentiCodeVerifier(Log log, Exclusions exclusions, SignatureVerificatio

public override SignatureVerificationResult VerifySignature(string path, string parent, string virtualPath)
{
#if NETCOREAPP
var svr = SignatureVerificationResult.UnsupportedFileTypeResult(path, parent, virtualPath);
string fullPath = svr.FullPath;
svr.AddDetail(DetailKeys.File, SignCheckResources.DetailSigned, SignCheckResources.NA);

return svr;
#else
SignatureVerificationResult svr = VerifyAuthentiCode(path, parent, virtualPath);

if (FinalizeResult)
Expand All @@ -44,10 +37,8 @@ public override SignatureVerificationResult VerifySignature(string path, string
}

return svr;
#endif
}

#if NETFRAMEWORK
protected SignatureVerificationResult VerifyAuthentiCode(string path, string parent, string virtualPath)
{
var svr = new SignatureVerificationResult(path, parent, virtualPath);
Expand Down Expand Up @@ -90,6 +81,5 @@ protected SignatureVerificationResult VerifyAuthentiCode(string path, string par

return svr;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ private bool VerifySignatureRsa()
{
foreach (CryptographicAttributeObject unsignedAttribute in signerInfo.UnsignedAttributes)
{
#if NETFRAMEWORK
if (String.Equals(unsignedAttribute.Oid.Value, WinCrypt.szOID_SIGNATURE_TIMESTAMP_ATTRIBUTE, StringComparison.OrdinalIgnoreCase))
{
Pkcs9AttributeObject timestampAttribute = new Pkcs9AttributeObject(unsignedAttribute.Values[0]);
Expand Down Expand Up @@ -284,9 +283,6 @@ private bool VerifySignatureRsa()
}
}
}
#else
throw new PlatformNotSupportedException("Timestamp verification is not supported on .NET Core.");
#endif
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public override SignatureVerificationResult VerifySignature(string path, string
// Defer to the base class to check the AuthentiCode signature
SignatureVerificationResult svr = base.VerifySignature(path, parent, virtualPath);

#if NETFRAMEWORK
if (VerifyRecursive)
{
StructuredStorage.OpenAndExtractStorages(path, svr.TempPath);
Expand All @@ -32,7 +31,7 @@ public override SignatureVerificationResult VerifySignature(string path, string

DeleteDirectory(svr.TempPath);
}
#endif

return svr;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
# if NETFRAMEWORK
using Microsoft.SignCheck.Interop.PortableExecutable;
#endif
using Microsoft.SignCheck.Logging;

namespace Microsoft.SignCheck.Verification
Expand Down Expand Up @@ -86,21 +88,24 @@ public SignatureVerificationManager(Exclusions exclusions, Log log, SignatureVer
Log = log;
Options = options;

#if NETFRAMEWORK
AddFileVerifier(new CabVerifier(log, exclusions, options, ".cab"));
AddFileVerifier(new PortableExecutableVerifier(log, exclusions, options, ".dll"));
AddFileVerifier(new ExeVerifier(log, exclusions, options, ".exe"));
AddFileVerifier(new JarVerifier(log, exclusions, options));
AddFileVerifier(new AuthentiCodeVerifier(log, exclusions, options, ".js"));
AddFileVerifier(new LzmaVerifier(log, exclusions, options));
AddFileVerifier(new MsiVerifier(log, exclusions, options));
AddFileVerifier(new MspVerifier(log, exclusions, options));
AddFileVerifier(new MsuVerifier(log, exclusions, options));
AddFileVerifier(new NupkgVerifier(log, exclusions, options));
AddFileVerifier(new AuthentiCodeVerifier(log, exclusions, options, ".psd1"));
AddFileVerifier(new AuthentiCodeVerifier(log, exclusions, options, ".psm1"));
AddFileVerifier(new AuthentiCodeVerifier(log, exclusions, options, ".ps1"));
AddFileVerifier(new AuthentiCodeVerifier(log, exclusions, options, ".ps1xml"));
AddFileVerifier(new VsixVerifier(log, exclusions, options));
#endif

AddFileVerifier(new LzmaVerifier(log, exclusions, options));
AddFileVerifier(new NupkgVerifier(log, exclusions, options));
AddFileVerifier(new XmlVerifier(log, exclusions, options));
AddFileVerifier(new ZipVerifier(log, exclusions, options));
}
Expand Down Expand Up @@ -257,7 +262,7 @@ public static FileVerifier GetFileVerifierByHeader(string path)
fileVerifier = GetFileVerifierByExtension(".cab");
}
}

#if NETFRAMEWORK
reader.BaseStream.Seek(0, SeekOrigin.Begin);
if (stream.Length > 2)
{
Expand All @@ -276,6 +281,7 @@ public static FileVerifier GetFileVerifierByHeader(string path)
}
}
}
#endif
}

return fileVerifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public override SignatureVerificationResult VerifySignature(string path, string
return svr;
}

#if NETFRAMEWORK
private bool TryGetTimestamp(PackageDigitalSignature packageSignature, out Timestamp timestamp)
{
bool isValidTimestampSignature = false;
Expand Down Expand Up @@ -119,13 +118,9 @@ private bool TryGetTimestamp(PackageDigitalSignature packageSignature, out Times

return isValidTimestampSignature;
}
#endif

private bool IsSigned(string path, SignatureVerificationResult result)
{
#if NETCOREAPP
return false;
#else
PackageDigitalSignature packageSignature = null;

using (var vsixStream = new FileStream(path, FileMode.Open, FileAccess.Read))
Expand Down Expand Up @@ -188,7 +183,6 @@ private bool IsSigned(string path, SignatureVerificationResult result)
}

return true;
#endif
}
}
}

0 comments on commit d098c84

Please sign in to comment.