mirror of
https://github.com/jakeswenson/BitBetter.git
synced 2025-07-12 22:43:27 +00:00
Merge 5b5d1301c9
into 676dd7b85c
This commit is contained in:
commit
c820c1e741
21
build.sh
21
build.sh
|
@ -1,5 +1,5 @@
|
|||
#!/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/"$//')
|
||||
|
@ -9,14 +9,19 @@ echo "Building BitBetter for BitWarden version $BW_VERSION"
|
|||
# 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 repository
|
||||
rm -rf $DIR/server
|
||||
git clone --branch "v${BW_VERSION}" --depth 1 https://github.com/bitwarden/server.git $DIR/server
|
||||
old_thumbprint=$(openssl x509 -fingerprint -noout -in $DIR/server/src/Core/licensing.cer | cut -d= -f2 | tr -d ':')
|
||||
new_thumbprint=$(openssl x509 -fingerprint -noout -in $DIR/.keys/cert.cert | cut -d= -f2 | tr -d ':')
|
||||
cp $DIR/.keys/cert.cert $DIR/server/src/Core/licensing.cer
|
||||
# Optional, has actually no effect
|
||||
sed -i -e "s/$old_thumbprint/$new_thumbprint/g" $DIR/server/src/Core/Services/Implementations/LicensingService.cs
|
||||
# Enable loose files for API, so Core.dll is accessible
|
||||
sed -i -e 's/PublishSingleFile=true/PublishSingleFile=false/g' $DIR/server/src/Api/Dockerfile
|
||||
|
||||
cp "$DIR/.keys/cert.cert" "$DIR/src/bitBetter/.keys"
|
||||
|
||||
docker run --rm -v "$DIR/src/bitBetter:/bitBetter" -w=/bitBetter mcr.microsoft.com/dotnet/sdk:8.0 sh build.sh
|
||||
|
||||
docker build --no-cache --build-arg BITWARDEN_TAG=ghcr.io/bitwarden/api:$BW_VERSION --label com.bitwarden.product="bitbetter" -t bitbetter/api "$DIR/src/bitBetter" # --squash
|
||||
docker build --no-cache --build-arg BITWARDEN_TAG=ghcr.io/bitwarden/identity:$BW_VERSION --label com.bitwarden.product="bitbetter" -t bitbetter/identity "$DIR/src/bitBetter" # --squash
|
||||
docker build --no-cache --label com.bitwarden.product="bitbetter" $DIR/server -f $DIR/server/src/Api/Dockerfile -t bitbetter/api
|
||||
docker build --no-cache --label com.bitwarden.product="bitbetter" $DIR/server -f $DIR/server/src/Identity/Dockerfile -t bitbetter/identity
|
||||
|
||||
docker tag bitbetter/api bitbetter/api:latest
|
||||
docker tag bitbetter/identity bitbetter/identity:latest
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
ARG BITWARDEN_TAG
|
||||
FROM ${BITWARDEN_TAG}
|
||||
|
||||
COPY bin/Release/net8.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
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
dotnet restore
|
||||
dotnet publish
|
Loading…
Reference in New Issue
Block a user