c# - 在 C# 中,在服务器端使用 SslStream.AuthenticateAsServer() 有什么意义?
问题描述
我正在尝试侦听端口上的安全 TCP 连接。我正在浏览微软文档上的服务器代码示例。我在这里粘贴以供快速参考:
static void ProcessClient (TcpClient client)
{
// A client has connected. Create the
// SslStream using the client's network stream.
SslStream sslStream = new SslStream(
client.GetStream(), false);
// Authenticate the server but don't require the client to authenticate.
try
{
sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired: false, checkCertificateRevocation: true);
// Display the properties and settings for the authenticated stream.
DisplaySecurityLevel(sslStream);
DisplaySecurityServices(sslStream);
DisplayCertificateInformation(sslStream);
DisplayStreamProperties(sslStream);
我的疑问是为什么服务器要对自己进行身份验证?或者我在这里错过了什么。
解决方案
也许你错过了“作为”。该调用告诉 SslStream 它应该为 TLS 握手(身份验证发生的地方)做准备,并且它在握手中扮演服务器角色。
所以它真的是“开始身份验证阶段,作为服务器”。
推荐阅读
- python - 使用 Python 拉取 AWK 脚本的依赖项
- api - 无法从 API 调用方法
- typescript - 如何使用数组值键入对象键
- apache-spark-sql - PySQL - 使用同一列中的两行计算百分比
- sql - 从多个列中删除零
- docker - 没有这样的文件或目录 package.json
- javascript - 在 DYGRAPH 中,我想在画布上(在柱形图中)永久显示所有数据点,在列的顶部?谢谢
- c# - 如何从对象列表中获取对象,这些对象列表中包含对象中另一个列表中的重复属性?
- ssis - SSIS 从 ODBC 查询结果中设置变量值
- virtual-machine - 如何提取 qcow2 虚拟磁盘映像?