2012-02-12 13 views
8
द्वारा स्वीकार कर लिया बनाने के लिए makecert का उपयोग कैसे करें

किसी को भी कैसे एक आत्म हस्ताक्षरित प्रमाणपत्र बनाने के लिए पर एक उदाहरण है, जो निम्नलिखित कोड द्वारा स्वीकार कर लिया जाएगा के साथ मुझे प्रदान कर सकते हैं इस्तेमाल कियाएक X509 प्रमाणपत्र WCF

makecert -pe myCertificate 

और

makecert -sv SignRoot.pvk -cy authority -r signroot.cer -a sha1 -n "CN=Dev Certification Authority" -ss my -sr localmachine 

और

makecert -r -pe -n "CN=Client" -ss MyApp -sky Exchange 

और मैं BouncyCastle साथ प्रमाण पत्र उत्पन्न करने की कोशिश की है, लेकिन हर बार जब मैं निम्नलिखित अपवाद हो रही है:

It is likely that certificate 'CN=Dev Certification Authority' may not have a 
private key that is capable of key exchange or the process may not have access 
rights for the private key. Please see inner exception for detail. 

और भीतरी अपवाद रिक्त है।

इसकी संभावना है कि यह एक चाल है, लेकिन मुझे यह नहीं मिल रहा है।

मैं अपनी डब्ल्यूसीएफ सेवा के लिए एक उचित प्रमाणपत्र कैसे उत्पन्न करूं ??

+2

की वजह से सर्वर त्रुटि के लिए प्रतिक्रिया करने, कैसे लिंक करने के लिए इस पर एक नजर डालें। http://msdn.microsoft.com/en-us/library/ff648498.aspx –

+0

यह लिंक मेरे लिए स्थापित करने के लिए सबसे उपयोगी था। यह सभी चरणों के माध्यम से चलता है। http://www.codeproject.com/Articles/96028/WCF-Service-with-custom-username-password-authenti – vikingben

उत्तर

1

निम्नलिखित कोड ढांचे 4.0 के लिए मेरे लिए काम करता है: यह
अपने LocalMachine
में विश्वसनीय प्रमाणपत्र के रूप में मैन्युअल रूप से अपने प्रमाण पत्र स्थापित करने के लिए आदेश से बस इंटरनेट एक्सप्लोरर से आपको इसे इंस्टॉल करने करने के लिए महत्वपूर्ण पहला है सर्वर स्थान खोलना

और दूसरा स्वयं हस्ताक्षर प्रमाण पत्र

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Security.Cryptography.X509Certificates; 
using System.Net; 
using System.Net.Security; 
namespace WCFSelfSignCert 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     //You have to install your certificate as trusted certificate in your LocalMachine 

     //create your service client/ procy 
     using (MyProxy.ServiceClient client = new MyProxy.ServiceClient()) 
     { 

      //server certification respond with an error, because doesnt recognize the autority 
      ServicePointManager.ServerCertificateValidationCallback += OnServerValError; 


      //Assign to self sign certificate 
      client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, 
      StoreName.Root, 
      X509FindType.FindBySubjectName, 
      "MY custom subject name"); //SubjectName(CN) from certificate 

      //make a test call to ensure that service responds 
      var res = client.echo("test"); 

      Console.WriteLine(res); 
      Console.ReadKey(); 
     } 

    } 

    public static bool OnServerValError(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
    { 
     //mute the error, or provide some custom validation code 
     return true; 

     //or more restrictive 

     // if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch) 
     //{ 


     // return true; 
     // } 
     // else 
     //{ 

     // return false; 
     // } 
    } 

    } 
} 
संबंधित मुद्दे