public DocumentDbHandler(IDocumentStore documentStore, ICryptographicService cryptographicService, IUserContextService userContextService)
 {
     _documentStore = documentStore;
     _documentStore.SetSession("Users");
     _cryptographicService = cryptographicService;
     _userContextService   = userContextService;
 }
Ejemplo n.º 2
0
 public UsersController(UserContext context,
                        ICryptographicService cryptographicServices,
                        ILogger <UsersController> logger)
 {
     _context = context;
     _cryptographicServices = cryptographicServices;
     _logger = logger;
 }
Ejemplo n.º 3
0
 public UserService(IUnitOfWork unitOfWork, IConfiguration configuration,
                    ICryptographicService cryptographicService)
 {
     _unitOfWork           = unitOfWork;
     _configuration        = configuration;
     _cryptographicService = cryptographicService;
     _userRepository       = unitOfWork.GetRepository <UserData>();
 }
Ejemplo n.º 4
0
        public WalletService(Client miyabiClient, TransactionService transactionService)
        {
            _cryptographicService = new Secp256k1EccService();
            _transactionService   = transactionService;
            var privateKey = _cryptographicService.CreatePrivateKey();

            _keyPair     = new KeyPair(privateKey);
            _assetClient = new AssetClient(miyabiClient);
        }
Ejemplo n.º 5
0
 public AuthenticateHandler(
     IUserAccountService userAccountService,
     IMapper mapper,
     ICryptographicService cryptographicService)
 {
     _userAccountService   = userAccountService;
     _mapper               = mapper;
     _cryptographicService = cryptographicService;
 }
Ejemplo n.º 6
0
 public AccountController(ICommandService commandService,
                          IQueryService queryService,
                          ICryptographicService cryptographicService,
                          IIdentityServerInteractionService interactionService)
 {
     _commandService       = commandService;
     _queryService         = queryService;
     _cryptographicService = cryptographicService;
     _interactionService   = interactionService;
 }
Ejemplo n.º 7
0
        public static async Task <InitializationResult <AuthenticatedStream> > RegisterWithServerAsync(
            Stream serverStream,
            byte[] presharedKey,
            Guid ownGuid,
            Guid serverGuid,
            IAuthenticatedConnectionFactory authenticatedConnectionFactory,
            X509Certificate2 clientCertificate,
            X509Certificate serverCertificate,
            ICryptographicService otp,
            CancellationToken token)
        {
            InitializationResult <AuthenticatedStream> From(CommunicationResult res) => From <AuthenticatedStream>(res);

            if (!otp.CanEncrypt)
            {
                throw new ArgumentException("otp needs to be able to encrypt");
            }
            token = token.AddTimeout(DefaultTimeout);

            await serverStream.WriteSafelyAsync(presharedKey, token);

            var serverGuidResult = await serverStream.ReceiveGuidSafelyAsync(token);

            if (!serverGuidResult.Successful)
            {
                return(From(serverGuidResult));
            }
            if (!serverGuidResult.Result.Equals(serverGuid))
            {
                return(new InitializationResult <AuthenticatedStream>
                {
                    Successful = false,
                    Error = new InitializationError
                    {
                        ErrorType = InitializationErrorType.Identification,
                        Message = $"Expected server to be '{serverGuid}', but instead found '{serverGuidResult.Result}'",
                    },
                });
            }
            await serverStream.WriteSafelyAsync(
                ownGuid,
                (int)InitiationMode.Otp,
                token);

            var exportCertificate    = clientCertificate.Export(X509ContentType.Cert);
            var encryptedCertificate = otp.Encrypt(exportCertificate);
            await serverStream.WriteSafelyAsync(
                (int)CommunicationData.PublicKey,
                encryptedCertificate.Length,
                encryptedCertificate,
                token);

            return(await EstablishEncryptedCommunication(false, serverGuid, authenticatedConnectionFactory,
                                                         serverStream, token));
        }
Ejemplo n.º 8
0
 public UserManagementService(
     IUserContext applicationContext,
     IUserAccountRepository userAccountRepository,
     ICryptographicService cryptographicService,
     IQueueDispatcher <IMessage> dispatcher) : base(applicationContext, dispatcher)
 {
     Check.NotNull(userAccountRepository, "userAccountRepository cannot be null");
     _userAccountRepository = userAccountRepository;
     _cryptographicService  = cryptographicService;
     _userAccountValidator  = new UserAccountValidator(_userAccountRepository);
 }
Ejemplo n.º 9
0
 public SignUpHandler(
     IUserAccountService userAccountService,
     IMapper mapper,
     IUnitOfWork unitOfWork,
     ICryptographicService cryptographicService)
 {
     _userAccountService   = userAccountService;
     _mapper               = mapper;
     _unitOfWork           = unitOfWork;
     _cryptographicService = cryptographicService;
 }
Ejemplo n.º 10
0
 public DataController(IAppDataService appDataService, IAccountService accountService, IWebStorageService webStorageService, ICryptographicService cryptographicService,
                       IMessageService messageService, IResourceService resourceService)
 {
     this.appDataService       = appDataService;
     this.accountService       = accountService;
     this.webStorageService    = webStorageService;
     this.cryptographicService = cryptographicService;
     this.messageService       = messageService;
     this.resourceService      = resourceService;
     feedManagerCompletion     = new TaskCompletionSource <FeedManager>();
 }
Ejemplo n.º 11
0
 public DataController(IAppDataService appDataService, IAccountService accountService, IWebStorageService webStorageService, ICryptographicService cryptographicService,
     IMessageService messageService, IResourceService resourceService)
 {
     this.appDataService = appDataService;
     this.accountService = accountService;
     this.webStorageService = webStorageService;
     this.cryptographicService = cryptographicService;
     this.messageService = messageService;
     this.resourceService = resourceService;
     feedManagerCompletion = new TaskCompletionSource<FeedManager>();
 }
Ejemplo n.º 12
0
        public UserManagementService(
			IUserContext applicationContext,
			IRepositorySessionFactory repositorySessionFactory,
			IUserAccountRepository userAccountRepository,
			ICryptographicService cryptographicService,
			IQueueDispatcher<IMessage> dispatcher)
            : base(applicationContext, repositorySessionFactory, dispatcher)
        {
            Check.NotNull(userAccountRepository, "userAccountRepository cannot be null");
            _userAccountRepository = userAccountRepository;
            _cryptographicService = cryptographicService;
            _userAccountValidator = new UserAccountValidator(_userAccountRepository);
        }
Ejemplo n.º 13
0
 public CryptographicServiceTests()
 {
     _cryptographicService = new CryptographicService();
 }
Ejemplo n.º 14
0
 public LoginService(BudgetContext context, ICryptographicService crypto, ICredentialHoldingService creds)
 {
     _context = context;
     _crypto  = crypto;
     _creds   = creds;
 }
Ejemplo n.º 15
0
 public UserStore(IUserContextService contextService, ILogger logger, ICryptographicService cryptographicService)
 {
     _contextService       = contextService;
     _logger               = logger;
     _cryptographicService = cryptographicService;
 }
Ejemplo n.º 16
0
 public UserService(ICryptographicService cryptographicService, IUserRepository userRepository)
 {
     _cryptographicService = cryptographicService;
     _userRepository       = userRepository;
 }
Ejemplo n.º 17
0
 public SqlUserAccountRepository(ICryptographicService cryptographicService)
 {
     _cryptographicService = cryptographicService;
 }
Ejemplo n.º 18
0
        public static async Task <InitializationResult> HandleInitializationOfClient(
            Stream clientStream,
            byte[] presharedKey,
            Guid serverGuid,
            IAuthenticatedConnectionFactory authenticatedConnectionFactory,
            ICryptographicService otp,
            Action <Guid, AuthenticatedStream> onClientConnected,
            Action <Guid, X509Certificate> onClientRegistered,
            Func <Guid, X509Certificate> getClientPublicKey,
            CancellationToken token)
        {
            token = token.AddTimeout(DefaultTimeout);
            if (token.IsCancellationRequested)
            {
                return(new InitializationResult
                {
                    Successful = false,
                    Error = new InitializationError
                    {
                        ErrorType = InitializationErrorType.CancellationRequested,
                    }
                });
            }
            if (!await GetAndVerifyPresharedKey(clientStream, presharedKey, token))
            {
                return(new InitializationResult
                {
                    Successful = false,
                    Error = new InitializationError
                    {
                        ErrorType = InitializationErrorType.Protocol,
                        Message = "The received pre-shared key did not match the pre-shared key for this application",
                    },
                });
            }
            await clientStream.WriteSafelyAsync(serverGuid, token);

            var clientGuidResult = await clientStream.ReceiveGuidSafelyAsync(token);

            if (!clientGuidResult.Successful)
            {
                return(InitializationResult.From(clientGuidResult));
            }
            var clientGuid           = clientGuidResult.Result;
            var initiationModeResult = await clientStream.ReceiveInt32SafelyAsync(token);

            if (!initiationModeResult.Successful)
            {
                return(InitializationResult.From(initiationModeResult));
            }
            switch ((InitiationMode)initiationModeResult.Result)
            {
            case InitiationMode.Otp:
                var clientRegistrationResult =
                    await HandleClientRegistrationSafelyAsync(clientStream, serverGuid, authenticatedConnectionFactory, otp, token);

                if (clientRegistrationResult.Successful)
                {
                    var(certificate, stream) = clientRegistrationResult.Result;
                    onClientRegistered(clientGuid, certificate);
                    onClientConnected(clientGuid, stream);
                }
                else
                {
                    return(clientRegistrationResult);
                }
                return(new InitializationResult
                {
                    Successful = true,
                });

            case InitiationMode.Standard:
                var clientCertificate = getClientPublicKey(clientGuid);
                if (clientCertificate == null)
                {
                    return(InitializationResult.Failed);
                }
                //var sessionKey = SymmetricKey.GenerateNewKey(symmetric.KeyLength);

                var encryptedStreamResult = await EstablishEncryptedCommunication(true, serverGuid, authenticatedConnectionFactory, clientStream, token);

                if (!encryptedStreamResult.Successful)
                {
                    return(encryptedStreamResult);
                }
                onClientConnected(clientGuid, encryptedStreamResult.Result);
                return(new InitializationResult
                {
                    Successful = true,
                });

            case InitiationMode.None:
                return(new InitializationResult()
                {
                    Successful = false,
                    Error = new InitializationError()
                    {
                        ErrorType = InitializationErrorType.Protocol,
                        Message = "Client did not send a valid initiation mode",
                    },
                });

            default:
                throw new ProtocolException($"invalid initiation mode {initiationModeResult.Result}");
            }
        }
Ejemplo n.º 19
0
 protected void AnAesCryptographicServiceWithValidKey()
 {
     CryptographicService = new AesCryptographicService(TestData.TestSymmetricKey);
 }
        public void CryptographicServiceSetUp()
        {
            var rngCryptoServiceProvider = new RNGCryptoServiceProvider();

            _cryptographicService = new CryptographicService(rngCryptoServiceProvider);
        }
Ejemplo n.º 21
0
        public static async Task <InitializationResult <(X509Certificate, AuthenticatedStream)> > HandleClientRegistrationSafelyAsync(
            Stream clientStream,
            Guid serverGuid,
            IAuthenticatedConnectionFactory authenticatedConnectionFactory,
            ICryptographicService otp,
            CancellationToken token)
        {
            InitializationResult <(X509Certificate, AuthenticatedStream)> From(CommunicationResult res) => From <(X509Certificate, AuthenticatedStream)>(res);

            if (!otp.CanDecrypt)
            {
                throw new ArgumentException("otp needs to be able to decrypt");
            }

            var dataTypeResult = await clientStream.ReceiveInt32SafelyAsync(token);

            if (!dataTypeResult.Successful)
            {
                return(From(dataTypeResult));
            }
            if ((CommunicationData)dataTypeResult.Result != CommunicationData.PublicKey)
            {
                return(new InitializationResult <(X509Certificate, AuthenticatedStream)>
                {
                    Successful = false,
                    Error = new InitializationError
                    {
                        ErrorType = InitializationErrorType.Protocol,
                        Message = $"Client sent unexpected data",
                    },
                });
            }

            var encryptedLengthResult = await clientStream.ReceiveInt32SafelyAsync(token);

            if (!encryptedLengthResult.Successful)
            {
                return(From(encryptedLengthResult));
            }
            var encryptedCertificateResult = await clientStream.ReadSafelyAsync(encryptedLengthResult.Result, token);

            if (!encryptedCertificateResult.Successful)
            {
                return(From(encryptedCertificateResult));
            }
            var clientCertificate = new X509Certificate(otp.Decrypt(encryptedCertificateResult.Result));

            var authenticationResult = await EstablishEncryptedCommunication(true, serverGuid, authenticatedConnectionFactory, clientStream, token);

            if (authenticationResult.Successful)
            {
                return(new InitializationResult <(X509Certificate, AuthenticatedStream)>
                {
                    Successful = true,
                    Result = (clientCertificate, authenticationResult.Result),
                });
            }
            else
            {
                return(InitializationResult <(X509Certificate, AuthenticatedStream)> .From(authenticationResult));
            }
        }