使用 MakeCert 为点到站点连接生成并导出证书Generate and export certificates for Point-to-Site connections using MakeCert

点到站点连接使用证书进行身份验证。Point-to-Site connections use certificates to authenticate. 本文说明如何使用 MakeCert 创建自签名根证书以及生成客户端证书。This article shows you how to create a self-signed root certificate and generate client certificates using MakeCert. 如果要查找不同的证书说明,请参阅证书 - PowerShell证书 - LinuxIf you are looking for different certificate instructions, see Certificates - PowerShell or Certificates - Linux.

虽然我们建议使用 Windows 10 PowerShell 步骤来创建证书,但提供这些 MakeCert 说明作为备选方法。While we recommend using the Windows 10 PowerShell steps to create your certificates, we provide these MakeCert instructions as an optional method. 使用任一方法生成的证书均可安装在支持的所有客户端操作系统上。The certificates that you generate using either method can be installed on any supported client operating system. 然而,MakeCert 具有以下限制:However, MakeCert has the following limitation:

  • 已弃用 MakeCert。MakeCert is deprecated. 这意味着此工具随时可能被删除。This means that this tool could be removed at any point. MakeCert 不再可用时,使用 MakeCert 生成的所有证书均不会受到任何影响。Any certificates that you already generated using MakeCert won't be affected when MakeCert is no longer available. MakeCert 仅用于生成证书,不用作验证机制。MakeCert is only used to generate the certificates, not as a validating mechanism.

创建自签名根证书Create a self-signed root certificate

以下步骤演示如何使用 MakeCert 创建自签名证书。The following steps show you how to create a self-signed certificate using MakeCert. 这些步骤并非特定于部署模型。These steps are not deployment-model specific. 它们同样适用于 Resource Manager 和经典部署模型。They are valid for both Resource Manager and classic.

  1. 下载并安装 MakeCertDownload and install MakeCert.

  2. 安装后,通常可在此路径中找到 makecert.exe 实用工具:“C:\Program Files (x86)\Windows Kits\10\bin<arch>”。After installation, you can typically find the makecert.exe utility under this path: 'C:\Program Files (x86)\Windows Kits\10\bin<arch>'. 但它也有可能安装到了另一位置。Although, it's possible that it was installed to another location. 以管理员身份打开命令提示符,并导航到 MakeCert 实用工具所在位置。Open a command prompt as administrator and navigate to the location of the MakeCert utility. 可使用以下示例,调整到适当的位置:You can use the following example, adjusting for the proper location:

    cd C:\Program Files (x86)\Windows Kits\10\bin\x64
    
  3. 在计算机上的“个人”证书存储中创建并安装证书。Create and install a certificate in the Personal certificate store on your computer. 以下示例将创建一个相应的 .cer 文件,在配置 P2S 时需要将此文件上传到 Azure。The following example creates a corresponding .cer file that you upload to Azure when configuring P2S. 使用想要用于证书的名称替换“P2SRootCert”和“P2SRootCert.cer”。Replace 'P2SRootCert' and 'P2SRootCert.cer' with the name that you want to use for the certificate. 该证书位于“Certificates - Current User\Personal\Certificates”中。The certificate is located in your 'Certificates - Current User\Personal\Certificates'.

    makecert -sky exchange -r -n "CN=P2SRootCert" -pe -a sha256 -len 2048 -ss My
    

导出公钥 (.cer)Export the public key (.cer)

创建自签名根证书之后,导出根证书公用密钥 .cer 文件(不导出私钥)。After creating a self-signed root certificate, export the root certificate public key .cer file (not the private key). 稍后要将此文件上传到 Azure。You will later upload this file to Azure. 可借助以下步骤导出自签名根证书的 .cer 文件:The following steps help you export the .cer file for your self-signed root certificate:

  1. 若要获取证书 .cer 文件,请打开“管理用户证书” 。To obtain a .cer file from the certificate, open Manage user certificates. 找到自签名根证书(通常位于“Certificates - Current User\Personal\Certificates”中),并右键单击。Locate the self-signed root certificate, typically in 'Certificates - Current User\Personal\Certificates', and right-click. 单击“所有任务” ,并单击“导出” 。Click All Tasks, and then click Export. 此操作将打开“证书导出向导” 。This opens the Certificate Export Wizard. 如果在 Current User\Personal\Certificates 下找不到证书,可能会意外地打开“Certificates - Local Computer”而不是“Certificates - Current User”)。If you can't find the certificate under Current User\Personal\Certificates, you may have accidentally opened "Certificates - Local Computer", rather than "Certificates - Current User"). 如果想要使用 PowerShell 在当前用户范围内打开证书管理程序,请在控制台窗口中键入“certmgr” 。If you want to open Certificate Manager in current user scope using PowerShell, you type certmgr in the console window.

    导出

  2. 在向导中,单击“下一步” 。In the Wizard, click Next.

    导出证书

  3. 选择“否,不导出私钥” ,并单击“下一步” 。Select No, do not export the private key, and then click Next.

    不要导出私钥

  4. 在“导出文件格式” 页上,选择“Base-64 编码的 X.509 (.CER)” ,并单击“下一步” 。On the Export File Format page, select Base-64 encoded X.509 (.CER)., and then click Next.

    Base-64 编码

  5. 对于“要导出的文件” ,“浏览” 到要将证书导出的目标位置。For File to Export, Browse to the location to which you want to export the certificate. 在“文件名” 中,为证书文件命名。For File name, name the certificate file. 然后单击“下一步”。 Then, click Next.

    浏览

  6. 单击“完成” 导出证书。Click Finish to export the certificate.

    完成

  7. 证书已成功导出。Your certificate is successfully exported.

    Success

  8. 导出的证书类似于以下内容:The exported certificate looks similar to this:

    已导出

  9. 如果使用记事本打开导出的证书,则会看到类似于此示例的一些内容。If you open the exported certificate using Notepad, you see something similar to this example. 蓝色的部分包含上传到 Azure 的信息。The section in blue contains the information that is uploaded to Azure. 如果使用记事本打开证书,并且内容不与此类似,则这通常意味着你没有使用 Base-64 编码的 X.509(.CER) 格式将其导出。If you open your certificate with Notepad and it does not look similar to this, typically this means you did not export it using the Base-64 encoded X.509(.CER) format. 此外,如果希望使用其他文本编辑器,请注意,某些编辑器可能会在后台引入意外的格式设置。Additionally, if you want to use a different text editor, understand that some editors can introduce unintended formatting in the background. 将此证书中的文本上传到 Azure 时,这可能会产生问题。This can create problems when uploaded the text from this certificate to Azure.

    使用记事本打开

exported.cer 文件必须上传到 Azure。The exported.cer file must be uploaded to Azure. 请参阅配置点到站点连接获取相关说明。For instructions, see Configure a Point-to-Site connection. 若要添加其他受信任的根证书,请参阅文章的此部分To add an additional trusted root certificate, see this section of the article.

导出自签名证书和用于存储它的私钥(可选)Export the self-signed certificate and private key to store it (optional)

可能想要导出自签名根证书并将它存储在安全位置。You may want to export the self-signed root certificate and store it safely. 如果需要,可以稍后在另一台计算机上安装此自签名证书,并生成更多客户端证书,或导出另一个 .cer 文件。If need be, you can later install it on another computer and generate more client certificates, or export another .cer file. 如果要将自签名根证书导出为 .pfx,请选择该根证书,并使用导出客户端证书中所述的步骤导出。To export the self-signed root certificate as a .pfx, select the root certificate and use the same steps as described in Export a client certificate.

创建和安装客户端证书Create and install client certificates

不要直接在客户端计算机上安装自签名的证书。You don't install the self-signed certificate directly on the client computer. 需要从自签名证书生成客户端证书。You need to generate a client certificate from the self-signed certificate. 然后导出客户端证书,并将其安装到客户端计算机上。You then export and install the client certificate to the client computer. 以下步骤并非特定于部署模型。The following steps are not deployment-model specific. 它们同样适用于 Resource Manager 和经典部署模型。They are valid for both Resource Manager and classic.

生成客户端证书Generate a client certificate

在使用点到站点连接连接到 VNet 的每台客户端计算机上,必须安装客户端证书。Each client computer that connects to a VNet using Point-to-Site must have a client certificate installed. 可以从自签名根证书生成客户端证书,导出并安装该客户端证书。You generate a client certificate from the self-signed root certificate, and then export and install the client certificate. 如果不安装客户端证书,身份验证会失败。If the client certificate is not installed, authentication fails.

以下步骤引导完成从自签名根证书生成客户端证书的过程。The following steps walk you through generating a client certificate from a self-signed root certificate. 可以从相同根证书生成多个客户端证书。You may generate multiple client certificates from the same root certificate. 使用以下步骤生成客户端证书时,客户端证书自动安装在用于生成该证书的计算机上。When you generate client certificates using the steps below, the client certificate is automatically installed on the computer that you used to generate the certificate. 如果想要在另一台客户端计算机上安装客户端证书,可以导出该证书。If you want to install a client certificate on another client computer, you can export the certificate.

  1. 在用于创建自签名证书的同一台计算机上,以管理员身份打开命令提示符。On the same computer that you used to create the self-signed certificate, open a command prompt as administrator.

  2. 修改并运行示例,生成客户端证书。Modify and run the sample to generate a client certificate.

    • 将“P2SRootCert”更改为生成客户端证书所用的自签名根证书的名称。Change "P2SRootCert" to the name of the self-signed root that you are generating the client certificate from. 确保使用创建自签名根时指定的根证书名称(无论“CN=”的值为何)。Make sure you are using the name of the root certificate, which is whatever the 'CN=' value was that you specified when you created the self-signed root.
    • 将 P2SChildCert 更改为希望生成的客户端证书使用的名称。Change P2SChildCert to the name you want to generate a client certificate to be.

    如果未经修改就运行以下示例,则个人证书存储中将有一个从根证书 P2SRootCert 生成的客户端证书,名为 P2SChildcert。If you run the following example without modifying it, the result is a client certificate named P2SChildcert in your Personal certificate store that was generated from root certificate P2SRootCert.

    makecert.exe -n "CN=P2SChildCert" -pe -sky exchange -m 96 -ss My -in "P2SRootCert" -is my -a sha256
    

导出客户端证书Export a client certificate

生成客户端证书时,该证书会自动安装在用于生成它的计算机上。When you generate a client certificate, it's automatically installed on the computer that you used to generate it. 如果想要在另一台客户端计算机上安装客户端证书,需要导出生成的客户端证书。If you want to install the client certificate on another client computer, you need to export the client certificate that you generated.

  1. 若要导出客户端证书,请打开“管理用户证书” 。To export a client certificate, open Manage user certificates. 生成的客户端证书默认位于“Certificates - Current User\Personal\Certificates”中。The client certificates that you generated are, by default, located in 'Certificates - Current User\Personal\Certificates'. 右键单击要导出的客户端证书,单击“所有任务” ,并单击“导出” 打开“证书导出向导” 。Right-click the client certificate that you want to export, click all tasks, and then click Export to open the Certificate Export Wizard.

    导出

  2. 在“证书导出向导”中,单击“下一步”以继续。 In the Certificate Export Wizard, click Next to continue.

    下一步

  3. 选择“是,导出私钥” ,并单击“下一步” 。Select Yes, export the private key, and then click Next.

    导出私钥

  4. 在“导出文件格式” 页上,保留选择默认值。On the Export File Format page, leave the defaults selected. 请务必选中“包括证书路径中的所有证书(如果可能)”。 Make sure that Include all certificates in the certification path if possible is selected. 此外,此设置还会导出成功客户端身份验证所需的根证书信息。This setting additionally exports the root certificate information that is required for successful client authentication. 否则,客户端身份验证会失败,因为客户端没有受信任的根证书。Without it, client authentication fails because the client doesn't have the trusted root certificate. 然后单击“下一步”。 Then, click Next.

    导出文件格式

  5. 在“安全性”页上,必须保护私钥。On the Security page, you must protect the private key. 如果选择使用密码,请务必记下或牢记为此证书设置的密码。If you select to use a password, make sure to record or remember the password that you set for this certificate. 然后单击“下一步”。 Then, click Next.

    security

  6. 在“要导出的文件” 中,“浏览” 到要将证书导出的目标位置。On the File to Export, Browse to the location to which you want to export the certificate. 在“文件名” 中,为证书文件命名。For File name, name the certificate file. 然后单击“下一步”。 Then, click Next.

    要导出的文件

  7. 单击“完成” 导出证书。Click Finish to export the certificate.

    完成

安装已导出的客户端证书Install an exported client certificate

若要安装客户端证书,请参阅安装客户端证书To install a client certificate, see Install a client certificate.

后续步骤Next steps

继续使用点到站点配置。Continue with your Point-to-Site configuration.

有关 P2S 故障排除信息,请参阅排查 Azure 点到站点连接问题For P2S troubleshooting information, Troubleshooting Azure point-to-site connections.