private void CreateSelfSignedCert() { Log.Info("Creating cert"); ServerCert = CertMan.CreateSelfSignedCertInMemory(SecureRandomStringGen.RandomString(128, true)); Log.Info("Created cert"); }
public AdminCommunictator( bool logToFile, int logFileRetainCount, bool verbose, bool showServerConsole, bool useUnencryptedCom) { AdminComConfig = new AdminComConfig() { LogToFile = logToFile, LogFileRetainCount = logFileRetainCount, Verbose = verbose, ShowServerConsole = showServerConsole, Username = SecureRandomStringGen.RandomString(64, true), Password = SecureRandomStringGen.RandomString(128, true), UnencryptedServerCom = useUnencryptedCom }; StartServiceManager = new ServiceManager <ServiceStart, bool>(() => CancelOperationTS.Token); StopServiceManager = new ServiceManager <ServiceStop, bool>(() => CancelOperationTS.Token); }
protected async Task Handshake() { var timeout = Config.StartInactivityShutdownTimeout; Log.Info("Checking handshake reflector (HR)"); var tcs = new TaskCompletionSource <string>(); var randomStr = SecureRandomStringGen.RandomString(64); using (var wsHRCheck = CreateWebSocket(ComServices.S_HANDSHAKE_REFLECTOR)) { wsHRCheck.OnOpen += (s, ev) => { Log.Debug("HR: onOpen"); wsHRCheck.Send(randomStr); }; wsHRCheck.OnMessage += (s, ev) => { Log.Debug($"HR: onMessage: {ev.Data}"); tcs.SetResult(ev.Data); }; wsHRCheck.OnClose += (s, ev) => { Log.Debug($"HR: onClose: Code={ev.Code} Reason='{ev.Reason}' WasClean={ev.WasClean}"); if (tcs.Task.IsCompleted) { return; } tcs.SetException(new InvalidOperationException($"HR socket was closed unexpectely; Code={ev.Code} Reason='{ev.Reason}' WasClean={ev.WasClean}")); }; using (var timeoutCancellationTokenSource = new CancellationTokenSource()) { var connectTask = Task.Run(() => wsHRCheck.Connect()); var connectedAndReceivedFeedbackTask = Task.WhenAll(tcs.Task, connectTask); var completedTask = await Task.WhenAny(Task.Delay(timeout, timeoutCancellationTokenSource.Token), connectedAndReceivedFeedbackTask); if (completedTask == connectedAndReceivedFeedbackTask) { timeoutCancellationTokenSource.Cancel(); await connectedAndReceivedFeedbackTask; } else { throw new TimeoutException("HR Timeout"); } } } if (!tcs.Task.IsCompletedSuccessfully) { throw new InvalidOperationException("HR did not completed successfully", tcs.Task.Exception); } if (!randomStr.Equals(tcs.Task.Result)) { throw new InvalidOperationException($"HR returned wrong data; expected '{randomStr}' got '{tcs.Task.Result}'"); } Log.Info("Handshake successful/Reflector operational"); }