public Task Update(CredentialValue value) { var serialized = JsonSerializer.Serialize(new CredentialValueRecord(value)); var encrypted = new EncryptedValue(dataProtector, serialized).Value(); return(Persist(key, encrypted)); }
public string Decrypt(EncryptedValue encryptedValue) { if (encryptedValue.Base64Iv == hardcodedValue.Base64Iv && encryptedValue.EncryptedBase64Value == hardcodedValue.EncryptedBase64Value) return "A secret"; throw new InvalidOperationException("Failed to deencrypt"); }
private CertifiedKeyPair(Asn1Sequence seq) { certOrEncCert = CertOrEncCert.GetInstance(seq[0]); if (seq.Count >= 2) { if (seq.Count == 2) { Asn1TaggedObject tagged = Asn1TaggedObject.GetInstance(seq[1]); if (tagged.TagNo == 0) { privateKey = EncryptedValue.GetInstance(tagged.GetObject()); } else { publicationInfo = PkiPublicationInfo.GetInstance(tagged.GetObject()); } } else { privateKey = EncryptedValue.GetInstance(Asn1TaggedObject.GetInstance(seq[1])); publicationInfo = PkiPublicationInfo.GetInstance(Asn1TaggedObject.GetInstance(seq[2])); } } }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { if (encryptedValue == null || String.IsNullOrEmpty(encryptedValue.EncryptedBase64Value)) { return(null); } if (!context.Headers.ContainsKey(EncryptionHeaders.RijndaelKeyIdentifier)) { return(null); } var decryptlabel = context.Headers[EncryptionHeaders.RijndaelKeyIdentifier]; var decryptRequest = new DecryptRequest { KeyId = decryptlabel }; var value = Convert.FromBase64String(encryptedValue.EncryptedBase64Value); decryptRequest.CiphertextBlob = new System.IO.MemoryStream(value); var response = _client.DecryptAsync(decryptRequest).GetAwaiter().GetResult(); if (response != null) { return(Encoding.UTF8.GetString(response.Plaintext.ToArray())); } return(null); }
public XElement RemoveElementBehavior(XElement element) { var value = element.Element(XName.Get("Value", "string")); if (value == null) { throw new ArgumentException("element must contain <value> element"); } var attribute = value.Attribute("iv"); if (attribute == null) { throw new ArgumentException("element must contain a <value> element with iv attribute"); } var encryptedValue = new EncryptedValue { Base64Iv = attribute.Value, EncryptedBase64Value = element.Value, }; var unencryptedValue = EncryptionService.Decrypt(encryptedValue); return(XElement.Parse(unencryptedValue)); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { if (encryptedValue.Base64Iv == hardcodedValue.Base64Iv && encryptedValue.EncryptedBase64Value == hardcodedValue.EncryptedBase64Value) return "A secret"; throw new InvalidOperationException("Failed to decrypt"); }
string IEncryptionService.Decrypt(EncryptedValue encryptedValue) { if (Key == null) { Logger.Warn("Cannot decrypt because a Key was not configured. Please specify 'RijndaelEncryptionServiceConfig' in your application's configuration file."); return(encryptedValue.EncryptedBase64Value); } var encrypted = Convert.FromBase64String(encryptedValue.EncryptedBase64Value); using (var rijndael = new RijndaelManaged()) { rijndael.Key = Key; rijndael.IV = Convert.FromBase64String(encryptedValue.Base64Iv); rijndael.Mode = CipherMode.CBC; using (var decryptor = rijndael.CreateDecryptor()) using (var memoryStream = new MemoryStream(encrypted)) using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)) using (var reader = new StreamReader(cryptoStream)) { return(reader.ReadToEnd()); } } }
string IEncryptionService.Decrypt(EncryptedValue encryptedValue) { if (Key == null) { Logger.Warn("Cannot decrypt because a Key was not configured. Please specify 'RijndaelEncryptionServiceConfig' in your application's configuration file."); return(encryptedValue.EncryptedBase64Value); } var decryptionKeys = new List <byte[]> { Key }; if (ExpiredKeys != null) { decryptionKeys.AddRange(ExpiredKeys); } var cryptographicExceptions = new List <CryptographicException>(); foreach (var key in decryptionKeys) { try { return(Decrypt(encryptedValue, key)); } catch (CryptographicException exception) { cryptographicExceptions.Add(exception); } } var message = string.Format("Could not decrypt message. Tried {0} keys.", decryptionKeys.Count); throw new AggregateException(message, cryptographicExceptions); }
public CertOrEncCert(EncryptedValue encryptedCert) { if (encryptedCert == null) { throw new ArgumentNullException("encryptedCert"); } this.encryptedCert = encryptedCert; }
public void EncryptIsRandom() { EncryptionService svc = new EncryptionService(); EncryptedValue a = svc.Encrypt("samepasscode", "somerandomdata"); EncryptedValue b = svc.Encrypt("samepasscode", "somerandomdata"); Assert.NotEqual(a.Base64EncryptedValue, b.Base64EncryptedValue); }
private static void DecryptJsonValue(JsonPasswordCrypto cryptoHandler, dynamic originalValue) { var valueToDecrypt = new EncryptedValue(originalValue.IV.Value, originalValue.Value.Value); var decryptedValue = cryptoHandler.Decrypt(valueToDecrypt); JObject valueToReplace = originalValue; valueToReplace.Replace(decryptedValue); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { if (encryptedValue.Base64Iv == hardcodedValue.Base64Iv && encryptedValue.EncryptedBase64Value == hardcodedValue.EncryptedBase64Value) { return("A secret"); } throw new InvalidOperationException("Failed to decrypt"); }
public string Decrypt(EncryptedValue encryptedValue) { if (encryptedValue.Base64Iv == "init_vector" && encryptedValue.EncryptedBase64Value == "encrypted_value") { return("A secret"); } throw new InvalidOperationException("Failed to deencrypt"); }
public CertOrEncCert(EncryptedValue encryptedCert) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (encryptedCert == null) { throw new ArgumentNullException("encryptedCert"); } this.encryptedCert = encryptedCert; }
public void DecryptSuccess() { EncryptionService svc = new EncryptionService(); EncryptedValue a = svc.Encrypt("C0mpl3xPa55w04d", "some random payload"); EncryptedValue b = svc.Encrypt("C0mpl3xPa55w04d", "some random payload", a.Base64Salt, a.Base64IV); Assert.Equal(a.Base64EncryptedValue, b.Base64EncryptedValue); }
public string Decrypt(EncryptedValue encryptedValue) { if (encryptedValue.Base64Iv == hardcodedValue.Base64Iv && encryptedValue.EncryptedBase64Value == hardcodedValue.EncryptedBase64Value) { return("A secret"); } throw new InvalidOperationException("Failed to decrypt"); }
public CertifiedKeyPair(CertOrEncCert certOrEncCert, EncryptedValue privateKey, PkiPublicationInfo publicationInfo) { if (certOrEncCert == null) { throw new ArgumentNullException("certOrEncCert"); } this.certOrEncCert = certOrEncCert; this.privateKey = privateKey; this.publicationInfo = publicationInfo; }
string Decrypt(EncryptedValue value) { if (encryptionServiceWithContext != null) { return(encryptionServiceWithContext.Decrypt(value, incomingContext)); } else { return(encryptionService.Decrypt(value)); } }
public CertifiedKeyPair(CertOrEncCert certOrEncCert, EncryptedValue privateKey, PkiPublicationInfo publicationInfo) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (certOrEncCert == null) { throw new ArgumentNullException("certOrEncCert"); } this.certOrEncCert = certOrEncCert; this.privateKey = privateKey; this.publicationInfo = publicationInfo; }
private void Button_Click(object sender, RoutedEventArgs e) { //Array of bytes is created byte[] EncryptedValue; string encr = ""; //Encrypted value is created by passing password and salt value EncryptedValue = EncryptionHelper.Encrypt(txtText.Text, "pw", "salt"); System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); encr = encoding.GetString(EncryptedValue, 0, EncryptedValue.Count()); txtEncryted.Text = encr.ToString(); txtDecrypted.Text = EncryptionHelper.Decrypt(EncryptedValue, "pw", "salt"); }
public void BaseSetUp() { conventions = BuildConventions(); var encryptedValue = new EncryptedValue { EncryptedBase64Value = EncryptedBase64Value, Base64Iv = "init_vector" }; var fakeEncryptionService = new FakeEncryptionService(encryptedValue); mutator = new EncryptionMutator(fakeEncryptionService, conventions); }
private CertOrEncCert(Asn1TaggedObject tagged) { if (tagged.TagNo == 0) { this.certificate = CmpCertificate.GetInstance(tagged.GetObject()); return; } if (tagged.TagNo == 1) { this.encryptedCert = EncryptedValue.GetInstance(tagged.GetObject()); return; } throw new ArgumentException("unknown tag: " + tagged.TagNo, "tagged"); }
public string Decrypt(EncryptedValue encryptedValue, IncomingContext incomingContext) { string keyIdentifier; if (TryGetKeyIdentifierHeader(out keyIdentifier, incomingContext)) { return DecryptUsingKeyIdentifier(encryptedValue, keyIdentifier); } else { Log.WarnFormat("Encrypted message has no '" + Headers.RijndaelKeyIdentifier + "' header. Possibility of data corruption. Please upgrade endpoints that send message with encrypted properties."); return DecryptUsingAllKeys(encryptedValue); } }
public string Decrypt(EncryptedValue encryptedValue) { string keyIdentifier; if (TryGetKeyIdentifierHeader(out keyIdentifier)) { return(DecryptUsingKeyIdentifier(encryptedValue, keyIdentifier)); } else { Log.WarnFormat("Encrypted message has no '" + Headers.RijndaelKeyIdentifier + "' header. Possibility of data corruption. Please upgrade endpoints that send message with encrypted properties."); return(DecryptUsingAllKeys(encryptedValue)); } }
private CertOrEncCert(Asn1TaggedObject tagged) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) if (tagged.TagNo == 0) { certificate = CmpCertificate.GetInstance(tagged.GetObject()); return; } if (tagged.TagNo == 1) { encryptedCert = EncryptedValue.GetInstance(tagged.GetObject()); return; } throw new ArgumentException(string.Concat((object)"unknown tag: ", (object)tagged.TagNo), "tagged"); }
public static EncryptedKey GetInstance(object o) { if (o is EncryptedKey) { return((EncryptedKey)o); } if (o is Asn1TaggedObject) { return(new EncryptedKey(EnvelopedData.GetInstance((Asn1TaggedObject)o, explicitly: false))); } if (o is EncryptedValue) { return(new EncryptedKey((EncryptedValue)o)); } return(new EncryptedKey(EncryptedValue.GetInstance(o))); }
static string Decrypt(EncryptedValue encryptedValue, byte[] key) { using (var rijndael = new RijndaelManaged()) { var encrypted = Convert.FromBase64String(encryptedValue.EncryptedBase64Value); rijndael.IV = Convert.FromBase64String(encryptedValue.Base64Iv); rijndael.Mode = CipherMode.CBC; rijndael.Key = key; using (var decryptor = rijndael.CreateDecryptor()) using (var memoryStream = new MemoryStream(encrypted)) using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)) using (var reader = new StreamReader(cryptoStream)) { return(reader.ReadToEnd()); } } }
public string Decrypt(EncryptedValue encryptedValue) { var cryptographicExceptions = new List<CryptographicException>(); foreach (var key in decryptionKeys) { try { return Decrypt(encryptedValue, key); } catch (CryptographicException exception) { cryptographicExceptions.Add(exception); } } var message = string.Format("Could not decrypt message. Tried {0} keys.", decryptionKeys.Count); throw new AggregateException(message, cryptographicExceptions); }
public void BaseSetUp() { FakeEncryptedValue = new EncryptedValue { EncryptedBase64Value = EncryptedBase64Value, Base64Iv = "init_vector" }; FakeEncryptedString = new WireEncryptedString { EncryptedValue = FakeEncryptedValue }; mutator = new EncryptionMessageMutator { EncryptionService = new FakeEncryptionService(FakeEncryptedValue) }; MessageConventionExtensions.IsEncryptedPropertyAction = property => typeof(WireEncryptedString).IsAssignableFrom(property.PropertyType); }
string DecryptUsingKeyIdentifier(EncryptedValue encryptedValue, string keyIdentifier) { byte[] decryptionKey; if (!keys.TryGetValue(keyIdentifier, out decryptionKey)) { throw new InvalidOperationException("Decryption key not available for key identifier '" + keyIdentifier + "'. Please add this key to the rijndael encryption service configuration. Key identifiers are case sensitive."); } try { return(Decrypt(encryptedValue, decryptionKey)); } catch (CryptographicException ex) { throw new InvalidOperationException("Unable to decrypt property using configured decryption key specified in key identifier header.", ex); } }
string DecryptUsingKeyIdentifier(EncryptedValue encryptedValue, string keyIdentifier) { byte[] decryptionKey; if (!keys.TryGetValue(keyIdentifier, out decryptionKey)) { throw new InvalidOperationException("Decryption key not available for key identifier '" + keyIdentifier + "'. Please add this key to the rijndael encryption service configuration. Key identifiers are case sensitive."); } try { return Decrypt(encryptedValue, decryptionKey); } catch (CryptographicException ex) { throw new InvalidOperationException("Unable to decrypt property using configured decryption key specified in key identifier header.", ex); } }
string DecryptUsingAllKeys(EncryptedValue encryptedValue) { var cryptographicExceptions = new List <CryptographicException>(); foreach (var key in decryptionKeys) { try { return(Decrypt(encryptedValue, key)); } catch (CryptographicException exception) { cryptographicExceptions.Add(exception); } } var message = string.Format("Could not decrypt message. Tried {0} keys.", decryptionKeys.Count); throw new AggregateException(message, cryptographicExceptions); }
public void Persist(string sessionKey, DateTimeOffset sessionExpirationTime, string requesterKey) { var cookieText = JsonSerializer.Serialize(new AnonInfo { SessionKey = sessionKey, SessionExpirationTime = sessionExpirationTime, RequesterKey = requesterKey }); var protectedText = new EncryptedValue(protector, cookieText).Value(); var options = new CookieOptions { HttpOnly = true, Secure = true, Path = "/", SameSite = SameSiteMode.Lax }; httpContextAccessor.HttpContext?.Response.Cookies.Append(cookieName, protectedText, options); SessionKey = sessionKey; SessionExpirationTime = sessionExpirationTime; RequesterKey = requesterKey; }
public void DecryptString() { const string KEY_ID = "bc436485-5092-42b8-92a3-0aa8b93536dc"; var mockContext = new Mock <IIncomingLogicalMessageContext>(); var headers = new Dictionary <string, string> { { EncryptionHeaders.RijndaelKeyIdentifier, KEY_ID } }; mockContext.SetupGet(p => p.Headers) .Returns(headers); const string ENCRYPT_VALUE = "This is a test value"; const string FAKE_ENCRYPTION = "FAKEENCRYPTEDVALUE"; var base64Encrypted = Convert.ToBase64String( new System.IO.MemoryStream(Encoding.UTF8.GetBytes(FAKE_ENCRYPTION)).ToArray()); var mockClient = new Mock <IAmazonKeyManagementService>(); mockClient.Setup(m => m.DecryptAsync(It.IsAny <DecryptRequest>(), default)) .ReturnsAsync(new DecryptResponse { Plaintext = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(ENCRYPT_VALUE)), KeyId = KEY_ID }); var encryptedValue = new EncryptedValue { EncryptedBase64Value = base64Encrypted }; var sut = new KMSEncryptionService(KEY_ID, mockClient.Object); var decrypted = sut.Decrypt(encryptedValue, mockContext.Object); decrypted.Should().NotBeNull(); decrypted.Should().BeEquivalentTo(ENCRYPT_VALUE); }
private CertifiedKeyPair(Asn1Sequence seq) { this.certOrEncCert = CertOrEncCert.GetInstance(seq[0]); if (seq.Count >= 2) { if (seq.Count == 2) { Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[1]); if (instance.TagNo == 0) { this.privateKey = EncryptedValue.GetInstance(instance.GetObject()); return; } this.publicationInfo = PkiPublicationInfo.GetInstance(instance.GetObject()); return; } else { this.privateKey = EncryptedValue.GetInstance(Asn1TaggedObject.GetInstance(seq[1])); this.publicationInfo = PkiPublicationInfo.GetInstance(Asn1TaggedObject.GetInstance(seq[2])); } } }
string IEncryptionService.Decrypt(EncryptedValue encryptedValue) { if (Key == null) { Logger.Warn("Cannot decrypt because a Key was not configured. Please specify 'RijndaelEncryptionServiceConfig' in your application's configuration file."); return encryptedValue.EncryptedBase64Value; } var encrypted = Convert.FromBase64String(encryptedValue.EncryptedBase64Value); using (var rijndael = new RijndaelManaged()) { rijndael.Key = Key; rijndael.IV = Convert.FromBase64String(encryptedValue.Base64Iv); rijndael.Mode = CipherMode.CBC; using (var decryptor = rijndael.CreateDecryptor()) using (var memoryStream = new MemoryStream(encrypted)) using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)) using (var reader = new StreamReader(cryptoStream)) { return reader.ReadToEnd(); } } }
public string Decrypt(EncryptedValue encryptedValue) { return encryptedValue.Base64Iv; }
public string Decrypt(EncryptedValue encryptedValue) { return null; }
static string Decrypt(EncryptedValue encryptedValue, byte[] key) { using (var rijndael = new RijndaelManaged()) { var encrypted = Convert.FromBase64String(encryptedValue.EncryptedBase64Value); rijndael.IV = Convert.FromBase64String(encryptedValue.Base64Iv); rijndael.Mode = CipherMode.CBC; rijndael.Key = key; using (var decryptor = rijndael.CreateDecryptor()) using (var memoryStream = new MemoryStream(encrypted)) using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)) using (var reader = new StreamReader(cryptoStream)) { return reader.ReadToEnd(); } } }
public string Decrypt(EncryptedValue encryptedValue) { throw new NotSupportedException("Please use overload Decrypt(string, IncomingContext)"); }
/// <summary> /// Updates configuration only in database. For reloading config must call Reload() after it /// </summary> /// <param name="dbManager"></param> /// <param name="domainID"></param> /// <param name="domainModule"></param> /// <param name="domainModuleFeature"></param> /// <param name="domainModuleFeatureConfig"></param> protected override void UpdateConfig(DBManager dbManager, long domainID, Dictionary<ModuleID, ModuleRec> domainModule, Dictionary<ModuleID, Dictionary<ModuleFeatureID, ModuleFeatureRec>> domainModuleFeature, Dictionary<ModuleID, Dictionary<ModuleFeatureID, Dictionary<string, string>>> domainModuleFeatureConfig) { using (IDBProvider dbInstance = SP.DB.GetInstance(dbManager)) { //start tx dbInstance.BeginTransaction(); DomainRec domRec = dbInstance._<DomainAccessor>().Domain(domainID); //translock //var dummy = Entity<DomainRec>.SelectForUpdate(dbInstance.Get, domRec.ID); SP.SessionContext.ExecuteInSystemSessionContext(domainID, () => { //clear module list dbInstance._<ModuleAccessor>().ClearModuleList(domainID); //go through provided foreach (ModuleRec module in domainModule.Values) { Util.Check.Ensure(module.DomainID == domainID, "DomainID mismatch"); bool isModuleEnabled = false; //clear feature list dbInstance._<ModuleAccessor>().ClearModuleFeatureList(domainID, module.ModuleID); //go through provided List<ModuleFeatureRec> fList = new List<ModuleFeatureRec>(); fList.AddRange(from t in domainModuleFeature[module.ModuleID].Values where t.ModuleFeatureID != ModuleFeatureID.Basic orderby t.Name select t); fList.Add((from t in domainModuleFeature[module.ModuleID].Values where t.ModuleFeatureID == ModuleFeatureID.Basic select t).First()); foreach (var feature in fList) { Util.Check.Ensure(feature.DomainID == domainID, "DomainID mismatch"); //clear config list dbInstance._<ModuleAccessor>().ClearFeatureConfigList(domainID, module.ModuleID, feature.ModuleFeatureID); //go through provided foreach (var configEntry in domainModuleFeatureConfig[module.ModuleID][feature.ModuleFeatureID]) { var evConfigValue = new EncryptedValue(configEntry.Value); //build config record ModuleFeatureConfigRec cfg = new ModuleFeatureConfigRec() { ModuleID = module.ModuleID, ModuleFeatureID = feature.ModuleFeatureID, ParamName = configEntry.Key, ParamValue = evConfigValue.Encrypted, ParamValueHash = evConfigValue.Hashed, ParamValueIV = evConfigValue.IV }; //save config Entity<ModuleFeatureConfigRec>.Insert(dbInstance.Get, cfg); } //feature set enabled if (domainID == SP.Const.SystemDomainID || ( module.ModuleID == ModuleID.Core && feature.ModuleFeatureID == ModuleFeatureID.Basic )) { feature.IsEnabled = true; } else { feature.IsEnabled = feature.IsEnabled; } if (!isModuleEnabled) { isModuleEnabled = feature.IsEnabled; } if (feature.ModuleFeatureID == ModuleFeatureID.Basic && isModuleEnabled) { feature.IsEnabled = true; } //save feature Entity<ModuleFeatureRec>.Insert(dbInstance.Get, feature); } //module set enabled module.IsEnabled = isModuleEnabled; //save module Entity<ModuleRec>.Insert(dbInstance.Get, module); } }); //commit tx dbInstance.CommitTransaction(); } }
protected override void InitConfig(DBManager dbManager) { Dictionary<ModuleID, ModuleRec> defaultModuleSetup; Dictionary<ModuleID, Dictionary<ModuleFeatureID, ModuleFeatureRec>> defaultFeatureSetup; Dictionary<ModuleID, Dictionary<ModuleFeatureID, Dictionary<string, string>>> defaultConfigSetup; _mci.InitDefaultModuleSetup(out defaultModuleSetup, out defaultFeatureSetup, out defaultConfigSetup); using (IDBProvider dbInstance = SP.DB.GetInstance(dbManager)) { //read domain list List<DomainRec> tmpDomainList = dbInstance._<DomainAccessor>().DomainList(); //by Shema: rebuild list so that system domain would be the first in the list //, need for job module IsDomainSpecific check List<DomainRec> domainList = new List<DomainRec>(); domainList.Add((from d in tmpDomainList where d.DomainID == SP.Const.SystemDomainID select d).First()); domainList.AddRange(from d in tmpDomainList where d.DomainID != SP.Const.SystemDomainID select d); //init vars var tmpDomainMap = new Dictionary<long, DomainRec>(); var tmpDomainModule = new Dictionary<long, Dictionary<ModuleID, ModuleRec>>(); var tmpDomainModuleFeature = new Dictionary<long, Dictionary<ModuleID, Dictionary<ModuleFeatureID, ModuleFeatureRec>>>(); var tmpDomainModuleFeatureConfig = new Dictionary<long, Dictionary<ModuleID, Dictionary<ModuleFeatureID, Dictionary<string, string>>>>(); //fill domain map tmpDomainList.ForEach(item => tmpDomainMap[item.DomainID] = item); //go through domain list foreach (var domain in domainList) { //start tx dbInstance.BeginTransaction(); //translock //var dummy = Entity<DomainRec>.SelectForUpdate(dbInstance.Get, domain.ID); long domainID = domain.DomainID; SP.SessionContext.ExecuteInSystemSessionContext(domainID, () => { //init default domain setup tmpDomainModule.Add(domainID, new Dictionary<ModuleID, ModuleRec>()); tmpDomainModuleFeature.Add(domainID, new Dictionary<ModuleID, Dictionary<ModuleFeatureID, ModuleFeatureRec>>()); tmpDomainModuleFeatureConfig.Add(domainID, new Dictionary<ModuleID, Dictionary<ModuleFeatureID, Dictionary<string, string>>>()); //read domain's module list List<ModuleRec> moduleList = dbInstance._<ModuleAccessor>().ModuleList(domainID); //clear domain's module list dbInstance._<ModuleAccessor>().ClearModuleList(domainID); //go through default module list foreach (ModuleRec defaultModule in defaultModuleSetup.Values) { var selectedModule = from item in moduleList where item.ModuleID == defaultModule.ModuleID select item; // ----------------- MODULE --------------------- // //record ModuleRec module = selectedModule.Count() > 0 ? selectedModule.First() : new ModuleRec() { ModuleID = defaultModule.ModuleID, Name = defaultModule.Name, Description = defaultModule.Description, IsEnabled = defaultModule.IsEnabled }; if (domainID == SP.Const.SystemDomainID || module.ModuleID == ModuleID.Core) { module.IsEnabled = true; } //save Entity<ModuleRec>.Insert(dbInstance.Get, module); tmpDomainModule[domainID].Add(module.ModuleID, module); // ----------------- MODULE FEATURES ------------ // tmpDomainModuleFeature[domainID].Add(module.ModuleID, new Dictionary<ModuleFeatureID, ModuleFeatureRec>()); tmpDomainModuleFeatureConfig[domainID].Add(module.ModuleID, new Dictionary<ModuleFeatureID, Dictionary<string, string>>()); //read module's feature list List<ModuleFeatureRec> moduleFeatureList = dbInstance._<ModuleAccessor>().ModuleFeatureList(domainID, module.ModuleID); //clear module's feature list dbInstance._<ModuleAccessor>().ClearModuleFeatureList(domainID, module.ModuleID); //got through default feature list List<ModuleFeatureRec> fList = new List<ModuleFeatureRec>(); fList.AddRange(from t in defaultFeatureSetup[module.ModuleID].Values where t.ModuleFeatureID != ModuleFeatureID.Basic orderby t.Name select t); fList.Add((from t in defaultFeatureSetup[module.ModuleID].Values where t.ModuleFeatureID == ModuleFeatureID.Basic select t).First()); foreach (var defaultFeature in fList) { var selectedFeature = from item in moduleFeatureList where item.ModuleFeatureID == defaultFeature.ModuleFeatureID select item; // ----------------- FEATURE ---------------- // //record ModuleFeatureRec feature = selectedFeature.Count() > 0 ? selectedFeature.First() : new ModuleFeatureRec() { ModuleID = defaultFeature.ModuleID, ModuleFeatureID = defaultFeature.ModuleFeatureID, Name = defaultFeature.Name, IsEnabled = defaultFeature.IsEnabled }; if (domainID == SP.Const.SystemDomainID || ( module.ModuleID == ModuleID.Core && feature.ModuleFeatureID == ModuleFeatureID.Basic )) { feature.IsEnabled = true; } else { feature.IsEnabled = module.IsEnabled && feature.IsEnabled; } if (feature.ModuleFeatureID == ModuleFeatureID.Basic && module.IsEnabled) { feature.IsEnabled = true; } //job module special logic - skip not domain specific job if (module.ModuleID == ModuleID.Job && domainID != SP.Const.SystemDomainID && feature.ModuleFeatureID != ModuleFeatureID.Basic && tmpDomainModuleFeatureConfig[SP.Const.SystemDomainID] [feature.ModuleID][feature.ModuleFeatureID][SP.Const.MOD_JOB_IsDomainSpecific] != SP.Const.MOD_Yes ) { continue; } //save Entity<ModuleFeatureRec>.Insert(dbInstance.Get, feature); tmpDomainModuleFeature[domainID][module.ModuleID].Add(feature.ModuleFeatureID, feature); // ------------- FEATURE CONFIG ------------- // tmpDomainModuleFeatureConfig[domainID][module.ModuleID].Add(feature.ModuleFeatureID, new Dictionary<string, string>()); //read feature's config list List<ModuleFeatureConfigRec> featureConfigList = dbInstance._<ModuleAccessor>() .FeatureConfigList(domainID, module.ModuleID, feature.ModuleFeatureID); //clear feature's config list dbInstance._<ModuleAccessor>().ClearFeatureConfigList(domainID, module.ModuleID, feature.ModuleFeatureID); //gor through default module feature list foreach (var defaultConfig in defaultConfigSetup[module.ModuleID][feature.ModuleFeatureID]) { //job module special logic - skip system domain level specific configuration if (module.ModuleID == ModuleID.Job && domainID != SP.Const.SystemDomainID && ( defaultConfig.Key == SP.Const.MOD_JOB_IsRunnable || defaultConfig.Key == SP.Const.MOD_JOB_IsRecordable || defaultConfig.Key == SP.Const.MOD_JOB_IsBackDateScheduleSupported || defaultConfig.Key == SP.Const.MOD_JOB_IsDomainSpecific || defaultConfig.Key == SP.Const.MOD_JOB_ScheduleString )) { continue; } //service module special logic - skip system domain level specific configuration if (module.ModuleID == ModuleID.Service && domainID != SP.Const.SystemDomainID && ( defaultConfig.Key == SP.Const.MOD_SERVICE_BASIC_PublicServiceAPIAllowedIPList )) { continue; } var selectedConfig = from item in featureConfigList where item.ParamName == defaultConfig.Key select item; string configValue; if (selectedConfig.Count() > 0) { var tmpRec = selectedConfig.First(); configValue = new EncryptedValue(tmpRec.ParamValue, tmpRec.ParamValueIV).Plain; } else { configValue = defaultConfig.Value; } // ----------------- CONFIG ------------- // var evConfigValue = new EncryptedValue(configValue); //record ModuleFeatureConfigRec cfg = new ModuleFeatureConfigRec() { ModuleID = module.ModuleID, ModuleFeatureID = feature.ModuleFeatureID, ParamName = defaultConfig.Key, ParamValue = evConfigValue.Encrypted, ParamValueHash = evConfigValue.Hashed, ParamValueIV = evConfigValue.IV }; //save Entity<ModuleFeatureConfigRec>.Insert(dbInstance.Get, cfg); tmpDomainModuleFeatureConfig[domainID][module.ModuleID][feature.ModuleFeatureID][defaultConfig.Key] = configValue; } } } }); //commit tx dbInstance.CommitTransaction(); } //result Interlocked.Exchange(ref _domainMap, tmpDomainMap); Interlocked.Exchange(ref _domainModule, tmpDomainModule); Interlocked.Exchange(ref _domainModuleFeature, tmpDomainModuleFeature); Interlocked.Exchange(ref _domainModuleFeatureConfig, tmpDomainModuleFeatureConfig); //init vendors InstallDomainVendors(dbInstance.Get, _vendorSetup); //init roles InstallDomainRoles(dbInstance.Get, _roleSetup); } }
public FakeEncryptionService(EncryptedValue hardcodedValue) { this.hardcodedValue = hardcodedValue; }