Skip to content

Commit

Permalink
Bindings refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
solidstore committed Aug 7, 2023
1 parent f646f02 commit 451ba3c
Show file tree
Hide file tree
Showing 14 changed files with 733 additions and 261 deletions.
4 changes: 3 additions & 1 deletion src/dtf/SfxCA/SfxCA.vcxproj
Expand Up @@ -67,7 +67,9 @@
</ItemGroup>

<ItemGroup>
<ResourceCompile Include="SfxCA.rc" />
<ResourceCompile Include="SfxCA.rc">
<Culture>0x0409</Culture>
</ResourceCompile>
</ItemGroup>

<ItemGroup>
Expand Down
293 changes: 90 additions & 203 deletions src/ext/Http/ca/sslcert.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/ext/Http/ca/wixhttpca.def
Expand Up @@ -10,6 +10,6 @@ EXPORTS
SchedHttpSniSslCertsInstall
SchedHttpSniSslCertsUninstall
ExecHttpSniSslCerts
SchedHttpSslCertsInstall
SchedHttpSslCertsUninstall
ExecHttpSslCerts
SchedHttpSslBindingsInstall
SchedHttpSslBindingsUninstall
ExecHttpSslBindings
11 changes: 7 additions & 4 deletions src/ext/Http/test/WixToolsetTest.Http/HttpExtensionFixture.cs
Expand Up @@ -29,22 +29,25 @@ public void CanBuildUsingSniSssl()
}

[Fact]
public void CanBuildUsingSsl()
public void CanBuildUsingSslBinding()
{
var folder = TestData.Get("TestData", "Ssl");
var build = new Builder(folder, typeof(HttpExtensionFactory), new[] { folder });

var results = build.BuildAndQuery(Build, "CustomAction", "Wix4HttpSslCert");
var results = build.BuildAndQuery(Build, "CustomAction", "Wix4HttpSslCertificate", "Wix4HttpSslBinding", "Wix4HttpSslBindingCertificates");
WixAssert.CompareLineByLine(new[]
{
"CustomAction:Wix4ExecHttpSslCertsInstall_X86\t11265\tWix4HttpCA_X86\tExecHttpSslCerts\t",
"CustomAction:Wix4ExecHttpSslCertsUninstall_X86\t11265\tWix4HttpCA_X86\tExecHttpSslCerts\t",
"CustomAction:Wix4InstallHttpCertificates_X86\t1\tWix4HttpCA_X86\tInstallCertificates\t",
"CustomAction:Wix4RollbackHttpSslCertsInstall_X86\t11521\tWix4HttpCA_X86\tExecHttpSslCerts\t",
"CustomAction:Wix4RollbackHttpSslCertsUninstall_X86\t11521\tWix4HttpCA_X86\tExecHttpSslCerts\t",
"CustomAction:Wix4SchedHttpSslCertsInstall_X86\t8193\tWix4HttpCA_X86\tSchedHttpSslCertsInstall\t",
"CustomAction:Wix4SchedHttpSslCertsUninstall_X86\t8193\tWix4HttpCA_X86\tSchedHttpSslCertsUninstall\t",
"Wix4HttpSslCert:ssle0Wgg93FXwXdLjwZWqv0HKBhhKE\t0.0.0.0\t8080\t[SOME_THUMBPRINT]\t\t\t\t2\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo",
"Wix4HttpSslCert:ssltjEpdUFkxO7rNF2TrXuGLJg5NwE\t0.0.0.0\t8081\t\t1234\t\t\t2\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo",
"CustomAction:Wix4UninstallHttpCertificates_X86\t1\tWix4HttpCA_X86\tUninstallCertificates\t",
"Wix4HttpSslBinding:ssltjEpdUFkxO7rNF2TrXuGLJg5NwE\t0.0.0.0\t8081\t\t\t\t2\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo",
"Wix4HttpSslBindingCertificates:ssltjEpdUFkxO7rNF2TrXuGLJg5NwE\tSomeCertificate",
"Wix4HttpSslCertificate:SomeCertificate\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo\tSome Certificate\t2\tMY\t8\t\t[SOME_PATH]\t[PFX_PASS]",
}, results);
}

Expand Down
Expand Up @@ -5,8 +5,15 @@
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component>
<File Source="example.txt" />
<http:SslCertificate Host="0.0.0.0" Port="8080" Thumbprint="[SOME_THUMBPRINT]" HandleExisting="fail" />
<http:SslCertificate Host="0.0.0.0" Port="8081" CertificateLookup="1234" HandleExisting="fail" />
<http:Certificate Id="SomeCertificate"
Name="Some Certificate"
StoreLocation="localMachine"
StoreName="my"
CertificatePath="[SOME_PATH]"
PFXPassword="[PFX_PASS]"/>
<http:SslBinding Host="0.0.0.0" Port="8081" HandleExisting="fail">
<http:CertificateRef Id="SomeCertificate" />
</http:SslBinding>
</Component>
</ComponentGroup>
</Fragment>
Expand Down
305 changes: 286 additions & 19 deletions src/ext/Http/wixext/HttpCompiler.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/ext/Http/wixext/HttpErrors.cs
Expand Up @@ -23,9 +23,15 @@ private static Message Message(SourceLineNumber sourceLineNumber, Ids id, Resour
return new Message(sourceLineNumber, MessageLevel.Error, (int)id, resourceManager, resourceName, args);
}

public static Message IllegalElementWithoutComponent(SourceLineNumber sourceLineNumbers, string elementName)
{
return Message(sourceLineNumbers, Ids.IllegalElementWithoutComponent, "The {0} element cannot be specified unless the element has a Component as an ancestor. A {0} that does not have a Component ancestor is not installed.", elementName);
}

public enum Ids
{
NoSecuritySpecified = 6701,
IllegalElementWithoutComponent = 6721,
}
}
}
42 changes: 36 additions & 6 deletions src/ext/Http/wixext/HttpTableDefinitions.cs
Expand Up @@ -23,16 +23,15 @@ public static class HttpTableDefinitions
symbolIdIsPrimaryKey: true
);

public static readonly TableDefinition WixHttpSslCert = new TableDefinition(
"Wix4HttpSslCert",
HttpSymbolDefinitions.WixHttpSslCert,
public static readonly TableDefinition WixHttpSslBinding = new TableDefinition(
"Wix4HttpSslBinding",
HttpSymbolDefinitions.WixHttpSslBinding,
new[]
{
new ColumnDefinition("WixHttpSslCert", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("WixHttpSslBinding", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("Host", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Host for the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Port", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Port for the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Thumbprint", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Thumbprint of the SSL certificate to find.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Certificate_", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Unknown, description: "The index into the Certificate table."),
new ColumnDefinition("AppId", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Optional application id for the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Store", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Certificate store containing the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("HandleExisting", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 2, description: "The behavior when trying to install a SSL certificate and it already exists."),
Expand All @@ -41,6 +40,35 @@ public static class HttpTableDefinitions
symbolIdIsPrimaryKey: true
);

public static readonly TableDefinition WixHttpSslBindingCertificates = new TableDefinition(
"Wix4HttpSslBindingCertificates",
HttpSymbolDefinitions.WixHttpSslBindingCertificates,
new[]
{
new ColumnDefinition("Binding_", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, keyTable: "Wix4HttpSslBinding", keyColumn: 1, description: "The index into the SslBinding table.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("Certificate_", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Text, keyTable: "Wix4HttpSslBindingificate", keyColumn: 1, description: "The index into the Certificate table.", modularizeType: ColumnModularizeType.Column),
},
symbolIdIsPrimaryKey: false
);

public static readonly TableDefinition WixHttpSslCertificate = new TableDefinition(
"Wix4HttpSslCertificate",
HttpSymbolDefinitions.WixHttpCertificate,
new[]
{
new ColumnDefinition("Certificate", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, keyColumn: 1, description: "Identifier for the certificate in the package.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, description: "Foreign key into the Component table used to determine install state", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("Name", ColumnType.String, 255, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Name to be used for the Certificate."),
new ColumnDefinition("StoreLocation", ColumnType.Number, 2, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 1, maxValue: 2, description: "Location of the target certificate store (CurrentUser == 1, LocalMachine == 2)"),
new ColumnDefinition("StoreName", ColumnType.String, 64, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Name of the target certificate store"),
new ColumnDefinition("Attributes", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 2147483647, description: "Attributes of the certificate"),
new ColumnDefinition("Binary_", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Identifier, keyTable: "Binary", keyColumn: 1, description: "Identifier to Binary table containing certificate.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("CertificatePath", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Property to path of certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("PFXPassword", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Hidden property to a pfx password", modularizeType: ColumnModularizeType.Property),
},
symbolIdIsPrimaryKey: true
);

public static readonly TableDefinition WixHttpUrlReservation = new TableDefinition(
"Wix4HttpUrlReservation",
HttpSymbolDefinitions.WixHttpUrlReservation,
Expand Down Expand Up @@ -73,7 +101,9 @@ public static class HttpTableDefinitions
WixHttpSniSslCert,
WixHttpUrlReservation,
WixHttpUrlAce,
WixHttpSslCert,
WixHttpSslCertificate,
WixHttpSslBinding,
WixHttpSslBindingCertificates,
};
}
}
14 changes: 11 additions & 3 deletions src/ext/Http/wixext/Symbols/HttpSymbolDefinitions.cs
Expand Up @@ -10,7 +10,9 @@ public enum HttpSymbolDefinitionType
WixHttpSniSslCert,
WixHttpUrlAce,
WixHttpUrlReservation,
WixHttpSslCert,
WixHttpSslBinding,
WixHttpCertificate,
WixHttpSslBindingCertificates,
}

public static partial class HttpSymbolDefinitions
Expand All @@ -34,15 +36,21 @@ public static IntermediateSymbolDefinition ByType(HttpSymbolDefinitionType type)
case HttpSymbolDefinitionType.WixHttpSniSslCert:
return HttpSymbolDefinitions.WixHttpSniSslCert;

case HttpSymbolDefinitionType.WixHttpSslCert:
return HttpSymbolDefinitions.WixHttpSslCert;
case HttpSymbolDefinitionType.WixHttpSslBinding:
return HttpSymbolDefinitions.WixHttpSslBinding;

case HttpSymbolDefinitionType.WixHttpUrlAce:
return HttpSymbolDefinitions.WixHttpUrlAce;

case HttpSymbolDefinitionType.WixHttpUrlReservation:
return HttpSymbolDefinitions.WixHttpUrlReservation;

case HttpSymbolDefinitionType.WixHttpCertificate:
return HttpSymbolDefinitions.WixHttpCertificate;

case HttpSymbolDefinitionType.WixHttpSslBindingCertificates:
return HttpSymbolDefinitions.WixHttpSslBindingCertificates;

default:
throw new ArgumentOutOfRangeException(nameof(type));
}
Expand Down
104 changes: 104 additions & 0 deletions src/ext/Http/wixext/Symbols/WixHttpCertificateSymbol.cs
@@ -0,0 +1,104 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.Http
{
using WixToolset.Data;
using WixToolset.Http.Symbols;

public static partial class HttpSymbolDefinitions
{
public static readonly IntermediateSymbolDefinition WixHttpCertificate = new IntermediateSymbolDefinition(
HttpSymbolDefinitionType.WixHttpCertificate.ToString(),
new[]
{
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.ComponentRef), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.Name), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.StoreLocation), IntermediateFieldType.Number),
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.StoreName), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.Attributes), IntermediateFieldType.Number),
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.BinaryRef), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.CertificatePath), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(HttpCertificateSymbolFields.PfxPassword), IntermediateFieldType.String),
},
typeof(WixHttpCertificateSymbol));
}
}

namespace WixToolset.Http.Symbols
{
using WixToolset.Data;
using WixToolset.Http;

public enum HttpCertificateSymbolFields
{
ComponentRef,
Name,
StoreLocation,
StoreName,
Attributes,
BinaryRef,
CertificatePath,
PfxPassword,
}

public class WixHttpCertificateSymbol : IntermediateSymbol
{
public WixHttpCertificateSymbol() : base(HttpSymbolDefinitions.WixHttpCertificate, null, null)
{
}

public WixHttpCertificateSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(HttpSymbolDefinitions.WixHttpCertificate, sourceLineNumber, id)
{
}

public IntermediateField this[HttpCertificateSymbolFields index] => this.Fields[(int)index];

public string ComponentRef
{
get => this.Fields[(int)HttpCertificateSymbolFields.ComponentRef].AsString();
set => this.Set((int)HttpCertificateSymbolFields.ComponentRef, value);
}

public string Name
{
get => this.Fields[(int)HttpCertificateSymbolFields.Name].AsString();
set => this.Set((int)HttpCertificateSymbolFields.Name, value);
}

public int StoreLocation
{
get => this.Fields[(int)HttpCertificateSymbolFields.StoreLocation].AsNumber();
set => this.Set((int)HttpCertificateSymbolFields.StoreLocation, value);
}

public string StoreName
{
get => this.Fields[(int)HttpCertificateSymbolFields.StoreName].AsString();
set => this.Set((int)HttpCertificateSymbolFields.StoreName, value);
}

public int Attributes
{
get => this.Fields[(int)HttpCertificateSymbolFields.Attributes].AsNumber();
set => this.Set((int)HttpCertificateSymbolFields.Attributes, value);
}

public string BinaryRef
{
get => this.Fields[(int)HttpCertificateSymbolFields.BinaryRef].AsString();
set => this.Set((int)HttpCertificateSymbolFields.BinaryRef, value);
}

public string CertificatePath
{
get => this.Fields[(int)HttpCertificateSymbolFields.CertificatePath].AsString();
set => this.Set((int)HttpCertificateSymbolFields.CertificatePath, value);
}

public string PfxPassword
{
get => this.Fields[(int)HttpCertificateSymbolFields.PfxPassword].AsString();
set => this.Set((int)HttpCertificateSymbolFields.PfxPassword, value);
}
}
}
55 changes: 55 additions & 0 deletions src/ext/Http/wixext/Symbols/WixHttpSslBindingCertificateSymbol.cs
@@ -0,0 +1,55 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.Http
{
using WixToolset.Data;
using WixToolset.Http.Symbols;

public static partial class HttpSymbolDefinitions
{
public static readonly IntermediateSymbolDefinition WixHttpSslBindingCertificates = new IntermediateSymbolDefinition(
HttpSymbolDefinitionType.WixHttpSslBindingCertificates.ToString(),
new[]
{
new IntermediateFieldDefinition(nameof(HttpSslBindingCertificatesSymbolFields.BindingRef), IntermediateFieldType.String),
new IntermediateFieldDefinition(nameof(HttpSslBindingCertificatesSymbolFields.CertificateRef), IntermediateFieldType.String),
},
typeof(WixHttpSslBindingCertificateSymbol));
}
}

namespace WixToolset.Http.Symbols
{
using WixToolset.Data;

public enum HttpSslBindingCertificatesSymbolFields
{
BindingRef,
CertificateRef,
}

public class WixHttpSslBindingCertificateSymbol : IntermediateSymbol
{
public WixHttpSslBindingCertificateSymbol() : base(HttpSymbolDefinitions.WixHttpSslBindingCertificates, null, null)
{
}

public WixHttpSslBindingCertificateSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(HttpSymbolDefinitions.WixHttpSslBindingCertificates, sourceLineNumber, id)
{
}

public IntermediateField this[HttpSslBindingCertificatesSymbolFields index] => this.Fields[(int)index];

public string BindingRef
{
get => this.Fields[(int)HttpSslBindingCertificatesSymbolFields.BindingRef].AsString();
set => this.Set((int)HttpSslBindingCertificatesSymbolFields.BindingRef, value);
}

public string CertificateRef
{
get => this.Fields[(int)HttpSslBindingCertificatesSymbolFields.CertificateRef].AsString();
set => this.Set((int)HttpSslBindingCertificatesSymbolFields.CertificateRef, value);
}
}
}

0 comments on commit 451ba3c

Please sign in to comment.