From 076b0a624bf00acdb137052e48a3ed315cac9796 Mon Sep 17 00:00:00 2001 From: Michiel Hazelhof Date: Tue, 15 Jul 2025 11:00:09 +0200 Subject: [PATCH 1/6] Upstream patches (#240) --- build.ps1 | 5 ++++- build.sh | 3 ++- generateKeys.ps1 | 3 +++ generateKeys.sh | 1 + licenseGen.ps1 | 3 +++ licenseGen.sh | 1 + src/bitBetter/Program.cs | 2 +- src/licenseGen/Dockerfile | 2 +- src/licenseGen/Program.cs | 8 +++++--- 9 files changed, 21 insertions(+), 7 deletions(-) diff --git a/build.ps1 b/build.ps1 index 54f6f6b..f3d79fc 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,3 +1,6 @@ +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $true + # define temporary directory $tempdirectory = "$pwd\temp" # define services to patch @@ -30,7 +33,7 @@ Copy-Item "$pwd\.keys\cert.cert" -Destination "$pwd\src\bitBetter" Copy-Item "$pwd\.keys\cert.pfx" -Destination "$pwd\src\licenseGen" # build bitBetter and clean the source directory after -docker build -t bitbetter/bitbetter "$pwd\src\bitBetter" +docker build --no-cache -t bitbetter/bitbetter "$pwd\src\bitBetter" Remove-Item "$pwd\src\bitBetter\cert.cert" -Force # gather all running instances diff --git a/build.sh b/build.sh index 97b544d..468e22c 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # define temporary directory TEMPDIRECTORY="$PWD/temp" @@ -33,7 +34,7 @@ cp -f "$PWD/.keys/cert.cert" "$PWD/src/bitBetter" cp -f "$PWD/.keys/cert.pfx" "$PWD/src/licenseGen" # build bitBetter and clean the source directory after -docker build -t bitbetter/bitbetter "$PWD/src/bitBetter" +docker build --no-cache -t bitbetter/bitbetter "$PWD/src/bitBetter" rm -f "$PWD/src/bitBetter/cert.cert" # gather all running instances diff --git a/generateKeys.ps1 b/generateKeys.ps1 index 690143f..d20aa14 100644 --- a/generateKeys.ps1 +++ b/generateKeys.ps1 @@ -1,3 +1,6 @@ +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $true + # get the basic openssl binary path $opensslbinary = "$Env:Programfiles\OpenSSL-Win64\bin\openssl.exe" diff --git a/generateKeys.sh b/generateKeys.sh index 4850fc2..d561aee 100755 --- a/generateKeys.sh +++ b/generateKeys.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # Check for openssl command -v openssl >/dev/null 2>&1 || { echo >&2 "openssl required but not found. Aborting."; exit 1; } diff --git a/licenseGen.ps1 b/licenseGen.ps1 index 3907946..36815d6 100644 --- a/licenseGen.ps1 +++ b/licenseGen.ps1 @@ -1,3 +1,6 @@ +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $true + if ($($args.Count) -lt 1) { echo "USAGE: [License Gen args...]" echo "ACTIONS:" diff --git a/licenseGen.sh b/licenseGen.sh index 29c9e62..3d93aa4 100755 --- a/licenseGen.sh +++ b/licenseGen.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e if [ $# -lt 1 ]; then echo "USAGE: [License Gen args...]" diff --git a/src/bitBetter/Program.cs b/src/bitBetter/Program.cs index e28030a..2d1ed78 100644 --- a/src/bitBetter/Program.cs +++ b/src/bitBetter/Program.cs @@ -29,7 +29,7 @@ internal class Program Console.WriteLine(embeddedResourceToRemove.Name); - EmbeddedResource embeddedResourceToAdd = new("Bit.Core.licensing.cer", cert) {Attributes = embeddedResourceToRemove.Attributes }; + EmbeddedResource embeddedResourceToAdd = new("Bit.Core.licensing.cer", cert) { Attributes = embeddedResourceToRemove.Attributes }; moduleDefMd.Resources.Add(embeddedResourceToAdd); moduleDefMd.Resources.Remove(embeddedResourceToRemove); diff --git a/src/licenseGen/Dockerfile b/src/licenseGen/Dockerfile index b552cca..b5aa0fb 100644 --- a/src/licenseGen/Dockerfile +++ b/src/licenseGen/Dockerfile @@ -12,4 +12,4 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 WORKDIR /app COPY --from=build /app . -ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--cert", "/app/cert.pfx" ] +ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--executable", "/app/Api", "--cert", "/app/cert.pfx" ] \ No newline at end of file diff --git a/src/licenseGen/Program.cs b/src/licenseGen/Program.cs index 160463f..581789f 100644 --- a/src/licenseGen/Program.cs +++ b/src/licenseGen/Program.cs @@ -377,7 +377,6 @@ internal class Program Set("Expires", DateTime.UtcNow.AddYears(100)); Set("Trial", false); Set("LicenseType", Enum.Parse(licenseTypeEnum, "User")); - Set("Hash", Convert.ToBase64String((Byte[])type.GetMethod("ComputeHash").Invoke(license, []))); Set("Signature", Convert.ToBase64String((Byte[])type.GetMethod("Sign").Invoke(license, [cert]))); @@ -437,8 +436,11 @@ internal class Program Set("Trial", false); Set("LicenseType", Enum.Parse(licenseTypeEnum, "Organization")); Set("LimitCollectionCreationDeletion", true); //This will be used in the new version of BitWarden but can be applied now - Set("AllowAdminAccessToAllCollectionItems", true); - Set("UseRiskInsights", true); + Set("AllowAdminAccessToAllCollectionItems", true); + Set("UseRiskInsights", true); + Set("UseOrganizationDomains", true); + Set("UseAdminSponsoredFamilies", true); + Set("UseRiskInsights", true); Set("UseOrganizationDomains", true); Set("UseAdminSponsoredFamilies", true); Set("Hash", Convert.ToBase64String((Byte[])type.GetMethod("ComputeHash").Invoke(license, []))); From 01cdfa28428b671c9de9eb7e029c0dafc1dca15f Mon Sep 17 00:00:00 2001 From: juliokele <8851893+juliokele@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:48:55 +0200 Subject: [PATCH 2/6] [unified] Fix patch according to upstream changes and fix build errors (#243) * Fix bitbetter patch according to upstream changes * Fix the builds by removing redundant already removed and stopped old instance --------- Co-authored-by: juliokele <> --- build.ps1 | 10 +++++----- build.sh | 10 +++++----- src/bitBetter/Program.cs | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build.ps1 b/build.ps1 index f3d79fc..6576d81 100644 --- a/build.ps1 +++ b/build.ps1 @@ -39,7 +39,7 @@ Remove-Item "$pwd\src\bitBetter\cert.cert" -Force # gather all running instances $oldinstances = docker container ps --all -f Name=bitwarden --format '{{.ID}}' -# stop all running instances +# stop and remove all running instances foreach ($instance in $oldinstances) { docker stop $instance docker rm $instance @@ -58,10 +58,10 @@ else } } -# stop and remove previous existing patch(ed) container -docker stop bitwarden-patch -docker rm bitwarden-patch -docker image rm bitwarden-patch +# remove previous existing patch(ed) image +if (docker image ls -q bitwarden-patch) { + docker image rm bitwarden-patch +} # start a new bitwarden instance so we can patch it $patchinstance = docker run -d --name bitwarden-patch ghcr.io/bitwarden/self-host:beta diff --git a/build.sh b/build.sh index 468e22c..f0417b1 100755 --- a/build.sh +++ b/build.sh @@ -40,7 +40,7 @@ rm -f "$PWD/src/bitBetter/cert.cert" # gather all running instances OLDINSTANCES=$(docker container ps --all -f Name=bitwarden --format '{{.ID}}') -# stop all running instances +# stop and remove all running instances for INSTANCE in ${OLDINSTANCES[@]}; do docker stop $INSTANCE docker rm $INSTANCE @@ -58,10 +58,10 @@ else fi fi -# stop and remove previous existing patch(ed) container -docker stop bitwarden-patch -docker rm bitwarden-patch -docker image rm bitwarden-patch +# remove previous existing patch(ed) image +if [ "$(docker image ls -q bitwarden-patch)" ]; then + docker image rm bitwarden-patch +fi # start a new bitwarden instance so we can patch it PATCHINSTANCE=$(docker run -d --name bitwarden-patch ghcr.io/bitwarden/self-host:beta) diff --git a/src/bitBetter/Program.cs b/src/bitBetter/Program.cs index 2d1ed78..c6c067e 100644 --- a/src/bitBetter/Program.cs +++ b/src/bitBetter/Program.cs @@ -41,7 +41,7 @@ internal class Program Console.WriteLine($"New Cert Thumbprint: {certificate.Thumbprint}"); - IEnumerable services = moduleDefMd.Types.Where(t => t.Namespace == "Bit.Core.Services"); + IEnumerable services = moduleDefMd.Types.Where(t => t.Namespace == "Bit.Core.Billing.Services"); TypeDef type = services.First(t => t.Name == "LicensingService"); MethodDef constructor = type.FindConstructors().First(); From a3803cb3bc4fa08017094e69fca616821a74604f Mon Sep 17 00:00:00 2001 From: juliokele <8851893+juliokele@users.noreply.github.com> Date: Tue, 29 Jul 2025 19:49:52 +0200 Subject: [PATCH 3/6] [unified] Fix licenseGen according to upstream changes (#247) * Dockerfile: remove not existing executable argument * licenseGen: fix classes according to upstream changes --------- Co-authored-by: juliokele <> --- src/licenseGen/Dockerfile | 2 +- src/licenseGen/Program.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/licenseGen/Dockerfile b/src/licenseGen/Dockerfile index b5aa0fb..2b5d261 100644 --- a/src/licenseGen/Dockerfile +++ b/src/licenseGen/Dockerfile @@ -12,4 +12,4 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 WORKDIR /app COPY --from=build /app . -ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--executable", "/app/Api", "--cert", "/app/cert.pfx" ] \ No newline at end of file +ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--cert", "/app/cert.pfx" ] \ No newline at end of file diff --git a/src/licenseGen/Program.cs b/src/licenseGen/Program.cs index 581789f..71149cf 100644 --- a/src/licenseGen/Program.cs +++ b/src/licenseGen/Program.cs @@ -53,7 +53,7 @@ internal class Program } Console.WriteLine("Interactive license mode..."); - + while (licenseType == "") { Console.WriteLine("What would you like to generate, a [u]ser license or an [o]rg license: "); @@ -238,7 +238,7 @@ internal class Program CommandArgument storage = config.Argument("Storage", "extra storage space in GB. Maximum is " + Int16.MaxValue + " (optional, default = max)"); CommandArgument businessName = config.Argument("BusinessName", "name for the organization (optional)"); CommandArgument key = config.Argument("Key", "your key id (optional)"); - + config.OnExecute(() => { if (!VerifyTopOptions()) @@ -360,7 +360,7 @@ internal class Program { Assembly core = AssemblyLoadContext.Default.LoadFromAssemblyPath(corePath); - Type type = core.GetType("Bit.Core.Models.Business.UserLicense"); + Type type = core.GetType("Bit.Core.Billing.Models.Business.UserLicense"); Type licenseTypeEnum = core.GetType("Bit.Core.Enums.LicenseType"); Object license = Activator.CreateInstance(type); @@ -393,7 +393,7 @@ internal class Program { Assembly core = AssemblyLoadContext.Default.LoadFromAssemblyPath(corePath); - Type type = core.GetType("Bit.Core.Models.Business.OrganizationLicense"); + Type type = core.GetType("Bit.Core.Billing.Models.Business.OrganizationLicense"); Type licenseTypeEnum = core.GetType("Bit.Core.Enums.LicenseType"); Type planTypeEnum = core.GetType("Bit.Core.Billing.Enums.PlanType"); From 34da077778e02d1ca9d9dd154673487e483aca49 Mon Sep 17 00:00:00 2001 From: Joseph Gigantino <128943406+Jgigantino31@users.noreply.github.com> Date: Tue, 29 Jul 2025 13:54:54 -0400 Subject: [PATCH 4/6] Update Program.cs (#241) Remove duplicate instances of: Set("UseRiskInsights", true); Set("UseOrganizationDomains", true); Set("UseAdminSponsoredFamilies", true); Signed-off-by: Joseph Gigantino <128943406+Jgigantino31@users.noreply.github.com> Co-authored-by: h44z --- src/licenseGen/Program.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/licenseGen/Program.cs b/src/licenseGen/Program.cs index 71149cf..c8b9ea0 100644 --- a/src/licenseGen/Program.cs +++ b/src/licenseGen/Program.cs @@ -440,9 +440,6 @@ internal class Program Set("UseRiskInsights", true); Set("UseOrganizationDomains", true); Set("UseAdminSponsoredFamilies", true); - Set("UseRiskInsights", true); - Set("UseOrganizationDomains", true); - Set("UseAdminSponsoredFamilies", true); Set("Hash", Convert.ToBase64String((Byte[])type.GetMethod("ComputeHash").Invoke(license, []))); Set("Signature", Convert.ToBase64String((Byte[])type.GetMethod("Sign").Invoke(license, [cert]))); From 3689cc5ba1e40c33c438da4f758783df23ba883c Mon Sep 17 00:00:00 2001 From: Joseph Gigantino <128943406+Jgigantino31@users.noreply.github.com> Date: Wed, 30 Jul 2025 13:51:51 -0400 Subject: [PATCH 5/6] Test generating user and organization licenses during build check (#251) Add commands to build check to test if the created licensegen image can actually generate user and organization licenses. licenseGen.sh will print the generated license to stdout and return zero if successful. If an error occurs, a non zero error code is returned which should cause a build error. --- .circleci/config.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6bbf697..acb6ba1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,4 +12,10 @@ jobs: command: ./generateKeys.sh - run: name: Build script - command: ./build.sh y \ No newline at end of file + command: ./build.sh y + - run: + name: Test generating user license + command: ./licenseGen.sh user TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23 + - run: + name: Test generating organization license + command: ./licenseGen.sh org TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23 From 29add2412656c8e656934e02baf54d955dfcee54 Mon Sep 17 00:00:00 2001 From: juliokele <8851893+juliokele@users.noreply.github.com> Date: Sun, 3 Aug 2025 18:11:30 +0200 Subject: [PATCH 6/6] licenseGen: fix OrganizationLicense namespace (#253) Co-authored-by: juliokele <> --- src/licenseGen/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/licenseGen/Program.cs b/src/licenseGen/Program.cs index c8b9ea0..e66b61d 100644 --- a/src/licenseGen/Program.cs +++ b/src/licenseGen/Program.cs @@ -393,7 +393,7 @@ internal class Program { Assembly core = AssemblyLoadContext.Default.LoadFromAssemblyPath(corePath); - Type type = core.GetType("Bit.Core.Billing.Models.Business.OrganizationLicense"); + Type type = core.GetType("Bit.Core.Billing.Organizations.Models.OrganizationLicense"); Type licenseTypeEnum = core.GetType("Bit.Core.Enums.LicenseType"); Type planTypeEnum = core.GetType("Bit.Core.Billing.Enums.PlanType");