How to automatically install User Certificates and root certificates on the web

Source: Internet
Author: User
Tags pkcs7 strtok

Author: Rainbow

One of Microsoft's xenroll interfaces, acceptpkcs7, provides the certificate installation function. This article describes how to use this interface to automatically install User Certificates and root certificates on the web, and provides some instance code.

I. Certificate Installation

One of Microsoft's xenroll interfaces, acceptpkcs7, provides the certificate installation function. The specific parameters are as follows:

HRESULT acceptPKCS7 (BSTR PKCS7). The pkcs7 parameter is a base64-encoded certificate.

To install a certificate on the web page, the process is as follows:

1. initialize xenroll. dll

Add in html code

 

 

 

 

<OBJECT id = XEnroll classid = clsid: 415698e4-e730-4e5c-a2b1-21490a70c8a1 codebase = "xenroll. dll">
</OBJECT>


2. Read the certificate

Certificates can be read from LDAP or databases. This is not our topic, So I skipped it here. For more information, see LDAP and other topics on this site.

3. Call the acceptPKCS7 Interface

The sample code is as follows:

On error resume next
SPKCS7 = you have obtained the certificate content
Err. clear
XEnroll. AcceptPkcs7 (sPKCS7)
If err. Number <> 0 then
If err. number =-2146885628 then
MsgBox "This certificate already exists in the system, or the certificate is not applied for on this machine"
Else
MsgBox "An error occurred while downloading the certificate. Error code =" & err. description
End if
Else


MsgBox "Certificate loaded successfully"
End if


Note: Only certificate requests generated on the local machine can install certificates in this way.

Ii. Install the root certificate

Another interface in Microsoft xenroll, acceptpkcs7, provides the root certificate installation function. The specific parameters are as follows:

[C ++] HRESULT InstallPKCS7 (BSTR PKCS7)
[Vb] Sub InstallPKCS7 (ByVal PKCS7 As String)


The pkcs7 parameter is a base64 encoded root certificate. to install the certificate on the web page, the process is the same as installing the user certificate.

1. How to automatically download and install the root certificate in asp

Note: // starts with an annotation.


<Html>
<Object id = "XEnroll" classid = "clsid: 415698e4-e730-4e5c-a2b1-21490a70c8a1" codebase = "xenroll. dll"> </object>
<Script Language = "VBScript">
On error resume next

XEnroll. InstallPKCS7 sPKCS7
If err. number = 438 then
Msgbox "install root certificate fail ."
Elseif err. number <> 0 then
Msgbox "install root certificate fail ."
Else
Msgbox "install root certificate success ."
End if
Window. close ()
</Script>
</Html>


The purpose of do while... loop is to generate a piece of vbscript code. The generated result is as follows:

SPKCS7 = ""
SPKCS7 = sPKCS7 & "----- begin certificate -----" & vbcrlf
SPKCS7 = sPKCS7 & "MIICMjCCAZugAwIBAgIBATANBgkqhkiG9w0BAQUFADAUMRIwEAYDVQQKEwlIWWRy" & vbcrlf
SPKCS7 = sPKCS7 & "b2luZm8wHhcNMDQwNDExMDczMzI0WhcNMzQwNDA0MDczMzI0WjAUMRIwEAYDVQQK" & vbcrlf
......
......
SPKCS7 = sPKCS7 & "BQADgYEAjYHzQkIp1dE5zyPcrybDvpoT/MmMcZ3q7GANncp9Kq8b0Bj0It8kPPyN" & vbcrlf
SPKCS7 = sPKCS7 & "JPit6rmgErPqPdj789Sr1H7/XjY + tuBJLV1idDPlqV44b3rBk/8 GjYmTmLuDOYBI" & vbcrlf
SPKCS7 = sPKCS7 & "XKqIEuO50QNJIdinCsCRyZ8h9O/VDTyMH4VUQsJ3YdZk2w3PrwU =" & vbcrlf
SPKCS7 = sPKCS7 & "----- end certificate -----" & vbcrlf


2. How to automatically download and install the root certificate in php

First, you need to get the certificate, for example, in the variable $ cert.

In this way, you only need to replace the sPKCS string generated in asp with the following code. The new content is included in $ newcert.

$ Newcert = "sPKCS7 = """;
$ Line = strtok ($ cert ,"");
While ($ line)
{
$ Newcert = $ newcert. "sPKCS7 = sPKCS7 &" ". $ line." "& vbcrlf ";
$ Line = strtok ("");
}
Echo $ newcert;
?>


Iii. Differences between installPKCS7 and acceptPKCS7

1. InstallPKCS7 can install the certificate chain

2. The first appearance in ICEnroll3

 

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.