473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

help me Certificate Verification (C#)

I am trying to access an Web. The problem is that they
expect the client to submit a certificate. I can access the site from
my browser, but it always asks which certificate I want to use. How
can I do this in my code.

So far I can get the certificate. It's properly
formatted, and I can instantiate a X509Certificate object
with it. But I can't figure out how to add it to the Root
store, so it is trusted. Even if I add it to the Root
with IE, I still get the "The underlying connection was
closed: Could not establish trust relationship with remote
server." error message, when I connect to the HTTPS
resource via C#.

here is my code:

using System;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;

public class CertPolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint sp, X509Certificate cert,
WebRequest request, int problem)
{
return true;
}
}

public class CertTest
{

public static void Main()
{
try
{
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create("https://myweb/");
objRequest.Method = "POST";
X509Certificate myCert =
X509Certificate.CreateFromCertFile(@"d:\a\cert.der ");
X509CertificateCollection x509 = objRequest.ClientCertificates;
x509.Add (myCert);
objRequest.ClientCertificates.Add(myCert);
ServicePointManager.CertificatePolicy = new CertPolicy();

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
}
catch( Exception e )
{
Console.WriteLine( e.ToString() );
}
}
}
Thanks for any help
Nov 17 '05 #1
1 2585
mb****@o2.pl (borovA) wrote in message news:<18**************************@posting.google. com>...
I am trying to access an Web. The problem is that they
expect the client to submit a certificate. I can access the site from
my browser, but it always asks which certificate I want to use. How
can I do this in my code.

So far I can get the certificate. It's properly
formatted, and I can instantiate a X509Certificate object
with it. But I can't figure out how to add it to the Root
store, so it is trusted. Even if I add it to the Root
with IE, I still get the "The underlying connection was
closed: Could not establish trust relationship with remote
server." error message, when I connect to the HTTPS
resource via C#.

here is my code:

using System;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;

public class CertPolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint sp, X509Certificate cert,
WebRequest request, int problem)
{
return true;
}
}

public class CertTest
{

public static void Main()
{
try
{
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create("https://myweb/");
objRequest.Method = "POST";
X509Certificate myCert =
X509Certificate.CreateFromCertFile(@"d:\a\cert.der ");
X509CertificateCollection x509 = objRequest.ClientCertificates;
x509.Add (myCert);
objRequest.ClientCertificates.Add(myCert);
ServicePointManager.CertificatePolicy = new CertPolicy();

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
}
catch( Exception e )
{
Console.WriteLine( e.ToString() );
}
}
}
Problem was trivial :-)

solution:
objRequest.ContentLength = 0;



Thanks for any help

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stephen Chell | last post by:
My java app gets an X509 certificate out of an XML signature, and I want to verify that the certificate is signed by any one of several trusted CAs. If we assume that all relevant CA...
1
by: Will | last post by:
(My 4 questins at end after explination) The code below was provided to me to "Popup" a window explaining what a Credit Card Verification Number is and where to find it on a card... it is used as...
2
by: Will | last post by:
(My 4 questins at end after explination) The code below was provided to me to "Popup" a window explaining what a Credit Card Verification Number is and where to find it on a card... it is used as...
1
by: borovA | last post by:
I am trying to access an Web. The problem is that they expect the client to submit a certificate. I can access the site from my browser, but it always asks which certificate I want to use. How...
2
by: Shaun Ram | last post by:
I am working on using DPAPI user profile store to encrypt a connection string in web.config file, using VB.NET 1. I have a situation here, I would not want the DPAPI User profile to be...
1
by: Yogesh Chawla - PD | last post by:
Hello All, I work for the State of Wisconsin and we are trying to build a reference implementation using python. Our goals are this: 1) establish an HTTPS connection between our client and...
0
by: Damon | last post by:
I've been pulling my hair out over this and I need some expert help. I'm trying to access an XML API using cURL over SSL. Here's the API address: ...
3
by: Tery | last post by:
I'm trying to implement the Handango.com HTTP POST registration method. The instructions are here: http://www.handango.com/marketing/developerTeam/HTTP_Post_Reg_Model_How2.doc I'm stuck on how...
5
by: nomad | last post by:
Hi, I was wondering if it was possible to add a service reference to a web service which requires an SSL certificate to authenticate? If not, if I have the SSL certificate installed via mmc...
0
by: Abhinay | last post by:
Hi there, This is abhinay, I am developing one java SSL socket based client/server application but I did't get proper answer of following questions. 1. Fow two way verification is it...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.