2013-10-01 167 views
2

所以我完全失去了證書。我在網上搜索瞭解這方面的解決方案和教程,並沒有發現任何可以幫助我的東西。 我想要做的是爲我的WCF客戶端 - 服務器應用程序同時擁有服務器和客戶端證書驗證。該應用程序託管在IIS上。 我希望它在我的開發計算機(服務器是本地主機)和測試(其中即時客戶端和服務器是一個Windows服務器)。客戶證書認證WCF

配置我現在是:

客戶:

<behaviors> 
    <endpointBehaviors> 
    <behavior name="myBehaviorConfig"> 
     <clientCredentials> 
     <clientCertificate findValue="CN=MyTestClientCertificate" 
          storeLocation="LocalMachine" 
          x509FindType="FindBySubjectDistinguishedName"/> 
     </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

<bindings> 
    <wsHttpBinding> 
    <binding name="MyBindingConfig"> 
     <security mode="TransportWithMessageCredential"> 
     <transport realm=""/> 
     <message clientCredentialType="Certificate"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

<client> 
    <endpoint address="https://localhost/Service.Calculator.svc" 
      binding="wsHttpBinding" 
      bindingConfiguration="MyBindingConfig" 
      behaviorConfiguration="MyBehaviorConfig" 
      contract="Service.ICalculator" 
      name="ICalculatorServiceEndpoint"> 
    <identity> 
     <servicePrincipalName value="host"/> 
    </identity> 
    </endpoint>  
</client> 

服務器:

<behaviors> 
    <serviceBehaviors> 
    <behavior name="myBehavior"> 
     <serviceCredentials> 
     <serviceCertificate findValue="CN=MyTestRootCA" 
          storeLocation="LocalMachine" 
          x509FindType="FindBySubjectDistinguishedName"/> 
     <userNameAuthentication userNamePasswordValidationMode="Windows"/> 
     <clientCertificate> 
      <authentication certificateValidationMode="PeerOrChainTrust"/> 
     </clientCertificate> 
     </serviceCredentials> 
     <serviceMetadata httpsGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <unity operationContextEnabled="true" 
      instanceContextEnabled="true" 
      contextChannelEnabled="true" 
      serviceHostBaseEnabled="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<bindings> 
    <wsHttpBinding> 
    <binding name="MyBinding"> 
     <security mode="TransportWithMessageCredential"> 
     <transport realm=""/> 
     <message clientCredentialType="Certificate"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

<services> 
    <service name="Service.Calculator" 
      behaviorConfiguration="myBehavior"> 
    <endpoint address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="MyBinding" 
       contract="Service.ICalculator" /> 
    <endpoint address="mex" 
       binding="mexHttpsBinding" 
       contract="IMetadataExchange" 
       name="CalculatorServiceMex" /> 
    </service> 
</services> 

「CN = MyTestRootCA」 是 「權威」 的 「創建」 證書和我把他放在本地計算機上的受信任的根證書以及本地計算機的個人目錄中。 它是客戶端證書「CN = MyTestClientCertificate」的頒發者。

很少有東西..

我知道這個客戶端證書應該在CurretUser目錄中的「MMC」,但是當它的存在,我有一個例外,該應用程序無法找到證書。 我試圖通過「FindBySubjectDistinguishedName」和「FindByThumbprint」找到它,兩次都是同樣的異常「不能找到證書與給定的標準...」,所以我把它放在LocalMachine和它的罰款。 任何人有一個想法,爲什麼它不工作?

我有很多問題和例外與此=目前是: 「私鑰不在X.509證書」 任何人都知道這個例外,並知道如何解決它?

非常感謝您的回答,我坐在這了幾天,現在

回答

1

您的配置文件沒有指定則ClientCertificate storeLocation值,因此客戶端證書必須在LOCALMACHINE店,這也是storeLocation的值爲,默認值爲

考慮從msdn下面的例子將客戶端證書的存儲位置:

<clientCertificate> 
    <certificate 
     findValue="www.cohowinery.com" 
     storeLocation="CurrentUser" 
     storeName="TrustedPeople" 
     x509FindType="FindByIssuerName" /> 
    <authentication … 

注:其他錯誤,「私鑰不X.509證書的頒發」,是最有可能拋出因爲您的證書沒有關聯的私鑰,或者您的進程的用戶上下文沒有訪問私鑰的權限。

+0

我確實在客戶端配置中指定了客戶端證書的存儲位置。你建議的代碼應該在服務器配置中?如果是的話,我應該指定什麼證書,客戶端證書位於客戶端的計算機上。 並關於第二個錯誤,我實際上有一個私鑰,我用它來創建客戶端證書,但不超過。我需要做些別的事嗎?比如把它放在一個特定的位置或者添加到配置中? – user2834816