Exemplo n.º 1
0
 public AuthenticationController(ICryptographer cryptographer, IPersistenceSession session, IAuth auth, IMessagingService messaging)
 {
     crypto = cryptographer;
     this.session = session;
     this.auth = auth;
     this.messaging = messaging;
 }
Exemplo n.º 2
0
 public FileSender(ICryptographer cryptographer,
                   ISender sender,
                   IRecognizer recognizer)
 {
     this.cryptographer = cryptographer;
     this.sender        = sender;
     this.recognizer    = recognizer;
 }
Exemplo n.º 3
0
 public UserService(IUserRepository userRepository,
                    ICryptographer cryptographer,
                    IUserServiceSettings settings)
 {
     _userRepository = userRepository;
     _cryptographer = cryptographer;
     _settings = settings;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountController"/> class.
 /// </summary>
 /// <param name="userSession">The user session.</param>
 /// <param name="memberService">The user repository.</param>
 /// <param name="authenticator">The authenticator.</param>
 /// <param name="cryptographer">The cryptographer.</param>
 /// <param name="authenticationService"></param>
 public AccountController(IUserSession userSession, IMemberService memberService, IAuthenticator authenticator, ICryptographer cryptographer, IAuthenticationService authenticationService)
     : base(userSession)
 {
     this.memberService = memberService;
     this.authenticator = authenticator;
     this.cryptographer = cryptographer;
     this.authenticationService = authenticationService;
 }
Exemplo n.º 5
0
 public CreateUserCommandHandler(IRepository <User, int> userRepository,
                                 IRepository <Contact, Guid> contactRepository,
                                 ICryptographer cryptographer)
 {
     _userRepository    = userRepository;
     _contactRepository = contactRepository;
     _cryptographer     = cryptographer;
 }
Exemplo n.º 6
0
 public AccessTokenProvider(IDataContext <TokenDocument> tokenDataContext, ICryptographer cryptographer)
 {
     this.tokenDataContext = tokenDataContext;
     this.cryptographer    = cryptographer;
     OnReceive             = ReceiveAuthenticationCode;
     OnCreate       = CreateAuthenticationCode;
     OnReceiveAsync = ReceiveAuthenticationCodeAsync;
     OnCreateAsync  = CreateAuthenticationCodeAsync;
 }
Exemplo n.º 7
0
        public void SetUp()
        {
            file          = new File("someFile", new byte[] { 1, 2, 3 });
            signedContent = new byte[] { 1, 7 };

            cryptographer = A.Fake <ICryptographer>();
            sender        = A.Fake <ISender>();
            recognizer    = A.Fake <IRecognizer>();
            fileSender    = new FileSender(cryptographer, sender, recognizer);
        }
        public RequestMessageCreator(
            IConnectionInternal connectionInternal,
            IServiceLocator serviceLocator)
        {
            _connectionInternal = connectionInternal;

            _healthVaultConfiguration = serviceLocator.GetInstance <HealthVaultConfiguration>();
            _telemetryInformation     = serviceLocator.GetInstance <SdkTelemetryInformation>();
            _cryptographer            = serviceLocator.GetInstance <ICryptographer>();
        }
Exemplo n.º 9
0
 public SingleFileSender(IDocumentChecker documentChecker,
                         ICryptographer cryptographer,
                         ISender sender,
                         IRecognizer recognizer)
 {
     this.documentChecker = documentChecker;
     this.cryptographer   = cryptographer;
     this.sender          = sender;
     this.recognizer      = recognizer;
 }
Exemplo n.º 10
0
 public FileSender(
     ICryptographer cryptographer,
     ISender sender,
     IRecognizer recognizer,
     Func <DateTime> now)
 {
     this.cryptographer = cryptographer;
     this.sender        = sender;
     this.recognizer    = recognizer;
     this.now           = now;
 }
Exemplo n.º 11
0
        public void SetUp()
        {
            // Постарайтесь вынести в SetUp всё неспецифическое конфигурирование так,
            // чтобы в конкретных тестах осталась только специфика теста,
            // без конфигурирования "обычного" сценария работы

            file          = new File("someFile", new byte[] { 1, 2, 3 });
            signedContent = new byte[] { 1, 7 };

            cryptographer = A.Fake <ICryptographer>();
            sender        = A.Fake <ISender>();
            recognizer    = A.Fake <IRecognizer>();
            fileSender    = new FileSender(cryptographer, sender, recognizer);
        }
Exemplo n.º 12
0
        public Result <Document> PrepareFileToSend(IRecognizer recognizer, ICryptographer cryptographer,
                                                   X509Certificate certificate, Func <DateTime> now)
        {
            return(Result.Of <Document>(() => recognizer.Recognize(this))
                   .Then(IsValidFormatVersion)
                   .Then(d => IsValidTimestamp(d, now))
                   .Then(d => SignDocument(d, cryptographer, certificate))
                   .RefineError("Can't prepare file to send"));
//			if (!IsValidFormatVersion(doc))
//				throw new FormatException($"Invalid format version: {doc.Format}");
//			if (!IsValidTimestamp(doc))
//				throw new FormatException($"Too old document: {doc.Created}");
//			doc.Content = cryptographer.Sign(doc.Content, certificate);
        }
        public CASTRequestParams(AppProvisioningInfo provInfo, ICryptographer cryptographer)
        {
            provInfo.ValidateRequired("provInfo");
            cryptographer.ValidateRequired("cryptographer");
            //
            // To create a session, we prove our possesion of the app shared secret
            // We do this by creating an HMAC of some HmacContent
            //
            HmacContent content    = new HmacContent(provInfo.AppIdInstance, cryptographer.HmacAlgorithm);
            string      xmlContent = content.ToXml();
            Hmac        hmac       = cryptographer.Hmac(provInfo.SharedSecret, xmlContent);

            this.AppIDInstance = provInfo.AppIdInstance;
            this.Credential    = new CASTCredential(hmac, content);
        }
Exemplo n.º 14
0
        public RegistrationService(ICryptographer cryptographer,
                                   IRegistrationMapper registrationMapper)
        {
            if (cryptographer == null)
            {
                throw new ArgumentNullException("cryptographer");
            }
            if (registrationMapper == null)
            {
                throw new ArgumentNullException("registrationMapper");
            }

            _cryptographer      = cryptographer;
            _registrationMapper = registrationMapper;
        }
Exemplo n.º 15
0
        public CASTRequestParams(AppProvisioningInfo provInfo, ICryptographer cryptographer)
        {            
            provInfo.ValidateRequired("provInfo");
            cryptographer.ValidateRequired("cryptographer");
            //
            // To create a session, we prove our possesion of the app shared secret
            // We do this by creating an HMAC of some HmacContent
            //
            HmacContent content = new HmacContent(provInfo.AppIdInstance, cryptographer.HmacAlgorithm);
            string xmlContent = content.ToXml();
            Hmac hmac = cryptographer.Hmac(provInfo.SharedSecret, xmlContent);

            this.AppIDInstance = provInfo.AppIdInstance;
            this.Credential = new CASTCredential(hmac, content);
        }
Exemplo n.º 16
0
        private static Result <Document> PrepareFileToSend(FileContent file, X509Certificate certificate,
                                                           IRecognizer recognizer, ICryptographer cryptographer, Func <DateTime> now)
        {
            var doc = recognizer.Recognize(file);

            if (!IsValidFormatVersion(doc))
            {
                return(Result.Fail <Document>($"Can't prepare file to send. Invalid format version {doc.Format}"));
            }
            if (!IsValidTimestamp(doc, now))
            {
                return(Result.Fail <Document>($"Can't prepare file to send. Too old document {doc.CreationDate}"));
            }
            doc = doc.SetContent(cryptographer.Sign(doc.Content, certificate));
            return(doc);
        }
Exemplo n.º 17
0
        public void SetUp()
        {
            // Постарайтесь вынести в SetUp всё неспецифическое конфигурирование так,
            // чтобы в конкретных тестах осталась только специфика теста,
            // без конфигурирования "обычного" сценария работы

            file          = new File("someFile", new byte[] { 1, 2, 3 });
            signedContent = new byte[] { 1, 7 };

            cryptographer = A.Fake <ICryptographer>();
            sender        = A.Fake <ISender>();
            recognizer    = A.Fake <IRecognizer>();
            fileSender    = new FileSender(cryptographer, sender, recognizer);

            document = new Document(file.Name, file.Content, DateTime.Now, "4.0");
            A.CallTo(() => recognizer.TryRecognize(file, out document))
            .Returns(true);
            A.CallTo(() => cryptographer.Sign(document.Content, certificate))
            .Returns(signedContent);
            A.CallTo(() => sender.TrySend(signedContent))
            .Returns(true);


            invalidFile          = new File("invalidFile", new byte[] { 1, 2, 3 });
            invalidSignedContent = new byte[] { 1, 7 };
            invalidDocument      = new Document(invalidFile.Name, invalidFile.Content, DateTime.Now, "111.222");

            A.CallTo(() => recognizer.TryRecognize(invalidFile, out invalidDocument))
            .Returns(true);
            A.CallTo(() => cryptographer.Sign(invalidDocument.Content, certificate))
            .Returns(invalidSignedContent);
            A.CallTo(() => sender.TrySend(invalidSignedContent))
            .Returns(true);


            couldNotSendFile          = new File("invalidFile", new byte[] { 1, 2, 3 });
            couldNotSendSignedContent = new byte[] { 1, 7 };
            couldNotSendDocument      = new Document(couldNotSendFile.Name, couldNotSendFile.Content, DateTime.Now, "4.0");

            A.CallTo(() => recognizer.TryRecognize(couldNotSendFile, out couldNotSendDocument))
            .Returns(true);
            A.CallTo(() => cryptographer.Sign(couldNotSendDocument.Content, certificate))
            .Returns(couldNotSendSignedContent);
            A.CallTo(() => sender.TrySend(couldNotSendSignedContent))
            .Returns(false);
        }
Exemplo n.º 18
0
        public void SetUp()
        {
            fileName = "temp.file";
            now      = DateTime.Now;
            random   = new Random();

            cryptographer = A.Fake <ICryptographer>();
            sender        = A.Fake <ISender>();
            recognizer    = A.Fake <IRecognizer>();
            fileSender    = new FileSender(cryptographer, sender, recognizer);

            A.CallTo(() => cryptographer.Sign(A <byte[]> ._, certificate))
            .Returns(GetFileContent());

            A.CallTo(() => sender.TrySend(A <byte[]> ._))
            .Returns(true);
        }
Exemplo n.º 19
0
        public void SetUp()
        {
            random = new Random();

            file          = new File("someFile", new byte[] { 1, 2, 3 });
            signedContent = new byte[] { 1, 7 };

            cryptographer = A.Fake <ICryptographer>();
            sender        = A.Fake <ISender>();
            recognizer    = A.Fake <IRecognizer>();
            fileSender    = new FileSender(cryptographer, sender, recognizer);

            A.CallTo(() => cryptographer.Sign(A <byte[]> .Ignored, certificate))
            .Returns(GenerateFileContent());
            A.CallTo(() => sender.TrySend(A <byte[]> .Ignored))
            .Returns(true);
        }
Exemplo n.º 20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="algorithm"></param>
        /// <returns></returns>
        public static ICryptographer GetCryptographer(CryptoAlgorithm algorithm)
        {
            ICryptographer crypto = null;

            switch (algorithm)
            {
            case CryptoAlgorithm.DES:
                crypto = new DESCryptographer();
                break;

            case CryptoAlgorithm.RC2:
                crypto = new RC2Cryptographer();
                break;

            case CryptoAlgorithm.Rijndael:
                crypto = new RijndaelCryptographer();
                break;

            case CryptoAlgorithm.TripleDES:
                crypto = new TripleDESCryptographer();
                break;

            case CryptoAlgorithm.RSA:
                crypto = new RSACryptorapher();
                break;

            case CryptoAlgorithm.MD5:
                crypto = new MD5HashCryptographer();
                break;

            case CryptoAlgorithm.HMACMD5:
                crypto = new HMACMD5HashCryptographer();
                break;

            case CryptoAlgorithm.SHA1:
                crypto = new SHA1HashCryptographer();
                break;

            default:
                Debug.Assert(false);
                break;
            }
            Debug.Assert(crypto != null);
            return(crypto);
        }
Exemplo n.º 21
0
        public void SetUp()
        {
            fileName    = "some.txt";
            now         = DateTime.Now;
            certificate = new X509Certificate();

            recognizer = A.Fake <IRecognizer>();

            cryptographer = A.Fake <ICryptographer>();
            A.CallTo(() => cryptographer.Sign(A <byte[]> ._, certificate))
            .ReturnsLazily(GetNewBytes);

            sender = A.Fake <ISender>();
            A.CallTo(() => sender.TrySend(A <byte[]> ._))
            .Returns(true);

            fileSender = new FileSender(cryptographer, sender, recognizer);
        }
Exemplo n.º 22
0
        public HealthVaultClient(
            AppInfo appInfo,
            ServiceInfo serviceInfo,
            IHttpTransport transport,
            IHttpStreamer streamer,
            ICryptographer cryptographer,
            bool useOnlineAuthModel,
            IWebAuthorizer authorizer)
        {
            appInfo.ValidateRequired("appInfo");
            serviceInfo.ValidateRequired("serviceInfo");
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            if (streamer == null)
            {
                throw new ArgumentNullException("streamer");
            }
            if (cryptographer == null)
            {
                throw new ArgumentNullException("cryptographer");
            }
            if (!useOnlineAuthModel && authorizer == null)
            {
                throw new ArgumentNullException("authorizer");
            }

            UseOnlineAuthModel = useOnlineAuthModel;
            m_appInfo          = appInfo;
            m_serviceInfo      = serviceInfo;
            m_transport        = transport;
            m_streamer         = streamer;
            m_cryptographer    = cryptographer;
            m_authorizer       = authorizer;

            m_serviceMethods = new ServiceMethods(this);
            m_recordMethods  = new RecordMethods(this);
            m_shell          = new Shell(this);

            m_secretStore = new SecretStore(MakeStoreName(m_appInfo.MasterAppId));
            m_state       = new ClientState();
            LoadState();
        }
Exemplo n.º 23
0
        public void SetUp()
        {
            // Тут мы задаем некоторые известны для всех тестов данные
            // и умолчательные поведения сервисов-заглушек.
            // Наша цель — сделать так, чтобы в конкретных тестах осталась только их специфика,
            // а конфигурирование "обычного" поведения не надо было повторять от теста к тесту
            cryptographer = A.Fake <ICryptographer>();
            sender        = A.Fake <ISender>();
            recognizer    = A.Fake <IRecognizer>();
            fileSender    = new FileSender(cryptographer, sender, recognizer);

            var signedContent = Guid.NewGuid().ToByteArray();

            A.CallTo(() => cryptographer.Sign(null, null))
            .WithAnyArguments()
            .Returns(signedContent);
            A.CallTo(() => sender.TrySend(signedContent))
            .Returns(true);
        }
Exemplo n.º 24
0
        public HealthVaultClient(
            AppInfo appInfo,
            ServiceInfo serviceInfo,
            IHttpTransport transport,
            IHttpStreamer streamer,
            ICryptographer cryptographer,
            IWebAuthorizer authorizer)
        {
            appInfo.ValidateRequired("appInfo");
            serviceInfo.ValidateRequired("serviceInfo");
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            if (streamer == null)
            {
                throw new ArgumentNullException("streamer");
            }
            if (cryptographer == null)
            {
                throw new ArgumentNullException("cryptographer");
            }
            if (authorizer == null)
            {
                throw new ArgumentNullException("authorizer");
            }

            m_appInfo = appInfo;
            m_serviceInfo = serviceInfo;
            m_transport = transport;
            m_streamer = streamer;
            m_cryptographer = cryptographer;
            m_authorizer = authorizer;

            m_serviceMethods = new ServiceMethods(this);
            m_recordMethods = new RecordMethods(this);
            m_shell = new Shell(this);

            m_secretStore = new SecretStore(MakeStoreName(m_appInfo.MasterAppId));
            m_state = new ClientState();
            LoadState();
        }
        public void InitializeTest()
        {
            _connection     = Substitute.For <IConnectionInternal>();
            _serviceLocator = Substitute.For <IServiceLocator>();

            _serviceLocator.GetInstance <HealthVaultConfiguration>()
            .Returns(new HealthVaultConfiguration
            {
                MasterApplicationId       = Guid.NewGuid(),
                RequestTimeToLiveDuration = new TimeSpan(hours: 0, minutes: 1, seconds: 5)
            });

            _serviceLocator.GetInstance <SdkTelemetryInformation>()
            .Returns(
                new SdkTelemetryInformation()
            {
                Category = "test", FileVersion = "test", OsInformation = "test"
            });

            ICryptographer mockCryptographer = Substitute.For <ICryptographer>();
            CryptoData     mockCryptoData    = new CryptoData()
            {
                Algorithm = "some", Value = "some"
            };

            mockCryptographer.Hmac(Arg.Any <string>(), Arg.Any <byte[]>())
            .Returns(mockCryptoData);

            mockCryptographer.Hash(Arg.Any <byte[]>())
            .Returns(mockCryptoData);

            _serviceLocator.GetInstance <ICryptographer>().Returns(mockCryptographer);

            _connection.SessionCredential.Returns(
                new SessionCredential()
            {
                SharedSecret = "someSharedSecret", Token = "someToken"
            });
        }
Exemplo n.º 26
0
        public void SetUp()
        {
            // Постарайтесь вынести в SetUp всё неспецифическое конфигурирование так,
            // чтобы в конкретных тестах осталась только специфика теста,
            // без конфигурирования "обычного" сценария работы

            file          = new File("someFile", new byte[] { 1, 2, 3 });
            signedContent = new byte[] { 1, 7 };

            cryptographer = A.Fake <ICryptographer>();
            sender        = A.Fake <ISender>();
            recognizer    = A.Fake <IRecognizer>();
            fileSender    = new FileSender(cryptographer, sender, recognizer);
            var goodDocument = new Document(file.Name, file.Content, DateTime.Now, "4.0");

            A.CallTo(() => recognizer.TryRecognize(A <File> .Ignored, out goodDocument))
            .Returns(true);
            A.CallTo(() => cryptographer.Sign(A <byte[]> .Ignored, A <X509Certificate> .Ignored))
            .Returns(signedContent);
            A.CallTo(() => sender.TrySend(A <byte[]> .Ignored))
            .Returns(true);
        }
Exemplo n.º 27
0
 public AuthenticationService(ICryptographer cryptographer)
 {
     _cryptographer = cryptographer;
 }
Exemplo n.º 28
0
        private AccountController GetController()
        {
            mockUserSession = mockery.DynamicMock<IUserSession>();
            mockMemberService = mockery.DynamicMock<IMemberService>();
            mockAuthenticator = mockery.DynamicMock<IAuthenticator>();
            mockCryptographer = mockery.DynamicMock<ICryptographer>();
            mockery.DynamicMock<IEmailService>();
            mockAuthenticationService = mockery.DynamicMock<IAuthenticationService>();

            var controller = new AccountController(mockUserSession, mockMemberService, mockAuthenticator, mockCryptographer, mockAuthenticationService);

            return controller;
        }
Exemplo n.º 29
0
 protected override HashController EstablishContext()
 {
     _cryptographer = Substitute.For <ICryptographer>();
     _logger        = Substitute.For <ILogger <HashController> >();
     return(new HashController(_cryptographer, _logger));
 }
 public Hash Hash(ICryptographer cryptographer)
 {
     return(cryptographer.Hash(this.ToXml()));
 }
Exemplo n.º 31
0
 static DigestHelper()
 {
     _config = ServiceLocator.Current.GetInstance<IConfigurationProvider>();
     _userService = ServiceLocator.Current.GetInstance<IUserService>();
     _cryptographer = ServiceLocator.Current.GetInstance<ICryptographer>();
 }
Exemplo n.º 32
0
 public Authenticator(IHttpContextProvider httpContextProvider, ICryptographer cryptographer, IRepository repository)
 {
     _cryptographer       = cryptographer;
     this.repository      = repository;
     _httpContextProvider = httpContextProvider;
 }
Exemplo n.º 33
0
 public UpdateUserCommandHandler(IUserRepository meetingRepository, ICryptographer cryptographer)
 {
     _repository    = meetingRepository;
     _cryptographer = cryptographer;
 }
Exemplo n.º 34
0
 public static IEnumerable <Result <FileContent> > SendFiles(FileContent[] files, X509Certificate certificate,
                                                             ISender sender, IRecognizer recognizer, ICryptographer cryptographer, Func <DateTime> now)
 {
     foreach (var file in files)
     {
         var doc = PrepareFileToSend(file, certificate, recognizer, cryptographer, now);
         if (!doc.IsSuccess)
         {
             yield return(Result.Fail <FileContent>(doc.Error));
         }
         else
         {
             sender.Send(doc.Value); //Can't send.
             yield return(Result.Ok(file));
         }
     }
 }
Exemplo n.º 35
0
        /// <summary>
        /// Sets the cryptographer.
        /// </summary>
        /// <param name="cryptographer">The cryptographer.</param>
        /// <exception cref="System.ArgumentNullException">The cryptographer parameter cannot be null</exception>
        public void SetCryptographer(ICryptographer cryptographer)
        {
            if (cryptographer == null)
            {
                throw new ArgumentNullException("cryptographer");
            }

            this.InternalCryptographer = cryptographer;
        }
Exemplo n.º 36
0
 public FirstLoadViewModel(IAppSettingsHandler setting, ICryptographer cryptographer)
 {
     this.setting       = setting;
     this.cryptographer = cryptographer;
 }
Exemplo n.º 37
0
 public ChangeUserPasswordCommandHandler(ICryptographer cryptographer,
                                         ICurrentUserRetriever <User> currentUserRetriever)
 {
     _cryptographer        = cryptographer;
     _currentUserRetriever = currentUserRetriever;
 }
Exemplo n.º 38
0
 public EncryptedObjectStore(IObjectStore inner, ICryptographer cryptographer, string encryptionKey)
 {
     m_inner = inner;
     m_cryptographer = cryptographer;
     m_encryptionKey = encryptionKey;
 }
 public Hash Hash(ICryptographer cryptographer)
 {
     return cryptographer.Hash(this.ToXml());
 }
Exemplo n.º 40
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="plainConnectString"></param>
        /// <returns></returns>
        public static string Encrypt(CryptoAlgorithm algorithm, string plainConnectString)
        {
            ICryptographer cryptographer = GetCryptographer(algorithm);

            return(cryptographer.Encrypt(plainConnectString));
        }
Exemplo n.º 41
0
 public TestWebService(IRepository repo, ICryptographer crypto)
 {
     _repo   = repo;
     _crypto = crypto;
 }
Exemplo n.º 42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IdentityService"/> class.
 /// </summary>
 /// <param name="userRepository">
 /// The user repository.
 /// </param>
 /// <param name="cryptographer">
 /// The cryptographer.
 /// </param>
 public IdentityService(IUserRepository userRepository, ICryptographer cryptographer)
 {
     this.userRepository = userRepository;
     this.cryptographer = cryptographer;
 }