Using pfx certificate to authenticate a webrequest

Discussion in 'ASP .Net' started by Nelson R., Jan 5, 2005.

  1. Nelson R.

    Nelson R. Guest

    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 (vs2003 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), since
    its the only format used by .net webrequest certificates (?)

    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(IAsyncResult asyncResult) at
    System.Net.HttpWebRequest.GetResponse()....


    From the error i can see that the certificate is invalid, because if i
    dont use the certificate i get the same error messagem.

    So... anyone knows how or point me to the right path to do a request
    from an https website, using an pfx file?


    Best regards,
    Nelson R.
    Nelson R., Jan 5, 2005
    #1
    1. Advertising

  2. Nelson R.

    Nelson R. Guest

    Hi,

    dont understand why nobody ever answer my questions about using
    certificates in aspnet (this is not my first post about this).

    Well, ive solved my problem. I had an pfx certificate installed and
    exported to x509 format. Using webrequest and the exported certificate
    i was getting an error accessing the website (https)

    The problem was because my ASPNET account didnt have the rights to
    access installed certificate.

    I had to use a microsoft tool (winhttpcertcfg) to give access to
    ASPNET account.

    Tool url:
    http://msdn.microsoft.com/library/d...cfg_exe__a_certificate_configuration_tool.asp


    Know all works...

    Hope this will help anyone who has the same problem...


    Best regards,
    Nelson R.
    Nelson R., Jan 10, 2005
    #2
    1. Advertising

  3. Nelson R.

    starter

    Joined:
    Sep 25, 2009
    Messages:
    1
    help on accessing https website

    Hi,
    How do you download the certficate..where to find the .cer file?
    can you please send me the code for same.

    thanks in advance.
    nidhi
    starter, Sep 25, 2009
    #3
  4. Nelson R.

    rmacone

    Joined:
    Mar 21, 2012
    Messages:
    1

    Hi Nelson R., I want thank you for your reply... this have help me a lot!!!
    Me too, I have not found relevant help on google or forum in web... :(
    I have not solved my problem completly, but I have seen a way to solve grace your response!!
    Have a nice day!!

    Bye, Roberto
    rmacone, Mar 21, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nelson Russa
    Replies:
    0
    Views:
    552
    Nelson Russa
    Nov 19, 2004
  2. Praveen Mohanan
    Replies:
    3
    Views:
    5,085
    Tony Morris
    May 4, 2006
  3. Nelson Russa

    Using pfx certificate to authenticate a webrequest

    Nelson Russa, Nov 22, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    156
    Nelson Russa
    Nov 22, 2004
  4. Nelson R.

    Using pfx certificate to authenticate a webrequest

    Nelson R., Nov 29, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    137
    Nelson R.
    Nov 29, 2004
  5. Certificate Authenticate

    , May 2, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    93
Loading...

Share This Page