public LicenseHelper() { asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); hashingProvider = new HashingProvider(); encodingService = new EncodingService(); objectSerializationProvider = new ObjectSerializationProvider(); symmetricEncryptionProvider = new SymmetricEncryptionProvider(); clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); clientLicenseService = new ClientLicenseService(clientLicenseRepository); serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); numberDataGenerator = new NumberDataGenerator(); packingService = new PackingService(numberDataGenerator); keygen = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); licenseActiviationProvider = new LicenseActiviationProvider(asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); service = new LicenseKeyService(keygen, packingService, clientLicenseService); productsProvider = new ProductsProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); zipCompressionProvider = new ZipCompressionProvider(); wcfPackagingService = new WcfPackagingService(zipCompressionProvider); //licenseSetsRepository = new LicenseSetsRepository(); //licenseSetService = new LicenseSetService(); //licenseService = new LicenseService(); License = new License(); License.Name = "UnitTest License"; License.UniqueId = Guid.NewGuid(); License.KeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); //string path = System.Reflection.Assembly.GetAssembly(typeof(LicenseHelper)).Location; string path = Helper.AssemblyDirectory; DllHash = encodingService.Encode(hashingProvider.HashFile(path + "\\WaveTech.Scutex.Licensing.dll")); PublicKey = encodingService.Encode(License.KeyPair.PublicKey); }
public void Before_each_test() { //ServicesRepository servicesRepository = new ServicesRepository(new ScutexEntities()); //CommonRepository commonRepository = new CommonRepository(new ScutexServiceEntities()); AsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); SymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); ObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); NumberDataGenerator numberDataGenerator = new NumberDataGenerator(); PackingService packingService = new PackingService(numberDataGenerator); MasterService masterService = new MasterService(commonRepository); CommonService commonService = new CommonService(); KeyPairService keyPairService = new KeyPairService(commonService, commonRepository); ServiceStatusProvider serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); servicesService = new ServicesService(servicesRepository, serviceStatusProvider, packingService, null, null, null, null, null, null); controlService = new ControlService(symmetricEncryptionProvider, keyPairService, packingService, masterService, objectSerializationProvider, asymmetricEncryptionProvider); service = new Scutex.Model.Service(); service.OutboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); service.InboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); service.ManagementInboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); service.ManagementOutboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); }
public void Before_each_test() { //ServicesRepository servicesRepository = new ServicesRepository(new ScutexEntities()); //CommonRepository commonRepository = new CommonRepository(new ScutexServiceEntities()); AsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); SymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); ObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); NumberDataGenerator numberDataGenerator = new NumberDataGenerator(); PackingService packingService = new PackingService(numberDataGenerator); MasterService masterService = new MasterService(commonRepository); CommonService commonService = new CommonService(); KeyPairService keyPairService = new KeyPairService(commonService, commonRepository); ServiceStatusProvider serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); servicesService = new ServicesService(servicesRepository, serviceStatusProvider, packingService, null, null, null, null, null, null); controlService = new ControlService(symmetricEncryptionProvider, keyPairService, packingService, masterService, objectSerializationProvider, asymmetricEncryptionProvider); service = new Scutex.Model.Service(); service.OutboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); service.InboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); service.ManagementInboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); service.ManagementOutboundKeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); }
public void Before_each_test() { clientLicenseRepoistory = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); clientLicenseService = new ClientLicenseService(clientLicenseRepoistory); serviceProductsRepository = new ServiceProductsRepository(new ScutexServiceEntities()); symmetricEncryptionProvider = new SymmetricEncryptionProvider(); asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); hashingProvider = new HashingProvider(); objectSerializationProvider = new ObjectSerializationProvider(); numberDataGenerator = new NumberDataGenerator(); packingService = new PackingService(numberDataGenerator); commonRepository = new CommonRepository(new ScutexServiceEntities()); clientRepository = new ClientRepository(new ScutexServiceEntities()); keyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); masterService = new MasterService(commonRepository); activationLogRepository = new ActivationLogRepoistory(new ScutexServiceEntities()); activationLogService = new ActivationLogService(activationLogRepository, hashingProvider); keyService = new KeyManagementService(clientRepository, licenseKeyService, activationLogService, hashingProvider, serviceProductsRepository); commonService = new CommonService(); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); path = path.Replace("file:\\", ""); var mockCommonService = new Mock<ICommonService>(); mockCommonService.Setup(common => common.GetPath()).Returns(path + "\\Data\\Client\\"); string masterServiceDataText; using (TextReader reader = new StreamReader(path + "\\Data\\MasterService.dat")) { masterServiceDataText = reader.ReadToEnd().Trim(); } masterServiceData = objectSerializationProvider.Deserialize<MasterServiceData>(masterServiceDataText); var mockCommonRepository = new Mock<ICommonRepository>(); mockCommonRepository.Setup(repo => repo.GetMasterServiceData()).Returns(masterServiceData); keyPairService = new KeyPairService(mockCommonService.Object, mockCommonRepository.Object); controlService = new ControlService(symmetricEncryptionProvider, keyPairService, packingService, masterService, objectSerializationProvider, asymmetricEncryptionProvider); servicesRepository = new ServicesRepository(new ScutexEntities()); serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); licenseActiviationProvider = new LicenseActiviationProvider(asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); servicesService = new ServicesService(servicesRepository, serviceStatusProvider, packingService, licenseActiviationProvider, null, null, null, null, null); licenseKeyService = new LicenseKeyService(keyGenerator, packingService, clientLicenseService); activationService = new ActivationService(controlService, keyService, keyPairService, objectSerializationProvider, asymmetricEncryptionProvider, null, null); string serviceData; using (TextReader reader = new StreamReader(path + "\\Data\\Service.dat")) { serviceData = reader.ReadToEnd().Trim(); } service = objectSerializationProvider.Deserialize<Service>(serviceData); }
public static void BatchSmallLicenseKeyGenrationTest() { IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); IHashingProvider hashingProvider = new HashingProvider(); IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider( asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator(); IPackingService packingService = new PackingService(numberDataGeneratorProvider); IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider); IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository); ISmallKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService); ClientLicense license = new ClientLicense(); LicenseGenerationOptions generationOptions = new LicenseGenerationOptions(); license.UniqueId = Guid.NewGuid(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); DateTime start = DateTime.Now; List <string> licenseKeys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000); Dictionary <string, string> doubleCheck = new Dictionary <string, string>(); DateTime end = DateTime.Now; foreach (string s in licenseKeys) { doubleCheck.Add(s, ""); Console.WriteLine(s); } Console.WriteLine(); Console.WriteLine("================================="); Console.WriteLine(string.Format("Key Generation took {0}", end - start)); Console.WriteLine(string.Format("Generated {0} unique license keys", licenseKeys.Count)); Console.WriteLine(); Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
public static void BatchSmallLicenseKeyGenrationTest() { IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); IHashingProvider hashingProvider = new HashingProvider(); IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider( asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator(); IPackingService packingService = new PackingService(numberDataGeneratorProvider); IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider); IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository); ISmallKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService); ClientLicense license = new ClientLicense(); LicenseGenerationOptions generationOptions = new LicenseGenerationOptions(); license.UniqueId = Guid.NewGuid(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); DateTime start = DateTime.Now; List<string> licenseKeys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000); Dictionary<string, string> doubleCheck = new Dictionary<string, string>(); DateTime end = DateTime.Now; foreach (string s in licenseKeys) { doubleCheck.Add(s, ""); Console.WriteLine(s); } Console.WriteLine(); Console.WriteLine("================================="); Console.WriteLine(string.Format("Key Generation took {0}", end - start)); Console.WriteLine(string.Format("Generated {0} unique license keys", licenseKeys.Count)); Console.WriteLine(); Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
public static void LicenseKeyGenerationTest() { IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); IHashingProvider hashingProvider = new HashingProvider(); IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider( asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator(); IPackingService packingService = new PackingService(numberDataGeneratorProvider); IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider); IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository); KeyGenerator staticKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); LicenseKeyService licenseKeyService = new LicenseKeyService(staticKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService); ClientLicense license = new ClientLicense(); LicenseGenerationOptions generationOptions = new LicenseGenerationOptions(); license.UniqueId = Guid.NewGuid(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); Dictionary <string, string> licenseKeys = new Dictionary <string, string>(); DateTime start = DateTime.Now; for (int i = 0; i < 100000; i++) { string key = licenseKeyService.GenerateLicenseKey("TEST", license, generationOptions); licenseKeys.Add(key, key.GetHashCode().ToString()); Console.WriteLine(key); } DateTime end = DateTime.Now; Console.WriteLine(start - end); }
public void TestLicenseKeyHashing() { IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); IHashingProvider hashingProvider = new HashingProvider(); IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider( asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator(); IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), new HashingProvider()); IPackingService packingService = new PackingService(numberDataGeneratorProvider); IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository); ILargeKeyGenerator largeKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); ISmallKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, largeKeyGenerator, packingService, clientLicenseService); ClientLicense license = new ClientLicense(); LicenseGenerationOptions generationOptions = new LicenseGenerationOptions(); license.UniqueId = Guid.NewGuid(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); Dictionary <string, string> licenseKeys = new Dictionary <string, string>(); List <string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000); foreach (string key in keys) { string hash = hashingProvider.ComputeHash(key, "SHA256"); licenseKeys.Add(hash, key); Console.WriteLine(key + "\t" + hash); Assert.IsTrue(hash.Equals(hashingProvider.ComputeHash(key, "SHA256"))); Assert.IsFalse(hash.Contains("'")); } }
public void Before_each_test() { asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); hashingProvider = new HashingProvider(); objectSerializationProvider = new ObjectSerializationProvider(); numberDataGenerator = new NumberDataGenerator(); packingService = new PackingService(numberDataGenerator); servicesService = new ServicesService(null, null, packingService, null, null, null, null, null, null); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); path = path.Replace("file:\\", ""); string serviceData; using (TextReader reader = new StreamReader(path + "\\Data\\Service.dat")) { serviceData = reader.ReadToEnd().Trim(); } service = objectSerializationProvider.Deserialize<Service>(serviceData); }
public void Before_each_test() { asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); hashingProvider = new HashingProvider(); objectSerializationProvider = new ObjectSerializationProvider(); numberDataGenerator = new NumberDataGenerator(); packingService = new PackingService(numberDataGenerator); servicesService = new ServicesService(null, null, packingService, null, null, null, null, null, null); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); path = path.Replace("file:\\", ""); string serviceData; using (TextReader reader = new StreamReader(path + "\\Data\\Service.dat")) { serviceData = reader.ReadToEnd().Trim(); } service = objectSerializationProvider.Deserialize <Service>(serviceData); }
public LicenseHelper() { asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); hashingProvider = new HashingProvider(); encodingService = new EncodingService(); objectSerializationProvider = new ObjectSerializationProvider(); symmetricEncryptionProvider = new SymmetricEncryptionProvider(); clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); clientLicenseService = new ClientLicenseService(clientLicenseRepository); serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); numberDataGenerator = new NumberDataGenerator(); packingService = new PackingService(numberDataGenerator); hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), new HashingProvider()); keygen = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); keyGeneratorLarge = new Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); licenseActiviationProvider = new LicenseActiviationProvider(asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); service = new LicenseKeyService(keygen, keyGeneratorLarge, packingService, clientLicenseService); productsProvider = new ProductsProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); zipCompressionProvider = new ZipCompressionProvider(); wcfPackagingService = new WcfPackagingService(zipCompressionProvider); //licenseSetsRepository = new LicenseSetsRepository(); //licenseSetService = new LicenseSetService(); //licenseService = new LicenseService(); License = new License(); License.Name = "UnitTest License"; License.UniqueId = Guid.NewGuid(); License.KeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High); //string path = System.Reflection.Assembly.GetAssembly(typeof(LicenseHelper)).Location; string path = Helper.AssemblyDirectory; DllHash = encodingService.Encode(hashingProvider.HashFile(path + "\\WaveTech.Scutex.Licensing.dll")); PublicKey = encodingService.Encode(License.KeyPair.PublicKey); }
public void Before_each_test() { clientLicenseRepoistory = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); clientLicenseService = new ClientLicenseService(clientLicenseRepoistory); serviceProductsRepository = new ServiceProductsRepository(new ScutexServiceEntities()); symmetricEncryptionProvider = new SymmetricEncryptionProvider(); asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); hashingProvider = new HashingProvider(); objectSerializationProvider = new ObjectSerializationProvider(); numberDataGenerator = new NumberDataGenerator(); packingService = new PackingService(numberDataGenerator); commonRepository = new CommonRepository(new ScutexServiceEntities()); clientRepository = new ClientRepository(new ScutexServiceEntities()); keyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); masterService = new MasterService(commonRepository); hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), new HashingProvider()); keyGeneratorLarge = new Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); var mockActivationLogRepository = new Mock <IActivationLogRepoistory>(); mockActivationLogRepository.Setup(log => log.SaveActivationLog(It.IsAny <Scutex.Model.ActivationLog>())); activationLogService = new ActivationLogService(mockActivationLogRepository.Object, hashingProvider); commonService = new CommonService(); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); path = path.Replace("file:\\", ""); var mockCommonService = new Mock <ICommonService>(); mockCommonService.Setup(common => common.GetPath()).Returns(path + "\\Data\\Client\\"); string masterServiceDataText; using (TextReader reader = new StreamReader(path + "\\Data\\MasterService.dat")) { masterServiceDataText = reader.ReadToEnd().Trim(); } masterServiceData = objectSerializationProvider.Deserialize <MasterServiceData>(masterServiceDataText); var mockCommonRepository = new Mock <ICommonRepository>(); mockCommonRepository.Setup(repo => repo.GetMasterServiceData()).Returns(masterServiceData); masterService = new MasterService(mockCommonRepository.Object); keyPairService = new KeyPairService(mockCommonService.Object, mockCommonRepository.Object); controlService = new ControlService(symmetricEncryptionProvider, keyPairService, packingService, masterService, objectSerializationProvider, asymmetricEncryptionProvider); servicesRepository = new ServicesRepository(new ScutexEntities()); serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider); licenseActiviationProvider = new LicenseActiviationProvider(asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); servicesService = new ServicesService(servicesRepository, serviceStatusProvider, packingService, licenseActiviationProvider, null, null, null, null, null); licenseKeyService = new LicenseKeyService(keyGenerator, keyGeneratorLarge, packingService, clientLicenseService); keyService = new KeyManagementService(clientRepository, licenseKeyService, activationLogService, hashingProvider, serviceProductsRepository); activationService = new ActivationService(controlService, keyService, keyPairService, objectSerializationProvider, asymmetricEncryptionProvider, activationLogService, masterService, commonService, null); string serviceData; using (TextReader reader = new StreamReader(path + "\\Data\\Service.dat")) { serviceData = reader.ReadToEnd().Trim(); } service = objectSerializationProvider.Deserialize <Service>(serviceData); }
public static void LicenseKeyGenerationTest() { IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); IHashingProvider hashingProvider = new HashingProvider(); IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider( asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator(); IPackingService packingService = new PackingService(numberDataGeneratorProvider); IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider); IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository); KeyGenerator staticKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); LicenseKeyService licenseKeyService = new LicenseKeyService(staticKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService); ClientLicense license = new ClientLicense(); LicenseGenerationOptions generationOptions = new LicenseGenerationOptions(); license.UniqueId = Guid.NewGuid(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); Dictionary<string, string> licenseKeys = new Dictionary<string, string>(); DateTime start = DateTime.Now; for (int i = 0; i < 100000; i++) { string key = licenseKeyService.GenerateLicenseKey("TEST", license, generationOptions); licenseKeys.Add(key, key.GetHashCode().ToString()); Console.WriteLine(key); } DateTime end = DateTime.Now; Console.WriteLine(start - end); }
public void TestLicenseKeyHashing() { IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); IHashingProvider hashingProvider = new HashingProvider(); IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider( asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator(); IPackingService packingService = new PackingService(numberDataGeneratorProvider); IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository); IKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, packingService, clientLicenseService); ClientLicense license = new ClientLicense(); LicenseGenerationOptions generationOptions = new LicenseGenerationOptions(); license.UniqueId = Guid.NewGuid(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); Dictionary<string, string> licenseKeys = new Dictionary<string, string>(); List<string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000); foreach (string key in keys) { string hash = hashingProvider.ComputeHash(key, "SHA256"); licenseKeys.Add(hash, key); Console.WriteLine(key + "\t" + hash); Assert.IsTrue(hash.Equals(hashingProvider.ComputeHash(key, "SHA256"))); Assert.IsFalse(hash.Contains("'")); } }
public static void SmallLicenseKeyGenrationTest() { IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider(); ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider(); IHashingProvider hashingProvider = new HashingProvider(); IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider(); ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider( asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator(); IPackingService packingService = new PackingService(numberDataGeneratorProvider); IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository); IKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, packingService, clientLicenseService); ClientLicense license = new ClientLicense(); LicenseGenerationOptions generationOptions = new LicenseGenerationOptions(); license.UniqueId = Guid.NewGuid(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); Dictionary<string, string> licenseKeys = new Dictionary<string, string>(); DateTime start = DateTime.Now; try { List<string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000); foreach (string key in keys) { string hash = hashingProvider.ComputeHash(key, "SHA256"); licenseKeys.Add(hash, key); Console.WriteLine(key); Console.WriteLine(hash + " " + hash.Equals(hashingProvider.ComputeHash(key, "SHA256"))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine(); Console.WriteLine("================================="); DateTime end = DateTime.Now; Console.WriteLine(string.Format("Key Generation took {0}", end - start)); Console.WriteLine(string.Format("Generated {0} unique license keys", licenseKeys.Count)); Console.WriteLine(); Console.WriteLine("Press enter to exit."); Console.ReadLine(); } }