Compare commits

...

23 Commits

Author SHA1 Message Date
h44z
31a08b7e89 fix error message after build (#263), improve readme (#266) 2025-12-09 22:04:28 +01:00
Michiel Hazelhof
5387d1803d Add note for the new lite version (#268)
Not sure about the correct url
2025-12-09 21:14:00 +01:00
captainhook
2c9e4fd9fa Enhance build script to support multi-platform builds and improve Docker build experience (#262)
* Enhance build script to support multi-platform builds and improve Docker build experience

* Update build.sh

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Correct value for --platform argument

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-12 19:01:34 +02:00
h44z
0e2c9d42aa Fix path of OrganizationLicense object (#254)
* Fix path of OrganizationLicense object (see https://github.com/bitwarden/server/tree/main/src/Core/Billing/Organizations/Models)
2025-08-10 10:53:29 +02:00
Joseph Gigantino
063ab1d316 Test generating user and organization licenses during build check (#252)
Add commands to build check to build licensegen image as well and test if the created licensegen image can actually generate user and organization licenses. run.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.

Signed-off-by: Joseph Gigantino <128943406+Jgigantino31@users.noreply.github.com>
2025-07-30 19:15:45 +02:00
h44z
df9e74bb7a Fix license generator according to upstream changes (#245) (#249) 2025-07-29 21:08:44 +00:00
Joseph Gigantino
ac01b0c7ec Update build.sh (#246)
Match change in upstream location of LicensingService.cs

Signed-off-by: Joseph Gigantino <128943406+Jgigantino31@users.noreply.github.com>
2025-07-29 19:45:55 +02:00
Pablo
f3e36ab404 [Fix] TRUSTED CERTIFICATE (#238)
Fix for this error:

unable to load certificate
140067633099200:error:0909006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
2025-07-11 05:10:23 -07:00
Lorenzo Moscati
b9c46fffb2 Update Program.cs (#237)
Set three new license options to true: UseRiskInsights, UseOrganizationDomains, and UseAdminSponsoredFamilies.
2025-07-10 22:43:22 +00:00
Genva
047c4ddf6f Build image from source (#234)
* Build image from source

* Clone only current version tag

* remove obsolete project

* support loading Core.dll from single file application

* pass single file application to license gen

* remove loose file parameter

* fix executable parameter

* Remove unnecessary changes in LicensingService.cs

* Revert "Remove unnecessary changes in LicensingService.cs"

This reverts commit d8465e1aec.

* Changed comment
2025-07-09 01:04:58 +00:00
h44z
676dd7b85c Fix warning in Dockerfile (#230) 2025-05-17 14:22:29 +00:00
Lorenzo Moscati
0b33567820 Updated container repository (#225)
Updated the container image registries from Docker Hub to GitHub Container Registry. Fixes #224
2025-03-29 17:16:26 +00:00
Alessandro
180ad94838 Move Manually generating Certificate & Key section in README.md (#216)
Move `Manually generating Certificate & Key` section from `Building BitBetter` to `Setting up BitBetter` and mark it as `Optional` instead of `Note`.

Co-authored-by: h44z <christoph.h@sprinternet.at>
2024-11-24 19:10:11 +01:00
vdmchkv
38c43a43c9 Prevent docker compose from attempting to pull BitBetter images from the Docker repository (#219)
Co-authored-by: Vadim Iouchkov <vadim.iouchkov@d-gl.de>
2024-11-24 19:02:48 +01:00
Michiel Hazelhof
bfc821e918 Update documentation to reflect changes (#214) 2024-11-03 10:22:14 +01:00
Michiel Hazelhof
3ec7b3d843 Quick and dirty fix (#213)
* Quick and dirty fix

* Don't push obsolete code

* Improve code
2024-11-01 14:36:03 +00:00
Shuttleu
7f64e2cd4a Update license to version 15 (#211)
Co-authored-by: captainhook <16797541+captainhook@users.noreply.github.com>
2024-10-10 14:29:59 +01:00
Michiel Hazelhof
a65277198c Use new location (#202) 2024-06-30 01:33:01 +00:00
kasperk81
12da7d7249 use correct framework (#193)
* use correct framework

* use correct framework
2024-03-30 09:31:27 +00:00
Jan Schöppach
3c703f517d Update to .NET 8.0 to fix building with bitwarden v2024.2.2 (#187)
* Update to .NET 8.0 to fix building with bitwarden v2024.2.2

* Also update license gen to .NET 8.0
2024-02-22 23:16:34 +00:00
Rakesh
b93c9487eb Update License to use Secrets Manager fully (#182) 2024-01-19 18:02:14 +00:00
Ayitaka
e173c06320 Updated license version to 12, added SM options, increased max seats (short to int) (#172)
* - Updated license version to 12
- Added new SM license options

* Change seats, smseats, smserviceaccounts from short to int, like they are in the Bitwarden server code, to allow for the accurate maximum amount of seats
2023-11-29 12:07:21 +00:00
Ayitaka
80c0808e72 Update licenseGen with latest version and options (#165)
- Changed Version to 10
- Uncommented UseScim
- Added UseCustomPermissions
2023-04-21 14:24:41 +02:00
11 changed files with 161 additions and 233 deletions

View File

@@ -13,3 +13,12 @@ jobs:
- run:
name: Build script
command: ./build.sh
- run:
name: Build licenseGen
command: ./src/licenseGen/build.sh
- run:
name: Test generating user license
command: ./src/licenseGen/run.sh ./.keys/cert.pfx user TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23
- run:
name: Test generating organization license
command: ./src/licenseGen/run.sh ./.keys/cert.pfx org TestName TestEmail@example.com 4a619d4a-522d-4c70-8596-affb5b607c23

View File

@@ -4,6 +4,8 @@ BitBetter is is a tool to modify Bitwarden's core dll to allow you to generate y
Please see the FAQ below for details on why this software was created.
Looking for a solution to the Lite (formerly unified) version of bitwarden, [go to the Lite branch](../../tree/lite).
_Beware! BitBetter does janky stuff to rewrite the bitwarden core dll and allow the installation of a self signed certificate. Use at your own risk!_
Credit to https://github.com/h44z/BitBetter and https://github.com/jakeswenson/BitBetter
@@ -14,8 +16,8 @@ Credit to https://github.com/h44z/BitBetter and https://github.com/jakeswenson/B
- [Getting Started](#getting-started)
- [Dependencies](#dependencies)
- [Setting up BitBetter](#setting-up-bitbetter)
- [Optional: Manually generating Certificate & Key](#optional-manually-generating-certificate--key)
- [Building BitBetter](#building-bitbetter)
- [Note: Manually generating Certificate & Key](#note-manually-generating-certificate--key)
- [Updating Bitwarden and BitBetter](#updating-bitwarden-and-bitbetter)
- [Generating Signed Licenses](#generating-signed-licenses)
- [Note: Alternative Ways to Generate License](#note-alternative-ways-to-generate-license)
@@ -40,6 +42,21 @@ With your dependencies installed, begin the installation of BitBetter by downloa
git clone https://github.com/jakeswenson/BitBetter.git
```
### Optional: Manually generating Certificate & Key
If you wish to generate your self-signed cert & key manually, you can run the following commands.
```bash
cd .keys
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.cert -days 36500 -outform DER -passout pass:test
openssl x509 -inform DER -in cert.cert -out cert.pem
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem -passin pass:test -passout pass:test
```
> Note that the password here must be `test`.<sup>[1](#f1)</sup>
---
## Building BitBetter
Now that you've set up your build environment, you can **run the main build script** to generate a modified version of the `bitwarden/api` and `bitwarden/identity` docker images.
@@ -54,14 +71,14 @@ This will create a new self-signed certificate in the `.keys` directory if one d
You may now simply create the file `/path/to/bwdata/docker/docker-compose.override.yml` with the following contents to utilize the modified images.
```yaml
version: '3'
services:
api:
image: bitbetter/api
pull_policy: never
identity:
image: bitbetter/identity
pull_policy: never
```
You'll also want to edit the `/path/to/bwdata/scripts/run.sh` file. In the `function restart()` block, comment out the call to `dockerComposePull`.
@@ -70,19 +87,6 @@ You'll also want to edit the `/path/to/bwdata/scripts/run.sh` file. In the `func
You can now start or restart Bitwarden as normal and the modified api will be used. **It is now ready to accept self-issued licenses.**
---
### Note: Manually generating Certificate & Key
If you wish to generate your self-signed cert & key manually, you can run the following commands.
```bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.cert -days 36500 -outform DER -passout pass:test
openssl x509 -inform DER -in cert.cert -out cert.pem
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem -passin pass:test -passout pass:test
```
> Note that the password here must be `test`.<sup>[1](#f1)</sup>
---
## Updating Bitwarden and BitBetter

View File

@@ -1,22 +1,62 @@
#!/bin/sh
set -e
DIR=`dirname "$0"`
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
BW_VERSION=$(curl -sL https://go.btwrdn.co/bw-sh-versions | grep '^ *"'coreVersion'":' | awk -F\: '{ print $2 }' | sed -e 's/,$//' -e 's/^"//' -e 's/"$//')
echo "Building BitBetter for BitWarden version $BW_VERSION"
# Enable BuildKit for better build experience and to ensure platform args are populated
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
# Determine host architecture to use as default BUILDPLATFORM / TARGETPLATFORM if not supplied.
# Allow override via environment variables when invoking the script.
HOST_UNAME_ARCH=$(uname -m 2>/dev/null || echo unknown)
case "$HOST_UNAME_ARCH" in
x86_64|amd64) DEFAULT_ARCH=amd64 ;;
aarch64|arm64) DEFAULT_ARCH=arm64 ;;
armv7l|armv7) DEFAULT_ARCH=arm/v7 ;;
*) DEFAULT_ARCH=amd64 ;;
esac
: "${BUILDPLATFORM:=linux/${DEFAULT_ARCH}}"
: "${TARGETPLATFORM:=linux/${DEFAULT_ARCH}}"
echo "Using BUILDPLATFORM=$BUILDPLATFORM TARGETPLATFORM=$TARGETPLATFORM"
# If there aren't any keys, generate them first.
[ -e "$DIR/.keys/cert.cert" ] || "$DIR/.keys/generate-keys.sh"
[ -e "$DIR/src/bitBetter/.keys" ] || mkdir "$DIR/src/bitBetter/.keys"
# Prepare Bitwarden server repository
rm -rf $DIR/server
git clone --branch "v${BW_VERSION}" --depth 1 https://github.com/bitwarden/server.git $DIR/server
cp "$DIR/.keys/cert.cert" "$DIR/src/bitBetter/.keys"
# Replace certificate file and thumbprint
old_thumbprint=$(openssl x509 -inform DER -fingerprint -noout -in $DIR/server/src/Core/licensing.cer | cut -d= -f2 | tr -d ':')
new_thumbprint=$(openssl x509 -inform DER -fingerprint -noout -in $DIR/.keys/cert.cert | cut -d= -f2 | tr -d ':')
sed -i -e "s/$old_thumbprint/$new_thumbprint/g" $DIR/server/src/Core/Billing/Services/Implementations/LicensingService.cs
cp $DIR/.keys/cert.cert $DIR/server/src/Core/licensing.cer
docker run --rm -v "$DIR/src/bitBetter:/bitBetter" -w=/bitBetter mcr.microsoft.com/dotnet/sdk:6.0 sh build.sh
docker build \
--no-cache \
--platform "$TARGETPLATFORM" \
--build-arg BUILDPLATFORM="$BUILDPLATFORM" \
--build-arg TARGETPLATFORM="$TARGETPLATFORM" \
--label com.bitwarden.product="bitbetter" \
-f $DIR/server/src/Api/Dockerfile \
-t bitbetter/api \
$DIR/server
docker build --no-cache --build-arg BITWARDEN_TAG=bitwarden/api:$BW_VERSION --label com.bitwarden.product="bitbetter" -t bitbetter/api "$DIR/src/bitBetter" # --squash
docker build --no-cache --build-arg BITWARDEN_TAG=bitwarden/identity:$BW_VERSION --label com.bitwarden.product="bitbetter" -t bitbetter/identity "$DIR/src/bitBetter" # --squash
docker build \
--no-cache \
--platform "$TARGETPLATFORM" \
--build-arg BUILDPLATFORM="$BUILDPLATFORM" \
--build-arg TARGETPLATFORM="$TARGETPLATFORM" \
--label com.bitwarden.product="bitbetter" \
-f $DIR/server/src/Identity/Dockerfile \
-t bitbetter/identity \
$DIR/server
docker tag bitbetter/api bitbetter/api:latest
docker tag bitbetter/identity bitbetter/identity:latest
@@ -24,5 +64,5 @@ docker tag bitbetter/api bitbetter/api:$BW_VERSION
docker tag bitbetter/identity bitbetter/identity:$BW_VERSION
# Remove old instances of the image after a successful build.
ids=$( docker images bitbetter/* | grep -E -v -- "CREATED|latest|${BW_VERSION}" | awk '{ print $3 }' )
ids=$( docker image ls --format="{{ .ID }} {{ .Tag }}" 'bitbetter/*' | grep -E -v -- "CREATED|latest|${BW_VERSION}" | awk '{ ids = (ids ? ids FS $1 : $1) } END { print ids }' )
[ -n "$ids" ] && docker rmi $ids || true

View File

@@ -1,11 +0,0 @@
ARG BITWARDEN_TAG
FROM ${BITWARDEN_TAG}
COPY bin/Debug/netcoreapp6.0/publish/* /bitBetter/
COPY ./.keys/cert.cert /newLicensing.cer
RUN set -e; set -x; \
dotnet /bitBetter/bitBetter.dll && \
mv /app/Core.dll /app/Core.orig.dll && \
mv /app/modified.dll /app/Core.dll && \
rm -rf /bitBetter && rm -rf /newLicensing.cer

View File

@@ -1,93 +0,0 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
namespace bitwardenSelfLicensor
{
class Program
{
static int Main(string[] args)
{
string cerFile;
string corePath;
if(args.Length >= 2) {
cerFile = args[0];
corePath = args[1];
} else if (args.Length == 1) {
cerFile = args[0];
corePath = "/app/Core.dll";
}
else {
cerFile = "/newLicensing.cer";
corePath = "/app/Core.dll";
}
var module = ModuleDefinition.ReadModule(new MemoryStream(File.ReadAllBytes(corePath)));
var cert = File.ReadAllBytes(cerFile);
var x = module.Resources.OfType<EmbeddedResource>()
.Where(r => r.Name.Equals("Bit.Core.licensing.cer"))
.First();
Console.WriteLine(x.Name);
var e = new EmbeddedResource("Bit.Core.licensing.cer", x.Attributes, cert);
module.Resources.Add(e);
module.Resources.Remove(x);
var services = module.Types.Where(t => t.Namespace == "Bit.Core.Services");
var type = services.First(t => t.Name == "LicensingService");
var licensingType = type.Resolve();
var existingCert = new X509Certificate2(x.GetResourceData());
Console.WriteLine($"Existing Cert Thumbprint: {existingCert.Thumbprint}");
X509Certificate2 certificate = new X509Certificate2(cert);
Console.WriteLine($"New Cert Thumbprint: {certificate.Thumbprint}");
var ctor = licensingType.GetConstructors().Single();
var rewriter = ctor.Body.GetILProcessor();
var instToReplace =
ctor.Body.Instructions.Where(i => i.OpCode == OpCodes.Ldstr
&& string.Equals((string)i.Operand, existingCert.Thumbprint, StringComparison.InvariantCultureIgnoreCase))
.FirstOrDefault();
if(instToReplace != null) {
rewriter.Replace(instToReplace, Instruction.Create(OpCodes.Ldstr, certificate.Thumbprint));
}
else {
Console.WriteLine("Cant find inst");
}
// foreach (var inst in ctor.Body.Instructions)
// {
// Console.Write(inst.OpCode.Name + " " + inst.Operand?.GetType() + " = ");
// if(inst.OpCode.FlowControl == FlowControl.Call) {
// Console.WriteLine(inst.Operand);
// }
// else if(inst.OpCode == OpCodes.Ldstr) {
// Console.WriteLine(inst.Operand);
// }
// else {Console.WriteLine();}
// }
module.Write("modified.dll");
return 0;
}
}
}

View File

@@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
</ItemGroup>
</Project>

View File

@@ -1,7 +0,0 @@
#!/bin/bash
set -e
set -x
dotnet restore
dotnet publish

View File

@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /licenseGen
@@ -12,6 +12,6 @@ RUN set -e; set -x; \
FROM bitbetter/api
COPY --from=build /licenseGen/bin/Debug/netcoreapp6.0/publish/* /app/
COPY --from=build /licenseGen/bin/Release/net8.0/publish/* /app/
ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--cert", "/cert.pfx" ]
ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--executable", "/app/Api", "--cert", "/cert.pfx" ]

View File

@@ -1,38 +1,40 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.Loader;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Extensions.CommandLineUtils;
using Newtonsoft.Json;
namespace bitwardenSelfLicensor
namespace BitwardenSelfLicensor
{
class Program
using Microsoft.Extensions.CommandLineUtils;
using Newtonsoft.Json;
using SingleFileExtractor.Core;
using System;
using System.IO;
using System.Runtime.Loader;
using System.Security.Cryptography.X509Certificates;
public static class Program
{
static int Main(string[] args)
public static int Main(string[] args)
{
var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication();
var app = new CommandLineApplication();
var cert = app.Option("--cert", "cert file", CommandOptionType.SingleValue);
var coreDll = app.Option("--core", "path to core dll", CommandOptionType.SingleValue);
var exec = app.Option("--executable", "path to Bitwarden single file executable", CommandOptionType.SingleValue);
bool certExists()
bool ExecExists() => File.Exists(exec.Value());
bool CertExists() => File.Exists(cert.Value());
bool CoreExists() => File.Exists(coreDll.Value());
bool VerifyTopOptions() =>
!string.IsNullOrWhiteSpace(cert.Value()) &&
(!string.IsNullOrWhiteSpace(coreDll.Value()) || !string.IsNullOrWhiteSpace(exec.Value())) &&
CertExists() &&
(CoreExists() || ExecExists());
string GetExtractedDll()
{
return File.Exists(cert.Value());
var coreDllPath = Path.Combine("extract", "Core.dll");
var reader = new ExecutableReader(exec.Value());
reader.ExtractToDirectory("extract");
var fileInfo = new FileInfo(coreDllPath);
return fileInfo.FullName;
}
bool coreExists()
{
return File.Exists(coreDll.Value());
}
bool verifyTopOptions()
{
return !string.IsNullOrWhiteSpace(cert.Value()) &&
!string.IsNullOrWhiteSpace(coreDll.Value()) &&
certExists() && coreExists();
}
string GetCoreDllPath() => CoreExists() ? coreDll.Value() : GetExtractedDll();
app.Command("interactive", config =>
{
string buff="", licensetype="", name="", email="", businessname="";
@@ -43,11 +45,11 @@ namespace bitwardenSelfLicensor
config.OnExecute(() =>
{
if (!verifyTopOptions())
if (!VerifyTopOptions())
{
if (!coreExists()) config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
if (!certExists()) config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
if (!ExecExists() && !string.IsNullOrWhiteSpace(exec.Value())) config.Error.WriteLine($"Cant find single file executable at: {exec.Value()}");
if (!CoreExists() && !string.IsNullOrWhiteSpace(coreDll.Value())) config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
if (!CertExists()) config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
config.ShowHelp();
return 1;
}
@@ -92,7 +94,7 @@ namespace bitwardenSelfLicensor
WriteLineOver("Please enter a business name, default is BitBetter. [Business Name]:");
buff = Console.ReadLine();
if (buff == "") businessname = "BitBetter";
else if (checkBusinessName(buff)) businessname = buff;
else if (CheckBusinessName(buff)) businessname = buff;
}
}
else
@@ -105,14 +107,14 @@ namespace bitwardenSelfLicensor
{
WriteLineOver("Please provide the username this license will be registered to. [username]:");
buff = Console.ReadLine();
if ( checkUsername(buff) ) name = buff;
if ( CheckUsername(buff) ) name = buff;
}
while (email == "")
{
WriteLineOver("Please provide the email address for the user " + name + ". [email]");
buff = Console.ReadLine();
if ( checkEmail(buff) ) email = buff;
if ( CheckEmail(buff) ) email = buff;
}
while (storage == 0)
@@ -125,7 +127,7 @@ namespace bitwardenSelfLicensor
}
else
{
if (checkStorage(buff)) storage = short.Parse(buff);
if (CheckStorage(buff)) storage = short.Parse(buff);
}
}
@@ -135,7 +137,7 @@ namespace bitwardenSelfLicensor
buff = Console.ReadLine();
if ( buff == "" || buff == "y" || buff == "Y" )
{
GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, storage, guid, null);
GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), GetCoreDllPath(), name, email, storage, guid, null);
}
else
{
@@ -149,7 +151,7 @@ namespace bitwardenSelfLicensor
buff = Console.ReadLine();
if ( buff == "" || buff == "y" || buff == "Y" )
{
GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, storage, installid, businessname, null);
GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), GetCoreDllPath(), name, email, storage, installid, businessname, null);
}
else
{
@@ -173,17 +175,11 @@ namespace bitwardenSelfLicensor
config.OnExecute(() =>
{
if (!verifyTopOptions())
if (!VerifyTopOptions())
{
if (!coreExists())
{
config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
}
if (!certExists())
{
config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
}
if (!ExecExists() && !string.IsNullOrWhiteSpace(exec.Value())) config.Error.WriteLine($"Cant find single file executable at: {exec.Value()}");
if (!CoreExists() && !string.IsNullOrWhiteSpace(coreDll.Value())) config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
if (!CertExists()) config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
config.ShowHelp();
return 1;
}
@@ -214,7 +210,7 @@ namespace bitwardenSelfLicensor
storageShort = (short) parsedStorage;
}
GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, storageShort, userId, key.Value);
GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), GetCoreDllPath(), name.Value, email.Value, storageShort, userId, key.Value);
return 0;
});
@@ -231,17 +227,11 @@ namespace bitwardenSelfLicensor
config.OnExecute(() =>
{
if (!verifyTopOptions())
if (!VerifyTopOptions())
{
if (!coreExists())
{
config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
}
if (!certExists())
{
config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
}
if (!ExecExists() && !string.IsNullOrWhiteSpace(exec.Value())) config.Error.WriteLine($"Cant find single file executable at: {exec.Value()}");
if (!CoreExists() && !string.IsNullOrWhiteSpace(coreDll.Value())) config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}");
if (!CertExists()) config.Error.WriteLine($"Cant find certificate at: {cert.Value()}");
config.ShowHelp();
return 1;
}
@@ -275,7 +265,7 @@ namespace bitwardenSelfLicensor
storageShort = (short) parsedStorage;
}
GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, storageShort, installationId, businessName.Value, key.Value);
GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), GetCoreDllPath(), name.Value, email.Value, storageShort, installationId, businessName.Value, key.Value);
return 0;
});
@@ -301,7 +291,7 @@ namespace bitwardenSelfLicensor
}
// checkUsername Checks that the username is a valid username
static bool checkUsername(string s)
private static bool CheckUsername(string s)
{
if ( string.IsNullOrWhiteSpace(s) ) {
WriteLineOver("The username provided doesn't appear to be valid.\n");
@@ -311,7 +301,7 @@ namespace bitwardenSelfLicensor
}
// checkBusinessName Checks that the Business Name is a valid username
static bool checkBusinessName(string s)
private static bool CheckBusinessName(string s)
{
if ( string.IsNullOrWhiteSpace(s) ) {
WriteLineOver("The Business Name provided doesn't appear to be valid.\n");
@@ -321,7 +311,7 @@ namespace bitwardenSelfLicensor
}
// checkEmail Checks that the email address is a valid email address
static bool checkEmail(string s)
private static bool CheckEmail(string s)
{
if ( string.IsNullOrWhiteSpace(s) ) {
WriteLineOver("The email provided doesn't appear to be valid.\n");
@@ -331,7 +321,7 @@ namespace bitwardenSelfLicensor
}
// checkStorage Checks that the storage is in a valid range
static bool checkStorage(string s)
private static bool CheckStorage(string s)
{
if (string.IsNullOrWhiteSpace(s))
{
@@ -347,23 +337,20 @@ namespace bitwardenSelfLicensor
}
// WriteLineOver Writes a new line to console over last line.
static void WriteLineOver(string s)
private static void WriteLineOver(string s)
{
Console.SetCursorPosition(0, Console.CursorTop -1);
Console.WriteLine(s);
}
// WriteLine This wrapper is just here so that console writes all look similar.
static void WriteLine(string s)
{
Console.WriteLine(s);
}
private static void WriteLine(string s) => Console.WriteLine(s);
static void GenerateUserLicense(X509Certificate2 cert, string corePath, string userName, string email, short storage, Guid userId, string key)
private static void GenerateUserLicense(X509Certificate2 cert, string corePath, string userName, string email, short storage, Guid userId, string key)
{
var core = AssemblyLoadContext.Default.LoadFromAssemblyPath(corePath);
var type = core.GetType("Bit.Core.Models.Business.UserLicense");
var type = core.GetType("Bit.Core.Billing.Models.Business.UserLicense");
var licenseTypeEnum = core.GetType("Bit.Core.Enums.LicenseType");
var license = Activator.CreateInstance(type);
@@ -392,13 +379,13 @@ namespace bitwardenSelfLicensor
Console.WriteLine(JsonConvert.SerializeObject(license, Formatting.Indented));
}
static void GenerateOrgLicense(X509Certificate2 cert, string corePath, string userName, string email, short storage, Guid instalId, string businessName, string key)
private static void GenerateOrgLicense(X509Certificate2 cert, string corePath, string userName, string email, short storage, Guid instalId, string businessName, string key)
{
var core = AssemblyLoadContext.Default.LoadFromAssemblyPath(corePath);
var type = core.GetType("Bit.Core.Models.Business.OrganizationLicense");
var type = core.GetType("Bit.Core.Billing.Organizations.Models.OrganizationLicense");
var licenseTypeEnum = core.GetType("Bit.Core.Enums.LicenseType");
var planTypeEnum = core.GetType("Bit.Core.Enums.PlanType");
var planTypeEnum = core.GetType("Bit.Core.Billing.Enums.PlanType");
var license = Activator.CreateInstance(type);
@@ -414,14 +401,14 @@ namespace bitwardenSelfLicensor
set("BillingEmail", email);
set("BusinessName", string.IsNullOrWhiteSpace(businessName) ? "BitBetter" : businessName);
set("Enabled", true);
set("Plan", "Custom");
set("PlanType", Enum.Parse(planTypeEnum, "Custom"));
set("Seats", (int)short.MaxValue);
set("Plan", "Enterprise (Annually)");
set("PlanType", Enum.Parse(planTypeEnum, "EnterpriseAnnually"));
set("Seats", int.MaxValue);
set("MaxCollections", short.MaxValue);
set("UsePolicies", true);
set("UseSso", true);
set("UseKeyConnector", true);
//set("UseScim", true); // available in version 10, which is not released yet
set("UseScim", true);
set("UseGroups", true);
set("UseEvents", true);
set("UseDirectory", true);
@@ -429,15 +416,25 @@ namespace bitwardenSelfLicensor
set("Use2fa", true);
set("UseApi", true);
set("UseResetPassword", true);
set("UseCustomPermissions", true);
set("MaxStorageGb", storage == 0 ? short.MaxValue : storage);
set("SelfHost", true);
set("UsersGetPremium", true);
set("Version", 9);
set("UsePasswordManager", true);
set("UseSecretsManager", true);
set("SmSeats", int.MaxValue);
set("SmServiceAccounts", int.MaxValue);
set("Version", 15); //This is set to 15 to use AllowAdminAccessToAllCollectionItems can be changed to 13 to just use Secrets Manager
set("Issued", DateTime.UtcNow);
set("Refresh", DateTime.UtcNow.AddYears(100).AddMonths(-1));
set("Expires", DateTime.UtcNow.AddYears(100));
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("UseOrganizationDomains", true);
set("UseAdminSponsoredFamilies", true);
set("Hash", Convert.ToBase64String((byte[])type.GetMethod("ComputeHash").Invoke(license, new object[0])));
set("Signature", Convert.ToBase64String((byte[])type.GetMethod("Sign").Invoke(license, new object[] { cert })));

View File

@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SingleFileExtractor.Core" Version="2.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>

View File

@@ -32,14 +32,14 @@ RECREATE_OV=${tmprecreate:-$RECREATE_OV}
if [[ $RECREATE_OV =~ ^[Yy]$ ]]
then
{
echo "version: '3'"
echo ""
echo "services:"
echo " api:"
echo " image: bitbetter/api:$BW_VERSION"
echo " pull_policy: never"
echo ""
echo " identity:"
echo " image: bitbetter/identity:$BW_VERSION"
echo " pull_policy: never"
echo ""
} > $BITWARDEN_BASE/bwdata/docker/docker-compose.override.yml
echo "BitBetter docker-compose override created!"
@@ -71,7 +71,7 @@ cd $BITWARDEN_BASE
./bitwarden.sh updateself
# Update the bitwarden.sh: automatically patch run.sh to fix docker-compose pull errors for private images
awk '1;/function downloadRunFile/{c=6}c&&!--c{print "sed -i '\''s/dccmd pull/dccmd pull --ignore-pull-failures || true/g'\'' $SCRIPTS_DIR/run.sh"}' $BITWARDEN_BASE/bitwarden.sh > tmp_bw.sh && mv tmp_bw.sh $BITWARDEN_BASE/bitwarden.sh
sed -i 's/chmod u+x $SCRIPTS_DIR\/run.sh/chmod u+x $SCRIPTS_DIR\/run.sh\n sed -i \x27s\/dccmd pull\/dccmd pull --ignore-pull-failures || true\/g\x27 $SCRIPTS_DIR\/run.sh/g' -i $BITWARDEN_BASE/bitwarden.sh
chmod +x $BITWARDEN_BASE/bitwarden.sh
echo "Patching bitwarden.sh completed..."