public async Task <DnsMessage> ResolveTlsAsync(IPEndPoint serverEndpoint, string serverCN, DnsMessage message, CancellationToken stoppingToken) { using (var server = new TcpClient()) { server.NoDelay = true; await server.ConnectAsync(serverEndpoint.Address, serverEndpoint.Port); using (SslStream serverStream = new SslStream( server.GetStream(), false, new RemoteCertificateValidationCallback(new SslStreamHelper(_logger).ValidateServerCertificate))) { await serverStream.AuthenticateAsClientAsync(serverCN); _logger.LogDebug($"Established {serverEndpoint}"); await SendTcpAsync(serverStream, message, stoppingToken); return(await ReadTcpAsync(serverStream, stoppingToken)); } } }
public async Task SendTcpAsync(Stream stream, DnsMessage message, CancellationToken stoppingToken) { await stream.WriteAsync(message.Length, 0, message.Length.Length, stoppingToken); await stream.WriteAsync(message.Data, 0, message.Data.Length, stoppingToken); }