473,385 Members | 1,343 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,385 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 2590
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.