473,466 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HttpWebRequest using Certificates

Hi everybody,

my VB.NET (Framework 2.0) client application has to do a HttpWebRequest (for
reading web-pages and downloading files) on a web server. The server uses a
self-signed certifiacte and the client application should also use a
self-signed certificate (of course, signed by the same self-made CA) so we
would have an authentication of both directions: the server to the client
and the other way round.

Is there a way to programmatically load the self-signed server certificate
in my VB application? Something like:

Private _WebClient As HttpWebRequest

Private _ClientCert As X509Certificate2 = LoadCert() ' This already works

_WebClient = CType(WebRequest.Create(_Server + "site.html"), HttpWebRequest)

_WebClient.ClientCertificates.Add(_ClientCert)

' Something like this.....

_WebClient.AuthorizedCertificateAuthorities.Add("M yCA.crt")

Dim NewResponse As HttpWebResponse = CType(_WebClient.GetResponse(),
HttpWebResponse)

So far my client does not accept the server certificate since it could not
establish the trust relationship! Of course, since my client does not know
about the CA. And I don't want to have to install the certificate/CA on each
machine that I need to install the software on.

Any ideas?

Thank you very much,

Josef
Mar 3 '06 #1
2 2175
Hello,

Here is a sample may help:

HttpWebRequest httprq = (HttpWebRequest)HttpWebRequest.Create(uri);
httprq.Method = "POST";
httprq.ContentType = "text/xml; charset=utf-8";

string certificateName = "ABC";
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates =
store.Certificates.Find(X509FindType.FindBySubject Name, certificateName,
true);
X509Certificate certificate = certificates[0];
httprq.ClientCertificates.Add(certificate);

//Response
HttpWebResponse httprp = (HttpWebResponse)httprq.GetResponse();

Also, The server certificate's root authority must be trusted by client and
the client certificate's root authority must be trusted by the server.

Regards,
Luke Zhang
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Mar 3 '06 #2
Hi Luke,

thanks for the advice with the certificat sore. What I'm trying to do write
know is to load all certificates (client, server, ca) into the corresponding
certificate stores. But
1. I still get the ..."Could not establish trust relationship for the
SSL'/TLS secure channel" error message
2. I cannot find the certificates I just added to the differen certificate
stores wihin the IE...

Here's the code...maybe I do something wrong while adding them...

Private _ClientCert As X509Certificate2

Private _ServerCert As X509Certificate2

Private _CACert As X509Certificate2

Public Sub New(ByVal ClientCertFile As String, ByVal ServerCertFile As
String, ByVal CACertFile As String)

_ClientCert = ReadCertificate(ClientCertFile)

_ServerCert = ReadCertificate(ServerCertFile)

_CACert = ReadCertificate(CACertFile)

Dim CAstore As New X509Store(StoreName.CertificateAuthority,
StoreLocation.LocalMachine)

CAstore.Open(OpenFlags.ReadWrite)

CAstore.Add(_CACert)

CAstore.Close()

Dim ServerStore As New X509Store(StoreName.TrustedPeople,
StoreLocation.LocalMachine)

ServerStore.Open(OpenFlags.ReadWrite)

ServerStore.Add(_ServerCert)

ServerStore.Close()

Dim ClientStore As New X509Store(StoreName.My, StoreLocation.LocalMachine)

ClientStore.Open(OpenFlags.ReadWrite)

ClientStore.Add(_ClientCert)

ClientStore.Close()

Thanx,

Josef
Mar 3 '06 #3

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

Similar topics

4
by: Steven Pu | last post by:
Hi, Specifically, the website I am trying to access is, https://gmail.google.com/ I've read elsewhere that Google only uses SSL2, while .NET uses SSL3 and is not backward compatible. Is...
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...
1
by: Deepak | last post by:
We retrieve data from a company called XYZ through httpwebrequest. The program is coded using VB.NET They have given a certificate to install. This certificate is included with the request...
1
by: Kevin Landymore | last post by:
I have a vb.net service running under a Domain account. I'm trying to call a web service on our Mainframe (IBM CICS via SSL and Client Certificates) and after a while (1 or 2 days.. thousands of...
2
by: Josef Brunner | last post by:
Hi everybody, my VB.NET (Framework 2.0) client application has to do a HttpWebRequest (for reading web-pages and downloading files) on a web server. The server uses a self-signed certifiacte and...
2
by: steveS | last post by:
Hi all, I'm having trouble connecting to a Java web service using HttpWebRequest. I get the error message "The request was aborted: Could not create SSL/TLS secure channel". The Java service...
0
by: steveS | last post by:
Hi all, I'm having trouble connecting to a Java web service using HttpWebRequest. I get the error message "The request was aborted: Could not create SSL/TLS secure channel". The Java service...
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...
0
by: nomad | last post by:
Hi, I am using HTTPWebRequest to add a client certificate. I am then using HTTPWebRequest to POST xml to a web service which requires the attached client certificate to authenticate with their...
1
by: am1974po | last post by:
I have 2 applications: One is simple windows application and the other is web service. They are both on the same machine, windows server 2003 - SP2. exactly the same code in both:...
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...
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...
1
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
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.