Skip to content

Commit

Permalink
Fix for netstandard2.0, add tests
Browse files Browse the repository at this point in the history
Unignore object file used for tests
  • Loading branch information
jtschuster committed Sep 5, 2024
1 parent b5ad0c2 commit 0f8c240
Show file tree
Hide file tree
Showing 72 changed files with 1,034 additions and 6,035 deletions.
2 changes: 2 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@
<TestProjectToBuild Include="$(InstallerProjectRoot)tests\AppHost.Bundle.Tests\AppHost.Bundle.Tests.csproj" />
<TestProjectToBuild Include="$(InstallerProjectRoot)tests\HostActivation.Tests\HostActivation.Tests.csproj" />
<TestProjectToBuild Include="$(InstallerProjectRoot)tests\Microsoft.NET.HostModel.Tests\Microsoft.NET.HostModel.Tests.csproj" />
<TestProjectToBuild Include="$(InstallerProjectRoot)tests\Melanzana.MachO.Tests\Melanzana.MachO.Tests.csproj" />
<TestProjectToBuild Include="$(InstallerProjectRoot)tests\Melanzana.CodeSign.Tests\Melanzana.CodeSign.Tests.csproj" />
<ProjectToBuild Include="@(TestProjectToBuild)" BuildInParallel="true" Test="true" Category="host" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@
<SystemDataSqlClientVersion>4.8.6</SystemDataSqlClientVersion>
<SystemDrawingCommonVersion>8.0.0</SystemDrawingCommonVersion>
<SystemIOFileSystemAccessControlVersion>5.0.0</SystemIOFileSystemAccessControlVersion>
<SystemFormatsAsn1Version>10.0.0-alpha.1.24454.1</SystemFormatsAsn1Version>
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
<SystemReflectionMetadataVersion>9.0.0-rc.1.24410.5</SystemReflectionMetadataVersion>
<SystemReflectionMetadataLoadContextVersion>9.0.0-rc.1.24410.5</SystemReflectionMetadataLoadContextVersion>
<SystemSecurityAccessControlVersion>6.0.0</SystemSecurityAccessControlVersion>
<SystemSecurityCryptographyCngVersion>5.0.0</SystemSecurityCryptographyCngVersion>
<SystemSecurityCryptographyOpenSslVersion>5.0.0</SystemSecurityCryptographyOpenSslVersion>
<SystemSecurityCryptographyPkcsVersion>5.0.0</SystemSecurityCryptographyPkcsVersion>
<SystemSecurityPrincipalWindowsVersion>5.0.0</SystemSecurityPrincipalWindowsVersion>
<SystemSecurityPermissionsVersion>7.0.0</SystemSecurityPermissionsVersion>
<SystemTextJsonVersion>9.0.0-rc.1.24410.5</SystemTextJsonVersion>
Expand Down
120 changes: 120 additions & 0 deletions src/installer/Microsoft.DotNet.CoreSetup.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppHost.Bundle.Tests", "tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.HostModel.Tests", "tests\Microsoft.NET.HostModel.Tests\Microsoft.NET.HostModel.Tests.csproj", "{9212E3B2-DFCB-4A24-99AA-ED5F9ACAA87F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "managed", "managed", "{9D78613B-C4A1-43C6-8BF1-6F91AA1627B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanzana.Streams", "managed\Melanzana.Streams\Melanzana.Streams.csproj", "{4980EA65-C461-4041-9FE9-2613F76A159C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanzana.BinaryFormat.Generator", "managed\Melanzana.BinaryFormat.Generator\Melanzana.BinaryFormat.Generator.csproj", "{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanzana.CodeSign", "managed\Melanzana.CodeSign\Melanzana.CodeSign.csproj", "{5ED844D4-DDEA-4801-B274-21CEC28C9C83}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanzana.MachO", "managed\Melanzana.MachO\Melanzana.MachO.csproj", "{A309152C-8D24-4631-A04F-C3D3C3370320}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DDD740C6-C716-45A7-99C5-4F8B2F2D77A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanzana.CodeSign.Tests", "tests\Melanzana.CodeSign.Tests\Melanzana.CodeSign.Tests.csproj", "{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Melanzana.MachO.Tests", "tests\Melanzana.MachO.Tests\Melanzana.MachO.Tests.csproj", "{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,11 +145,115 @@ Global
{9212E3B2-DFCB-4A24-99AA-ED5F9ACAA87F}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{9212E3B2-DFCB-4A24-99AA-ED5F9ACAA87F}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{9212E3B2-DFCB-4A24-99AA-ED5F9ACAA87F}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Debug|x64.ActiveCfg = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Debug|x64.Build.0 = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Release|Any CPU.Build.0 = Release|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Release|x64.ActiveCfg = Release|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.Release|x64.Build.0 = Release|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{4980EA65-C461-4041-9FE9-2613F76A159C}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Debug|x64.ActiveCfg = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Debug|x64.Build.0 = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Release|Any CPU.Build.0 = Release|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Release|x64.ActiveCfg = Release|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.Release|x64.Build.0 = Release|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Debug|x64.ActiveCfg = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Debug|x64.Build.0 = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Release|Any CPU.Build.0 = Release|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Release|x64.ActiveCfg = Release|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.Release|x64.Build.0 = Release|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{5ED844D4-DDEA-4801-B274-21CEC28C9C83}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Debug|x64.ActiveCfg = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Debug|x64.Build.0 = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Release|Any CPU.Build.0 = Release|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Release|x64.ActiveCfg = Release|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.Release|x64.Build.0 = Release|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{A309152C-8D24-4631-A04F-C3D3C3370320}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Debug|x64.ActiveCfg = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Debug|x64.Build.0 = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Release|Any CPU.Build.0 = Release|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Release|x64.ActiveCfg = Release|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.Release|x64.Build.0 = Release|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Debug|x64.ActiveCfg = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Debug|x64.Build.0 = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Release|Any CPU.Build.0 = Release|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Release|x64.ActiveCfg = Release|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.Release|x64.Build.0 = Release|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28B9726D-802B-478D-AF7A-B9243B9E180B}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4980EA65-C461-4041-9FE9-2613F76A159C} = {9D78613B-C4A1-43C6-8BF1-6F91AA1627B6}
{51193AE2-50BE-4899-9068-AA8E9C2A9C7D} = {9D78613B-C4A1-43C6-8BF1-6F91AA1627B6}
{5ED844D4-DDEA-4801-B274-21CEC28C9C83} = {9D78613B-C4A1-43C6-8BF1-6F91AA1627B6}
{A309152C-8D24-4631-A04F-C3D3C3370320} = {9D78613B-C4A1-43C6-8BF1-6F91AA1627B6}
{C0790B96-7FB8-4B9F-B8D7-AD1C9F585A1B} = {DDD740C6-C716-45A7-99C5-4F8B2F2D77A5}
{4407B895-F3E2-40BD-9B9B-9CB3C98B860F} = {DDD740C6-C716-45A7-99C5-4F8B2F2D77A5}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@ public partial class Generator : ISourceGenerator
{
public void Initialize(GeneratorInitializationContext context)
{
#if DEBUG
//if (!Debugger.IsAttached)
//{
// Debugger.Launch();
//}
#endif

context.RegisterForPostInitialization((pi) => pi.AddSource("BinaryFormat.Attribute.cs", AttributeSource));
context.RegisterForSyntaxNotifications(() => new MySyntaxReceiver());
}

public void Execute(GeneratorExecutionContext context)
{
MySyntaxReceiver syntaxReceiver = (MySyntaxReceiver)context.SyntaxContextReceiver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>annotations</Nullable>
<NoWarn>NoWarn;IDE0073;SA1518;SA1028;SA1020;IDE0170;IDE0060;CA1822;SA1400;RS1036;CA1852</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.0-6.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersion)" PrivateAssets="all" />
<ProjectReference Include="../plist-cil/plist-cil.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static string ReadAnyAsnString(this AsnReader tavReader)
throw new CryptographicException("Invalid DER encoding");
}
}

public static bool IsAppleDeveloperCertificate(this X509Certificate2 certificate)
{
// FIXME: We should check the certificate anchor and only allow the following OIDs in extensions:
Expand All @@ -43,7 +43,14 @@ public static bool IsAppleDeveloperCertificate(this X509Certificate2 certificate
// 1.2.840.113635.100.6.1.13 (Developer ID)
// 1.2.840.113635.100.6.1.7 (Distribution)
// 1.2.840.113635.100.6.1.4 (iPhone Distribution)
return certificate.Extensions.Any(e => e.Oid?.Value?.StartsWith("1.2.840.113635.100.6.1.") ?? false);
foreach(var ext in certificate.Extensions)
{
if (ext.Oid?.Value?.StartsWith("1.2.840.113635.100.6.1.") == true)
{
return true;
}
}
return false;
}

public static string GetTeamId(this X509Certificate2 certificate)
Expand Down
29 changes: 7 additions & 22 deletions src/installer/managed/Melanzana.CodeSign/Blobs/CmsWrapperBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,26 @@
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Linq;
using Claunia.PropertyList;

namespace Melanzana.CodeSign.Blobs
{
public class CmsWrapperBlob
{
private readonly static string rootCertificatePath = "Melanzana.CodeSign.Certificates.RootCertificate.cer";
private readonly static string g1IntermediateCertificatePath = "Melanzana.CodeSign.Certificates.IntermediateG1Certificate.cer";
private readonly static string g3IntermediateCertificatePath = "Melanzana.CodeSign.Certificates.IntermediateG3Certificate.cer";

private static X509Certificate2 GetManifestCertificate(string name)
{
var memoryStream = new MemoryStream();
using (var manifestStream = typeof(CmsWrapperBlob).Assembly.GetManifestResourceStream(name))
{
Debug.Assert(manifestStream != null);
manifestStream.CopyTo(memoryStream);
manifestStream!.CopyTo(memoryStream);
}
return new X509Certificate2(memoryStream.ToArray());
}

public static byte[] Create(
X509Certificate2? developerCertificate,
AsymmetricAlgorithm? privateKey,
byte[] dataToSign,
HashType[] hashTypes,
byte[][] cdHashes)
Expand All @@ -55,28 +51,17 @@ public static byte[] Create(

// Try to build full chain
var chain = new X509Chain();
var chainPolicy = new X509ChainPolicy { TrustMode = X509ChainTrustMode.CustomRootTrust };
chainPolicy.CustomTrustStore.Add(GetManifestCertificate(rootCertificatePath));
chainPolicy.CustomTrustStore.Add(GetManifestCertificate(g1IntermediateCertificatePath));
chainPolicy.CustomTrustStore.Add(GetManifestCertificate(g3IntermediateCertificatePath));
chain.ChainPolicy = chainPolicy;
// Retry with default policy and system certificate store
chain.ChainPolicy = new X509ChainPolicy();
if (chain.Build(developerCertificate))
{
certificatesList.AddRange(chain.ChainElements.Select(e => e.Certificate).ToArray());
}
else
{
// Retry with default policy and system certificate store
chain.ChainPolicy = new X509ChainPolicy();
if (chain.Build(developerCertificate))
foreach(var ce in chain.ChainElements)
{
certificatesList.AddRange(chain.ChainElements.Select(e => e.Certificate).ToArray());
certificatesList.Add(ce.Certificate);
}
}

var cmsSigner = privateKey == null ?
new CmsSigner(developerCertificate) :
new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, developerCertificate, privateKey);
var cmsSigner = new CmsSigner(developerCertificate);
cmsSigner.Certificates.AddRange(certificatesList);
cmsSigner.IncludeOption = X509IncludeOption.None;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public long Size(CodeDirectoryVersion version)

long codeDirectorySize = GetFixedHeaderSize(version);
codeDirectorySize += utf8Identifier.Length + 1;
if (!String.IsNullOrEmpty(teamId))
if (!string.IsNullOrEmpty(teamId))
codeDirectorySize += utf8TeamId.Length + 1;
codeDirectorySize += (specialSlotCount + codeSlotCount) * hashSize;
if (version >= CodeDirectoryVersion.SupportsPreEncrypt)
Expand Down Expand Up @@ -103,7 +103,7 @@ public byte[] Build(Stream machOStream)
baselineHeader.HashSize = hashSize;
baselineHeader.HashType = HashType;
baselineHeader.Platform = 0; // TODO
baselineHeader.Log2PageSize = (byte)Math.Log2(pageSize);
baselineHeader.Log2PageSize = (byte)MathHelpers.Log2(pageSize);
baselineHeader.Reserved = 0;
var scatterHeader = new CodeDirectoryScatterHeader();
scatterHeader.ScatterOffset = 0;
Expand All @@ -113,7 +113,7 @@ public byte[] Build(Stream machOStream)
codeLimit64Header.Reserved = 0;
codeLimit64Header.CodeLimit64 = execLength >= uint.MaxValue ? execLength : 0;
var execSegementHeader = new CodeDirectoryExecSegmentHeader();
execSegementHeader.Base = textSegment.FileOffset;
execSegementHeader.Base = textSegment!.FileOffset;
execSegementHeader.Limit = textSegment.FileSize;
execSegementHeader.Flags = ExecutableSegmentFlags;

Expand Down
Loading

0 comments on commit 0f8c240

Please sign in to comment.