本文整理汇总了C#中System.Net.Security.SslStream.EndAuthenticateAsServer方法的典型用法代码示例。如果您正苦于以下问题:C# SslStream.EndAuthenticateAsServer方法的具体用法?C# SslStream.EndAuthenticateAsServer怎么用?C# SslStream.EndAuthenticateAsServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Security.SslStream
的用法示例。
在下文中一共展示了SslStream.EndAuthenticateAsServer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connectionHandler
public connectionHandler(Socket socket, HttpServer server, bool secure)
{
Socket = socket;
_requestId = Rnd.Next();
_requestStart = DateTime.UtcNow;
_server = server;
_secure = secure;
_server.Log.Info(4, "{0:X8} Incoming connection from {1}".Fmt(_requestId, socket.RemoteEndPoint));
_buffer = new byte[1024];
_bufferDataOffset = 0;
_bufferDataLength = 0;
_headersSoFar = "";
lock (server._activeConnectionHandlers)
server._activeConnectionHandlers.Add(this);
var stream = new NetworkStream(socket, ownsSocket: true);
if (_secure)
{
var secureStream = new SslStream(stream);
_stream = secureStream;
secureStream.BeginAuthenticateAsServer(new X509Certificate2(server.Options.CertificatePath, server.Options.CertificatePassword), false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12, true, ar =>
{
try
{
secureStream.EndAuthenticateAsServer(ar);
}
catch (Exception e)
{
Socket.Close();
cleanupIfDone();
if (_server.ResponseExceptionHandler != null)
_server.ResponseExceptionHandler(null, e, null);
return;
}
receiveMoreHeaderData();
}, null);
}
else
{
_stream = stream;
receiveMoreHeaderData();
}
}
示例2: ProcessConnection
void ProcessConnection(Socket listener, IAsyncResult ar)
{
Socket ns = listener.EndAccept (ar);
ns.NoDelay = true;
SslStream ssl = new SslStream (new NetworkStream (ns, true));
ssl.BeginAuthenticateAsServer (cert, (IAsyncResult ar2) => {
try {
ssl.EndAuthenticateAsServer (ar2);
Protocol p = new Protocol ();
p.OnMessage += (incoming) => {
var hdr = incoming.Header;
// TODO timeout handling
if (hdr ["type"].AsString(null) != "request") {
Logger.LogError ("received non-request");
incoming.Discard ();
return;
}
if (!hdr.ContainsKey ("request_id")) {
Logger.LogError ("Received request with no request_id");
incoming.Discard ();
return;
}
var id = hdr ["request_id"];
reqh (incoming, (reply) => {
reply.Header ["type"] = "reply";
reply.Header ["request_id"] = id;
p.SendMessage (reply);
});
};
p.OnClose += (error) => {
Logger.LogInfo ("scamp connection closed: {0}", error);
};
p.Start (ssl);
} catch (Exception ex) {
Logger.LogError ("connection server authenticate: {0}", ex);
}
}, null);
}