473,795 Members | 2,554 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 2609
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
1477
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
1589
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
1794
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
3439
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
2470
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
10436
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
10213
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...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
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
7538
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
6780
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.