mirror of
				https://github.com/jakeswenson/BitBetter.git
				synced 2025-10-31 04:43:25 +00:00 
			
		
		
		
	fixed
This commit is contained in:
		
							parent
							
								
									b1a8ec5031
								
							
						
					
					
						commit
						92555591f5
					
				|  | @ -13,9 +13,24 @@ namespace bitwardenSelfLicensor | |||
|         static int Main(string[] args) | ||||
|         { | ||||
|             var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication(); | ||||
|             var cert = app.Option("-c | --cert", "cert file", CommandOptionType.SingleValue); | ||||
|             var cert = app.Option("--cert", "cert file", CommandOptionType.SingleValue); | ||||
|             var coreDll = app.Option("--core", "path to core dll", CommandOptionType.SingleValue); | ||||
| 
 | ||||
|             bool certExists() { | ||||
|                 return File.Exists(cert.Value()); | ||||
|             } | ||||
| 
 | ||||
|             bool coreExists() { | ||||
|                 return File.Exists(coreDll.Value()); | ||||
|             } | ||||
| 
 | ||||
|             bool verifyTopOptions() | ||||
|             { | ||||
|                 return !string.IsNullOrWhiteSpace(cert.Value()) && | ||||
|                        !string.IsNullOrWhiteSpace(coreDll.Value()) && | ||||
|                        certExists() && coreExists(); | ||||
|             } | ||||
| 
 | ||||
|             app.Command("user", config => | ||||
|             { | ||||
|                 var name = config.Argument("Name", "your name"); | ||||
|  | @ -25,13 +40,22 @@ namespace bitwardenSelfLicensor | |||
| 
 | ||||
|                 config.OnExecute(() => | ||||
|                 { | ||||
|                     if (!cert.HasValue() || !coreDll.HasValue()) | ||||
|                     if (!verifyTopOptions()) | ||||
|                     { | ||||
|                         app.ShowHelp(); | ||||
|                         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; | ||||
|                     } | ||||
|                     else if (string.IsNullOrWhiteSpace(name.Value) || string.IsNullOrWhiteSpace(email.Value)) | ||||
|                     { | ||||
|                         config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}'"); | ||||
|                         config.ShowHelp("user"); | ||||
|                         return 1; | ||||
|                     } | ||||
|  | @ -51,16 +75,24 @@ namespace bitwardenSelfLicensor | |||
| 
 | ||||
|                 config.OnExecute(() => | ||||
|                 { | ||||
|                     if (!cert.HasValue() || !coreDll.HasValue()) | ||||
|                     if (!verifyTopOptions()) | ||||
|                     { | ||||
|                         app.ShowHelp(); | ||||
|                         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; | ||||
|                     } | ||||
|                     else if (string.IsNullOrWhiteSpace(name.Value) || | ||||
|                             string.IsNullOrWhiteSpace(email.Value) || | ||||
|                             string.IsNullOrWhiteSpace(installId.Value)) | ||||
|                     { | ||||
|                         config.Error.WriteLine("Missing arguments"); | ||||
|                         config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}' InstallId='{installId.Value}'"); | ||||
|                         config.ShowHelp("org"); | ||||
|                         return 1; | ||||
|                     } | ||||
|  | @ -68,7 +100,9 @@ namespace bitwardenSelfLicensor | |||
|                     if (!Guid.TryParse(installId.Value, out Guid installationId)) | ||||
|                     { | ||||
|                         config.Error.WriteLine("Unable to parse your installation id as a GUID"); | ||||
|                         config.Error.WriteLine($"Here's a new guid: {Guid.NewGuid()}"); | ||||
|                         config.ShowHelp("org"); | ||||
|                         return 1; | ||||
|                     } | ||||
| 
 | ||||
|                     GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name.Value, email.Value, installationId, key.Value); | ||||
|  | @ -125,7 +159,7 @@ namespace bitwardenSelfLicensor | |||
|             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 }))); | ||||
| 
 | ||||
|             Console.WriteLine(JsonConvert.SerializeObject(license)); | ||||
|             Console.WriteLine(JsonConvert.SerializeObject(license, Formatting.Indented)); | ||||
|         } | ||||
| 
 | ||||
|         static void GenerateOrgLicense(X509Certificate2 cert, string corePath, | ||||
|  | @ -167,7 +201,7 @@ namespace bitwardenSelfLicensor | |||
|             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 }))); | ||||
| 
 | ||||
|             Console.WriteLine(JsonConvert.SerializeObject(license)); | ||||
|             Console.WriteLine(JsonConvert.SerializeObject(license, Formatting.Indented)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -7,5 +7,5 @@ cd $script_dir | |||
| dotnet restore | ||||
| dotnet publish | ||||
| 
 | ||||
| docker build . -t bitbetter/licenseGen # --squash | ||||
| docker build . -t bitbetter/licensegen # --squash | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,10 +2,11 @@ | |||
| 
 | ||||
| script_dir=`cd $(dirname $0); pwd` | ||||
| 
 | ||||
| if [ "$#" -ne "1" ]; then | ||||
|     echo "USAGE: $0 <ABSOLUTE PATH TO CERT.PFX>" | ||||
| if [ "$#" -lt "1" ]; then | ||||
|     echo "USAGE: $0 <ABSOLUTE PATH TO CERT.PFX> [License Gen args...]" | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| docker run -it -v "$1:/cert.pfx" bitbetter/licensegen | ||||
| cert_path=$1 | ||||
| shift | ||||
| docker run -it -v "$cert_path:/cert.pfx" bitbetter/licensegen "$@" | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user