大网数据广告活动
域与目录服务

Mutual Authentication in a Windows Sockets Service with SCP

· 52CE 我爱测

The topics in this section include code examples that show how to perform mutual authentication with a service that publishes itself using a service connection point (SCP).

The topics in this section include code examples that show how to perform mutual authentication with a service that publishes itself using a service connection point (SCP). The examples are based on a Microsoft Windows Sockets service that uses an SSPI package to handle the mutual authentication negotiation between a client and the service. Use the following procedures to implement mutual authentication within this scenario.

To register SPNs in a directory when a service is installed

  1. Call the DsGetSpn function to compose service principal names (SPNs) for the service.
  2. Call the DsWriteAccountSpn function to register the SPNs on the service account or computer account in whose context the service will run. This step must be performed by a domain administrator; an exception is that a service running under the LocalSystem account can register its SPN in the form "<service class>/<host>" on the computer account of the service host.

To verify configuration at service startup

  • Verify that the appropriate SPNs are registered on the account under which the service is running. For more information, see Logon Account Maintenance Tasks.

To authenticate the service at client startup

  1. Retrieve connection data from the service's service connection point.
  2. Establish a connection to the service.
  3. Call the DsMakeSpn function to compose an SPN for the service. Compose the SPN from the known service class string, and the data retrieved from the service connection point. This data includes the host name of the server on which the service is running. Be aware that the host name must be a DNS name.
  4. Use an SSPI security package to perform the authentication:
    1. Call the AcquireCredentialsHandle function to acquire the client's credentials.
    2. Pass the client credentials and the SPN to the InitializeSecurityContext function to generate a security blob to send to the service for authentication. Set the ISC_REQ_MUTUAL_AUTH flag to request mutual authentication.
    3. Exchange blobs with the service until the authentication is complete.
  5. Verify the returned capabilities mask for the ISC_REQ_MUTUAL_AUTH flag to verify that mutual authentication was performed.
  6. If the authentication was successful, exchange traffic with the authenticated service. Use digital signing to ensure that messages between client and service have not been tampered with. Unless performance requirements are severe, use encryption. For more information and a code example that shows how to use the MakeSignature, VerifySignature, EncryptMessage, and DecryptMessage functions in an SSPI package, see Ensuring Communication Integrity During Message Exchange.

To authenticate the client by the service when a client connects

  1. Load an SSPI security package that supports mutual authentication.
  2. When a client connects, use the security package to perform the authentication:
    1. Call the AcquireCredentialsHandle function to acquire the service credentials.
    2. Pass the service credentials and the security blob received from the client to the AcceptSecurityContext function to generate a security blob to send back to the client.
    3. Exchange blobs with the client until the authentication is complete.
  3. Check the returned capabilities mask for the ASC_RET_MUTUAL_AUTH flag to verify that mutual authentication was performed.
  4. If the authentication was successful, exchange traffic with the authenticated client. Use digital signing and encryption unless performance is an issue.

For more information and a code example for this mutual authentication scenario, see:

For more information, see:

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。