protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <SubstitutionObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long signHash, valueHash; DictionaryConfiguration dictionaryConfiguration; object value; long surrogateId; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } dictionaryConfiguration = this.GetDictionaryConfiguration(oxymoronEngine, columnConfiguration); valueHash = this.GetValueHash(oxymoronEngine, dictionaryConfiguration.RecordCount, columnValue); surrogateId = valueHash; value = GetSubstitution(oxymoronEngine, dictionaryConfiguration, metaColumn, surrogateId, columnValue); return(value); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <ObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long valueHash; object value; long randomSeed; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } valueHash = this.GetValueHash(oxymoronEngine, null, columnValue); randomSeed = valueHash; value = GetShuffle(randomSeed, columnValue); return(value); }
private DictionaryConfiguration GetDictionaryConfiguration(IOxymoronEngine oxymoronEngine, ColumnConfiguration <SubstitutionObfuscationStrategyConfiguration> columnConfiguration) { DictionaryConfiguration dictionaryConfiguration; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if (columnConfiguration.ObfuscationStrategySpecificConfiguration.DictionaryReference.SafeToString().Trim().ToLower() == string.Empty) { dictionaryConfiguration = new DictionaryConfiguration(); } else { dictionaryConfiguration = oxymoronEngine.ObfuscationConfiguration.DictionaryConfigurations.SingleOrDefault(d => d.DictionaryId.SafeToString().Trim().ToLower() == columnConfiguration.ObfuscationStrategySpecificConfiguration.DictionaryReference.SafeToString().Trim().ToLower()); } if ((object)dictionaryConfiguration == null) { throw new InvalidOperationException(string.Format("Unknown dictionary reference '{0}' specified for column '{1}'.", columnConfiguration.ObfuscationStrategySpecificConfiguration.DictionaryReference, columnConfiguration.ColumnName)); } return(dictionaryConfiguration); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <ObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long valueHash; object value; long randomSeed; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } valueHash = this.GetValueHash(oxymoronEngine, null, metaColumn.ColumnName); randomSeed = valueHash; // create a new repeatable yet random-ish math funcion using the random seed, then executes for column value value = GetSurrogateKey(randomSeed, columnValue); return(value); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <MaskingObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { object value; double maskingFactor; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } maskingFactor = (columnConfiguration.ObfuscationStrategySpecificConfiguration.MaskingPercentValue.GetValueOrDefault() / 100.0); value = GetMask(maskingFactor, columnValue); return(value); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <VarianceObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long signHash, valueHash; object value; double varianceFactor; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } signHash = this.GetSignHash(oxymoronEngine, columnValue); valueHash = this.GetValueHash(oxymoronEngine, columnConfiguration.ObfuscationStrategySpecificConfiguration.VariancePercentValue, columnValue); varianceFactor = ((((valueHash <= 0 ? 1 : valueHash)) * ((signHash % 2 == 0 ? 1.0 : -1.0))) / 100.0); value = GetVariance(varianceFactor, columnValue); return(value); }
/// <summary> /// IDTSRuntimeComponent100 (OK) /// </summary> public override void PostExecute() { this.OxymoronEngine.Dispose(); this.OxymoronEngine = null; this.DictionaryConfigurationToAdapterMappings.Clear(); this.InputColumnInfos.Clear(); base.PostExecute(); }
protected long GetValueHash(IOxymoronEngine oxymoronEngine, long?size, object value) { long hash; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } hash = oxymoronEngine.GetBoundedHash(size ?? DEFAULT_HASH_BUCKET_SIZE, value); return(hash); }
/// <summary> /// IDTSRuntimeComponent100 /// </summary> public override void PreExecute() { ObfuscationConfiguration obfuscationConfiguration; IDTSInput100 dtsInput100; ColumnInfo columnInfo; this.TryLaunchDebugger(); obfuscationConfiguration = this.ComponentMetadataWrapper.GetObfuscationConfiguration(); this.OxymoronEngine = new OxymoronEngine(this, obfuscationConfiguration); foreach (DictionaryConfiguration dictionaryConfiguration in obfuscationConfiguration.DictionaryConfigurations) { IDictionaryAdapter dictionaryAdapter; dictionaryAdapter = new DtsDictionaryAdapter(); this.DictionaryAdapters.Add(dictionaryAdapter); dictionaryAdapter.Initialize(dictionaryConfiguration.DictionaryAdapterConfiguration); dictionaryAdapter.InitializePreloadCache(dictionaryConfiguration, this.OxymoronEngine.SubstitutionCacheRoot); this.DictionaryConfigurationToAdapterMappings.Add(dictionaryConfiguration, dictionaryAdapter); } // interogate input columns and stash away for later use dtsInput100 = this.ComponentMetaData.InputCollection[0]; foreach (IDTSInputColumn100 dtsInputColumn100 in dtsInput100.InputColumnCollection) { columnInfo = new ColumnInfo(); columnInfo.name = dtsInputColumn100.Name; columnInfo.bufferColumnIndex = this.BufferManager.FindColumnByLineageID(dtsInput100.Buffer, dtsInputColumn100.LineageID); columnInfo.columnDisposition = dtsInputColumn100.ErrorRowDisposition; columnInfo.lineageId = dtsInputColumn100.LineageID; columnInfo.type = dtsInputColumn100.DataType; columnInfo.length = dtsInputColumn100.Length; columnInfo.precision = dtsInputColumn100.Precision; columnInfo.scale = dtsInputColumn100.Scale; columnInfo.codepage = dtsInputColumn100.CodePage; this.InputColumnInfos.Add(columnInfo); } }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <ScriptObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } return(CompileCSharpCode(columnValue, columnConfiguration.ObfuscationStrategySpecificConfiguration.SourceCode)); }
public object GetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration columnConfiguration, IMetaColumn metaColumn, object columnValue) { ColumnConfiguration <TObfuscationStrategyConfiguration> _columnConfiguration; object value; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnValue == DBNull.Value) { columnValue = null; } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } _columnConfiguration = new ColumnConfiguration <TObfuscationStrategyConfiguration>(columnConfiguration); if ((object)_columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } value = this.CoreGetObfuscatedValue(oxymoronEngine, _columnConfiguration, metaColumn, columnValue); return(value); }
protected override Task PostExecuteAsyncInternal(IContext context, RecordConfiguration configuration, CancellationToken cancellationToken) { if ((object)context == null) { throw new ArgumentNullException(nameof(context)); } if ((object)configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if ((object)this.OxymoronEngine != null) { this.OxymoronEngine.Dispose(); } this.OxymoronEngine = null; return(Task.CompletedTask); }
protected override Task PreExecuteAsyncInternal(IContext context, RecordConfiguration configuration, CancellationToken cancellationToken) { ResolveDictionaryValueDelegate resolveDictionaryValueCallback; IObfuscationSpec obfuscationSpec; if ((object)context == null) { throw new ArgumentNullException(nameof(context)); } if ((object)configuration == null) { throw new ArgumentNullException(nameof(configuration)); } resolveDictionaryValueCallback = (spec, key) => key; obfuscationSpec = new __XX(); this.OxymoronEngine = new OxymoronEngine(resolveDictionaryValueCallback, obfuscationSpec); return(Task.CompletedTask); }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration<ObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { long signHash, valueHash; object value; string sharedSecret; if ((object)columnConfiguration == null) throw new ArgumentNullException("columnConfiguration"); if ((object)metaColumn == null) throw new ArgumentNullException("metaColumn"); if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); signHash = this.GetSignHash(oxymoronEngine, columnValue); valueHash = this.GetValueHash(oxymoronEngine, null, columnValue); sharedSecret = ((valueHash <= 0 ? 1 : valueHash) * (signHash % 2 == 0 ? -1 : 1)).ToString("X"); value = GetCipher(sharedSecret, columnValue); return value; }
protected override object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <DefaultingObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue) { object value; if ((object)columnConfiguration == null) { throw new ArgumentNullException("columnConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)columnConfiguration.ObfuscationStrategySpecificConfiguration == null) { throw new InvalidOperationException(string.Format("Configuration missing: '{0}'.", "ObfuscationStrategyConfiguration")); } value = GetDefault(metaColumn.ColumnIsNullable ?? columnConfiguration.ObfuscationStrategySpecificConfiguration.DefaultingCanBeNull ?? false, metaColumn.ColumnType); return(value); }
private static object GetSubstitution(IOxymoronEngine oxymoronEngine, DictionaryConfiguration dictionaryConfiguration, IMetaColumn metaColumn, long surrogateId, object value) { Type valueType; string _value; const bool SUBSTITUTION_CACHE_ENABLED = true; IDictionary <long, object> dictionaryCache; if ((object)oxymoronEngine == null) { throw new ArgumentNullException("oxymoronEngine"); } if ((object)dictionaryConfiguration == null) { throw new ArgumentNullException("dictionaryConfiguration"); } if ((object)metaColumn == null) { throw new ArgumentNullException("metaColumn"); } if ((object)value == null) { return(null); } valueType = value.GetType(); if (valueType != typeof(String)) { return(null); } _value = (String)value; if (DataTypeFascade.Instance.IsWhiteSpace(_value)) { return(_value); } _value = _value.Trim(); if ((dictionaryConfiguration.RecordCount ?? 0L) <= 0L) { return(null); } if (!SUBSTITUTION_CACHE_ENABLED || !oxymoronEngine.SubstitutionCacheRoot.TryGetValue(dictionaryConfiguration.DictionaryId, out dictionaryCache)) { dictionaryCache = new Dictionary <long, object>(); if (SUBSTITUTION_CACHE_ENABLED) { oxymoronEngine.SubstitutionCacheRoot.Add(dictionaryConfiguration.DictionaryId, dictionaryCache); } } if (!SUBSTITUTION_CACHE_ENABLED || !dictionaryCache.TryGetValue(surrogateId, out value)) { if (dictionaryConfiguration.PreloadEnabled) { throw new InvalidOperationException(string.Format("Cache miss when is preload enabled for dictionary '{0}'; current cache slot item count: {1}.", dictionaryConfiguration.DictionaryId, dictionaryCache.Count)); } value = oxymoronEngine.OxymoronHost.GetValueForIdViaDictionaryResolution(dictionaryConfiguration, metaColumn, surrogateId); if (SUBSTITUTION_CACHE_ENABLED) { dictionaryCache.Add(surrogateId, value); } } return(value); }
protected abstract object CoreGetObfuscatedValue(IOxymoronEngine oxymoronEngine, ColumnConfiguration <TObfuscationStrategyConfiguration> columnConfiguration, IMetaColumn metaColumn, object columnValue);