Allow the WPF Browser Application to automatically download and install the digital certificate)

Source: Internet
Author: User

Original address: http://hi.csdn.net/link.php? Url = http://blog.csdn.net % 2 fstarlee

In my article "create digital certificate for WPF Browser Application", I provided a method to create a digital certificate for WPF Browser Application, this avoids "Trust not granted" errors and makes it a real "full trust" WPF Browser Application.
To access the WPF Browser Application on a client computer, you must install a digital certificate on the client computer. If many clients access the certificate, they must download and install the certificate on their own. To this end, you must provide users with an installation method for digital certificates and digital certificates that can be downloaded. It can be said that it brings a lot of inconvenience to users.
The following provides a method for the client to automatically download and install the digital certificate when accessing the WPF Browser Application in a browser.
This method involves two steps: first, write a program to download and install the digital certificate, and then include the program in the installation program of the WPF Browser Application.
Download and install the digital certificate program is relatively simple, as long as you use C # To create a console application, and then add the following code. (In this example, a console program named certificateinstaller is created)

Using system;
Using system. net;
Using system. Windows. forms;
Using system. Security. cryptography. x509certificates;
Namespace certificateinstaller
{
Class Program
{
Static void main (string [] ARGs)
{
Try
{
If (ARGs. length> 0)
{
WebClient = new WebClient ();
Byte [] certificatefile = WebClient. downloaddata (ARGs [0]);
If (certificatefile. length> 0)
{
Installcertificate (storename. authroot, certificatefile );
Installcertificate (storename. trustedpublisher, certificatefile );
}
Else
{
Showerrormessage ("can't download the Certificate file .");
}
}
}
Catch (system. Exception ex)
{
Showerrormessage (ex. Message );
}
}
Static void installcertificate (storename storagename, byte [] certificatefile)
{
X509certificate2 certificate = new x509certificate2 (certificatefile );
X509store store = new x509store (storagename, storelocation. localmachine );
Store. Open (openflags. readwrite );
Store. Remove (certificate );
Store. Add (certificate );
Store. Close ();
}
Static void showerrormessage (string strerrormessage)
{
MessageBox. Show (strerrormessage, "certificate installation error", messageboxbuttons. OK, messageboxicon. Error );
}
}
}

Next, add the compiled certificateinstaller.exe to the installation program of the WPF Browser Application.
1. Find the windowsinstaller3_1 folder under the directory c: \ Program Files \ microsoft sdks \ windows \ v6.0a \ bootstrapper \ packages.
2. copy and paste the windowsinstaller3_1 folder and rename it certificateinstaller.
3. Copy certificateinstaller.exe to the C: \ Program Files \ microsoft sdks \ windows \ v6.0a \ bootstrapper \ packages \ certificateinstaller folder.
4. Change product. XML in the folder to the following content.

<? XML version = "1.0" encoding = "UTF-8"?>
<Product
Xmlns = "http://schemas.microsoft.com/developer/2004/01/bootstrapper"
Productcode = "certificateinsteraller"
>
<Packagefiles copyallpackagefiles = "true">
<Packagefile name = "certificateinstaller.exe"/>
</Packagefiles>
<Commands reboot = "immediate">
<Command packagefile = "certificateinstaller.exe"
Arguments = 'HTTP: // xxx/xxx. Cer'
Estimatedinstallseconds = "30">
<Exitcodes>
<Exitcode value = "0" result = "success"/>
<Exitcode value = "1641" result = "successreboot"/>
<Exitcode value = "3010" result = "successreboot"/>
<Defaultexitcode result = "fail" formatmessagefromsystem = "true" string = "generalfailure"/>
</Exitcodes>
</Command>
</Commands>
</Product>
<? XML version = "1.0" encoding = "UTF-8"?>

<Product
Xmlns = "http://schemas.microsoft.com/developer/2004/01/bootstrapper"
Productcode = "certificateinsteraller"
>

<Packagefiles copyallpackagefiles = "true">
<Packagefile name = "certificateinstaller.exe"/>
</Packagefiles>

<Commands reboot = "immediate">
<Command packagefile = "certificateinstaller.exe"
Arguments = 'HTTP: // xxx/xxx. Cer'
Estimatedinstallseconds = "30">
<Exitcodes>
<Exitcode value = "0" result = "success"/>
<Exitcode value = "1641" result = "successreboot"/>
<Exitcode value = "3010" result = "successreboot"/>
<Defaultexitcode result = "fail" formatmessagefromsystem = "true" string = "generalfailure"/>
</Exitcodes>
</Command>
</Commands>
</Product>
"Http: // xxx/xxx. CER is the link to the digital certificate that can be downloaded (it can be placed on the same web server as the WPF Browser Application, which facilitates management. Of course, it can also be stored on a web server that any user can access ).
5. Enter the "en" folder and Change Package. XML to the following content.

<? XML version = "1.0" encoding = "UTF-8"?>
<Package
Xmlns = "http://schemas.microsoft.com/developer/2004/01/bootstrapper"
Name = "displayname"
Culture = "culture"
>
<Strings>
<String name = "displayname"> my certificate insteraller </string>
</Strings>
</Package>
<? XML version = "1.0" encoding = "UTF-8"?>

<Package
Xmlns = "http://schemas.microsoft.com/developer/2004/01/bootstrapper"
Name = "displayname"
Culture = "culture"
>

<Strings>
<String name = "displayname"> my certificate insteraller </string>
</Strings>

</Package>

6. Open the WPF Browser Application.
7. Select the "publish" option in the property panel and click "preequisites.

8. in the pop-up "preequisites" dialog box, select "create setup program to install prerequisite components" and find "my certificate insteraler" in the list (if not found, close Vs and open it again), select it, and click "OK.

9. re-release the WPF Browser Application.

The following describes how to install a digital certificate on the client.
1. When you access the WPF Browser Application through a browser on the client, a page similar to the following will appear.

We can see that "my certificate insteraler" has been included in the installer.
2. Click "run" to bring up the following dialog box.

3. Click "run" and click "run" in the pop-up dialog box.

4. The installation dialog box will pop up. Click "Export installer.exe" and then click "Run certificateinstaller.exe" to automatically download and install the digital certificate.

Through the above steps, the digital certificate is automatically installed on the client computer. Later, you can directly access the WPF Browser Application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.