Reputation: 1713
Currently we manually go to a url to download a root cert. However there is now a need to automate it. I am looking for C# examples of how to accomplish this. I would like to give the url as a parameter, and then the program must take over and open this url in the background, download and install the requested certificate, without the user having to do anything, or know what happened. There is no prompt for a user name and password, when you do it manually, so this library should enable me to make such a call.
Please give me some advice on what to do, or some handy articles I can read to get me going?
Upvotes: 2
Views: 2698
Reputation: 73
Here's example how to get a root certificate from Certification Authority
// address - CA address
public static void InstallRootCert(string address)
{
// getting root cert
ICertRequest2 objRequest = new CCertRequest();
string rootCert = objRequest.GetCACertificate(0, address, 0);
byte[] buffer = Encoding.UTF8.GetBytes(rootCert);
// installing
var store = new X509Store("Root", StoreLocation.CurrentUser);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
var root = new X509Certificate2(buffer);
store.Add(root);
}
Upvotes: 1
Reputation: 823
Download with whatever http request method you like. Install it like:
app.ClientCertificates.Add(
new System.Security.Cryptography.X509Certificates.X509Certificate2(
@"c:\Downloads\testcert.pfx", "password"));
See here for more info on managing certificates: http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspx
Upvotes: 0
Reputation: 70369
Since the information you provide is rather general some general pointers on how you could implement this:
The download can be achieved via a WebClient
and/or HttpWebRequest
.
As for the installation you can do that via X509Store
together with StoreName.Root
- for details and sample source see http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509store.aspx
Upvotes: 0