mirror of
				https://github.com/jakeswenson/BitBetter.git
				synced 2025-10-31 12:53:25 +00:00 
			
		
		
		
	Follow master updates and general improvements (#194)
* Use correct framework * Upgrade packages * Remove unused variable * Migrate away from deprecated package * Improve naming * Fix typo * Simplify constructors
This commit is contained in:
		
							parent
							
								
									c8192610dc
								
							
						
					
					
						commit
						0a45513872
					
				|  | @ -12,7 +12,7 @@ namespace bitBetter; | ||||||
| 
 | 
 | ||||||
| internal class Program | internal class Program | ||||||
| { | { | ||||||
|     private static Int32 Main(String[] args) |     private static Int32 Main() | ||||||
|     { |     { | ||||||
|         const String certFile = "/app/cert.cert"; |         const String certFile = "/app/cert.cert"; | ||||||
|         String[] files = Directory.GetFiles("/app/mount", "Core.dll", SearchOption.AllDirectories); |         String[] files = Directory.GetFiles("/app/mount", "Core.dll", SearchOption.AllDirectories); | ||||||
|  |  | ||||||
|  | @ -2,11 +2,11 @@ | ||||||
| 
 | 
 | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <OutputType>Exe</OutputType> |     <OutputType>Exe</OutputType> | ||||||
|     <TargetFramework>netcoreapp8.0</TargetFramework> |     <TargetFramework>net8.0</TargetFramework> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="dnlib" Version="3.6.0" /> |     <PackageReference Include="dnlib" Version="4.4.0" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </Project> | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ using System.IO; | ||||||
| using System.Reflection; | using System.Reflection; | ||||||
| using System.Runtime.Loader; | using System.Runtime.Loader; | ||||||
| using System.Security.Cryptography.X509Certificates; | using System.Security.Cryptography.X509Certificates; | ||||||
| using Microsoft.Extensions.CommandLineUtils; | using McMaster.Extensions.CommandLineUtils; | ||||||
| using Newtonsoft.Json; | using Newtonsoft.Json; | ||||||
| 
 | 
 | ||||||
| namespace licenseGen; | namespace licenseGen; | ||||||
|  | @ -35,7 +35,7 @@ internal class Program | ||||||
| 
 | 
 | ||||||
|         app.Command("interactive", config => |         app.Command("interactive", config => | ||||||
|         { |         { | ||||||
|             String buff, licensetype="", name="", email="", businessname=""; |             String buff, licenseType = "", name = "", email = "", businessName=""; | ||||||
|             Int16 storage = 0; |             Int16 storage = 0; | ||||||
| 
 | 
 | ||||||
|             Boolean validGuid = false, validInstallid = false; |             Boolean validGuid = false, validInstallid = false; | ||||||
|  | @ -45,8 +45,8 @@ internal class Program | ||||||
|             { |             { | ||||||
|                 if (!VerifyTopOptions()) |                 if (!VerifyTopOptions()) | ||||||
|                 { |                 { | ||||||
|                     if (!CoreExists()) config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); |                     if (!CoreExists()) config.Error.WriteLine($"Can't find core dll at: {coreDll.Value()}"); | ||||||
|                     if (!CertExists()) config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); |                     if (!CertExists()) config.Error.WriteLine($"Can't find certificate at: {cert.Value()}"); | ||||||
| 
 | 
 | ||||||
|                     config.ShowHelp(); |                     config.ShowHelp(); | ||||||
|                     return 1; |                     return 1; | ||||||
|  | @ -54,14 +54,14 @@ internal class Program | ||||||
| 
 | 
 | ||||||
|                 Console.WriteLine("Interactive license mode..."); |                 Console.WriteLine("Interactive license mode..."); | ||||||
|                  |                  | ||||||
|                 while (licensetype == "") |                 while (licenseType == "") | ||||||
|                 { |                 { | ||||||
|                     Console.WriteLine("What would you like to generate, a [u]ser license or an [o]rg license: "); |                     Console.WriteLine("What would you like to generate, a [u]ser license or an [o]rg license: "); | ||||||
|                     buff = Console.ReadLine(); |                     buff = Console.ReadLine(); | ||||||
| 
 | 
 | ||||||
|                     if(buff == "u") |                     if(buff == "u") | ||||||
|                     { |                     { | ||||||
|                         licensetype = "user"; |                         licenseType = "user"; | ||||||
|                         Console.WriteLine("Okay, we will generate a user license."); |                         Console.WriteLine("Okay, we will generate a user license."); | ||||||
| 
 | 
 | ||||||
|                         while (validGuid == false) |                         while (validGuid == false) | ||||||
|  | @ -75,7 +75,7 @@ internal class Program | ||||||
|                     } |                     } | ||||||
|                     else if (buff == "o") |                     else if (buff == "o") | ||||||
|                     { |                     { | ||||||
|                         licensetype = "org"; |                         licenseType = "org"; | ||||||
|                         Console.WriteLine("Okay, we will generate an organization license."); |                         Console.WriteLine("Okay, we will generate an organization license."); | ||||||
| 
 | 
 | ||||||
|                         while (validInstallid == false) |                         while (validInstallid == false) | ||||||
|  | @ -87,17 +87,17 @@ internal class Program | ||||||
|                             else Console.WriteLine("The install-id provided does not appear to be valid."); |                             else Console.WriteLine("The install-id provided does not appear to be valid."); | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|                         while (businessname == "") |                         while (businessName == "") | ||||||
|                         { |                         { | ||||||
|                             Console.WriteLine("Please enter a business name, default is BitBetter. [Business Name]: "); |                             Console.WriteLine("Please enter a business name, default is BitBetter. [Business Name]: "); | ||||||
|                             buff = Console.ReadLine(); |                             buff = Console.ReadLine(); | ||||||
|                             if (buff == "") |                             if (buff == "") | ||||||
|                             { |                             { | ||||||
|                                 businessname = "BitBetter"; |                                 businessName = "BitBetter"; | ||||||
|                             } |                             } | ||||||
|                             else if (CheckBusinessName(buff)) |                             else if (CheckBusinessName(buff)) | ||||||
|                             { |                             { | ||||||
|                                 businessname = buff; |                                 businessName = buff; | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|  | @ -141,7 +141,7 @@ internal class Program | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 if (licensetype == "user") |                 if (licenseType == "user") | ||||||
|                 { |                 { | ||||||
|                     Console.WriteLine("Confirm creation of \"user\" license for username: \"" + name + "\", email: \"" + email + "\", Storage: \"" + storage + " GB\", User-GUID: \"" + guid + "\"? Y/n"); |                     Console.WriteLine("Confirm creation of \"user\" license for username: \"" + name + "\", email: \"" + email + "\", Storage: \"" + storage + " GB\", User-GUID: \"" + guid + "\"? Y/n"); | ||||||
|                     buff = Console.ReadLine(); |                     buff = Console.ReadLine(); | ||||||
|  | @ -155,13 +155,13 @@ internal class Program | ||||||
|                         return 0; |                         return 0; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 else if (licensetype == "org") |                 else if (licenseType == "org") | ||||||
|                 { |                 { | ||||||
|                     Console.WriteLine("Confirm creation of \"organization\" license for business name: \"" + businessname + "\", username: \"" + name + "\", email: \"" + email + "\", Storage: \"" + storage + " GB\", Install-ID: \"" + installid + "\"? Y/n"); |                     Console.WriteLine("Confirm creation of \"organization\" license for business name: \"" + businessName + "\", username: \"" + name + "\", email: \"" + email + "\", Storage: \"" + storage + " GB\", Install-ID: \"" + installid + "\"? Y/n"); | ||||||
|                     buff = Console.ReadLine(); |                     buff = Console.ReadLine(); | ||||||
|                     if ( buff is "" or "y" or "Y" ) |                     if ( buff is "" or "y" or "Y" ) | ||||||
|                     { |                     { | ||||||
|                         GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, storage, installid, businessname, null); |                         GenerateOrgLicense(new X509Certificate2(cert.Value(), "test"), coreDll.Value(), name, email, storage, installid, businessName, null); | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|                     { |                     { | ||||||
|  | @ -173,7 +173,6 @@ internal class Program | ||||||
|                 return 0; |                 return 0; | ||||||
|             }); |             }); | ||||||
|         }); |         }); | ||||||
| 
 |  | ||||||
|         app.Command("user", config => |         app.Command("user", config => | ||||||
|         { |         { | ||||||
|             CommandArgument name = config.Argument("Name", "your name"); |             CommandArgument name = config.Argument("Name", "your name"); | ||||||
|  | @ -188,11 +187,11 @@ internal class Program | ||||||
|                 { |                 { | ||||||
|                     if (!CoreExists()) |                     if (!CoreExists()) | ||||||
|                     { |                     { | ||||||
|                         config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); |                         config.Error.WriteLine($"Can't find core dll at: {coreDll.Value()}"); | ||||||
|                     } |                     } | ||||||
|                     if (!CertExists()) |                     if (!CertExists()) | ||||||
|                     { |                     { | ||||||
|                         config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); |                         config.Error.WriteLine($"Can't find certificate at: {cert.Value()}"); | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     config.ShowHelp(); |                     config.ShowHelp(); | ||||||
|  | @ -202,14 +201,14 @@ internal class Program | ||||||
|                 if (String.IsNullOrWhiteSpace(name.Value) || String.IsNullOrWhiteSpace(email.Value)) |                 if (String.IsNullOrWhiteSpace(name.Value) || String.IsNullOrWhiteSpace(email.Value)) | ||||||
|                 { |                 { | ||||||
|                     config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}'"); |                     config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}'"); | ||||||
|                     config.ShowHelp("user"); |                     config.ShowHelp(true); | ||||||
|                     return 1; |                     return 1; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 if (String.IsNullOrWhiteSpace(userIdArg.Value) || !Guid.TryParse(userIdArg.Value, out Guid userId)) |                 if (String.IsNullOrWhiteSpace(userIdArg.Value) || !Guid.TryParse(userIdArg.Value, out Guid userId)) | ||||||
|                 { |                 { | ||||||
|                     config.Error.WriteLine("User ID not provided"); |                     config.Error.WriteLine("User ID not provided"); | ||||||
|                     config.ShowHelp("user"); |                     config.ShowHelp(true); | ||||||
|                     return 1; |                     return 1; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|  | @ -220,7 +219,7 @@ internal class Program | ||||||
|                     if (parsedStorage is > Int16.MaxValue or < 0) |                     if (parsedStorage is > Int16.MaxValue or < 0) | ||||||
|                     { |                     { | ||||||
|                         config.Error.WriteLine("The storage value provided is outside the accepted range of [0-" + Int16.MaxValue + "]"); |                         config.Error.WriteLine("The storage value provided is outside the accepted range of [0-" + Int16.MaxValue + "]"); | ||||||
|                         config.ShowHelp("org"); |                         config.ShowHelp(true); | ||||||
|                         return 1; |                         return 1; | ||||||
|                     } |                     } | ||||||
|                     storageShort = (Int16) parsedStorage; |                     storageShort = (Int16) parsedStorage; | ||||||
|  | @ -246,11 +245,11 @@ internal class Program | ||||||
|                 { |                 { | ||||||
|                     if (!CoreExists()) |                     if (!CoreExists()) | ||||||
|                     { |                     { | ||||||
|                         config.Error.WriteLine($"Cant find core dll at: {coreDll.Value()}"); |                         config.Error.WriteLine($"Can't find core dll at: {coreDll.Value()}"); | ||||||
|                     } |                     } | ||||||
|                     if (!CertExists()) |                     if (!CertExists()) | ||||||
|                     { |                     { | ||||||
|                         config.Error.WriteLine($"Cant find certificate at: {cert.Value()}"); |                         config.Error.WriteLine($"Can't find certificate at: {cert.Value()}"); | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     config.ShowHelp(); |                     config.ShowHelp(); | ||||||
|  | @ -262,7 +261,7 @@ internal class Program | ||||||
|                     String.IsNullOrWhiteSpace(installId.Value)) |                     String.IsNullOrWhiteSpace(installId.Value)) | ||||||
|                 { |                 { | ||||||
|                     config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}' InstallId='{installId.Value}'"); |                     config.Error.WriteLine($"Some arguments are missing: Name='{name.Value}' Email='{email.Value}' InstallId='{installId.Value}'"); | ||||||
|                     config.ShowHelp("org"); |                     config.ShowHelp(true); | ||||||
|                     return 1; |                     return 1; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|  | @ -270,7 +269,7 @@ internal class Program | ||||||
|                 { |                 { | ||||||
|                     config.Error.WriteLine("Unable to parse your installation id as a GUID"); |                     config.Error.WriteLine("Unable to parse your installation id as a GUID"); | ||||||
|                     config.Error.WriteLine($"Here's a new guid: {Guid.NewGuid()}"); |                     config.Error.WriteLine($"Here's a new guid: {Guid.NewGuid()}"); | ||||||
|                     config.ShowHelp("org"); |                     config.ShowHelp(true); | ||||||
|                     return 1; |                     return 1; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|  | @ -281,7 +280,7 @@ internal class Program | ||||||
|                     if (parsedStorage is > Int16.MaxValue or < 0) |                     if (parsedStorage is > Int16.MaxValue or < 0) | ||||||
|                     { |                     { | ||||||
|                         config.Error.WriteLine("The storage value provided is outside the accepted range of [0-" + Int16.MaxValue + "]"); |                         config.Error.WriteLine("The storage value provided is outside the accepted range of [0-" + Int16.MaxValue + "]"); | ||||||
|                         config.ShowHelp("org"); |                         config.ShowHelp(true); | ||||||
|                         return 1; |                         return 1; | ||||||
|                     } |                     } | ||||||
|                     storageShort = (Int16) parsedStorage; |                     storageShort = (Int16) parsedStorage; | ||||||
|  | @ -379,8 +378,8 @@ internal class Program | ||||||
|         Set("Trial", false); |         Set("Trial", false); | ||||||
|         Set("LicenseType", Enum.Parse(licenseTypeEnum, "User")); |         Set("LicenseType", Enum.Parse(licenseTypeEnum, "User")); | ||||||
| 
 | 
 | ||||||
|         Set("Hash", Convert.ToBase64String((Byte[])type.GetMethod("ComputeHash").Invoke(license, Array.Empty<Object>()))); |         Set("Hash", Convert.ToBase64String((Byte[])type.GetMethod("ComputeHash").Invoke(license, []))); | ||||||
|         Set("Signature", Convert.ToBase64String((Byte[])type.GetMethod("Sign").Invoke(license, new Object[] { cert }))); |         Set("Signature", Convert.ToBase64String((Byte[])type.GetMethod("Sign").Invoke(license, [cert]))); | ||||||
| 
 | 
 | ||||||
|         Console.WriteLine(JsonConvert.SerializeObject(license, Formatting.Indented)); |         Console.WriteLine(JsonConvert.SerializeObject(license, Formatting.Indented)); | ||||||
|         return; |         return; | ||||||
|  | @ -439,8 +438,8 @@ internal class Program | ||||||
|         Set("LicenseType", Enum.Parse(licenseTypeEnum, "Organization")); |         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("LimitCollectionCreationDeletion", true); //This will be used in the new version of BitWarden but can be applied now | ||||||
| 
 | 
 | ||||||
|         Set("Hash", Convert.ToBase64String((Byte[])type.GetMethod("ComputeHash").Invoke(license, Array.Empty<Object>()))); |         Set("Hash", Convert.ToBase64String((Byte[])type.GetMethod("ComputeHash").Invoke(license, []))); | ||||||
|         Set("Signature", Convert.ToBase64String((Byte[])type.GetMethod("Sign").Invoke(license, new Object[] { cert }))); |         Set("Signature", Convert.ToBase64String((Byte[])type.GetMethod("Sign").Invoke(license, [cert]))); | ||||||
| 
 | 
 | ||||||
|         Console.WriteLine(JsonConvert.SerializeObject(license, Formatting.Indented)); |         Console.WriteLine(JsonConvert.SerializeObject(license, Formatting.Indented)); | ||||||
|         return; |         return; | ||||||
|  |  | ||||||
|  | @ -2,12 +2,12 @@ | ||||||
| 
 | 
 | ||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <OutputType>Exe</OutputType> |     <OutputType>Exe</OutputType> | ||||||
|     <TargetFramework>netcoreapp8.0</TargetFramework> |     <TargetFramework>net8.0</TargetFramework> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" /> |     <PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" /> | ||||||
|     <PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> |     <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||||||
|     <PackageReference Include="System.Runtime.Loader" Version="4.3.0" /> |     <PackageReference Include="System.Runtime.Loader" Version="4.3.0" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user