示例#1
0
 public EncryptedConfigurationElement(
     [NotNull] IConfigurationElement <string> configurationElement, [NotNull] string passwordName, [NotNull] IDataProtection dataProtection)
 {
     _ConfigurationElement = configurationElement ?? throw new ArgumentNullException(nameof(configurationElement));
     _PasswordName         = passwordName ?? throw new ArgumentNullException(nameof(passwordName));
     _DataProtection       = dataProtection ?? throw new ArgumentNullException(nameof(dataProtection));
 }
示例#2
0
        public byte[] GetXmlBytes(IDataProtection dataProtection)
        {
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Indent   = true;
            xmlWriterSettings.Encoding = Encoding.UTF8;
            MemoryStream memoryStream = new MemoryStream();
            XmlWriter    xmlWriter    = XmlWriter.Create(memoryStream, xmlWriterSettings);

            using (xmlWriter)
            {
                xmlWriter.WriteStartElement("DataSourceDefinition", "http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource");
                xmlWriter.WriteElementString("Extension", this.Extension);
                xmlWriter.WriteElementString("ConnectString", this.GetConnectionString(dataProtection));
                xmlWriter.WriteElementString("CredentialRetrieval", this.CredentialsRetrieval.ToString());
                if (this.CredentialsRetrieval == CredentialsRetrievalOption.Prompt || this.CredentialsRetrieval == CredentialsRetrievalOption.Store)
                {
                    xmlWriter.WriteElementString("WindowsCredentials", this.WindowsCredentials.ToString());
                }
                if (this.CredentialsRetrieval == CredentialsRetrievalOption.Prompt)
                {
                    xmlWriter.WriteElementString("Prompt", string.IsNullOrEmpty(this.Prompt) ? "" : this.Prompt);
                }
                if (this.CredentialsRetrieval == CredentialsRetrievalOption.Store)
                {
                    xmlWriter.WriteElementString("ImpersonateUser", this.ImpersonateUser.ToString());
                }
                xmlWriter.WriteElementString("Enabled", this.Enabled.ToString());
                xmlWriter.WriteEndElement();
                xmlWriter.Flush();
                return(memoryStream.ToArray());
            }
        }
        private void ConstructFromXml(string dataSourcesXml, bool clientLoad, IDataProtection dataProtection)
        {
            XmlDocument xmlDocument = new XmlDocument();

            try
            {
                XmlUtil.SafeOpenXmlDocumentString(xmlDocument, dataSourcesXml);
            }
            catch (XmlException ex)
            {
                throw new MalformedXmlException(ex);
            }
            try
            {
                foreach (XmlNode childNode in (xmlDocument.SelectSingleNode("/DataSources") ?? throw new InvalidXmlException()).ChildNodes)
                {
                    DataSourceInfo dataSource = DataSourceInfo.ParseDataSourceNode(childNode, clientLoad, dataProtection);
                    Add(dataSource);
                }
            }
            catch (XmlException)
            {
                throw new InvalidXmlException();
            }
        }
        public static string Unprotect([NotNull] this IDataProtection dataProtection, [NotNull] string protectedString, [NotNull] string passwordName)
        {
            if (dataProtection == null)
            {
                throw new ArgumentNullException(nameof(dataProtection));
            }

            if (protectedString == null)
            {
                throw new ArgumentNullException(nameof(protectedString));
            }

            byte[] protectedBytes;
            try
            {
                protectedBytes = Convert.FromBase64String(protectedString);
            }
            catch (FormatException ex)
            {
                throw new DataProtectionException($"Unable to unprotect data: {ex.Message}", ex);
            }

            var unprotectedBytes = dataProtection.Unprotect(protectedBytes, passwordName);

            return(Encoding.UTF8.GetString(unprotectedBytes));
        }
示例#5
0
 public SecureStringWrapper GetPassword(IDataProtection dataProtection)
 {
     if (this.m_passwordSecureString == null && this.m_passwordEncrypted != null)
     {
         this.m_passwordSecureString = new SecureStringWrapper(dataProtection.UnprotectDataToString(this.m_passwordEncrypted, "Password"));
     }
     return(this.m_passwordSecureString);
 }
        public static byte[] Unprotect([NotNull] this IDataProtection dataProtection, [NotNull] byte[] protectedData)
        {
            if (dataProtection == null)
            {
                throw new ArgumentNullException(nameof(dataProtection));
            }

            return(dataProtection.Unprotect(protectedData, DefaultPasswordName));
        }
示例#7
0
 public DataSourceHelper(byte[] encryptedDomainAndUserName, byte[] encryptedPassword, IDataProtection dataProtection)
 {
     this.m_encryptedDomainAndUserName = encryptedDomainAndUserName;
     this.m_encryptedPassword          = encryptedPassword;
     if (dataProtection == null)
     {
         throw new ArgumentNullException("dataProtection");
     }
     this.m_dp = dataProtection;
 }
示例#8
0
        public string GetPasswordDecrypted(IDataProtection dataProtection)
        {
            SecureStringWrapper password = this.GetPassword(dataProtection);

            if (password != null)
            {
                return(password.ToString());
            }
            return(null);
        }
示例#9
0
 public void SetCredentials(DatasourceCredentialsCollection allCredentials, IDataProtection dataProtection)
 {
     if (allCredentials != null)
     {
         foreach (DatasourceCredentials allCredential in allCredentials)
         {
             this.SetCredentials(allCredential, dataProtection);
         }
     }
 }
示例#10
0
 /// <summary>
 /// Create a new keychain
 /// </summary>
 /// <param name="options">The creation options</param>
 /// <param name="dataProtection">A object that can encrypt and decrypt data</param>
 /// <param name="logger">A logger for the keychain</param>
 public Keychain(KeychainOptions options, IDataProtection dataProtection, ILogger <Keychain> logger)
 {
     path                = options.Path;
     this.logger         = logger;
     this.dataProtection = dataProtection;
     if (!ReadEncryptedData())
     {
         logger.LogError("Failed to read keychain");
     }
 }
 public DatabaseConnectionFactory(
     [NotNull] IContainer container, [NotNull] IConfiguration configuration, [NotNull] ILogger logger, [NotNull] IDatabaseMigrator databaseMigrator,
     [NotNull] IDataProtection dataProtection)
 {
     _Container        = container ?? throw new ArgumentNullException(nameof(container));
     _Configuration    = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _Logger           = logger ?? throw new ArgumentNullException(nameof(logger));
     _DatabaseMigrator = databaseMigrator ?? throw new ArgumentNullException(nameof(databaseMigrator));
     _DataProtection   = dataProtection ?? throw new ArgumentNullException(nameof(dataProtection));
 }
示例#12
0
 public void SetCredentials(DatasourceCredentialsCollection allCredentials, IDataProtection dataProtection)
 {
     if (allCredentials == null)
     {
         return;
     }
     foreach (DatasourceCredentials allCredential in allCredentials)
     {
         SetCredentials(allCredential, dataProtection);
     }
 }
        public static string Unprotect([NotNull] this IDataProtection dataProtection, [NotNull] string protectedString)
        {
            if (dataProtection == null)
            {
                throw new ArgumentNullException(nameof(dataProtection));
            }

            if (protectedString == null)
            {
                throw new ArgumentNullException(nameof(protectedString));
            }

            return(Unprotect(dataProtection, protectedString, DefaultPasswordName));
        }
示例#14
0
 internal RenderingContext(RenderingContext copy, Uri contextUri, EmbeddedImageHashtable embeddedImages, ImageStreamNames imageStreamNames, ICatalogItemContext subreportICatalogItemContext)
 {
     m_commonInfo       = copy.m_commonInfo;
     m_inPageSection    = false;
     m_prefix           = null;
     m_eventInfo        = copy.m_eventInfo;
     m_reportSnapshot   = copy.ReportSnapshot;
     m_processedItems   = null;
     m_cachedHiddenInfo = copy.m_cachedHiddenInfo;
     m_contextUri       = contextUri;
     m_embeddedImages   = embeddedImages;
     m_imageStreamNames = imageStreamNames;
     m_currentReportICatalogItemContext = subreportICatalogItemContext;
     m_jobContext     = copy.m_jobContext;
     m_dataProtection = copy.m_dataProtection;
 }
示例#15
0
 internal RenderingContext(RenderingContext copy, string prefix)
 {
     m_commonInfo       = copy.m_commonInfo;
     m_inPageSection    = true;
     m_prefix           = prefix;
     m_eventInfo        = null;
     m_reportSnapshot   = null;
     m_processedItems   = null;
     m_cachedHiddenInfo = null;
     m_contextUri       = copy.m_contextUri;
     m_embeddedImages   = copy.EmbeddedImages;
     m_imageStreamNames = copy.ImageStreamNames;
     m_currentReportICatalogItemContext = m_commonInfo.TopLevelReportContext;
     m_jobContext     = copy.m_jobContext;
     m_dataProtection = copy.m_dataProtection;
 }
示例#16
0
 internal RenderingContext(ReportSnapshot reportSnapshot, string rendererID, DateTime executionTime, EmbeddedImageHashtable embeddedImages, ImageStreamNames imageStreamNames, EventInformation eventInfo, ICatalogItemContext reportContext, Uri contextUri, NameValueCollection reportParameters, Microsoft.ReportingServices.ReportProcessing.ReportProcessing.GetReportChunk getChunkCallback, ChunkManager.RenderingChunkManager chunkManager, IGetResource getResourceCallback, Microsoft.ReportingServices.ReportProcessing.ReportProcessing.GetChunkMimeType getChunkMimeType, Microsoft.ReportingServices.ReportProcessing.ReportProcessing.StoreServerParameters storeServerParameters, bool retrieveRenderingInfo, UserProfileState allowUserProfileState, ReportRuntimeSetup reportRuntimeSetup, IJobContext jobContext, IDataProtection dataProtection)
 {
     m_commonInfo       = new CommonInfo(rendererID, executionTime, reportContext, reportParameters, getChunkCallback, chunkManager, getResourceCallback, getChunkMimeType, storeServerParameters, retrieveRenderingInfo, allowUserProfileState, reportRuntimeSetup, reportSnapshot.Report.IntermediateFormatVersion);
     m_inPageSection    = false;
     m_prefix           = null;
     m_eventInfo        = eventInfo;
     m_reportSnapshot   = reportSnapshot;
     m_processedItems   = null;
     m_cachedHiddenInfo = null;
     m_contextUri       = contextUri;
     m_embeddedImages   = embeddedImages;
     m_imageStreamNames = imageStreamNames;
     m_currentReportICatalogItemContext = m_commonInfo.TopLevelReportContext;
     m_jobContext     = jobContext;
     m_dataProtection = dataProtection;
 }
        public static string Protect([NotNull] this IDataProtection dataProtection, [NotNull] string unprotectedString, [NotNull] string passwordName)
        {
            if (dataProtection == null)
            {
                throw new ArgumentNullException(nameof(dataProtection));
            }

            if (unprotectedString == null)
            {
                throw new ArgumentNullException(nameof(unprotectedString));
            }

            var unprotectedBytes = Encoding.UTF8.GetBytes(unprotectedString);
            var protectedBytes   = dataProtection.Protect(unprotectedBytes, passwordName);

            return(Convert.ToBase64String(protectedBytes));
        }
示例#18
0
        public TwitchConnection(IDataProtection dataProtection)
        {
            _dataProtection = dataProtection;
            var clientOptions = new ClientOptions
            {
                MessagesAllowedInPeriod = 750,
                ThrottlingPeriod        = TimeSpan.FromSeconds(30)
            };
            WebSocketClient customClient = new WebSocketClient(clientOptions);

            Client = new TwitchClient(customClient);

            Client.OnLog               += Client_OnLog;
            Client.OnJoinedChannel     += Client_OnJoinedChannel;
            Client.OnMessageReceived   += Client_OnMessageReceived;
            Client.OnWhisperReceived   += Client_OnWhisperReceived;
            Client.OnConnected         += Client_OnConnected;
            Client.OnError             += Client_OnError;
            Client.OnConnectionError   += Client_OnConnectionError;
            Client.OnNoPermissionError += Client_OnNoPermissionError;
        }
        internal void SetCredentials(DatasourceCredentials credentials, IDataProtection dataProtection)
        {
            int num = 0;

            while (true)
            {
                if (num < Count)
                {
                    DataSourceInfo dataSourceInfo = this[num];
                    if (dataSourceInfo.CredentialsRetrieval != DataSourceInfo.CredentialsRetrievalOption.Prompt)
                    {
                        break;
                    }
                    dataSourceInfo.SetUserName(credentials.UserName, dataProtection);
                    dataSourceInfo.SetPassword(credentials.Password, dataProtection);
                    num++;
                    continue;
                }
                return;
            }
            throw new InternalCatalogException("Non-promptable data source appeared in prompt collection!");
        }
示例#20
0
 public DataSetContext(string targetChunkNameInSnapshot, string cachedDataChunkName, bool mustCreateDataChunk, IRowConsumer consumerRequest, ICatalogItemContext itemContext, RuntimeDataSourceInfoCollection dataSources, string requestUserName, DateTime executionTimeStamp, ParameterInfoCollection parameters, IChunkFactory createChunkFactory, ReportProcessing.ExecutionType interactiveExecution, CultureInfo culture, UserProfileState allowUserProfileState, UserProfileState initialUserProfileState, IProcessingDataExtensionConnection createDataExtensionInstanceFunction, CreateAndRegisterStream createStreamCallbackForScalability, ReportRuntimeSetup dataSetRuntimeSetup, IJobContext jobContext, IDataProtection dataProtection)
 {
     m_targetChunkNameInSnapshot = targetChunkNameInSnapshot;
     m_cachedDataChunkName       = cachedDataChunkName;
     m_mustCreateDataChunk       = mustCreateDataChunk;
     m_consumerRequest           = consumerRequest;
     m_itemContext          = itemContext;
     m_dataSources          = dataSources;
     m_requestUserName      = requestUserName;
     m_executionTimeStamp   = executionTimeStamp;
     m_parameters           = parameters;
     m_createChunkFactory   = createChunkFactory;
     m_interactiveExecution = interactiveExecution;
     m_culture = culture;
     m_allowUserProfileState               = allowUserProfileState;
     m_initialUserProfileState             = initialUserProfileState;
     m_createDataExtensionInstanceFunction = createDataExtensionInstanceFunction;
     m_createStreamCallbackForScalability  = createStreamCallbackForScalability;
     m_dataSetRuntimeSetup = dataSetRuntimeSetup;
     m_jobContext          = jobContext;
     m_dataProtection      = dataProtection;
 }
示例#21
0
 protected PublishingContextBase(PublishingContextKind publishingContextKind, ICatalogItemContext catalogContext, IChunkFactory createChunkFactory, AppDomain compilationTempAppDomain, bool generateExpressionHostWithRefusedPermissions, ReportProcessingFlags processingFlags, AspNetCore.ReportingServices.ReportProcessing.ReportProcessing.CheckSharedDataSource checkDataSourceCallback, AspNetCore.ReportingServices.ReportProcessing.ReportProcessing.ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, DataSourceInfoCollection originalDataSources, AspNetCore.ReportingServices.ReportProcessing.ReportProcessing.CheckSharedDataSet checkDataSetCallback, AspNetCore.ReportingServices.ReportProcessing.ReportProcessing.ResolveTemporaryDataSet resolveTemporaryDataSetCallback, DataSetInfoCollection originalDataSets, IConfiguration configuration, IDataProtection dataProtection, bool isInternalRepublish, bool isPackagedReportArchive, bool isRdlx, bool traceAtomicScopes)
 {
     this.m_publishingContextKind    = publishingContextKind;
     this.m_catalogContext           = catalogContext;
     this.m_createChunkFactory       = createChunkFactory;
     this.m_compilationTempAppDomain = compilationTempAppDomain;
     this.m_generateExpressionHostWithRefusedPermissions = generateExpressionHostWithRefusedPermissions;
     this.m_processingFlags                    = processingFlags;
     this.m_checkDataSourceCallback            = checkDataSourceCallback;
     this.m_checkDataSetCallback               = checkDataSetCallback;
     this.m_resolveTemporaryDataSourceCallback = resolveTemporaryDataSourceCallback;
     this.m_resolveTemporaryDataSetCallback    = resolveTemporaryDataSetCallback;
     this.m_originalDataSources                = originalDataSources;
     this.m_originalDataSets                   = originalDataSets;
     this.m_configuration           = configuration;
     this.m_dataProtection          = dataProtection;
     this.m_isInternalRepublish     = isInternalRepublish;
     this.m_traceAtomicScopes       = traceAtomicScopes;
     this.m_isPackagedReportArchive = isPackagedReportArchive;
     this.m_isRdlx = isRdlx;
     this.m_publishingVersioning = new PublishingVersioning(this.m_configuration, this);
 }
示例#22
0
        private void SetCredentials(DatasourceCredentials credentials, IDataProtection dataProtection)
        {
            string promptID = credentials.PromptID;

            if (this.m_collectionByPrompt == null)
            {
                if (this.GetByOriginalName(promptID) != null)
                {
                    throw new DataSourceNoPromptException(promptID);
                }
                throw new DataSourceNotFoundException(promptID);
            }
            PromptBucket bucketByOriginalName = this.m_collectionByPrompt.GetBucketByOriginalName(promptID);

            if (bucketByOriginalName == null)
            {
                if (this.GetByOriginalName(promptID) != null)
                {
                    throw new DataSourceNoPromptException(promptID);
                }
                throw new DataSourceNotFoundException(promptID);
            }
            bucketByOriginalName.SetCredentials(credentials, dataProtection);
        }
示例#23
0
        internal ProcessingContext(ICatalogItemContext reportContext, string requestUserName, ParameterInfoCollection parameters, ReportProcessing.OnDemandSubReportCallback subReportCallback, IGetResource getResourceFunction, IChunkFactory createChunkFactory, ReportProcessing.ExecutionType interactiveExecution, CultureInfo culture, UserProfileState allowUserProfileState, UserProfileState initialUserProfileState, ReportRuntimeSetup reportRuntimeSetup, CreateAndRegisterStream createStreamCallback, bool isHistorySnapshot, IJobContext jobContext, IExtensionFactory extFactory, IDataProtection dataProtection)
        {
            Global.Tracer.Assert(reportContext != null, "(null != reportContext)");
            m_reportContext           = reportContext;
            m_requestUserName         = requestUserName;
            m_parameters              = parameters;
            m_queryParameters         = m_parameters.GetQueryParameters();
            m_subReportCallback       = subReportCallback;
            m_getResourceFunction     = getResourceFunction;
            m_chunkFactory            = createChunkFactory;
            m_interactiveExecution    = interactiveExecution;
            m_userLanguage            = culture;
            m_allowUserProfileState   = allowUserProfileState;
            m_initialUserProfileState = initialUserProfileState;
            m_reportRuntimeSetup      = reportRuntimeSetup;
            m_createStreamCallback    = createStreamCallback;
            m_isHistorySnapshot       = isHistorySnapshot;
            ChunkFactoryAdapter @object = new ChunkFactoryAdapter(m_chunkFactory);

            m_createReportChunkCallback = @object.CreateReportChunk;
            m_jobContext     = jobContext;
            m_extFactory     = extFactory;
            m_dataProtection = dataProtection;
        }
示例#24
0
 public TwitchBot(IDataProtection dataProtection, IEnumerable <IMessageHandler> messageHandlers)
     : base(dataProtection)
 {
     _messageHandlers = messageHandlers;
 }
示例#25
0
 public string GetUserName(IDataProtection dataProtection)
 {
     return(dataProtection.UnprotectDataToString(this.m_userNameEncrypted, "UserName"));
 }
示例#26
0
 public void SetUserName(string userName, IDataProtection dataProtection)
 {
     this.m_userNameEncrypted = dataProtection.ProtectData(userName, "UserName");
 }
示例#27
0
 public PublishingContext(ICatalogItemContext catalogContext, byte[] reportDefinition, IChunkFactory createChunkFactory, AppDomain compilationTempAppDomain, bool generateExpressionHostWithRefusedPermissions, ReportProcessingFlags processingFlags, IConfiguration configuration, IDataProtection dataProtection)
     : this(catalogContext, reportDefinition, createChunkFactory, compilationTempAppDomain, generateExpressionHostWithRefusedPermissions, processingFlags, null, null, null, null, null, null, configuration, dataProtection, isInternalRepublish : false, isPackagedReportArchive : false, isRdlx : false)
 {
 }
示例#28
0
 public PublishingContext(ICatalogItemContext catalogContext, byte[] reportDefinition, IChunkFactory createChunkFactory, AppDomain compilationTempAppDomain, bool generateExpressionHostWithRefusedPermissions, ReportProcessingFlags processingFlags, ReportProcessing.CheckSharedDataSource checkDataSourceCallback, ReportProcessing.ResolveTemporaryDataSource resolveTemporaryDataSourceCallback, DataSourceInfoCollection originalDataSources, ReportProcessing.CheckSharedDataSet checkDataSetCallback, ReportProcessing.ResolveTemporaryDataSet resolveTemporaryDataSetCallback, DataSetInfoCollection originalDataSets, IConfiguration configuration, IDataProtection dataProtection, bool isInternalRepublish, bool isPackagedReportArchive, bool isRdlx)
     : base(PublishingContextKind.Full, catalogContext, createChunkFactory, compilationTempAppDomain, generateExpressionHostWithRefusedPermissions, processingFlags, checkDataSourceCallback, resolveTemporaryDataSourceCallback, originalDataSources, checkDataSetCallback, resolveTemporaryDataSetCallback, originalDataSets, configuration, dataProtection, isInternalRepublish, isPackagedReportArchive, isRdlx, traceAtomicScopes : false)
 {
     m_definition = reportDefinition;
 }
示例#29
0
 public static IConfigurationElement <string> WithEncryption(
     [NotNull] this IConfigurationElement <string> configurationElement, [NotNull] string passwordName, [NotNull] IDataProtection dataProtection)
 => new EncryptedConfigurationElement(configurationElement, passwordName, dataProtection);
示例#30
0
        // TODO: #28 Replace CredentialsExtensions with AutoMapper profiles.
        public static ConnectionCredentials ToTwitchLib(this TwitchCredentials credentials, IDataProtection dataProtection)
        {
            if (credentials.AuthToken == null)
            {
                throw new System.ArgumentException("Unable to convert null AuthToken", nameof(credentials));
            }

            return(new ConnectionCredentials(credentials.Username, dataProtection.Unprotect(credentials.AuthToken).BytesToString()));
        }
        /// <summary>
        /// Inits the provider
        /// </summary>
        public void Init( string sectionName, ListDictionary configStorageParameters, IDataProtection dataProtection )
        {
            // Inits the provider properties
            _sectionName = sectionName;

            _applicationDocumentPath = configStorageParameters[ "path" ] as string;
            if( _applicationDocumentPath == null )
                _applicationDocumentPath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            else
                _applicationDocumentPath = Path.GetFullPath( _applicationDocumentPath );

            string signedString = configStorageParameters[ "signed" ] as string;
            if( signedString != null && signedString.Length != 0 )
                _isSigned = bool.Parse( signedString );

            string encryptedString = configStorageParameters[ "encrypted" ] as string;
            if( encryptedString != null && encryptedString.Length != 0 )
                _isEncrypted = bool.Parse( encryptedString );

            string refreshOnChangeString = configStorageParameters[ "refreshOnChange" ] as string;
            if( refreshOnChangeString != null && refreshOnChangeString.Length != 0 )
                _isRefreshOnChange = bool.Parse( refreshOnChangeString );

            this._dataProtection = dataProtection;

            if( ( _isSigned || _isEncrypted ) && _dataProtection == null )
                throw new ConfigurationException( Resource.ResourceManager[ "RES_ExceptionInvalidDataProtectionConfiguration", _sectionName ] );

            //  here we set up a file-watch that, if refreshOnChange is enabled, will fire an event when config
            //  changes and cause cache to flush
            if( _isRefreshOnChange )
            {
                if(Path.IsPathRooted(_applicationDocumentPath))
                    _fileWatcherApp = new FileSystemWatcher(Path.GetDirectoryName(_applicationDocumentPath), Path.GetFileName(_applicationDocumentPath));
                else
                    _fileWatcherApp = new FileSystemWatcher(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Path.GetFileName(_applicationDocumentPath));

                _fileWatcherApp.EnableRaisingEvents = true;
                _fileWatcherApp.Changed += new FileSystemEventHandler( OnChanged );

            }
            _isInitOk = true;
        }