Using pfx certificate to authenticate a webrequest

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Using pfx certificate to authenticate a webrequest

    Hi,

    i need to get some info from a website page that requires an
    certificate.

    Ive got the provided certificate installed in IE, and when accessing
    the website page, it shows a window to select the client certificate
    and then shows the page correctly.

    Im trying to do this by code (C# aspnet), using webrequest.

    The certificate is in an pfx file and does not require password. I've
    exported the file using IE to DER encoded binary X.509 (.cer).

    My code:

    X509Certificate certificate =
    X509Certificate.CreateFromCertFile(Server.MapPath( "file.cer"));
    HttpWebRequest req =
    (HttpWebRequest)WebRequest.Create("https://websiteurl");
    req.Method="POST";
    req.ClientCertificates.Add(certificate);

    // ...
    // here goes the request response read
    // ...


    I got this error:

    System.Net.WebException: The underlying connection was closed: Could
    not establish secure channel for SSL/TLS. --->
    System.ComponentModel.Win32Exception: The message received was
    unexpected or badly formatted at
    System.Net.TlsStream.EndRead(IAsyncResult asyncResult) at
    System.Net.Connection.ReadCallback(IAsyncResult asyncResult) --- End
    of inner exception stack trace --- at
    System.Net.HttpWebRequest.CheckFinalStatus() at
    System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult) at
    System.Net.HttpWebRequest.GetResponse()....


    Can anyone help me about this subject?

    Best regards,
    Nelson Russa
    Nelson Russa Guest

  2. Similar Questions and Discussions

    1. Win32::OLE and CAPICOM to find a certificate in certificate store will raise exception
      Hi, I am trying to use win32::OLE to access certificate store via CAPICOM. If certificates in the store meet the searching criteria, the...
    2. WebRequest with no UrlEncode text.
      I am working on a WebRequest with xml data. The web service accepts the query string with no url encoding. I must pass the <> characters as they...
    3. How do I undo WebRequest.RegisterPrefix
      I am using a third party library (SVG#) which uses WebRequest.RegisterPrefix to register a custom handler for the "http://" prefix using the code: ...
    4. Webrequest - The operation has timed-out.
      I am building a Windows Forms application to consume Webservices provided by the jboss server. I used the Windows WSDL.exe tool to generate the...
    5. Certificate Server and Windows XP - Cannot install certificate
      Hello all, I would like to implement certificate server. I have installed the service on Win2003 server in standalone mode. I have created from...
  3. #2

    Default Using pfx certificate to authenticate a webrequest

    Hi,

    i need to get some info from a website page that requires an
    certificate.

    Ive got the provided certificate installed in IE, and when accessing
    the website page, it shows a window to select the client certificate
    and then shows the page correctly.

    Im trying to do this by code (C# aspnet), using webrequest.

    The certificate is in an pfx file and does not require password. I've
    exported the file using IE to DER encoded binary X.509 (.cer).

    My code:

    X509Certificate certificate =
    X509Certificate.CreateFromCertFile(Server.MapPath( "file.cer"));
    HttpWebRequest req =
    (HttpWebRequest)WebRequest.Create("https://websiteurl");
    req.Method="POST";
    req.ClientCertificates.Add(certificate);

    HttpWebResponse result = (HttpWebResponse) req.GetResponse();
    ReceiveStream = result.GetResponseStream();
    // ...
    // ...


    I got this error:

    System.Net.WebException: The underlying connection was closed: Could
    not establish secure channel for SSL/TLS. --->
    System.ComponentModel.Win32Exception: The message received was
    unexpected or badly formatted at
    System.Net.TlsStream.EndRead(IAsyncResult asyncResult) at
    System.Net.Connection.ReadCallback(IAsyncResult asyncResult) --- End
    of inner exception stack trace --- at
    System.Net.HttpWebRequest.CheckFinalStatus() at
    System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult) at
    System.Net.HttpWebRequest.GetResponse()....


    Can anyone help me about this subject?

    Best regards,
    Nelson R.
    Nelson R. Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139