mirror of
https://github.com/jakeswenson/BitBetter.git
synced 2025-12-16 19:26:18 +00:00
License Generator Interactive Mode (#23)
* Added a Key Generating script To make the keygen process a bit easier I've added a `generate-keys.sh` script that can be found in the `.keys` directory. It will generate the key & cert and bundle them into the required pkcs#12 file. I've updated the readme to include instructions on the script. * Generate bitbetter/identiry container with modified Core.dll Added the generation of a second modified container, bitbetter/identity, which contains the modified dll. Fixes #12. This works on my testing environment but has not gone through extensive testing. I'd recommend a review and cleanup of this commit before it is merged into the develop or master branches. * Updated Docs I've taken the steps written out by @online-stuff and consolidated/organized them into the README. This closes #13. In a future update it might be worth adding a docs/ directory and breaking the readme into several docs that link to one another. * Updated build.sh Build now checks for and creates missing .keys directories. * Added subj to allow for non-interactive use. * Generate keys on build. * Circle-ci needs to gen keys to test build * Generate keys if they don't exist. Don't overwrite if keys already exist. * Generate keys online in the .keys directory * Updated README.md * Added initial interactive options * Functional implementation of licensegen interactive mode. * Bumped Newtonson.Json version Never versions of the dotnet-sdk have issues with older Newtonsoft versions. 12.0.1 seems to satisfy the widest variety of sdk versions. * Removing old readme * Removed Duplicate Section * Fixed typo This fixes and closes issue #24.
This commit is contained in:
@@ -33,6 +33,121 @@ namespace bitwardenSelfLicensor
|
||||
certExists() && coreExists();
|
||||
}
|
||||
|
||||
app.Command("interactive", config =>
|
||||
{
|
||||
string buff="", licensetype="", name="", email="", businessname="";
|
||||
|
||||
bool valid_guid = false, valid_installid = false;
|
||||
Guid guid, installid;
|
||||
|
||||
config.OnExecute(() =>
|
||||
{
|
||||
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()}");
|
||||
|
||||
config.ShowHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
WriteLine("Interactive license mode...");
|
||||
|
||||
while (licensetype == "")
|
||||
{
|
||||
WriteLine("What would you like to generate, a [u]ser license or an [o]rg license?");
|
||||
buff = Console.ReadLine();
|
||||
|
||||
if(buff == "u")
|
||||
{
|
||||
licensetype = "user";
|
||||
WriteLineOver("Okay, we will generate a user license.");
|
||||
|
||||
while (valid_guid == false)
|
||||
{
|
||||
WriteLine("Please provide the user's guid — refer to the Readme for details on how to retrieve this. [GUID]:");
|
||||
buff = Console.ReadLine();
|
||||
|
||||
if (Guid.TryParse(buff, out guid))valid_guid = true;
|
||||
else WriteLineOver("The user-guid provided does not appear to be valid.");
|
||||
}
|
||||
}
|
||||
else if (buff == "o")
|
||||
{
|
||||
licensetype = "org";
|
||||
WriteLineOver("Okay, we will generate an organization license.");
|
||||
|
||||
while (valid_installid == false)
|
||||
{
|
||||
WriteLine("Please provide your Bitwarden Install-ID — refer to the Readme for details on how to retrieve this. [Install-ID]:");
|
||||
buff = Console.ReadLine();
|
||||
|
||||
if (Guid.TryParse(buff, out installid)) valid_installid = true;
|
||||
else WriteLineOver("The install-id provided does not appear to be valid.");
|
||||
}
|
||||
|
||||
while (businessname == "")
|
||||
{
|
||||
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
|
||||
{
|
||||
WriteLineOver("Unrecognized option \'" + buff + "\'. ");
|
||||
}
|
||||
}
|
||||
|
||||
while (name == "")
|
||||
{
|
||||
WriteLineOver("Please provide the username this license will be registered to. [username]:");
|
||||
buff = Console.ReadLine();
|
||||
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 (licensetype == "user")
|
||||
{
|
||||
WriteLineOver("Confirm creation of \"user\" license for username: \"" + name + "\", email: \"" + email + "\", User-GUID: \"" + guid + "\"? Y/n");
|
||||
buff = Console.ReadLine();
|
||||
if ( buff == "" || buff == "y" || buff == "Y" )
|
||||
{
|
||||
GenerateUserLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, guid, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLineOver("Exiting...");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (licensetype == "org")
|
||||
{
|
||||
WriteLineOver("Confirm creation of \"organization\" license for business name: \"" + businessname + "\", username: \"" + name + "\", email: \"" + email + "\", Install-ID: \"" + installid + "\"? Y/n");
|
||||
buff = Console.ReadLine();
|
||||
if ( buff == "" || buff == "y" || buff == "Y" )
|
||||
{
|
||||
GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, installid, businessname, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLineOver("Exiting...");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
});
|
||||
|
||||
app.Command("user", config =>
|
||||
{
|
||||
var name = config.Argument("Name", "your name");
|
||||
@@ -82,6 +197,7 @@ namespace bitwardenSelfLicensor
|
||||
var name = config.Argument("Name", "your name");
|
||||
var email = config.Argument("Email", "your email");
|
||||
var installId = config.Argument("InstallId", "your installation id (GUID)");
|
||||
var businessName = config.Argument("BusinessName", "name For the organization (optional)");
|
||||
var key = config.Argument("Key", "your key id (optional)");
|
||||
var help = config.HelpOption("--help | -h | -?");
|
||||
|
||||
@@ -118,7 +234,7 @@ namespace bitwardenSelfLicensor
|
||||
return 1;
|
||||
}
|
||||
|
||||
GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, installationId, key.Value);
|
||||
GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, installationId, businessName.Value, key.Value);
|
||||
|
||||
return 0;
|
||||
});
|
||||
@@ -143,6 +259,49 @@ namespace bitwardenSelfLicensor
|
||||
}
|
||||
}
|
||||
|
||||
// checkUsername Checks that the username is a valid username
|
||||
static bool checkUsername(string s)
|
||||
{
|
||||
if ( string.IsNullOrWhiteSpace(s) ) {
|
||||
WriteLineOver("The username provided doesn't appear to be valid.\n");
|
||||
return false;
|
||||
}
|
||||
return true; // TODO: Actually validate
|
||||
}
|
||||
|
||||
// checkBusinessName Checks that the Business Name is a valid username
|
||||
static bool checkBusinessName(string s)
|
||||
{
|
||||
if ( string.IsNullOrWhiteSpace(s) ) {
|
||||
WriteLineOver("The Business Name provided doesn't appear to be valid.\n");
|
||||
return false;
|
||||
}
|
||||
return true; // TODO: Actually validate
|
||||
}
|
||||
|
||||
// checkEmail Checks that the email address is a valid email address
|
||||
static bool checkEmail(string s)
|
||||
{
|
||||
if ( string.IsNullOrWhiteSpace(s) ) {
|
||||
WriteLineOver("The email provided doesn't appear to be valid.\n");
|
||||
return false;
|
||||
}
|
||||
return true; // TODO: Actually validate
|
||||
}
|
||||
|
||||
// WriteLineOver Writes a new line to console over last line.
|
||||
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);
|
||||
}
|
||||
|
||||
static void GenerateUserLicense(X509Certificate2 cert, string corePath,
|
||||
string userName, string email, Guid userId, string key)
|
||||
{
|
||||
@@ -176,7 +335,7 @@ namespace bitwardenSelfLicensor
|
||||
}
|
||||
|
||||
static void GenerateOrgLicense(X509Certificate2 cert, string corePath,
|
||||
string userName, string email, Guid instalId, string key)
|
||||
string userName, string email, Guid instalId, string businessName, string key)
|
||||
{
|
||||
var core = AssemblyLoadContext.Default.LoadFromAssemblyPath(corePath);
|
||||
|
||||
@@ -194,7 +353,7 @@ namespace bitwardenSelfLicensor
|
||||
set("Id", Guid.NewGuid());
|
||||
set("Name", userName);
|
||||
set("BillingEmail", email);
|
||||
set("BusinessName", "BitBetter");
|
||||
set("BusinessName", string.IsNullOrWhiteSpace(businessName) ? "BitBetter" : businessName);
|
||||
set("Enabled", true);
|
||||
set("Plan", "Custom");
|
||||
set("PlanType", (byte)6);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
|
||||
script_dir=`cd $(dirname $0); pwd`
|
||||
|
||||
# Grab the absolute path to the default pfx location
|
||||
cert_path=`cd ./.keys; ls -d -1 $PWD/cert.pfx`
|
||||
|
||||
if [ "$#" -lt "1" ]; then
|
||||
echo "USAGE: $0 <ABSOLUTE PATH TO CERT.PFX> [License Gen args...]"
|
||||
exit 1
|
||||
elif [ "$#" -ge "2" ]; then
|
||||
# If a cert path is provided manually, override the default
|
||||
cert_path=$1
|
||||
shift
|
||||
fi
|
||||
cert_path=$1
|
||||
shift
|
||||
|
||||
docker run -it -v "$cert_path:/cert.pfx" bitbetter/licensegen "$@"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user