Exemplo n.º 1
0
        private static async Task TestForAlert(SecurePipeOptions securePipeOptions, byte[] messageToSend)
        {
            using (var pool = new MemoryPool())
            {
                var pipeFactory      = new PipeOptions(pool);
                var connection       = new LoopbackPipeline(pipeFactory);
                var secureConnection = securePipeOptions.CreateConnection(connection.ServerPipeline);

                var writer = connection.ClientPipeline.Output.Alloc();
                writer.Write(messageToSend);
                await writer.FlushAsync();

                var result = await connection.ClientPipeline.Input.ReadAsync();

                var exception = CheckForAlert(result.Buffer);
                connection.ClientPipeline.Input.Advance(result.Buffer.End);
                var closeConnection = await secureConnection;
                closeConnection.Dispose();
                throw exception;
            }
        }
Exemplo n.º 2
0
        private static async Task ConnectWithSslStream(PipeOptions factory, SecurePipeOptions securePipeOptions, byte[] message)
        {
            var loopback         = new LoopbackPipeline(factory);
            var stream           = loopback.ClientPipeline.GetStream();
            var secureConnection = securePipeOptions.CreateConnection(loopback.ServerPipeline);
            var ignore           = Echo(secureConnection);

            using (var sslStream = new SslStream(stream, false, CertVal))
            {
                await sslStream.AuthenticateAsClientAsync("localhost");

                await sslStream.WriteAsync(message, 0, message.Length);

                var returnBuffer = new byte[message.Length];
                var byteCount    = 0;
                while (byteCount < message.Length)
                {
                    byteCount += await sslStream.ReadAsync(returnBuffer, byteCount, returnBuffer.Length - byteCount);
                }
                Assert.Equal(message, returnBuffer);
            }
            secureConnection.Result.Dispose();
        }