本文整理汇总了C#中System.Net.Security.SslStream.AuthenticateAsServer方法的典型用法代码示例。如果您正苦于以下问题:C# SslStream.AuthenticateAsServer方法的具体用法?C# SslStream.AuthenticateAsServer怎么用?C# SslStream.AuthenticateAsServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Security.SslStream
的用法示例。
在下文中一共展示了SslStream.AuthenticateAsServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpConnection
public HttpConnection(ILogger logger, Socket sock, EndPointListener epl, bool secure, X509Certificate cert, string connectionId)
{
_connectionId = connectionId;
_logger = logger;
this.sock = sock;
this.epl = epl;
this.secure = secure;
this.cert = cert;
this.SetSocketTimeout(sock);
if (secure == false)
{
stream = new NetworkStream(sock, false);
}
else
{
//ssl_stream = epl.Listener.CreateSslStream(new NetworkStream(sock, false), false, (t, c, ch, e) =>
//{
// if (c == null)
// return true;
// var c2 = c as X509Certificate2;
// if (c2 == null)
// c2 = new X509Certificate2(c.GetRawCertData());
// client_cert = c2;
// client_cert_errors = new int[] { (int)e };
// return true;
//});
//stream = ssl_stream.AuthenticatedStream;
ssl_stream = new SslStream(new NetworkStream(sock, false), false);
ssl_stream.AuthenticateAsServer(cert);
stream = ssl_stream;
}
timer = new ResumableTimer(OnTimeout);
Init();
}
示例2: dajStrumienJakoSerwer
protected override Stream dajStrumienJakoSerwer(TcpClient polaczenie)
{
var strumien = new SslStream(polaczenie.GetStream(), false);
strumien.AuthenticateAsServer(certyfikat, false, SslProtocols.Tls, false);
return strumien;
}
示例3: ListenerThreadEntry
static void ListenerThreadEntry()
{
try
{
var listener = new TcpListener(IPAddress.Any, Port);
listener.Start();
using (var socket = listener.AcceptSocket())
{
var serverCertificate = new X509Certificate2(CertsPath + @"\test.pfx");
var stream = new NetworkStream(socket);
using (var sslStream = new SslStream(stream, false))
{
sslStream.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, false);
// terminate the connection
sslStream.Close();
socket.Disconnect(false);
socket.Close();
// this code will fail
using (var reader = new StreamReader(sslStream))
{
var line = reader.ReadLine();
Console.WriteLine("> " + line);
}
}
}
}
catch (Exception exc)
{
Console.WriteLine(exc);
}
}
示例4: processClient
private void processClient(TcpClient client)
{
X509Certificate certificate = new X509Certificate("..\\..\\..\\Certificate\\Certificate.pfx", "KTYy77216");
// SslStream; leaveInnerStreamOpen = false;
SslStream stream = new SslStream(client.GetStream(), false);
try
{
// clientCertificateRequired = false
// checkCertificateRevocation = true;
stream.AuthenticateAsServer(certificate, false, SslProtocols.Tls, true);
Console.WriteLine("Waiting for client message ...");
// Read a message from the client
string input = readMessage(stream);
Console.WriteLine("Received: {0}", input);
// Write a message to the client
byte[] message = Encoding.UTF8.GetBytes("Hello client, this is a message from the server :)<EOF>");
Console.WriteLine("Sending message to client ...");
stream.Write(message);
}
catch (Exception e)
{
Console.WriteLine(e);
stream.Close();
client.Close();
return;
}
finally
{
stream.Close();
client.Close();
}
}
示例5: OnAcceptUpgrade
protected override Stream OnAcceptUpgrade(Stream stream, out SecurityMessageProperty remoteSecurity)
{
SslStream stream2 = new SslStream(stream, false, new RemoteCertificateValidationCallback(this.ValidateRemoteCertificate));
try
{
stream2.AuthenticateAsServer(this.parent.ServerCertificate, this.parent.RequireClientCertificate, SslProtocols.Default, false);
}
catch (AuthenticationException exception)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityNegotiationException(exception.Message, exception));
}
catch (IOException exception2)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityNegotiationException(System.ServiceModel.SR.GetString("NegotiationFailedIO", new object[] { exception2.Message }), exception2));
}
if (System.ServiceModel.Security.SecurityUtils.ShouldValidateSslCipherStrength())
{
System.ServiceModel.Security.SecurityUtils.ValidateSslCipherStrength(stream2.CipherStrength);
}
remoteSecurity = this.clientSecurity;
if (this.IsChannelBindingSupportEnabled)
{
this.channelBindingToken = ChannelBindingUtility.GetToken(stream2);
}
return stream2;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:SslStreamSecurityUpgradeAcceptor.cs
示例6: Zombie
public Zombie(ServerMainForm form, TcpClient client)
{
this.mainForm = form;
this.zombieListView = mainForm.zombieListView;
this.client = client;
this.netStream = client.GetStream();
sslStream = new SslStream(netStream);
if (sslSecured)
{
// Build the server cert from resources
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CCSURAT_Server.Resources.Server.pfx");
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
serverCertificate = new X509Certificate2(bytes, "cs492");
sslStream.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, false);
// Create stream writer/reader objects, could be used for easier read/write
sw = new StreamWriter(sslStream);
sr = new StreamReader(sslStream);
}
this.active = true;
// initialize monitor list
monitors = new List<ControlClasses.Monitor>();
// initialize ping check objects
pingSender = new Ping();
// request basic PC info (computer name, username, cpu, etc...)
this.SendData("[[START]][[/START]]");
Console.Beep();
}
示例7: InterceptConnect
/// <summary>
/// Intercepts a HTTP CONNECT so we can filter the encrypted requests
/// </summary>
public static Stream InterceptConnect(Request request, Stream clientStream, CachedConnection remote)
{
//This code may work but it has not been tested yet.
string certPath = Path.Combine (Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"HitProxy"), "server.pfx");
if (File.Exists (certPath) == false)
throw new FileNotFoundException ("Need a server certificate", certPath);
X509Certificate cert = X509Certificate2.CreateFromCertFile (certPath);
request.Response = new Response (remote);
request.Response.HttpVersion = "HTTP/1.1";
request.Response.HttpCode = HttpStatusCode.OK;
request.Response.HTTPMessage = HttpStatusCode.OK.ToString ();
request.Response.KeepAlive = false;
request.Response.Add ("Proxy-Agent: HitProxy");
request.Response.SendHeaders (clientStream);
//Client
SslStream ssl = new SslStream (clientStream, false, RemoteCertificateValidation, LocalCertValidation);
try {
ssl.AuthenticateAsServer (cert, false, System.Security.Authentication.SslProtocols.Tls, false);
} catch (Exception e) {
Console.WriteLine (e.Message);
throw;
}
//Remote server
SslStream remoteSsl = new SslStream (remote.Stream, false, RemoteCertificateValidation);
remoteSsl.AuthenticateAsClient (request.Uri.Host);
remote.Stream = remoteSsl;
return ssl;
}
示例8: handler
///<summary>
///Forwards incoming clientdata to PacketHandler.
///</summary>
public void handler()
{
clientStream = new SslStream(tcpClient.GetStream(), true);
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Kettler_X7_Lib.Objects.Packet pack = null;
X509Certificate serverCertificate = serverControl.getCertificate();
try
{
clientStream.AuthenticateAsServer(serverCertificate,false, SslProtocols.Tls, false);
}
catch (Exception)
{
Console.WriteLine("Authentication failed");
disconnect();
}
for (; ; )
{
try
{
pack = formatter.Deserialize(clientStream) as Kettler_X7_Lib.Objects.Packet;
PacketHandler.getPacket(serverControl, this, pack);
}
catch
{
disconnect();
}
Thread.Sleep(10);
}
}
示例9: connectForwardServerCallBack
public static void connectForwardServerCallBack(IAsyncResult ar)
{
ProxyConnection conn = (ProxyConnection)ar.AsyncState;
conn.serverSocket.EndConnect(ar);
ProxySwapDataTask proxy = new ProxySwapDataTask(conn);
//now we have both server socket and client socket, we can pass the data back and forth for both side
System.Diagnostics.Debug.Assert(true == conn.clientSocket.Connected);
System.Diagnostics.Debug.Assert(true == conn.serverSocket.Connected);
WinTunnel.WriteTextToConsole(string.Format("ProxyConnection#{0}-- client socket or server socket start receiving data....",
conn.connNumber));
WinTunnel.connMgr.AddConnection(conn);
conn.clientStream = conn.clientSocket.GetStream();
if (conn.m_bHttpsClient)
{
SslStream sslStream = new SslStream(conn.clientSocket.GetStream(), false);
sslStream.AuthenticateAsServer(WinTunnel.CertificateForClientConnection, false, SslProtocols.Tls, true);
conn.clientStream = sslStream;
}
conn.serverStream = conn.serverSocket.GetStream();
if (conn.m_bHttpsServer)
{
SslStream sslStream = new SslStream(conn.serverStream, false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient(conn.serverName);
conn.serverStream = sslStream;
}
conn.clientStream.BeginRead(conn.clientReadBuffer, 0, ProxyConnection.BUFFER_SIZE, new AsyncCallback(clientReadCallBack), conn);
//Read data from the server socket
conn.serverStream.BeginRead(conn.serverReadBuffer, 0, ProxyConnection.BUFFER_SIZE, new AsyncCallback(serverReadCallBack), conn);
}
示例10: Client
public Client(TcpClient client, ServerHandler handler, bool ssl)
{
Handler = handler;
RawClient = client;
if (!ssl) {
Writer = new StreamWriter(RawClient.GetStream());
Reader = new StreamReader(RawClient.GetStream());
} else {
if (cert == null) {
var path = Path.GetFullPath(Path.Combine(References.GCPD_FOLDER, Config.User.Ssl_Cert_Path));
if (!(new FileInfo(path)).Exists)
throw new Exception("certificate does not exist at " + path);
cert = new X509Certificate2(path, Config.User.Ssl_Cert_Pass);
}
try {
SslStream stream = new SslStream(RawClient.GetStream(), false);
stream.AuthenticateAsServer(cert, false, System.Security.Authentication.SslProtocols.Tls, false);
Writer = new StreamWriter(stream);
Reader = new StreamReader(stream);
} catch (IOException e) {
client.Close();
throw e;
}
}
ThreadPool.QueueUserWorkItem((object o) => { AssignHostName(); });
}
示例11: ExtendConnection
public Stream ExtendConnection(Stream stream)
{
var ssl = new SslStream(stream, false, _validation);
#if (UAP10_0 || DOTNET5_4 || NETSTANDARD || NETSTANDARDAPP1_5)
ssl.AuthenticateAsServerAsync(_certificate, _validation != null, SslProtocols.Tls12, false).Wait();
#else
ssl.AuthenticateAsServer(_certificate, _validation != null, SslProtocols.Tls12, false);
#endif
return ssl;
}
示例12: OneSsl
//サーバ接続
public OneSsl(Socket socket, X509Certificate2 x509Certificate2)
{
_stream = new SslStream(new NetworkStream(socket));
try{
_stream.AuthenticateAsServer(x509Certificate2);
} catch (Exception){
}
_stream.ReadTimeout = 5000;
_stream.WriteTimeout = 5000;
}
示例13: Client
public Client(TcpClient clientSocket)
{
_clientSocket = clientSocket;
var sslStream = new SslStream(clientSocket.GetStream(), false);
sslStream.AuthenticateAsServer(Server.GetServer().Certificate, false, SslProtocols.Tls, true);
Stream = new BinaryStream(sslStream);
BetterConsole.WriteLog("Connection secured.");
StartClientThread();
}
示例14: DesktopNetworkStream
/// <summary>
/// Initializes a server instance of <see cref="DesktopNetworkStream"/>.
/// </summary>
/// <param name="tcpClient">TCP client.</param>
/// <param name="certificate">Certificate for authenticated connection.</param>
/// <remarks>Ownership of <paramref name="tcpClient"/> remains with the caller, including responsibility for
/// disposal. Therefore, a handle to <paramref name="tcpClient"/> is <em>not</em> stored when <see cref="DesktopNetworkStream"/>
/// is initialized with this server-side constructor.</remarks>
internal DesktopNetworkStream(TcpClient tcpClient, X509Certificate certificate)
{
Stream stream = tcpClient.GetStream();
if (certificate != null)
{
var ssl = new SslStream(stream, false);
ssl.AuthenticateAsServer(certificate, false, SslProtocols.Tls, false);
stream = ssl;
}
this.networkStream = stream;
}
示例15: Authenticate
/// <summary>
/// Authenticates as server
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
protected SslStream Authenticate(SslStream stream)
{
try {
stream.AuthenticateAsServer(this.Certificate);
this.ConnectionState = ConnectionState.ConnectionReady;
}
catch (AuthenticationException e) {
this.Shutdown(e);
}
return stream;
}