Generate and export certificates for User VPN P2S connections: PowerShell - Azure Virtual WAN (2024)

  • Article

User VPN (point-to-site) configurations can be configured to require certificates to authenticate. This article shows you how to create a self-signed root certificate and generate client certificates using PowerShell on Windows 10 (or later) or Windows Server 2016 (or later).

The PowerShell cmdlets that you use to generate certificates are part of the operating system and don't work on other versions of Windows. The host operating system is only used to generate the certificates. Once the certificates are generated, you can upload them or install them on any supported client operating system.

If you don't have a computer that meets the operating system requirement, you can use MakeCert to generate certificates. The certificates that you generate using either method can be installed on any supported client operating system.

Create a self-signed root certificate

Use the New-SelfSignedCertificate cmdlet to create a self-signed root certificate. For additional parameter information, see New-SelfSignedCertificate.

  1. From a computer running Windows 10 or later, or Windows Server 2016, open a Windows PowerShell console with elevated privileges.

  2. Create a self-signed root certificate. The following example creates a self-signed root certificate named 'P2SRootCert' that's automatically installed in 'Certificates-Current User\Personal\Certificates'. You can view the certificate by opening certmgr.msc, or Manage User Certificates.

    Make any needed modifications before using this sample. The 'NotAfter' parameter is optional. By default, without this parameter, the certificate expires in 1 year.

    $params = @{ Type = 'Custom' Subject = 'CN=P2SRootCert' KeySpec = 'Signature' KeyExportPolicy = 'Exportable' KeyUsage = 'CertSign' KeyUsageProperty = 'Sign' KeyLength = 2048 HashAlgorithm = 'sha256' NotAfter = (Get-Date).AddMonths(24) CertStoreLocation = 'Cert:\CurrentUser\My'}$cert = New-SelfSignedCertificate @params
  3. Leave the PowerShell console open and proceed with the next steps to generate a client certificate.

Generate a client certificate

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 isn't 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, export the certificate.

The examples use the New-SelfSignedCertificate cmdlet to generate a client certificate.

Example 1 - PowerShell console session still open

Use this example if you haven't closed your PowerShell console after creating the self-signed root certificate. This example continues from the previous section and uses the declared '$cert' variable. If you closed the PowerShell console after creating the self-signed root certificate, or are creating additional client certificates in a new PowerShell console session, use the steps in Example 2.

Modify and run the example to generate a client certificate. If you run the following example without modifying it, the result is a client certificate named 'P2SChildCert'. If you want to name the child certificate something else, modify the CN value. Don't change the TextExtension when running this example. The client certificate that you generate is automatically installed in 'Certificates - Current User\Personal\Certificates' on your computer.

 $params = @{ Type = 'Custom' Subject = 'CN=P2SChildCert' DnsName = 'P2SChildCert' KeySpec = 'Signature' KeyExportPolicy = 'Exportable' KeyLength = 2048 HashAlgorithm = 'sha256' NotAfter = (Get-Date).AddMonths(18) CertStoreLocation = 'Cert:\CurrentUser\My' Signer = $cert TextExtension = @( '2.5.29.37={text}1.3.6.1.5.5.7.3.2') } New-SelfSignedCertificate @params

Example 2 - New PowerShell console session

If you're creating additional client certificates, or aren't using the same PowerShell session that you used to create your self-signed root certificate, use the following steps:

  1. Identify the self-signed root certificate that is installed on the computer. This cmdlet returns a list of certificates that are installed on your computer.

    Get-ChildItem -Path "Cert:\CurrentUser\My"
  2. Locate the subject name from the returned list, then copy the thumbprint that is located next to it to a text file. In the following example, there are two certificates. The CN name is the name of the self-signed root certificate from which you want to generate a child certificate. In this case, 'P2SRootCert'.

    Thumbprint Subject---------- -------AED812AD883826FF76B4D1D5A77B3C08EFA79F3F CN=P2SChildCert47181AA8C1B4D34EEDB2F3D3BEC5839F3FE52D655 CN=P2SRootCert
  3. Declare a variable for the root certificate using the thumbprint from the previous step. Replace THUMBPRINT with the thumbprint of the root certificate from which you want to generate a child certificate.

    $cert = Get-ChildItem -Path "Cert:\CurrentUser\My\<THUMBPRINT>"

    For example, using the thumbprint for P2SRootCert in the previous step, the variable looks like this:

    $cert = Get-ChildItem -Path "Cert:\CurrentUser\My\7181AA8C1B4D34EEDB2F3D3BEC5839F3FE52D655"
  4. Modify and run the example to generate a client certificate. If you run the following example without modifying it, the result is a client certificate named 'P2SChildCert'. If you want to name the child certificate something else, modify the CN value. Don't change the TextExtension when running this example. The client certificate that you generate is automatically installed in 'Certificates - Current User\Personal\Certificates' on your computer.

    $params = @{ Type = 'Custom' Subject = 'CN=P2SChildCert' DnsName = 'P2SChildCert1' KeySpec = 'Signature' KeyExportPolicy = 'Exportable' KeyLength = 2048 HashAlgorithm = 'sha256' NotAfter = (Get-Date).AddMonths(18) CertStoreLocation = 'Cert:\CurrentUser\My' Signer = $cert TextExtension = @( '2.5.29.37={text}1.3.6.1.5.5.7.3.2')}New-SelfSignedCertificate @params

Export the root certificate public key (.cer)

After you create a self-signed root certificate, export the root certificate .cer file (not the private key). You'll later upload the necessary certificate data contained in the file to Azure. The following steps help you export the .cer file for your self-signed root certificate and retrieve the necessary certificate data.

  1. To get the certificate .cer file, open Manage user certificates.

    Locate the self-signed root certificate, typically in "Certificates - Current User\Personal\Certificates", and right-click. Click All Tasks -> Export. This opens the Certificate Export Wizard.

    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".

  2. In the wizard, click Next.

  3. Select No, do not export the private key, and then click Next.

  4. On the Export File Format page, select Base-64 encoded X.509 (.CER)., and then click Next.

  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. You'll see a confirmation saying "The export was successful".

  8. Go to the location where you exported the certificate and open it using a text editor, such as Notepad. If you exported the certificate in the required Base-64 encoded X.509 (.CER) format, you'll see text similar to the following example. The section highlighted in blue contains the information that you copy and upload to Azure.

    If your file doesn't look similar to the example, typically that means you didn't export it using the Base-64 encoded X.509(.CER) format. Additionally, if you use a text editor other than Notepad, understand that some editors can introduce unintended formatting in the background. This can create problems when uploaded the text from this certificate to Azure.

Export the self-signed root certificate and private key to store it (optional)

You may want to export the self-signed root certificate and store it safely as backup. If need be, you can later install it on another computer and generate more client certificates. 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.

Export the 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 first export the client certificate.

  1. To export a client certificate, open Manage user 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.

  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

Each client that connects over a P2S connection requires a client certificate to be installed locally. For steps to install a certificate, see Install client certificates.

Next steps

Continue with the Virtual WAN steps for user VPN connections.

Generate and export certificates for User VPN P2S connections: PowerShell - Azure Virtual WAN (2024)

FAQs

How to generate a P2S certificate? ›

Login to Azure portal, navigate to Virtual Network Gateways page, and select the P2S gateway. Select the “Point-to-site configuration” in P2S gateway settings blade. The uploaded certificate will be displayed here. Click “Download VPN client” to download & install the VPN client.

How to export a VPN certificate? ›

Right-click the client certificate that you want to export, click all tasks, and then click Export to open the Certificate Export Wizard. In the Certificate Export Wizard, click Next to continue. Select Yes, export the private key, and then click Next. On the Export File Format page, leave the defaults selected.

How do I create a certificate in Azure PowerShell? ›

The certificate may be self-signed if required. A simple method to create the certificate is via PowerShell 'New-SelfSignedCertificate' cmdlet (see later). Add the certificate to the application by going to the overview page and clicking on 'Add certificate or secret' and uploading the . cer file.

How do I create a P2S VPN in Azure? ›

Go to “Virtual network gateways” in the Azure portal. Click on “Add” to create a new virtual network gateway. Provide the necessary details such as gateway type, VPN type, SKU, and virtual network settings. Select the same resource group created in Step 2.

How to create a certificate with PowerShell? ›

Creating self-signed SSL certificates
  1. Open the PowerShell Console in admin mode.
  2. Use the cmdlet New-SelfSignedCertificate to create a self-signed certificate. Copy Code. Code. New-SelfSignedCertificate -DnsName "server.domain.test" -CertStoreLocation "cert:\LocalMachine\My"
  3. Optional: Copy the thumbprint for later use.
Jun 14, 2023

How do I export a self-signed certificate from PowerShell? ›

Export Self-signed Certificate using PowerShell

To export the certificate from certificate store to file, run the 'Export-Certificate' cmdlet. The $Certificate variable in the previous command stores your certificate in the current session and allows you to export it.

How do I Export a user certificate? ›

In Windows Start, type 'Run' –> type 'mmc', and click on 'OK' to open the MMC console.
  1. Add/Remove Snap-in. ...
  2. Add Certificate Snap-in. ...
  3. Add Computer Account to Export Computer Certificate. ...
  4. Select the Computer You Want to Export the Certificate From. ...
  5. Select the Certificate You Want to Export. ...
  6. Export the Certificate.
Sep 15, 2022

Where can I get a VPN certificate? ›

Right-click the VPN Gateway element and select Tools > Generate Certificate. In the Generate Certificate dialog box, enter the certificate information. Select the Public Key Algorithm according to the requirements of your organization. Note: The Public Key Algorithm can be different from the internal CA type.

How to Export VPN certificate windows 10? ›

Export using IIS
  1. Go to Start >> Administrative Tools >> Internet Information Services (IIS) Manager.
  2. Select the server on which the certificate is installed.
  3. Choose the Server Certificates option on the central menu:
  4. Right-click on the needed certificate and select Export.

How do I get all Certificates in PowerShell? ›

Handy Certificate PowerShell Commands
  1. Get-ChildItem -path cert:\LocalMachine\My – This will show you all certificates in the Local Machines Personal Store.
  2. Get-ChildItem -path “Thumbprint” -recurse – This will search all certificate stores for the thumbprint you specified.
Apr 12, 2018

How to generate a certificate? ›

Create an SSL Certificate in 5 Easy Steps
  1. Step 1: Generate the CSR for the SSL Certificate. ...
  2. Step 2: Purchase an SSL Certificate from the Desired Vendor. ...
  3. Step 3: Configure and Verify the SSL. ...
  4. Step 4: Complete Verification. ...
  5. Step 5: Download the SSL Certificate.
Sep 1, 2022

How do I Create a certificate in Azure? ›

In the Azure portal, from the left menu, select App Services > <app-name>. On your app's navigation menu, select Certificates. In the Managed certificates pane, select Add certificate. Select the custom domain for the free certificate, and then select Validate.

How to connect with P2S VPN? ›

Steps to establish P2S VPN Connection:-
  1. Create a virtual network from the Azure portal with default configurations. ...
  2. Under the Basic category, select a subscription type, choose an existing resource group or create a new one, assign a name to the virtual network, and select a region where the VNET would be deployed.
Apr 3, 2023

What is P2S VPN in Azure? ›

A Point-to-Site (P2S) VPN gateway connection lets you create a secure connection to your virtual network from an individual client computer. A P2S connection is established by starting it from the client computer.

How to generate a client authentication certificate? ›

Create a client certificate (CLI)
  1. Generate a key pair. openssl genrsa -out device_cert_key_filename.key 2048.
  2. Create a CSR for the client certificate. openssl req -new \ -key device_cert_key_filename.key \ -out device_cert_csr_filename.csr. ...
  3. Create a client certificate from the CSR.

How to generate a self-signed certificate? ›

Generation of a self-signed SSL certificate involves a simple 3-step procedure:
  1. STEP 1: Create the server private key.
  2. STEP 2: Create the certificate signing request (CSR)
  3. STEP 3: Sign the certificate using the private key and CSR.

How do I create a self signed certificate p12? ›

Procedure
  1. Open the openssl command line to create and initialize a new PKCS12 key store.
  2. Create a new self-signed certificate: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj /CN=MyHost.com.
  3. Create a PKCS12 file :

How do I create a self-signed intermediate certificate? ›

Create Intermediate CA Certificates
  1. Create an OpenSSL configuration file called ca_intermediate. ...
  2. Generate the private key using a strong encryption algorithm such as 4096-bit AES256. ...
  3. Create a signing request. ...
  4. Sign the intermediate signing request with the root CA certificate.

Top Articles
Latest Posts
Article information

Author: Jamar Nader

Last Updated:

Views: 6388

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Jamar Nader

Birthday: 1995-02-28

Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

Phone: +9958384818317

Job: IT Representative

Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.