Skip to content

Commit

Permalink
chore: correct the behavior of the start/stop methods
Browse files Browse the repository at this point in the history
Change interface method names
  • Loading branch information
ArachisH committed Mar 31, 2024
1 parent 5ed4dad commit 0ba14e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Tanji.Infrastructure/Services/IWebInterceptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public interface IWebInterceptionService
{
public bool IsIntercepting { get; }

public void StopWebInterception();
public void StartWebInterception();
public void Stop();
public void Start();

public ValueTask<string> InterceptTicketAsync(CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,31 @@ public EavesdropInterceptionService(ILogger<EavesdropInterceptionService> logger
Eavesdropper.Certifier = new Certifier("Tanji", "Tanji Root Certificate Authority");
}

public void StopWebInterception() => TryStartWebTrafficInterception(_logger, _options.ProxyListenPort);
public void StartWebInterception() => Eavesdropper.Terminate();
public void Start()
{
if (Eavesdropper.IsRunning) return;
if (Eavesdropper.Certifier == null)
{
_logger.LogCritical("Eavesdropper Certifier instance is null.");
throw new NullReferenceException("Eavesdropper Certifier instance is null.");
}

if (Eavesdropper.Certifier.CreateTrustedRootCertificate())
{
_logger.LogInformation("Initiating system wide HTTP/S interceptor on port: {ProxyListenPort}", _options.ProxyListenPort);
Eavesdropper.Initiate(_options.ProxyListenPort);
}
else
{
if (!Eavesdropper.IsOnlyInterceptingHttp)
{
_logger.LogCritical("User declined to trust self-signed certificate, and will therefore be unable to intercepted HTTPS traffic from the system.");
throw new Exception("User declined to trust self-signed certificate, and will therefore be unable to intercepted HTTPS traffic from the system.");
}
else _logger.LogInformation("User declined to add self-signed certificate as authority to trusted store on local machine.");
}
}
public void Stop() => Eavesdropper.Terminate();

public ValueTask<string> InterceptTicketAsync(CancellationToken cancellationToken = default)
{
Expand Down

0 comments on commit 0ba14e2

Please sign in to comment.