473,804 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.X 509Certificates ;

public class CertPolicy : ICertificatePol icy
{
public bool CheckValidation Result(ServiceP oint sp, X509Certificate cert,
WebRequest request, int problem)
{
return true;
}
}

public class CertTest
{

public static void Main()
{
try
{
HttpWebRequest objRequest =
(HttpWebRequest )WebRequest.Cre ate("https://myweb/");
objRequest.Meth od = "POST";
X509Certificate myCert =
X509Certificate .CreateFromCert File(@"d:\a\cer t.der");
X509Certificate Collection x509 = objRequest.Clie ntCertificates;
x509.Add (myCert);
objRequest.Clie ntCertificates. Add(myCert);
ServicePointMan ager.Certificat ePolicy = new CertPolicy();

HttpWebResponse objResponse = (HttpWebRespons e)objRequest.Ge tResponse();
}
catch( Exception e )
{
Console.WriteLi ne( e.ToString() );
}
}
}
Thanks for any help
Nov 17 '05 #1
1 2610
mb****@o2.pl (borovA) wrote in message news:<18******* *************** ****@posting.go ogle.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.X 509Certificates ;

public class CertPolicy : ICertificatePol icy
{
public bool CheckValidation Result(ServiceP oint sp, X509Certificate cert,
WebRequest request, int problem)
{
return true;
}
}

public class CertTest
{

public static void Main()
{
try
{
HttpWebRequest objRequest =
(HttpWebRequest )WebRequest.Cre ate("https://myweb/");
objRequest.Meth od = "POST";
X509Certificate myCert =
X509Certificate .CreateFromCert File(@"d:\a\cer t.der");
X509Certificate Collection x509 = objRequest.Clie ntCertificates;
x509.Add (myCert);
objRequest.Clie ntCertificates. Add(myCert);
ServicePointMan ager.Certificat ePolicy = new CertPolicy();

HttpWebResponse objResponse = (HttpWebRespons e)objRequest.Ge tResponse();
}
catch( Exception e )
{
Console.WriteLi ne( e.ToString() );
}
}
}
Problem was trivial :-)

solution:
objRequest.Cont entLength = 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
1478
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 certificates are stored in the "cacerts" file in the local JDK, what is a simple way of verifying that the original certificate is signed by one of these trusted CAs? Please outline the steps my code should perform. (I couldn't find any simple examples...
1
1590
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 people enter their credit card info on an ecommerce site. This is the first such site (Shopping Cart) I have done and this code was provded by a user of the standard ASP Shopping Cart software (CandyPress shopping cart.) It works, but I don't...
2
1654
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 people enter their credit card info on an ecommerce site. This is the first such site (Shopping Cart) I have done and this code was provded by a user of the standard ASP Shopping Cart software (CandyPress shopping cart.) It works, but I don't...
1
458
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 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...
2
1795
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 Administrator dependent, and I would like to load a user profile I have created for encryption & decryption directly. In other words I want to load the user profile without having have administrator privileges. I’m using VB.NET, & would like to deviate...
1
3441
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 ourselves 2) exchange client and server certificates to perform mutual authentication
0
2220
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: https://tps-test.voiceeclipse.com/cgi-bin/ve_xml.cgi Here's what I'm doing:
3
2471
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 to encrypt a value using the public key in the Handango certificate. Does anyone have any suggestions or sample asp.net code on how to implement this?
5
7723
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 snap-in, is there another way to send an XML payload to the web service with an SSL certificatre attached to the request? Appreciate any thoughts on this as I am a bit of a newbie.
0
1231
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 neccesory to import certificate from both side alredy ? 2. What should do to get, store (in trust store ) and use (public key) certificate from client/server while transaction ( handshaking ) ?
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.