473,396 Members | 2,061 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,396 software developers and data experts.

HttpWebRequest and client certs?

Is there any way to programmatically select a particular client certificate
and associate it with an HttpWebRequest instance? I know using WinINet this
was possible.
Erin.
Nov 15 '05 #1
3 12916
Erin,

Sure.

System.Security.Cryptography.X509Certificates.X509 Certificate cert =

System.Security.Cryptography.X509Certificates.X509 Certificate.CreateFromCert
File(@certPath);
ServicePointManager.CertificatePolicy = new CertPolicy();
HttpWebRequest tuReq = (HttpWebRequest)WebRequest.Create(addr + "?" + TU);
tuReq.ClientCertificates.Add(cert);

tuReq.ContentType = "application/x-www-form-urlencoded";

tuReq.Method = "GET";

Make sure you have a class (either your class or another) that implements
ICertificatePolicy or your app will hang because of the untrusted cert
issue.

EX:

class CertPolicy: ICertificatePolicy

{

public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,

WebRequest request, int certificateProblem)

{

return true;

}

}

Alex



"EMonaco" <er********@nospam.net> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
Is there any way to programmatically select a particular client certificate and associate it with an HttpWebRequest instance? I know using WinINet this was possible.
Erin.

Nov 15 '05 #2
Trebek,

Thanks, was able to dig up an ASP.NET example code and came up with

httpreq = (HttpWebRequest) HttpWebRequest.Create(this.tbURL.Text);

httpreq.Method = sMethod;
// Has a client certificate file been given?

if(this.tbCERTPATH.Text.Length>0)

{

try

{

httpreq.ClientCertificates.Add(System.Security.Cry ptography.X509Certificates
..X509Certificate.CreateFromCertFile(this.tbCERTPA TH.Text));

}

catch(System.Exception pe)

{

System.Diagnostics.Debug.WriteLine(pe.ToString());

}

}

I assume I need an implemented ICertificatePolicy if the server certificate
is not trusted on the given client?

Erin.

"Trebek" <tr****@intheformofaquestion.com> wrote in message
news:3f***********************@nnrp.fuse.net...
Erin,

Sure.

System.Security.Cryptography.X509Certificates.X509 Certificate cert =

System.Security.Cryptography.X509Certificates.X509 Certificate.CreateFromCert File(@certPath);
ServicePointManager.CertificatePolicy = new CertPolicy();
HttpWebRequest tuReq = (HttpWebRequest)WebRequest.Create(addr + "?" + TU);
tuReq.ClientCertificates.Add(cert);

tuReq.ContentType = "application/x-www-form-urlencoded";

tuReq.Method = "GET";

Make sure you have a class (either your class or another) that implements
ICertificatePolicy or your app will hang because of the untrusted cert
issue.

EX:

class CertPolicy: ICertificatePolicy

{

public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,

WebRequest request, int certificateProblem)

{

return true;

}

}

Alex



"EMonaco" <er********@nospam.net> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
Is there any way to programmatically select a particular client

certificate
and associate it with an HttpWebRequest instance? I know using WinINet

this
was possible.
Erin.


Nov 15 '05 #3
Yes, even if the client IS trusted, I suggest doing it because the in the
early releases (Beta and maybe 1.0 - can't remember), this was buggy and
never really worked as intended.

Alex

"EMonaco" <er********@nospam.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Trebek,

Thanks, was able to dig up an ASP.NET example code and came up with

httpreq = (HttpWebRequest) HttpWebRequest.Create(this.tbURL.Text);

httpreq.Method = sMethod;
// Has a client certificate file been given?

if(this.tbCERTPATH.Text.Length>0)

{

try

{

httpreq.ClientCertificates.Add(System.Security.Cry ptography.X509Certificates .X509Certificate.CreateFromCertFile(this.tbCERTPAT H.Text));

}

catch(System.Exception pe)

{

System.Diagnostics.Debug.WriteLine(pe.ToString());

}

}

I assume I need an implemented ICertificatePolicy if the server certificate is not trusted on the given client?

Erin.

"Trebek" <tr****@intheformofaquestion.com> wrote in message
news:3f***********************@nnrp.fuse.net...
Erin,

Sure.

System.Security.Cryptography.X509Certificates.X509 Certificate cert =

System.Security.Cryptography.X509Certificates.X509 Certificate.CreateFromCert
File(@certPath);
ServicePointManager.CertificatePolicy = new CertPolicy();
HttpWebRequest tuReq = (HttpWebRequest)WebRequest.Create(addr + "?" + TU);

tuReq.ClientCertificates.Add(cert);

tuReq.ContentType = "application/x-www-form-urlencoded";

tuReq.Method = "GET";

Make sure you have a class (either your class or another) that implements ICertificatePolicy or your app will hang because of the untrusted cert
issue.

EX:

class CertPolicy: ICertificatePolicy

{

public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate
certificate,

WebRequest request, int certificateProblem)

{

return true;

}

}

Alex



"EMonaco" <er********@nospam.net> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
Is there any way to programmatically select a particular client

certificate
and associate it with an HttpWebRequest instance? I know using WinINet

this
was possible.
Erin.



Nov 15 '05 #4

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

Similar topics

2
by: Richard Shea | last post by:
Hi - Hoped someone who's done this could provide some pointers. I'm interested in developing a script which would make use of openssl_x509_read to read a certificate presented in the HTTP headers...
8
by: Soeren S. Joergensen | last post by:
Hi, From a win-service I do a HttpWebRequest to a secure url with some parameters to get some simple data from a remote system used later on in a worker thread. When making the request from...
3
by: Tim Burris | last post by:
At the top here i will put a quick description of my problem followed by the long description. This way you want get bored reading! : short version what is the best/recommended way for ASPNET...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
3
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to...
0
by: lnap | last post by:
Hey everybody, I've got what I hope to be a simple question. I'm currently working on a project that uses IIS to request a Client Cert (X509) from a CAC/Smart Card. However, we want to get away...
2
by: Eli Criffield | last post by:
Does anyone have an example setup of a XML-RPC sever using client side certs for authentication? And instead of having a list of certs allowed to connect, I'd like to allow any cert signed by my...
1
by: Joe | last post by:
Hello, I'm currently using a C# class library which is also converted quickly to a console app by adding a MAIN and adjusting the building configuration. I'm using this page as a reference to the...
2
by: =?Utf-8?B?TGFycnlLdXBlcm1hbg==?= | last post by:
Our WebDev team seems to have found a problem that exposes a bug in .NET 2.0. This problem can be shown when trying to access a WebService using SSL and through a proxy server after using the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.