共用方式為


安全性通道層範例

下列範例說明 通道層 的安全性

透過 TCP 的 Windows 傳輸安全性:用戶端:RequestReplyTcpClientWithWindowsTransportSecurityExample、伺服器:RequestReplyTcpServerWithWindowsTransportSecurityExample

透過命名管道的 Windows 傳輸安全性:用戶端:RequestReplyNamedPipesClientWithWindowsTransportSecurityExample,伺服器:RequestReplyNamedPipesServerWithWindowsTransportSecurityExample

SSL 傳輸安全性:用戶端:HttpClientWithSslExample、伺服器:HttpServerWithSslExample

使用者名稱在 SSL 混合模式安全性下:用戶端:HttpClientWithUsernameOverSslExample,伺服器:HttpServerWithUsernameOverSslExample

透過 SSL 混合模式安全性的使用者名稱:客戶端:HttpClientWithKerberosOverSslExample、伺服器:HttpServerWithKerberosOverSslExample

透過 SSL 混合模式安全性的使用者名稱:MetadataImportWithUsernameOverSslExample。 透過 SSL 混合模式安全性發行的令牌:MetadataImportWithIssuedTokenOverSslExample。 X509 憑證透過 SSL 混合模式安全性:MetadataImportWithX509OverSslExample

One-Time 安全性範例的設定

若要執行 WWSAPI 安全性範例,您必須設定 SSL 的用戶端和伺服器憑證,以及 HTTP 標頭驗證的本機用戶帳戶。 開始之前,您需要下列工具:

  • MakeCert.exe (可在 Windows 7 SDK 中使用。
  • 從 Windows Server 2003 開始的 Windows SDK 中提供 CertUtil.exe 或 CertMgr.exe(CertUtil.exe。Windows 7 SDK 中提供 CertMgr.exe。您只需要其中一個工具。
  • HttpCfg.exe:( 只有在您使用 Windows 2003 或 Windows XP 時,才需要此程式。此工具可在 Windows XP SP2 支援工具中取得,也隨附於 Windows Server 2003 資源套件工具 CD。

如果您藉由安裝 Windows 7 SDK 來取得 WWSAPI 範例,您可以在 \%ProgramFiles%\Microsoft SDK\Windows\v7.0\bin 下找到 MakeCert.exe 和 CertMgr.exe。

在命令提示字元中執行以下五步驟設定(如果您使用 Windows Vista 及更新版本,請以管理員身分執行命令提示字元):

  1. 產生自我簽署憑證作為憑證授權機構 (CA) 或簽發者:MakeCert.exe -ss Root -sr LocalMachine -n “CN=Fake-Test-CA” -cy 授權機構 -r -sk “CAKeyContainer”
  2. 使用先前憑證作為簽發者產生伺服器證書:MakeCert.exe -ss My -sr LocalMachine -n “CN=localhost” -sky exchange -is Root -ir LocalMachine -in Fake-Test-CA -sk “ServerKeyContainer”
  3. 執行下列其中一個命令來尋找伺服器證書的指紋(40 個字元的 SHA-1 哈希),並使用簽發者 Fake-Test-CA 搜尋名為 localhost 的憑證:
    • CertUtil.exe -store 我的localhost
    • CertMgr.exe -s -r LocalMachine My
  4. 使用 HTTP.SYS,註冊無空格的伺服器證書指紋:
    • 在 Windows Vista 和更新版本上(“appid” 選項為任意 GUID):Netsh.exe http add sslcert ipport=0.0.0.0:8443 appid={00001111-aaaa-2222-bbbb-3333cccc4444} certhash=<40CharacterThumbprint>
    • 在 Windows XP 或 2003 上:HttpCfg.exe 設定 ssl -i 0.0.0.0:8443 -h <40CharacterThumbprint>
  5. 建立本機使用者:Net 使用者「TestUserForBasicAuth」 「TstPWD@*4Bsic」 /add

若要清除憑證、SSL 憑證系結和先前步驟中建立的用戶帳戶,請執行下列命令。 請注意,如果有多個相同名稱的憑證,CertMgr.exe 將需要您的確認才能刪除它們。

  • CertMgr.exe -del -c -n Fake-Test-CA -s -r LocalMachine 根
  • CertMgr.exe -del -c -n localhost -s -r LocalMachine My
  • Netsh.exe http delete sslcert ipport=0.0.0.0:8443 (或 HttpCfg.exe 刪除 ssl -i 0.0.0.0:8443)
  • Net 帳號 「TestUserForBasicAuth」 /delete

請確定只有一個名為「Fake-Test-CA」的根證書。 如果您不確定,宜先嘗試使用上面的清除命令來清除這些憑證(並忽略錯誤),通常這是安全的,然後再開始五個步驟的設定。