19

मेरे पास एक विंडोज फोन ऐप है, जो 8.1 के लिए बनाया गया है, और कार्यों में से एक क्लाइंट-सर्वर प्रमाणपत्र परिदृश्य था। मेरा ऐप ठीक काम करता है, मैं क्लाइंट प्रमाणपत्र भेज सकता हूं और सर्वर पर लॉगिन कर सकता हूं। हालांकि विंडोज 8.10.14xxxx में अपग्रेड करने के बाद यह संभव नहीं था। मैंने वायरशर्क निशान लिया और ऐसा लगता है कि प्रमाण पत्र कभी नहीं भेजा जाता है। संदेश की सामग्री लंबाई 0.नवीनतम विंडोज फोन को अपग्रेड करने के बाद प्रमाण पत्र भेजने में विफल 8.1

मैं प्रमाण पत्र दर्ज करने के लिए HttpClient.SendAsync (प्रतीक्षा) और HttpBaseProtocolFilter का उपयोग करता हूं। यह अपग्रेड से पहले सही काम किया।

कोई विचार? क्या कुछ टूट गया है?

सबसे पहले मैं pfx स्थापित करने हूँ

async private void btnInstall_Click(object sender, RoutedEventArgs e) 
{ 
    //Install the self signed client cert to the user certificate store 

    string CACertificate = null; 
    try 
    { 
     Uri uri = new Uri("ms-appx:///certificates/test.pfx"); 
     var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri); 
     IBuffer buffer = await FileIO.ReadBufferAsync(file); 
     using (DataReader dataReader = DataReader.FromBuffer(buffer)) 
     { 
      byte[] bytes = new byte[buffer.Length]; 
      dataReader.ReadBytes(bytes); 
      // convert to Base64 for using with ImportPfx 
      CACertificate = System.Convert.ToBase64String(bytes); 
     } 
     await CertificateEnrollmentManager.UserCertificateEnrollmentManager.ImportPfxDataAsync(
      CACertificate, 
      "xxxxx", 
      ExportOption.Exportable, 
      KeyProtectionLevel.NoConsent, 
      InstallOptions.None, 
      "ClientCert1"); 


    } 
    catch (Exception ex) 
    { 
     //; 
    } 
} 

तब मैं सेवा

string serviceURL = "https://my.web.services"; 
Certificate cert = null; 

CertificateQuery query = new CertificateQuery(); 
query.FriendlyName = "ClientCert1"; 
IReadOnlyCollection<Certificate> certs = await CertificateStores.FindAllAsync(query); 

HttpBaseProtocolFilter bpf = new HttpBaseProtocolFilter(); 
//if you install the CA you don't need to ignore the ServerCertificate Errors 
//bpf.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); 

if (certs.Count > 0) 
{ 
    cert = certs.ElementAt(0); 
    bpf.ClientCertificate = cert; 
} 

HttpClient httpClient = new HttpClient(bpf); 
try 
{ 

    var response = await httpClient.GetInputStreamAsync(new Uri(serviceURL)); 
    //take data 
} 
catch (Exception ex) 
{    
    //0x80072F0D 
} 

मैं हमेशा एक को छोड़कर (0x80072F0D) ले रहा हूँ बोल रहा हूँ जब 8.10.14xxxx विंडोज फोन में चल रहा है। मेरा कोड अपडेट से पहले काम करता था, अब मैं हमेशा यह रिटर्न कोड ले रहा हूं। प्रमाणपत्र httpClient में लोड किया गया है। जब मैं डीबगर के साथ ऐप को रोकता हूं तो ऐसा लगता है कि प्रमाणपत्र वहां है, हालांकि 0x800072F0D का अर्थ है कि प्रमाणपत्र भेजा नहीं गया है ???

परिदृश्य में एक मध्यवर्ती प्रमाणपत्र प्राधिकरण है। वह प्रमाणपत्र पीएफएक्स में शामिल है। क्या मुझे इसे किसी भी तरह स्थापित करने की ज़रूरत है?

+0

क्या आपके पास एक रिप्रो है? – kiewic

+0

@kiewic क्या आप इस मुद्दे को जानते हैं? मैं कुछ स्रोत कोड साझा कर सकता हूं। – cateof

+0

हां, मैं एक नज़र डाल सकता हूं। आप गिटहब या कहीं और पर रेपो डाल सकते हैं। – kiewic

उत्तर

1

मुझे लगता है कि आप पहले से ही ऐप प्रमाणपत्र प्रमाणपत्र में क्लाइंट प्रमाणपत्र डाल चुके हैं। यदि नहीं तो इन्हें करें:
1) पीएफएक्स फ़ाइल डाउनलोड करें।
2)

await CertificateEnrollmentManager.ImportPfxDataAsync(certString, "Your_PFX_Password", ExportOption.Exportable, KeyProtectionLevel.NoConsent, InstallOptions.None, friendlyName); 

3 का पालन करके एप्लिकेशन की प्रमाणपत्र संग्रह में प्रमाणपत्र स्थापित) प्रमाणपत्र संग्रह में प्रमाण पत्र के लिए जाँच करें।

CertificateQuery certQuery = new CertificateQuery(); 
certQuery.FriendlyName = friendlyName; 
IReadOnlyList<Certificate> certs = await CertificateStores.FindAllAsync(certQuery); 

certs[0] आपके पास आवश्यक प्रमाणपत्र होना चाहिए।

4) अब, HTTP अनुरोध करने के लिए प्रमाण पत्र संलग्न करने के लिए

HttpBaseProtocolFilter protolFilter = new HttpBaseProtocolFilter(); 
protolFilter.ClientCertificate = certs[0] //from previous step 
HttpClient client = new HttpClient(protolFilter) 

पुनश्च: आप System.Net.htpp.HttpClient उपयोग नहीं करना चाहिए। इसके बजाय आपको Windows.Web.Http.HttpClient का उपयोग करना चाहिए।

+0

नहीं, यह काम नहीं करता है। यह सही प्रक्रिया प्रतीत होता है, मैं पहले से ही उन पंक्तियों को कॉल कर रहा हूं (ऊपर मेरा कोड देखें) हालांकि विंडोज फोन स्थापित करने के बाद 8.1 इन लाइनों को अपडेट नहीं करते हैं। – cateof

+0

आप किस डिवाइस का उपयोग कर रहे हैं? एक सुझाव है, अपने डिवाइस पर एक हार्ड रीसेट करें और फिर कोशिश करें। और आपकी समस्या थोड़ा अजीब है। –

+0

यह नोकिया लुमिया 925 है। मुझे नहीं लगता कि हार्ड रीसेट कुछ हल करता है। – cateof

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