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; }
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; }
public LocalDataProtectionProvider( IProtectedData protectedData, IDataProtectionProvider dataProtectionProvider, IPlatformService platformService) : base(protectedData, dataProtectionProvider) { this.platformService = platformService; }
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; }
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)); }
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; }
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)); }
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()); } } }
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()); }
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); } }
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; }
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(); } }
public PasswordStorage(IProtectedData protectedData) { this.protectedData = protectedData; }
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(); }
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(); }
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); } } }
/// <summary> /// Constructor /// </summary> public PasswordStorage(IProtectedData protectedData) { this.protectedData = protectedData; }
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); }
internal DpapiDataProtector(IProtectedData shim, byte[] combinedPurposes, DataProtectionScope scope) { _combinedPurposes = combinedPurposes; _scope = scope; _shim = shim; }
public TimeLineController(ITimeLineService timeLineService, IProtectedData protectedData) { this.timeLineService = timeLineService; this.protectedData = protectedData; }
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))); } } }
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); } }
public AccountController(IProtectedData protectedData) : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()))) { this.protectedData = protectedData; }
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); }