Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed install/FirefoxAction.CA.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions install/firefox-action/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
obj/
packages/
.vs/
32 changes: 32 additions & 0 deletions install/firefox-action/CustomAction.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">

<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.

WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.

Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.

In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true".

For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->

<supportedRuntime version="v4.0" />
<!--supportedRuntime version="v2.0.50727"/-->

</startup>

<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->

</configuration>
136 changes: 136 additions & 0 deletions install/firefox-action/FirefoxAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2019-2024 Estonian Information System Authority
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Linq;
using WixToolset.Dtf.WindowsInstaller;

namespace FirefoxAction
{
public class FirefoxActions
{
const string KEY_NAME = "ExtensionSettings";

[CustomAction]
public static ActionResult ExtensionSettingsInstall(Session session)
{
// Instead of catching and logging errors and returning ActionResult.Failure,
// we simply let all exceptions through. In both cases the installation fails
// with error status 1603, but when letting exceptions through the raw exception
// stack trace will be logged in installer log which gives more information.

var extensionSettings = session.GetExtensionSettings();
session.Log("Begin ExtensionSettingsInstall " + extensionSettings.UUID);
using (RegistryKey firefox = Utils.FirefoxKey())
{
var json = firefox.GetJSON(KEY_NAME, "{}");
json[extensionSettings.UUID] = new JObject
{
["installation_mode"] = "normal_installed",
["install_url"] = extensionSettings.URL
};
firefox.SetValue(KEY_NAME, json.ToString().Split('\n'));
return ActionResult.Success;
}
}

[CustomAction]
public static ActionResult ExtensionSettingsRemove(Session session)
{
var extensionSettings = session.GetExtensionSettings();
session.Log("Begin ExtensionSettingsRemove " + extensionSettings.UUID);
using (RegistryKey firefox = Utils.FirefoxKey())
{
var json = firefox.GetJSON(KEY_NAME);
if (json != null)
{
json[extensionSettings.UUID] = new JObject
{
["installation_mode"] = "blocked"
};
firefox.SetValue(KEY_NAME, json.ToString().Split('\n'));
}
}
return ActionResult.Success;
}
}

internal static class Utils
{
internal static (string UUID, string URL) GetExtensionSettings(this Session session)
{
// Deferred custom actions cannot directly access installer properties from session,
// only the CustomActionData property is available, see README how to populate it.
return (
session.CustomActionData["EXTENSIONSETTINGS_UUID"],
session.CustomActionData["EXTENSIONSETTINGS_URL"]
);
}

internal static RegistryKey FirefoxKey()
{
using (RegistryKey mozilla = Registry.LocalMachine.OpenOrCreateSubKey(@"Software\Policies\Mozilla", true))
{
return mozilla.OpenOrCreateSubKey(@"Firefox", true);
}
}

internal static RegistryKey OpenOrCreateSubKey(this RegistryKey registryKey, string name, bool writable = false)
{
return registryKey.OpenSubKey(name, writable) ?? registryKey.CreateSubKey(name);
}

internal static string GetStringValue(this RegistryKey registryKey, string name, string defaultValue = null)
{
if (!registryKey.GetValueNames().Any(name.Equals))
return defaultValue;
switch (registryKey.GetValueKind(name))
{
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
return (string)registryKey.GetValue(name, defaultValue);
case RegistryValueKind.MultiString:
return string.Join("\n", (string[])registryKey.GetValue(name));
default: return defaultValue;
}
}

internal static JObject GetJSON(this RegistryKey registryKey, string name, string defaultValue = null)
{
string value = registryKey.GetStringValue(name, defaultValue);
if (value == null)
{
return null;
}
try
{
return JObject.Parse(value);
}
catch (JsonReaderException)
{
return new JObject();
}
}
}
}
17 changes: 17 additions & 0 deletions install/firefox-action/FirefoxAction.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net40</TargetFramework>
<Copyright>Copyright © 2019</Copyright>
<Company>RIA</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<Content Include="CustomAction.config" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="WixToolset.Dtf.CustomAction" Version="4.0.5" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions install/firefox-action/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-2023 Estonian Information System Authority

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions install/firefox-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# WiX custom action for installing a Firefox extension with enterprise policy

*FirefoxAction* is a custom action for WiX that installs the given Firefox
extension with the Firefox enterprise policy engine.

The custom action should be added to a WiX project as follows, it must be deferred
and not use impersonation (i.e. run in privileged mode for registry access):

<Binary Id="FirefoxAction.CA.dll" SourceFile="$(sys.SOURCEFILEDIR)FirefoxAction.CA.dll" />
<CustomAction Id="ExtensionSettingsInstall" Return="check" Execute="deferred" Impersonate="no"
BinaryKey="FirefoxAction.CA.dll" DllEntry="ExtensionSettingsInstall" />
<CustomAction Id="ExtensionSettingsRemove" Return="check" Execute="deferred" Impersonate="no"
BinaryKey="FirefoxAction.CA.dll" DllEntry="ExtensionSettingsRemove" />

The Firefox extension UUID and AMO URL must be passed in via `CustomSettingsData` properties via
dedicated custom actions as follows:

<CustomAction Id="SetExtensionSettingsForInstall" Property="ExtensionSettingsInstall"
Value="EXTENSIONSETTINGS_UUID=$(var.FIREFOX_UUID);EXTENSIONSETTINGS_URL=$(var.FIREFOX_URL)" />
<CustomAction Id="SetExtensionSettingsForRemove" Property="ExtensionSettingsRemove"
Value="EXTENSIONSETTINGS_UUID=$(var.FIREFOX_UUID);EXTENSIONSETTINGS_URL=$(var.FIREFOX_URL)" />

The custom actions must be scheduled in `InstallExecuteSequence` as follows:

<InstallExecuteSequence>
<Custom Action="SetExtensionSettingsForInstall" Before="InstallInitialize" />
<Custom Action="ExtensionSettingsInstall" Before="InstallFinalize">
NOT REMOVE="ALL"
</Custom>
<Custom Action="SetExtensionSettingsForRemove" Before="InstallInitialize" />
<Custom Action="ExtensionSettingsRemove" Before="InstallFinalize">
REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE
</Custom>
</InstallExecuteSequence>

The code has been forked from the [OpenEID Windows installer project](https://github.com/open-eid/windows-installer/blob/master/FirefoxActionWix/).
6 changes: 2 additions & 4 deletions install/web-eid.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
<Launch Condition="Installed OR (VersionNT &gt;= 603)" Message="[ProductName] requires Windows 8.1 or higher." />
<ui:WixUI Id="WixUI_Minimal2" />

<!-- See https://github.com/web-eid/wix-custom-action-firefox-extension-install/blob/main/README.md and
https://github.com/web-eid/wix-custom-action-firefox-extension-install/blob/main/src/FirefoxAction.cs
-->
<Binary Id="FirefoxAction.CA.dll" SourceFile="$(sys.SOURCEFILEDIR)FirefoxAction.CA.dll" />
<!-- See install/firefox-action/FirefoxAction.cs -->
<Binary Id="FirefoxAction.CA.dll" SourceFile="$(var.FirefoxActionDll)" />
<CustomAction Id="ExtensionSettingsInstall" Return="check" Execute="deferred" Impersonate="no"
BinaryRef="FirefoxAction.CA.dll" DllEntry="ExtensionSettingsInstall" />
<CustomAction Id="ExtensionSettingsNoInstall" Return="check" Execute="deferred" Impersonate="no"
Expand Down
20 changes: 19 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ if(WIN32)
endif()
set(WEBEID_PATH web-eid.exe)
set(BASE_FILE $<TARGET_NAME:web-eid>_${PROJECT_VERSION}.$ENV{PLATFORM})
find_program(MSBUILD msbuild)
set(FIREFOX_ACTION_DLL ${CMAKE_CURRENT_BINARY_DIR}/FirefoxAction.CA.dll)
add_custom_command(
OUTPUT ${FIREFOX_ACTION_DLL}
COMMAND ${MSBUILD} ${CMAKE_SOURCE_DIR}/install/firefox-action/FirefoxAction.csproj
/restore /t:rebuild /property:Configuration=Release
"/property:OutDir=${CMAKE_CURRENT_BINARY_DIR}/"
DEPENDS
${CMAKE_SOURCE_DIR}/install/firefox-action/FirefoxAction.cs
${CMAKE_SOURCE_DIR}/install/firefox-action/FirefoxAction.csproj
${CMAKE_SOURCE_DIR}/install/firefox-action/CustomAction.config
COMMENT "Building Firefox custom action DLL"
)
add_custom_target(firefox-action DEPENDS ${FIREFOX_ACTION_DLL})
set(WIX_CMD wix.exe build -nologo
-arch $ENV{PLATFORM}
-ext WixToolset.UI.wixext
Expand All @@ -32,12 +46,13 @@ if(WIN32)
-d jsonfirefox=${CMAKE_CURRENT_BINARY_DIR}/eu.webeid.firefox.json
-d FIREFOX_URL="${FIREFOX_URL}"
-d FIREFOX_UUID="${FIREFOX_UUID}"
-d FirefoxActionDll=${FIREFOX_ACTION_DLL}
-d app_path=$<TARGET_FILE:web-eid>
${CMAKE_SOURCE_DIR}/install/web-eid.wxs
${CMAKE_SOURCE_DIR}/install/WelcomeDlg.wxs
${CMAKE_SOURCE_DIR}/install/WixUI_Minimal.wxs
)
add_custom_target(installer DEPENDS web-eid
add_custom_target(installer DEPENDS web-eid firefox-action
COMMAND ${WIX_CMD} -o "${BASE_FILE}.msi"
#Build MSI with QT
COMMAND ${WIX_CMD} -d qt_path=${Qt6_DIR}/../../../bin -o "${BASE_FILE}.qt.msi"
Expand All @@ -50,6 +65,9 @@ if(WIN32)
COMMAND ${SIGNCMD} "$<$<BOOL:${CROSSSIGNCERT}>:/ph;/ac;${CROSSSIGNCERT}>" $<TARGET_FILE:web-eid>
COMMAND_EXPAND_LISTS
)
add_custom_command(TARGET firefox-action POST_BUILD
COMMAND ${SIGNCMD} ${FIREFOX_ACTION_DLL}
)
add_custom_command(TARGET installer POST_BUILD
COMMAND ${SIGNCMD} "${BASE_FILE}.msi" "${BASE_FILE}.qt.msi"
WORKING_DIRECTORY $<TARGET_FILE_DIR:web-eid>
Expand Down
Loading