Beispiel #1
0
 public EditVenueModel(UserManager <Employee> userManager,
                       RoleManager <EmployeeRole> roleManager,
                       ICoordinatesService coordinates,
                       CompanyRepository companies,
                       VenueRepository venues,
                       TagRepository tags,
                       ImageRepository images,
                       ISettings settings,
                       DocumentRepository documents,
                       VenueDocumentRepository venueDocuments,
                       IMessagePublisher messagePublisher,
                       Constants constants,
                       ICryptoHelper cryptoHelper,
                       VenueOpeningTimeRepository venueOpeningTimes)
 {
     this.coordinates       = coordinates;
     this.userManager       = userManager;
     this.roleManager       = roleManager;
     this.venues            = venues;
     this.tags              = tags;
     this.images            = images;
     this.settings          = settings;
     this.documents         = documents;
     this.venueDocuments    = venueDocuments;
     this.companies         = companies;
     this.messagePublisher  = messagePublisher;
     this.constants         = constants;
     this.cryptoHelper      = cryptoHelper;
     this.venueOpeningTimes = venueOpeningTimes;
 }
        public async Task Invoke(HttpContext context)
        {
            try
            {
                IHeaderDictionary headers       = context.Request.Headers;
                ICookieHelper     _cookieHelper = context.GetInstanceFromContext <ICookieHelper>();
                IJWTHelper        _JWTHelper    = context.GetInstanceFromContext <IJWTHelper>();
                ICryptoHelper     _cryptoHelper = context.GetInstanceFromContext <ICryptoHelper>();

                string cookie = _cookieHelper.GetCookie(_cookieHelper.GetCookieName());

                // Get JWT from request header.
                string hdrJWT = _JWTHelper.getBearerHeaderValue(headers);

                // If header doesn't have a JWT but the cookie does, add the cookie's JWT to the header.
                if (String.IsNullOrEmpty(hdrJWT) && !String.IsNullOrEmpty(cookie))
                {
                    string decryptedJWTToken = _cryptoHelper.decrypt(cookie);
                    _JWTHelper.setClaimsFromCookie(decryptedJWTToken);
                    string bearerToken = string.Format("Bearer {0}", cookie);
                    headers.SetCommaSeparatedValues("Authorization", bearerToken);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                await _next.Invoke(context);
            }
        }
Beispiel #3
0
 public ApiController(IConfiguration configuration, ICookieHelper cookieHelper, IJWTHelper JWTHelper, ICryptoHelper cryptoHelper)
 {
     _configuration = configuration;
     _cookieHelper  = cookieHelper;
     _JWTHelper     = JWTHelper;
     _cryptoHelper  = cryptoHelper;
 }
Beispiel #4
0
        public virtual void Setup()
        {
            try
            {
                _testDataDirectory   = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory))), "TestData");
                _sampleUser          = JsonConvert.DeserializeObject <User>(File.ReadAllText(Path.Combine(_testDataDirectory, "sampleUser.json")));
                _cyrptoHelper        = new CryptoHelper();
                _sampleUser.Password = _cyrptoHelper.Hash(_sampleUser.Password);

                _mapper = new MapperConfiguration(mc =>
                {
                    mc.AddProfile(new MappingProfile(_cyrptoHelper));
                }).CreateMapper();

                _userClaims = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString()),
                    new Claim(ClaimTypes.Sid, _sampleUser.Id.ToString()),
                    new Claim(ClaimTypes.Email, _sampleUser.Email)
                }, "mock"));
            }
            catch
            {
                // Ignored
            }
        }
Beispiel #5
0
        public async Task Invoke(HttpContext context)
        {
            try
            {
                IHeaderDictionary headers       = context.Request.Headers;
                ICookieHelper     _cookieHelper = context.GetInstanceFromContext <ICookieHelper>();
                IJWTHelper        _JWTHelper    = context.GetInstanceFromContext <IJWTHelper>();
                ICryptoHelper     _cryptoHelper = context.GetInstanceFromContext <ICryptoHelper>();

                string cookieName = _cookieHelper.GetCookieName();
                if (!_cookieHelper.isCookieDeleted(cookieName))
                {
                    string updatedToken   = _JWTHelper.updateJWTToken();
                    string encryptedToken = _cryptoHelper.encrypt(updatedToken);
                    _cookieHelper.UpdateCookie(encryptedToken);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                await _next.Invoke(context);
            }
        }
Beispiel #6
0
 public AuthenHelper(ISessionHelper sessionHelper, ICryptoHelper cryptoHelper, IServiceHelper serviceHelper, ICacheHelper cacheHelper)
 {
     _httpContext = HttpContext.Current;
     _sessionHelper = sessionHelper;
     _cryptoHelper = cryptoHelper;
     _serviceHelper = serviceHelper;
     _cacheHelper = cacheHelper;
 }
 public CardService(ICardRepository cardRepository, ISmsService smsService,
                    ICardHelper cardHelper, ICryptoHelper cryptoHelper)
 {
     _cardRepository = cardRepository;
     _smsService     = smsService;
     _cardHelper     = cardHelper;
     _cryptoHelper   = cryptoHelper;
 }
Beispiel #8
0
 public ValidateExpiredTokenFilter(IConfiguration configuration, ILogger <ValidateUnAttendanceFilter> logger,
                                   ICryptoHelper cryptoHelper, ConfigSettings configSettings)
 {
     _configuration  = configuration;
     _cryptoHelper   = cryptoHelper;
     _configSettings = configSettings;
     _logger         = logger;
 }
Beispiel #9
0
 public Handler(IUnitOfWork unitOfWork,
                IJwtGenerator jwtGenerator, UtilFactory utilFactory, IMapperHelper mapperHelper)
 {
     _unitOfWork   = unitOfWork;
     _jwtGenerator = jwtGenerator;
     _cryptoHelper = utilFactory.CryptoHelper;
     _mapperHelper = mapperHelper;
 }
Beispiel #10
0
 public MoneyTransactionController(
     IAccountService accountService,
     ITransactionService transactionService,
     ICryptoHelper cryptoHelper)
 {
     _accountService     = accountService;
     _transactionService = transactionService;
     _cryptoHelper       = cryptoHelper;
 }
 public TransactionController(IAccountService accountService, ICurrencyService currencyService, ITransactionService transactionService,
                              ICryptoHelper cryptoHelper, ICardHelper cardHelper)
 {
     _accountService     = accountService;
     _currencyService    = currencyService;
     _transactionService = transactionService;
     _cryptoHelper       = cryptoHelper;
     _cardHelper         = cardHelper;
 }
Beispiel #12
0
        public void RijndaelEncrypt()
        {
            ICryptoHelper crytographyHelper = CryptoFactory.Create(CryptographyAlgorithm.Rijndael);

            crytographyHelper.Entropy = ENCRYPTION_VALID_PASSWORD;
            string encryptedString = crytographyHelper.Encrypt(ENCRYPTION_TEST_STRING, StringEncodingType.Hex);

            Assert.IsFalse(StringHelper.Match(encryptedString, ENCRYPTION_TEST_STRING, true), "Encrypted String Equals String Passed In");
        }
Beispiel #13
0
 public UsersController(IUserRepository userRepository,
                        ICryptoHelper cryptoHelper,
                        IMapper mapper,
                        IOptions <JwtIssuerOptions> jwtOptions)
 {
     _userRepository = userRepository;
     _cryptoHelper   = cryptoHelper;
     _mapper         = mapper;
     _jwtOptions     = jwtOptions.Value;
 }
Beispiel #14
0
 public AccountService(IAccountRepository accountRepository, ICardRepository cardRepository,
                       IAccountHelper accountHelper, ICardHelper cardHelper, ISmsService smsService, ICryptoHelper cryptoHelper)
 {
     _accountRepository = accountRepository;
     _cardRepository    = cardRepository;
     _accountHelper     = accountHelper;
     _cardHelper        = cardHelper;
     _cryptoHelper      = cryptoHelper;
     _smsService        = smsService;
 }
Beispiel #15
0
 private void CreateHelper(CryptographyAlgorithm algorithm, string key)
 {
     if (key.Trim().Length == 0)
     {
         helper = CryptoFactory.Create(algorithm);
     }
     else
     {
         helper = CryptoFactory.Create(algorithm, key);
     }
 }
 public UserService(
     IUserRepository userRepository,
     ITokenService tokenService,
     ICryptoHelper crypoHelper,
     IMovementRepository movementeRepository)
 {
     _userRepository     = userRepository;
     _tokenService       = tokenService;
     _crypoHelper        = crypoHelper;
     _movementRepository = movementeRepository;
 }
Beispiel #17
0
 public UserController
 (
     IUserService userService,
     IConfiguration configuration,
     PermissionCachingManager cache,
     ICryptoHelper cryptoHelper
 )
 {
     _userService   = userService;
     _configuration = configuration;
     _cache         = cache;
     _cryptoHelper  = cryptoHelper;
 }
Beispiel #18
0
        public void RijndaelDecryptValidPassword()
        {
            ICryptoHelper crytographyHelper = CryptoFactory.Create(CryptographyAlgorithm.Rijndael);

            crytographyHelper.Entropy = ENCRYPTION_VALID_PASSWORD;
            string encryptedString = crytographyHelper.Encrypt(ENCRYPTION_TEST_STRING, StringEncodingType.Hex);

            ICryptoHelper crytographyHelper2 = CryptoFactory.Create(CryptographyAlgorithm.Rijndael);

            crytographyHelper2.Entropy = ENCRYPTION_VALID_PASSWORD;
            string decriptedString = crytographyHelper2.Decrypt(encryptedString, StringEncodingType.Hex);

            Assert.AreEqual(ENCRYPTION_TEST_STRING, decriptedString);
        }
        /// <summary>
        /// Recreates the specified current.
        /// </summary>
        /// <param name="current">The current.</param>
        /// <param name="cryptoType">Type of the crypto.</param>
        /// <param name="privateKeyPath">The private key path.</param>
        /// <param name="privateKeyPassword">The private key password.</param>
        /// <param name="publicKeyPath">The public key path.</param>
        /// <returns>Implementation of crypto helper.</returns>
        public static ICryptoHelper Recreate(ref ICryptoHelper current,
            CryptoType cryptoType,
            string privateKeyPath,
            string privateKeyPassword,
            string publicKeyPath)
        {
           if ((current == null) ||
                (current.Type != cryptoType))
            {
                current = CreateRSA(cryptoType, privateKeyPath, privateKeyPassword, publicKeyPath);
            }

            return current;
        }
        /// <summary>
        /// Recreates the specified current.
        /// </summary>
        /// <param name="current">The current.</param>
        /// <param name="cryptoType">Type of the crypto.</param>
        /// <param name="privateKeyPath">The private key path.</param>
        /// <param name="privateKeyPassword">The private key password.</param>
        /// <param name="publicKeyPath">The public key path.</param>
        /// <returns>Implementation of crypto helper.</returns>
        public static ICryptoHelper Recreate(ref ICryptoHelper current,
                                             CryptoType cryptoType,
                                             string privateKeyPath,
                                             string privateKeyPassword,
                                             string publicKeyPath)
        {
            if ((current == null) ||
                (current.Type != cryptoType))
            {
                current = CreateRSA(cryptoType, privateKeyPath, privateKeyPassword, publicKeyPath);
            }

            return(current);
        }
Beispiel #21
0
 public AuthoriseController(EmployeeRepository employees,
                            EmployeeSessionRepository employeeSessions, UserRepository users,
                            UserSessionRepository userSessions, TokenUtil tokenUtil, ISettings settings,
                            IBillingManager billingManager, ICryptoHelper crypto)
 {
     this.employees        = employees;
     this.employeeSessions = employeeSessions;
     this.users            = users;
     this.userSessions     = userSessions;
     this.tokenUtil        = tokenUtil;
     this.settings         = settings;
     this.billingManager   = billingManager;
     this.crypto           = crypto;
 }
Beispiel #22
0
        public MappingProfile(ICryptoHelper cryptoHelper)
        {
            // viewmodel -> entity
            CreateMap <NewUserRequest, User>().ForMember(dest => dest.Password, src => src.MapFrom(x => cryptoHelper.Hash(x.Password)));

            CreateMap <ProjectTaskCreateViewModel, ProjectTask>().ReverseMap();
            CreateMap <ProjectTaskViewModel, ProjectTask>().ReverseMap();

            CreateMap <ProjectCreateViewModel, Project>().ReverseMap();
            CreateMap <ProjectViewModel, Project>().ReverseMap();
            CreateMap <ProjectAndTasksViewModel, Project>().ReverseMap();

            // entity -> viewmodel
            CreateMap <User, UserViewModel>();
        }
Beispiel #23
0
 public UserService
 (
     IUserRepository userRepo,
     ICryptoHelper crypytoHelper,
     IJWTokenHelper tokenHelper,
     IRoleAssignmentRepository roleAssignmentRepo,
     IPermissionRepository permissionRepo
 )
 {
     _userRepo           = userRepo;
     _crypytoHelper      = crypytoHelper;
     _tokenHelper        = tokenHelper;
     _roleAssignmentRepo = roleAssignmentRepo;
     _permissionRepo     = permissionRepo;
 }
 public AuthenticationManager(
     ILogger <AuthenticationManager> logger,
     VkAppConfig vkAppConfig,
     ICryptoHelper cryptoHelper,
     ISecurityManager securityManager,
     IAsyncRepository <AuthenticationAccount> accountsRepo,
     IAsyncRepository <User> usersRepo)
 {
     this.logger          = logger;
     this.vkAppConfig     = vkAppConfig;
     this.cryptoHelper    = cryptoHelper;
     this.securityManager = securityManager;
     this.accountsRepo    = accountsRepo;
     this.usersRepo       = usersRepo;
 }
Beispiel #25
0
        public SessionManager(
            // Providers.
            IEntityProvider <Session> sessionProvider,
            IEntityProvider <User> userProvider,

            // Helpers.
            ICryptoHelper cryptoHelper,
            IDateTimeHelper dateTimeHelper)
        {
            SessionProvider = sessionProvider;
            UserProvider    = userProvider;

            CryptoHelper   = cryptoHelper;
            DateTimeHelper = dateTimeHelper;

            ApiSecret = Environment.GetEnvironmentVariable("WEBCHAT_API_SECRET");
        }
Beispiel #26
0
        public static IConfiguration Decrypt(this IConfiguration config, ICryptoHelper crypto)
        {
            string key;
            string foundVal;
            string decryptedVal;
            List <ConfigSetting> configList = config.GetConfigSettings();
            string encPrefix = config["ConfigOptions:Cryptography:EncValPrefix"];

            for (int i = 0; i < configList.Count; i++)
            {
                foundVal = configList[i].SettingValue;
                if (foundVal.StartsWith(encPrefix) && foundVal != encPrefix)
                {
                    key          = configList[i].SettingKey;
                    decryptedVal = crypto.Unprotect(key, foundVal, encPrefix);
                    config[key]  = decryptedVal;
                }
            }
            return(config);
        }
Beispiel #27
0
 public PaymentOAuthCallbackController(CompanyRepository companies,
                                       EmployeeRepository employees,
                                       EmployeeRoleRepository roles,
                                       Constants constants,
                                       ISettings settings,
                                       ICryptoHelper cryptoHelper,
                                       IDistributedCache cache,
                                       IMessagePublisher messagePublisher,
                                       ILoggerFactory loggerFactory)
 {
     this.companies        = companies;
     this.employees        = employees;
     this.roles            = roles;
     this.constants        = constants;
     this.settings         = settings;
     this.cryptoHelper     = cryptoHelper;
     this.cache            = cache;
     this.messagePublisher = messagePublisher;
     this.logger           = loggerFactory.CreateLogger(nameof(PaymentOAuthCallbackController));
 }
Beispiel #28
0
        public static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            var serviceCollection = new ServiceCollection();

            // build a local configuration that contains the plain-text encryption configuration settings.
            config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

            // use the settings in the initial configuration to initialize Microsoft DPAPI
            // This can also be done in Startup.ConfigureServices using the standard Configuration from DI
            serviceCollection.AddDataProtectionServices(config);
            var serviceProvider = serviceCollection.BuildServiceProvider();

            crypto = serviceProvider.GetRequiredService <ICryptoHelper>();


            // create an instance of StringEncryptor using the service provider and Encryption Prefix string
            var instance = ActivatorUtilities.CreateInstance <StringEncryptor>(serviceProvider, config["ConfigOptions:Cryptography:EncValPrefix"], crypto);

            instance.UserLoop();
        }
Beispiel #29
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Data Protection Services using the configuration loaded from DI.
            // This is required to add Microsoft Data Protection services to DI, and to create a service for ICryptoHelper which performs the cryptography tasks.
            // The configuration must have section ConfigOptions:Cryptography with plain text values for ClientScope, EncValPrefix, and KeyStore.
            // These configuration values are required to initialize encyrption services, so they must be in plain text.
            services.AddDataProtectionServices(Configuration);

            // Get the DPAPI Service provider which a dependency of CryptoHelper
            var serviceProvider = services.BuildServiceProvider();

            //Add ICryptoHelper, with its dependency, to DI
            ICryptoHelper crypto = serviceProvider.GetRequiredService <ICryptoHelper>();

            //  DECRYPT the configuration values - Setting values will be decrypted if they begin with the Encrypted Value Prefix (EncValPrefix)
            Configuration.Decrypt(crypto);

            // Use decrypted configuration to initialize other services like data access, authentication, and authorization
            // other services...
            services.AddRazorPages();
        }
Beispiel #30
0
 public UserRepository(IConfiguration configuration, ICryptoHelper cryptoHelper, ILogger <UserRepository> logger) : base(configuration)
 {
     this.configuration = configuration;
     this.cryptoHelper  = cryptoHelper;
     this.logger        = logger;
 }
 public AuthComponent(ICryptoHelper cryptoHelper)
 {
   this.cryptoHelper = cryptoHelper;      
 }
Beispiel #32
0
 public WebUserStore(EmployeeRepository accountRepository, EmployeeRoleRepository roles, ICryptoHelper cryptoHelper)
 {
     _accountRepository = accountRepository;
     _cryptoHelper      = cryptoHelper;
     this.roles         = roles;
 }
 public TokenComponent(ICryptoHelper cryptoHelper)
 {
   this.cryptoHelper = cryptoHelper;
 }
Beispiel #34
0
 public CaptchaHelper()
 {
     cryptoHelper = new MD5CryptoHelper();
 }