コード例 #1
1
        public Connection(IMessageBus newMessageBus,
                          JsonSerializer jsonSerializer,
                          string baseSignal,
                          string connectionId,
                          IList<string> signals,
                          IList<string> groups,
                          ILoggerFactory loggerFactory,
                          IAckHandler ackHandler,
                          IPerformanceCounterManager performanceCounterManager,
                          IProtectedData protectedData,
                          IMemoryPool pool)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException("loggerFactory");
            }

            _bus = newMessageBus;
            _serializer = jsonSerializer;
            _baseSignal = baseSignal;
            _connectionId = connectionId;
            _signals = new List<string>(signals.Concat(groups));
            _groups = new DiffSet<string>(groups);
            _logger = loggerFactory.CreateLogger<Connection>();
            _ackHandler = ackHandler;
            _counters = performanceCounterManager;
            _protectedData = protectedData;
            _excludeMessage = m => ExcludeMessage(m);
            _pool = pool;
        }
コード例 #2
1
ファイル: Connection.cs プロジェクト: Djohnnie/Sonarr
        public Connection(IMessageBus newMessageBus,
                          IJsonSerializer jsonSerializer,
                          string baseSignal,
                          string connectionId,
                          IList<string> signals,
                          IList<string> groups,
                          ITraceManager traceManager,
                          IAckHandler ackHandler,
                          IPerformanceCounterManager performanceCounterManager,
                          IProtectedData protectedData)
        {
            if (traceManager == null)
            {
                throw new ArgumentNullException("traceManager");
            }

            _bus = newMessageBus;
            _serializer = jsonSerializer;
            _baseSignal = baseSignal;
            _connectionId = connectionId;
            _signals = new List<string>(signals.Concat(groups));
            _groups = new DiffSet<string>(groups);
            _traceSource = traceManager["SignalR.Connection"];
            _ackHandler = ackHandler;
            _counters = performanceCounterManager;
            _protectedData = protectedData;
        }
コード例 #3
0
 public LocalDataProtectionProvider(
     IProtectedData protectedData,
     IDataProtectionProvider dataProtectionProvider,
     IPlatformService platformService) : base(protectedData, dataProtectionProvider)
 {
     this.platformService = platformService;
 }
コード例 #4
0
ファイル: Connection.cs プロジェクト: titan04/Sonarr
        public Connection(IMessageBus newMessageBus,
                          IJsonSerializer jsonSerializer,
                          string baseSignal,
                          string connectionId,
                          IList <string> signals,
                          IList <string> groups,
                          ITraceManager traceManager,
                          IAckHandler ackHandler,
                          IPerformanceCounterManager performanceCounterManager,
                          IProtectedData protectedData)
        {
            if (traceManager == null)
            {
                throw new ArgumentNullException("traceManager");
            }

            _bus           = newMessageBus;
            _serializer    = jsonSerializer;
            _baseSignal    = baseSignal;
            _connectionId  = connectionId;
            _signals       = new List <string>(signals.Concat(groups));
            _groups        = new DiffSet <string>(groups);
            _traceSource   = traceManager["SignalR.Connection"];
            _ackHandler    = ackHandler;
            _counters      = performanceCounterManager;
            _protectedData = protectedData;
        }
コード例 #5
0
        private string GetUrl(IProtectedData protectedData, Client.Connection connection, string groupsToken)
        {
            // Generate a valid token
            string connectionToken = protectedData.Protect(Guid.NewGuid().ToString("d") + ':', Purposes.ConnectionToken);

            return(GetUrl(protectedData, connection, connectionToken, groupsToken));
        }
コード例 #6
0
        public Connection(IMessageBus newMessageBus,
                          JsonSerializer jsonSerializer,
                          string baseSignal,
                          string connectionId,
                          IList <string> signals,
                          IList <string> groups,
                          ILoggerFactory loggerFactory,
                          IAckHandler ackHandler,
                          IPerformanceCounterManager performanceCounterManager,
                          IProtectedData protectedData,
                          IMemoryPool pool)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException("loggerFactory");
            }

            _bus            = newMessageBus;
            _serializer     = jsonSerializer;
            _baseSignal     = baseSignal;
            _connectionId   = connectionId;
            _signals        = new List <string>(signals.Concat(groups));
            _groups         = new DiffSet <string>(groups);
            _logger         = loggerFactory.CreateLogger <Connection>();
            _ackHandler     = ackHandler;
            _counters       = performanceCounterManager;
            _protectedData  = protectedData;
            _excludeMessage = m => ExcludeMessage(m);
            _pool           = pool;
        }
コード例 #7
0
        private string GetUrl(IProtectedData protectedData, Client.Connection connection)
        {
            // Generate a valid token
            string groupsToken = protectedData.Protect(JsonConvert.SerializeObject(new[] { connection.ConnectionToken }), Purposes.Groups);

            return(GetUrl(protectedData, connection, groupsToken));
        }
コード例 #8
0
ファイル: SecurityFacts.cs プロジェクト: netdebug/SignalR
        public async Task ConnectionIdsCantBeUsedAsGroups()
        {
            using (var host = new MemoryHost())
            {
                IProtectedData protectedData = null;

                host.Configure(app =>
                {
                    var config = new ConnectionConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    app.MapSignalR <MyConnection>("/echo", config);

                    protectedData = config.Resolver.Resolve <IProtectedData>();
                });

                var connection = new Client.Connection("http://memoryhost/echo");

                using (connection)
                {
                    var connectionTcs = new TaskCompletionSource <string>();
                    var spyTcs        = new TaskCompletionSource <string>();

                    connection.Received += data =>
                    {
                        connectionTcs.SetResult(data.Trim());
                    };

                    await connection.Start(host).OrTimeout();

                    EventSourceStreamReader reader = null;

                    await Task.Run(async() =>
                    {
                        var url      = GetUrl(protectedData, connection);
                        var response = await host.Get(url, r => { }, isLongRunning: true);
                        reader       = new EventSourceStreamReader(connection, response.GetStream());

                        reader.Message = sseEvent =>
                        {
                            if (sseEvent.EventType == EventType.Data &&
                                sseEvent.Data != "initialized" &&
                                sseEvent.Data != "{}")
                            {
                                spyTcs.TrySetResult(sseEvent.Data);
                            }
                        };

                        reader.Start();
                    });

                    await connection.Send("STUFFF").OrTimeout();

                    Assert.Equal("STUFFF", await connectionTcs.Task.OrTimeout());
                }
            }
        }
コード例 #9
0
        private string GetUrl(IProtectedData protectedData, Client.Connection connection, string connectionToken, string groupsToken)
        {
            var sb = new StringBuilder(connection.Url);

            sb.Append("?connectionToken=")
            .Append(Uri.EscapeDataString(connectionToken))
            .Append("&transport=serverSentEvents")
            .Append("&groupsToken=")
            .Append(Uri.EscapeDataString(groupsToken));

            return(sb.ToString());
        }
コード例 #10
0
ファイル: Connection.cs プロジェクト: titan04/Sonarr
        internal static void PopulateResponseState(PersistentResponse response,
                                                   DiffSet <string> groupSet,
                                                   IJsonSerializer serializer,
                                                   IProtectedData protectedData,
                                                   string connectionId)
        {
            bool anyChanges = groupSet.DetectChanges();

            if (anyChanges)
            {
                // Create a protected payload of the sorted list
                IEnumerable <string> groups = groupSet.GetSnapshot();

                // Remove group prefixes before any thing goes over the wire
                string groupsString = connectionId + ':' + serializer.Stringify(PrefixHelper.RemoveGroupPrefixes(groups));;

                // The groups token
                response.GroupsToken = protectedData.Protect(groupsString, Purposes.Groups);
            }
        }
コード例 #11
0
ファイル: Connection.cs プロジェクト: stirno/SignalR
 public Connection(IMessageBus newMessageBus,
                   IJsonSerializer jsonSerializer,
                   string baseSignal,
                   string connectionId,
                   IList<string> signals,
                   IList<string> groups,
                   ITraceManager traceManager,
                   IAckHandler ackHandler,
                   IPerformanceCounterManager performanceCounterManager,
                   IProtectedData protectedData)
 {
     _bus = newMessageBus;
     _serializer = jsonSerializer;
     _baseSignal = baseSignal;
     _connectionId = connectionId;
     _signals = new HashSet<string>(signals, StringComparer.OrdinalIgnoreCase);
     _groups = new DiffSet<string>(groups);
     _traceSource = new Lazy<TraceSource>(() => traceManager["SignalR.Connection"]);
     _ackHandler = ackHandler;
     _counters = performanceCounterManager;
     _protectedData = protectedData;
 }
コード例 #12
0
        public void ConnectionIdsCantBeUsedAsGroups()
        {
            using (var host = new MemoryHost())
            {
                IProtectedData protectedData = null;

                host.Configure(app =>
                {
                    var config = new ConnectionConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    app.MapConnection <MyConnection>("/echo", config);

                    protectedData = config.Resolver.Resolve <IProtectedData>();
                });

                var connection = new Client.Connection("http://memoryhost/echo");

                var connectionTcs = new TaskCompletionSource <string>();
                var spyTcs        = new TaskCompletionSource <string>();

                connection.Received += data =>
                {
                    connectionTcs.SetResult(data.Trim());
                };

                connection.Start(host).Wait();

                var tcs = new TaskCompletionSource <object>();
                EventSourceStreamReader reader = null;

                Task.Run(async() =>
                {
                    try
                    {
                        string url   = GetUrl(protectedData, connection);
                        var response = await host.Get(url);
                        reader       = new EventSourceStreamReader(connection, response.GetStream());

                        reader.Message = sseEvent =>
                        {
                            if (sseEvent.EventType == EventType.Data &&
                                sseEvent.Data != "initialized" &&
                                sseEvent.Data != "{}")
                            {
                                spyTcs.TrySetResult(sseEvent.Data);
                            }
                        };

                        reader.Start();
                        tcs.TrySetResult(null);
                    }
                    catch (Exception ex)
                    {
                        tcs.TrySetException(ex);
                    }
                });

                tcs.Task.Wait();

                connection.SendWithTimeout("STUFFF");

                Assert.True(connectionTcs.Task.Wait(TimeSpan.FromSeconds(5)));
                Assert.Equal("STUFFF", connectionTcs.Task.Result);
                Assert.False(spyTcs.Task.Wait(TimeSpan.FromSeconds(5)));

                connection.Stop();
            }
        }
コード例 #13
0
 public PasswordStorage(IProtectedData protectedData)
 {
     this.protectedData = protectedData;
 }
コード例 #14
0
        private string GetUrl(IProtectedData protectedData, Client.Connection connection, string connectionToken, string groupsToken)
        {
            var sb = new StringBuilder(connection.Url);
            sb.Append("?connectionToken=")
              .Append(Uri.EscapeDataString(connectionToken))
              .Append("&transport=serverSentEvents")
              .Append("&groupsToken=")
              .Append(Uri.EscapeDataString(groupsToken));

            return sb.ToString();
        }
コード例 #15
0
ファイル: SecurityFacts.cs プロジェクト: stirno/SignalR
        private string GetUrl(IProtectedData protectedData, Client.Connection connection)
        {
            // Generate a valid token
            string token = protectedData.Protect(Guid.NewGuid().ToString("d") + ':', Purposes.ConnectionToken);
            string groupsToken = protectedData.Protect(JsonConvert.SerializeObject(new[] { connection.ConnectionToken }), Purposes.Groups);

            var sb = new StringBuilder("http://memoryhost/echo/");
            sb.Append("?connectionToken=")
              .Append(Uri.EscapeDataString(token))
              .Append("&transport=serverSentEvents")
              .Append("&groupsToken=")
              .Append(Uri.EscapeDataString(groupsToken));

            return sb.ToString();
        }
コード例 #16
0
ファイル: Connection.cs プロジェクト: stirno/SignalR
        internal static void PopulateResponseState(PersistentResponse response, 
                                                   DiffSet<string> groupSet, 
                                                   IJsonSerializer serializer, 
                                                   IProtectedData protectedData)
        {
            DiffPair<string> groupDiff = groupSet.GetDiff();

            if (groupDiff.AnyChanges)
            {
                // Create a protected payload of the sorted list
                IEnumerable<string> groups = groupSet.GetSnapshot();

                // No groups so do nothing
                if (groups.Any())
                {
                    // Remove group prefixes before any thing goes over the wire
                    string groupsString = serializer.Stringify(PrefixHelper.RemoveGroupPrefixes(groups));

                    // The groups token
                    response.GroupsToken = protectedData.Protect(groupsString, Purposes.Groups);
                }
            }
        }
コード例 #17
0
 /// <summary>
 ///     Constructor
 /// </summary>
 public PasswordStorage(IProtectedData protectedData)
 {
     this.protectedData = protectedData;
 }
コード例 #18
0
        private string GetUrl(IProtectedData protectedData, Client.Connection connection)
        {
            // Generate a valid token
            string groupsToken = protectedData.Protect(JsonConvert.SerializeObject(new[] { connection.ConnectionToken }), Purposes.Groups);

            return GetUrl(protectedData, connection, groupsToken);
        }
コード例 #19
0
 internal DpapiDataProtector(IProtectedData shim, byte[] combinedPurposes, DataProtectionScope scope)
 {
     _combinedPurposes = combinedPurposes;
     _scope            = scope;
     _shim             = shim;
 }
コード例 #20
0
 public TimeLineController(ITimeLineService timeLineService, IProtectedData protectedData)
 {
     this.timeLineService = timeLineService;
     this.protectedData = protectedData;
 }
コード例 #21
0
        public async Task GroupsTokenIsPerConnectionId()
        {
            using (var host = new MemoryHost())
            {
                IProtectedData protectedData = null;

                host.Configure(app =>
                {
                    var config = new HubConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    app.MapSignalR <MyGroupConnection>("/echo", config);

                    protectedData = config.Resolver.Resolve <IProtectedData>();
                });

                var connection = new Client.Connection("http://memoryhost/echo");

                using (connection)
                {
                    var inGroup = new AsyncManualResetEvent();

                    connection.Received += data =>
                    {
                        if (data == "group")
                        {
                            inGroup.Set();
                        }
                    };

                    await connection.Start(host);

                    await inGroup.WaitAsync(TimeSpan.FromSeconds(10));

                    Assert.NotNull(connection.GroupsToken);

                    var spyWh            = new AsyncManualResetEvent();
                    var hackerConnection = new Client.Connection(connection.Url)
                    {
                        ConnectionId = "hacker"
                    };

                    var url      = GetUrl(protectedData, connection, connection.GroupsToken);
                    var response = await host.Get(url, r => { }, isLongRunning : true);

                    var reader = new EventSourceStreamReader(hackerConnection, response.GetStream());

                    reader.Message = sseEvent =>
                    {
                        if (sseEvent.EventType == EventType.Data &&
                            sseEvent.Data != "initialized" &&
                            sseEvent.Data != "{}")
                        {
                            spyWh.Set();
                        }
                    };

                    reader.Start();
                    await connection.Send("random");

                    Assert.False(await spyWh.WaitAsync(TimeSpan.FromSeconds(5)));
                }
            }
        }
コード例 #22
0
ファイル: Connection.cs プロジェクト: Djohnnie/Sonarr
        internal static void PopulateResponseState(PersistentResponse response,
                                                   DiffSet<string> groupSet,
                                                   IJsonSerializer serializer,
                                                   IProtectedData protectedData,
                                                   string connectionId)
        {
            bool anyChanges = groupSet.DetectChanges();

            if (anyChanges)
            {
                // Create a protected payload of the sorted list
                IEnumerable<string> groups = groupSet.GetSnapshot();

                // Remove group prefixes before any thing goes over the wire
                string groupsString = connectionId + ':' + serializer.Stringify(PrefixHelper.RemoveGroupPrefixes(groups)); ;

                // The groups token
                response.GroupsToken = protectedData.Protect(groupsString, Purposes.Groups);
            }
        }
コード例 #23
0
 public AccountController(IProtectedData protectedData)
     : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
 {
     this.protectedData = protectedData;
 }
コード例 #24
0
        private string GetUrl(IProtectedData protectedData, Client.Connection connection, string groupsToken)
        {
            // Generate a valid token
            string connectionToken = protectedData.Protect(Guid.NewGuid().ToString("d") + ':', Purposes.ConnectionToken);

            return GetUrl(protectedData, connection, connectionToken, groupsToken);
        }