예제 #1
0
        private async Task GetFileFromOneDrive()
        {
            try
            {
                await AuthenticateAsync();

                IItemRequestBuilder builder = client.Drive.Special.AppRoot.ItemWithPath(FILENAME);
                Item file = await builder.Request().GetAsync();

                Stream contentStream = await builder.Content.Request().GetAsync();

                content = "";

                using (var reader = new StreamReader(contentStream))
                {
                    content = await reader.ReadToEndAsync();
                }

                if (!string.IsNullOrWhiteSpace(content) && encrypter != null && encrypter.IsInitialized)
                {
                    decrypted = encrypter.Decrypt(content);

                    _isInitialSetup = false;
                }
            }
            catch (OneDriveException ex)
            {
                if (ex.IsMatch(OneDriveErrorCode.ItemNotFound.ToString()))
                {
                    _isInitialSetup = true;
                }
            }
        }
예제 #2
0
        public async Task <FullEmailServiceModel> GetEmailFullInfo(int emailID, string userName)
        {
            var applicationEmail = await context.Applications.FindAsync(emailID);

            var currentUser = await userManager.FindByNameAsync(userName);

            var permittedOp = await ReturnPermitedUpdates(applicationEmail.ApplicationStatus, currentUser);

            var allowedToWork = await IsTheLoggedUserPermitedToUpdateTheEmail(currentUser, applicationEmail);

            var serviceApplicationEmail = new FullEmailServiceModel
            {
                EmailId            = applicationEmail.Id,
                Emailreceived      = applicationEmail.Received,
                EmailSender        = encrypter.Decrypt(applicationEmail.Email),
                EmailStatus        = applicationEmail.ApplicationStatus,
                Body               = encrypter.Decrypt(applicationEmail.Body),
                OperatorId         = applicationEmail.OperatorId,
                PermitedOperations = permittedOp,
                AllowedToWork      = allowedToWork,
                CurrentDataStamp   = applicationEmail.LastChange.Ticks.ToString()
            };

            return(serviceApplicationEmail);
        }
예제 #3
0
        public void Configure(DefaultTenantSettings options)
        {
            var settings = _emailSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            // We have no settings to configure

            if (settings != null)
            {
                // Decrypt the connection string
                if (!string.IsNullOrWhiteSpace(settings.ConnectionString))
                {
                    try
                    {
                        options.ConnectionString = _encrypter.Decrypt(settings.ConnectionString);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the default tenant connection string. {e.Message}");
                        }
                    }
                }

                options.TablePrefix = settings.TablePrefix;

                var smtpSettings = settings.SmtpSettings;
                if (smtpSettings != null)
                {
                    options.SmtpSettings.DefaultFrom             = smtpSettings.DefaultFrom;
                    options.SmtpSettings.DeliveryMethod          = smtpSettings.DeliveryMethod;
                    options.SmtpSettings.PickupDirectoryLocation = smtpSettings.PickupDirectoryLocation;
                    options.SmtpSettings.Host                  = smtpSettings.Host;
                    options.SmtpSettings.Port                  = smtpSettings.Port;
                    options.SmtpSettings.EnableSsl             = smtpSettings.EnableSsl;
                    options.SmtpSettings.RequireCredentials    = smtpSettings.RequireCredentials;
                    options.SmtpSettings.UseDefaultCredentials = smtpSettings.UseDefaultCredentials;
                    options.SmtpSettings.UserName              = smtpSettings.UserName;

                    // Decrypt the password
                    if (!String.IsNullOrWhiteSpace(smtpSettings.Password))
                    {
                        try
                        {
                            options.SmtpSettings.Password = _encrypter.Decrypt(smtpSettings.Password);
                        }
                        catch (Exception e)
                        {
                            if (_logger.IsEnabled(LogLevel.Error))
                            {
                                _logger.LogError(e, $"There was a problem decrypting the SMTP password. {e.Message}");
                            }
                        }
                    }
                }
            }
        }
        public void Configure(PlatoTwitterOptions options)
        {
            var settings = _TwitterSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            if (settings != null)
            {
                // ------------------
                // Consumer Keys
                // ------------------

                options.ConsumerKey = settings.ConsumerKey;

                // Decrypt the secret
                if (!String.IsNullOrWhiteSpace(settings.ConsumerSecret))
                {
                    try
                    {
                        options.ConsumerSecret = _encrypter.Decrypt(settings.ConsumerSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Twitter consumer key secret. {e.Message}");
                        }
                    }
                }

                // ------------------
                // Access Tokens
                // ------------------

                options.AccessToken = settings.AccessToken;

                // Decrypt the secret
                if (!String.IsNullOrWhiteSpace(settings.AccessTokenSecret))
                {
                    try
                    {
                        options.AccessTokenSecret = _encrypter.Decrypt(settings.AccessTokenSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Twitter access token secret. {e.Message}");
                        }
                    }
                }
            }
        }
예제 #5
0
        public T Get <T>(string key)
        {
            ValidationUtils.ArgumentNotNull(key, nameof(key));
            ValidationUtils.KeyNotFound(Has(key), key);

            string data = _storage.Read(key);

            data = _encrypter.Decrypt(data);
            var value = _serializer.Deserialize <T>(data);

            return(value);
        }
예제 #6
0
        async Task <TwitterSettingsViewModel> GetModel()
        {
            var settings = await _twitterSettingsStore.GetAsync();

            if (settings != null)
            {
                // Decrypt the secret
                var consumerSecret    = string.Empty;
                var accessTokenSecret = string.Empty;

                if (!string.IsNullOrWhiteSpace(settings.ConsumerSecret))
                {
                    try
                    {
                        consumerSecret = _encrypter.Decrypt(settings.ConsumerSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Twitter consumer secret. {e.Message}");
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(settings.AccessTokenSecret))
                {
                    try
                    {
                        accessTokenSecret = _encrypter.Decrypt(settings.AccessTokenSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Twitter access token secret. {e.Message}");
                        }
                    }
                }

                return(new TwitterSettingsViewModel()
                {
                    ConsumerKey = _platoOptions.DemoMode ? "123456789" : settings.ConsumerKey,
                    ConsumerSecret = _platoOptions.DemoMode ? "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx" : consumerSecret,
                    CallbackPath = _platoOptions.DemoMode ? string.Empty : settings.CallbackPath.ToString(),
                    AccessToken = _platoOptions.DemoMode ? "123456789" : settings.AccessToken,
                    AccessTokenSecret = _platoOptions.DemoMode ? "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx" : accessTokenSecret
                });
            }

            // return default settings
            return(new TwitterSettingsViewModel());
        }
        public void Configure(PlatoFacebookOptions options)
        {
            var settings = _facebookSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            if (settings != null)
            {
                options.AppId = settings.AppId;

                // Decrypt the secret
                if (!String.IsNullOrWhiteSpace(settings.AppSecret))
                {
                    try
                    {
                        options.AppSecret = _encrypter.Decrypt(settings.AppSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Facebook app secret. {e.Message}");
                        }
                    }
                }
            }
        }
        public async Task <List <EmailServiceModel> > ListEmails(int filter, int multyplier)

        {
            var currentListedEmails = (multyplier - 1) * 10;
            var emailsToBeListed    = multyplier * 10;
            var app = new List <Application>();

            if (filter != 0)
            {
                // app = context.Applications.Where(f=>f.ApplicationStatus==(ApplicationStatus)filter).ToList();
                app = context.Applications.Where(f => f.ApplicationStatus == (ApplicationStatus)filter)
                      .OrderBy(d => d.Id).Skip(currentListedEmails).Take(emailsToBeListed).ToList();
            }
            else
            {
                app = context.Applications.OrderBy(d => d.Id).Skip(currentListedEmails).Take(emailsToBeListed).ToList();
            }

            var applications = app.Select(b => new EmailServiceModel
            {
                EmailId       = b.Id,
                Emailreceived = b.Received,
                EmailSender   = encrypter.Decrypt(b.Email),
                EmailStatus   = b.ApplicationStatus,
                Attachments   = b.AttachmentsCount,
            });

            return(applications.ToList());
        }
예제 #9
0
        public void Configure(DemoOptions options)
        {
            var settings = _demoSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            if (settings != null)
            {
                // ------------------
                // Default administrator account
                // ------------------

                options.AdminUserName = settings.AdminUserName;

                // Decrypt the password
                if (!String.IsNullOrWhiteSpace(settings.AdminPassword))
                {
                    try
                    {
                        options.AdminPassword = _encrypter.Decrypt(settings.AdminPassword);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the demo administrator password. {e.Message}");
                        }
                    }
                }
            }
        }
예제 #10
0
        public void Configure(PlatoSlackOptions options)
        {
            var settings = _slackSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            if (settings != null)
            {
                if (!String.IsNullOrWhiteSpace(settings.WebHookUrl))
                {
                    try
                    {
                        options.WebHookUrl = _encrypter.Decrypt(settings.WebHookUrl);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Slack Web Hook URL. {e.Message}");
                        }
                    }
                }
            }
        }
예제 #11
0
        async Task <DemoSettingsViewModel> GetModel()
        {
            var settings = await _demoSettingsStore.GetAsync();

            if (settings != null)
            {
                // Decrypt the password
                var adminPassword = string.Empty;

                if (!string.IsNullOrWhiteSpace(settings.AdminPassword))
                {
                    try
                    {
                        adminPassword = _encrypter.Decrypt(settings.AdminPassword);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the demo administrator password. {e.Message}");
                        }
                    }
                }

                return(new DemoSettingsViewModel()
                {
                    AdminUserName = settings.AdminUserName,
                    AdminPassword = adminPassword
                });
            }

            // return default settings
            return(new DemoSettingsViewModel());
        }
예제 #12
0
        async Task <SlackSettingsViewModel> GetModel()
        {
            var settings = await _TwitterSettingsStore.GetAsync();

            if (settings != null)
            {
                // Decrypt the secret
                var webHookUrl = string.Empty;

                if (!string.IsNullOrWhiteSpace(settings.WebHookUrl))
                {
                    try
                    {
                        webHookUrl = _encrypter.Decrypt(settings.WebHookUrl);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError($"There was a problem dencrypting the Slack Web Hook URL. {e.Message}");
                        }
                    }
                }

                return(new SlackSettingsViewModel()
                {
                    WebHookUrl = webHookUrl
                });
            }

            // return default settings
            return(new SlackSettingsViewModel());
        }
        public void Configure(PlatoGitHubOptions options)
        {
            var settings = _githubSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            if (settings != null)
            {
                options.ClientId = settings.ClientId;

                // Decrypt the secret
                if (!String.IsNullOrWhiteSpace(settings.ClientSecret))
                {
                    try
                    {
                        options.ClientSecret = _encrypter.Decrypt(settings.ClientSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the GitHub client secret. {e.Message}");
                        }
                    }
                }

                if (settings.CallbackPath.HasValue)
                {
                    options.CallbackPath = settings.CallbackPath;
                }
            }
        }
예제 #14
0
        protected override void MapDomainFields(ChargeCardEntity entity, ChargeCard domainObjectToMapTo)
        {
            // TODO: persist encrypted fields.
            DataRecorderMetaData metaData = _metaDataFactory.CreateDataRecorderMetaData(
                entity.OrganizationRoleUserCreatorId,
                entity.DateCreated);

            domainObjectToMapTo.Id                   = entity.ChargeCardId;
            domainObjectToMapTo.CVV                  = _encrypter.Decrypt(entity.Cvv);
            domainObjectToMapTo.CardIssuer           = entity.CardIssuer;
            domainObjectToMapTo.ExpirationDate       = entity.ExpirationDate;
            domainObjectToMapTo.IsDebit              = entity.IsDebitCard;
            domainObjectToMapTo.NameOnCard           = entity.NameOnCard;
            domainObjectToMapTo.Number               = _encrypter.Decrypt(entity.Number);
            domainObjectToMapTo.TypeId               = (ChargeCardType)entity.TypeId;
            domainObjectToMapTo.DataRecorderMetaData = metaData;
        }
        public void DecryptFile(string source, string dest, EncryptionType enc)
        {
            string     ciphertext = TextUtils.BytesToString(System.IO.File.ReadAllBytes(source));
            IEncrypter encrypter  = GetEncrypter(enc);
            string     plaintext  = encrypter.Decrypt(ciphertext);

            System.IO.File.WriteAllBytes(dest, TextUtils.StringToBytes(plaintext));
        }
예제 #16
0
        public void Configure(SmtpSettings options)
        {
            var settings = _emailSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            // We have no settings to configure

            var smtpSettings = settings?.SmtpSettings;

            if (smtpSettings != null)
            {
                options.DefaultFrom             = smtpSettings.DefaultFrom;
                options.DeliveryMethod          = smtpSettings.DeliveryMethod;
                options.PickupDirectoryLocation = smtpSettings.PickupDirectoryLocation;
                options.Host                  = smtpSettings.Host;
                options.Port                  = smtpSettings.Port;
                options.EnableSsl             = smtpSettings.EnableSsl;
                options.RequireCredentials    = smtpSettings.RequireCredentials;
                options.UseDefaultCredentials = smtpSettings.UseDefaultCredentials;
                options.UserName              = smtpSettings.UserName;
                options.BatchSize             = smtpSettings.BatchSize;
                options.SendAttempts          = smtpSettings.SendAttempts;
                options.PollingInterval       = smtpSettings.PollingInterval;
                options.EnablePolling         = smtpSettings.EnablePolling;

                // Decrypt the password
                if (!String.IsNullOrWhiteSpace(smtpSettings.Password))
                {
                    try
                    {
                        options.Password = _encrypter.Decrypt(smtpSettings.Password);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the SMTP password. {e.Message}");
                        }
                    }
                }
            }
        }
예제 #17
0
        public async Task <object> GetValueAsync(string box, string key, string encryptionKey)
        {
            var entryBox = await _boxRepository.GetAsync(box);

            if (entryBox == null)
            {
                throw new ArgumentException($"Box '{box}' has not been found.");
            }

            var entry = entryBox.GetEntry(key);

            if (entry == null)
            {
                return(null);
            }

            var value = _encrypter.Decrypt(entry.Value, entry.Salt, encryptionKey);

            return(JsonConvert.DeserializeObject(value));
        }
예제 #18
0
        async Task <GoogleSettingsViewModel> GetModel()
        {
            var settings = await _googleSettingsStore.GetAsync();

            if (settings != null)
            {
                // Decrypt the secret
                var secret = string.Empty;
                if (!string.IsNullOrWhiteSpace(settings.ClientSecret))
                {
                    try
                    {
                        secret = _encrypter.Decrypt(settings.ClientSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Google client secret. {e.Message}");
                        }
                    }
                }

                return(new GoogleSettingsViewModel()
                {
                    ClientId = _platoOptions.DemoMode ? "123456789" : settings.ClientId,
                    ClientSecret = _platoOptions.DemoMode ? "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx" : secret,
                    CallbackPath = _platoOptions.DemoMode ? string.Empty : settings.CallbackPath.ToString(),
                    TrackingId = _platoOptions.DemoMode ? "UA-123456789-0" : settings.TrackingId
                });
            }

            // return default settings
            return(new GoogleSettingsViewModel()
            {
                ClientId = string.Empty,
                ClientSecret = string.Empty,
                CallbackPath = string.Empty,
                TrackingId = string.Empty
            });
        }
예제 #19
0
        async Task <FacebookSettingsViewModel> GetModel()
        {
            var settings = await _facebookSettingsStore.GetAsync();

            if (settings != null)
            {
                // Decrypt the secret
                var secret = string.Empty;
                if (!string.IsNullOrWhiteSpace(settings.AppSecret))
                {
                    try
                    {
                        secret = _encrypter.Decrypt(settings.AppSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the Facebook app secret. {e.Message}");
                        }
                    }
                }

                return(new FacebookSettingsViewModel()
                {
                    AppId = _platoOptions.DemoMode ? "123456789" : settings.AppId,
                    AppSecret = _platoOptions.DemoMode ? "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx" : secret,
                    CallbackPath = _platoOptions.DemoMode ? string.Empty : settings.CallbackPath.ToString()
                });
            }

            // return default settings
            return(new FacebookSettingsViewModel()
            {
                AppId = string.Empty,
                AppSecret = string.Empty
            });
        }
예제 #20
0
        // -----------------

        private async Task <EditTenantSettingsViewModel> GetModel()
        {
            var settings = await _tenantSettingsStore.GetAsync();

            if (settings != null)
            {
                // Decrypt connection string
                var connectionString = string.Empty;
                if (!String.IsNullOrWhiteSpace(settings.ConnectionString))
                {
                    try
                    {
                        connectionString = _encrypter.Decrypt(settings.ConnectionString);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the default tenant connection string. {e.Message}");
                        }
                    }
                }

                // Decrypt password
                var password = string.Empty;
                if (!String.IsNullOrWhiteSpace(settings.SmtpSettings.Password))
                {
                    try
                    {
                        password = _encrypter.Decrypt(settings.SmtpSettings.Password);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the default tenant connection string. {e.Message}");
                        }
                    }
                }

                return(new EditTenantSettingsViewModel()
                {
                    ConnectionString = connectionString,
                    TablePrefix = settings.TablePrefix,
                    SmtpSettings = new SmtpSettingsViewModel()
                    {
                        DefaultFrom = _platoOptions.DemoMode
                            ? "*****@*****.**"
                            : settings.SmtpSettings.DefaultFrom,
                        Host = _platoOptions.DemoMode
                            ? "smtp.example.com"
                            : settings.SmtpSettings.Host,
                        Port = settings.SmtpSettings.Port,
                        UserName = _platoOptions.DemoMode
                            ? "*****@*****.**"
                            : settings.SmtpSettings.UserName,
                        Password = _platoOptions.DemoMode
                            ? ""
                            : password,
                        RequireCredentials = settings.SmtpSettings.RequireCredentials,
                        EnableSsl = settings.SmtpSettings.EnableSsl
                    }
                });
            }

            return(new EditTenantSettingsViewModel());
        }
예제 #21
0
 //takes input and decrypts it
 public String Decrypt(String input)
 {
     return(worker.Decrypt(input));
 }