Skip to content

Commit

Permalink
add firewall extension decompiler, make msi modifications work, add s…
Browse files Browse the repository at this point in the history
…ervice name, edge traversal and interface type attributes
  • Loading branch information
chrisbednarski committed Jul 30, 2023
1 parent 5e9901d commit 3565918
Show file tree
Hide file tree
Showing 11 changed files with 1,097 additions and 307 deletions.
780 changes: 580 additions & 200 deletions src/ext/Firewall/ca/firewall.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace WixToolsetTest.Firewall
using WixInternal.Core.TestPackage;
using WixToolset.Firewall;
using Xunit;
using System.IO;
using System.Xml.Linq;

public class FirewallExtensionFixture
{
Expand All @@ -25,8 +27,10 @@ public void CanBuildUsingFirewall()
"CustomAction:Wix4RollbackFirewallExceptionsUninstall_X86\t3329\tWix4FWCA_X86\tExecFirewallExceptions\t",
"CustomAction:Wix4SchedFirewallExceptionsInstall_X86\t1\tWix4FWCA_X86\tSchedFirewallExceptionsInstall\t",
"CustomAction:Wix4SchedFirewallExceptionsUninstall_X86\t1\tWix4FWCA_X86\tSchedFirewallExceptionsUninstall\t",
"Wix4FirewallException:ExampleFirewall\tExampleApp\t*\t42\t6\t[#filNdJBJmq3UCUIwmXS8x21aAsvqzk]\t0\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tAn app-based firewall exception\t1",
"Wix4FirewallException:fex70IVsYNnbwiHQrEepmdTPKH8XYs\tExamplePort\tLocalSubnet\t42\t6\t\t0\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception\t2",
"Wix4FirewallException:ExampleFirewall\tExampleApp\t*\t42\t6\t[#filNdJBJmq3UCUIwmXS8x21aAsvqzk]\t4\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tAn app-based firewall exception\t1\t\tAll\t\t",
"Wix4FirewallException:fex70IVsYNnbwiHQrEepmdTPKH8XYs\tExamplePort\tLocalSubnet\t42\t6\t\t5\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception\t2\tftpsrv\tLan\t\t",
"Wix4FirewallException:fexiVb_lnYx2.K.OSyNlgawFJVTqEw\tdefertouser\t\t\t\tfw.exe\t4\t\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDefer to user edge traversal\t1\t\t\t3\t",
"Wix4FirewallException:ServiceInstall.nested\tExamplePort\tLocalSubnet\t3546-7890\t6\t\t5\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception for a windows service\t1\tsvc1\tWireless,Lan,RemoteAccess\t1\t",
}, results);
}

Expand All @@ -45,11 +49,37 @@ public void CanBuildUsingFirewallARM64()
"CustomAction:Wix4RollbackFirewallExceptionsUninstall_A64\t3329\tWix4FWCA_A64\tExecFirewallExceptions\t",
"CustomAction:Wix4SchedFirewallExceptionsInstall_A64\t1\tWix4FWCA_A64\tSchedFirewallExceptionsInstall\t",
"CustomAction:Wix4SchedFirewallExceptionsUninstall_A64\t1\tWix4FWCA_A64\tSchedFirewallExceptionsUninstall\t",
"Wix4FirewallException:ExampleFirewall\tExampleApp\t*\t42\t6\t[#filNdJBJmq3UCUIwmXS8x21aAsvqzk]\t0\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tAn app-based firewall exception\t1",
"Wix4FirewallException:fex70IVsYNnbwiHQrEepmdTPKH8XYs\tExamplePort\tLocalSubnet\t42\t6\t\t0\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception\t2",
"Wix4FirewallException:ExampleFirewall\tExampleApp\t*\t42\t6\t[#filNdJBJmq3UCUIwmXS8x21aAsvqzk]\t4\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tAn app-based firewall exception\t1\t\tAll\t\t",
"Wix4FirewallException:fex70IVsYNnbwiHQrEepmdTPKH8XYs\tExamplePort\tLocalSubnet\t42\t6\t\t5\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception\t2\tftpsrv\tLan\t\t",
"Wix4FirewallException:fexiVb_lnYx2.K.OSyNlgawFJVTqEw\tdefertouser\t\t\t\tfw.exe\t4\t\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tDefer to user edge traversal\t1\t\t\t3\t",
"Wix4FirewallException:ServiceInstall.nested\tExamplePort\tLocalSubnet\t3546-7890\t6\t\t5\t2147483647\tfilNdJBJmq3UCUIwmXS8x21aAsvqzk\tA port-based firewall exception for a windows service\t1\tsvc1\tWireless,Lan,RemoteAccess\t1\t",
}, results);
}

[Fact]
public void CanRoundtripFirewallExceptions()
{
var folder = TestData.Get(@"TestData", "UsingFirewall");
var build = new Builder(folder, typeof(FirewallExtensionFactory), new[] { folder });
var output = Path.Combine(folder, "FirewallExceptionDecompile.xml");

build.BuildAndDecompileAndBuild(Build, Decompile, output);

var doc = XDocument.Load(output);
var firewallElementNames = doc.Descendants().Where(e => e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/firewall")
.Select(e => e.Name.LocalName)
.ToArray();

WixAssert.CompareLineByLine(new[]
{
"FirewallException",
"FirewallException",
"FirewallException",
"FirewallException",
}, firewallElementNames);
}


private static void Build(string[] args)
{
var result = WixRunner.Execute(args);
Expand All @@ -65,5 +95,10 @@ private static void BuildARM64(string[] args)
var result = WixRunner.Execute(newArgs.ToArray());
result.AssertSuccess();
}
private static void Decompile(string[] args)
{
var result = WixRunner.Execute(args);
result.AssertSuccess();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:fw="http://wixtoolset.org/schemas/v4/wxs/firewall">
xmlns:fw="http://wixtoolset.org/schemas/v4/wxs/firewall"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component>
<File Name="fw.exe" Source="example.txt">
<Shortcut Id="FwShortcut" Directory="INSTALLFOLDER" Name="Firewall" />
<fw:FirewallException Id="ExampleFirewall" Description="An app-based firewall exception" Name="ExampleApp" Port="42">
<fw:FirewallException Id="ExampleFirewall" Description="An app-based firewall exception" Name="ExampleApp" Port="42" InterfaceTypes="2147483647">
<fw:RemoteAddress Value="*" />
</fw:FirewallException>
</File>

<fw:FirewallException Description="A port-based firewall exception" Name="ExamplePort" Port="42" Outbound="yes" Scope="localSubnet" />
<fw:FirewallException Description="A port-based firewall exception" Name="ExamplePort" Port="42" Outbound="yes" Scope="localSubnet" Service="ftpsrv" IgnoreFailure="yes" InterfaceTypes="2"/>

<ServiceInstall Name="svc1" Type="ownProcess" Start="disabled" ErrorControl="ignore" >
<fw:FirewallException Id="ServiceInstall.nested" EdgeTraversal="Allow" IgnoreFailure="true" Description="A port-based firewall exception for a windows service" Name="ExamplePort" Port="3546-7890" Outbound="no" Scope="localSubnet" InterfaceTypes="7"/>
</ServiceInstall>

<fw:FirewallException Description="Defer to user edge traversal" Name="defertouser" Program="fw.exe" EdgeTraversal="DeferToUser" />
</Component>
</ComponentGroup>
</Fragment>
Expand Down
Loading

0 comments on commit 3565918

Please sign in to comment.