PKI Proxy - Signing Files with Azure Key Vault
Requirements: PKI Proxy
Contents
Introduction
PKI Proxy is a secure key server which enables remote code and document signing using centrally stored keys. It can share certificates stored in a variety of locations and formats, such as PFX files, the Windows certificate store, and hardware tokens.
This article is a guide for signing files using certificates stored in Azure Key Vault. PKI Proxy connects to the vault on behalf of your users, and each signing or decryption operation is performed by Azure Key Vault itself, so the certificate's private key never leaves the vault. Client machines connect to PKI Proxy using the PKCS#11 driver, the Windows Key Storage Provider (KSP), the command line tools, or the Web API, exactly as they would for any other shared certificate. They do not need Azure credentials or network access to Azure.
This article explains how to prepare Azure and PKI Proxy, share a certificate from the vault, and keep the connection authorized. For general information about installing and configuring PKI Proxy, see Getting Started with PKI Proxy.
Preparing Azure
PKI Proxy connects to Azure Key Vault using OAuth 2.0, signing in as an Azure user through your own Microsoft Entra ID app registration. Before sharing a certificate, set up the following in the Azure portal.
Register an Application
In Microsoft Entra ID, go to App registrations and create a new registration:
- Add the Mobile and desktop applications platform with the redirect URI http://localhost. PKI Proxy receives the sign-in response on a local port, and Azure allows any port for localhost redirect URIs on this platform.
- Under API permissions, add the Azure Key Vault delegated permission user_impersonation. Grant admin consent if your organization requires it.
- Note the Application (client) ID and the Directory (tenant) ID. You will need both in PKI Proxy.
If your app registration requires a client secret, create one under Certificates & secrets and note its value.
Create a Key Vault
If you do not already have a key vault, create one in the Azure portal:
- Search for Key vaults and click Create.
- On the Basics tab, select the subscription and resource group, and enter a name for the vault. The name must be globally unique, 3 to 24 characters long, and contain only letters, digits and hyphens. This is the name you will enter in PKI Proxy.
- Select the region and pricing tier. The Standard tier is sufficient for certificates with software-protected keys. The Premium tier is needed for certificates with HSM-protected keys.
- On the Access configuration tab, select the permission model: Azure role-based access control (recommended) or Vault access policy. This determines how access is granted in the next step.
- Click Review + create, then Create.
With Azure role-based access control, creating the vault does not give you permission to manage its certificates. To create or import certificates in the vault, assign yourself a role such as Key Vault Administrator or Key Vault Certificates Officer on the vault.
Grant Access to the Vault
The Azure user that PKI Proxy signs in as must be allowed to read the certificates in the vault and use their keys. Depending on how the vault is configured, either assign Azure roles such as Key Vault Certificate User and Key Vault Crypto User (for vaults using Azure role-based access control), or add an access policy that grants the List and Get certificate permissions, and the List, Get, Sign, Verify, Decrypt and Encrypt key permissions.
Add a Certificate
Create or import the certificate in the vault if it does not already exist. In the Azure portal, open your key vault, go to Objects > Certificates, and click Generate/Import. PKI Proxy shares existing certificates, and does not create new certificates in the vault.
Note: If you plan to use SignTool for code signing, the certificate must have the Code Signing EKU (1.3.6.1.5.5.7.3.3). Azure Key Vault will not include that EKU by default, so if you are creating a new certificate, use "Advanced Policy Configuration" and add "1.3.6.1.5.5.7.3.3" to the list of EKUs.
Certificates with both RSA and EC keys are supported.
Preparing PKI Proxy
The PKI Proxy application controls which certificates are shared, and which users have access to them. Run the PKI Proxy application by following the links in the start menu, or by running PKIProxy.exe from the installation directory.
The Settings tab contains settings for the server itself. You can enable or disable TLS, generate or select a TLS certificate, and choose which port the server will use. If TLS is enabled, note the fingerprint of the TLS certificate, as client systems will need it to trust the server.

Create a User
Users must authenticate to PKI Proxy in order to perform any operations with the shared certificates. These are PKI Proxy users, and are separate from the Azure user that PKI Proxy signs in as. To create a user, go to the Users tab and click New.... Each user can be assigned one of the following authentication methods:
| Secret Key | A pre-shared secret key is used along with the specified user. Each request and response is individually authenticated using a signature scheme. |
| HTTP Basic | Standard HTTP Basic authentication is performed using the defined user and password. |
| HTTP NTLM | HTTP NTLM authentication is performed. When adding a user in the PKI Proxy application choose the current Windows user, or select another existing user. |

You can also create a user later, while sharing the certificate.
Add a Certificate from Azure Key Vault
- In the PKI Proxy application, go to the Certificates tab and click New....
- Click Select Certificate or Key..., then select the Azure Key Vault tab.
- Enter the name of your key vault. This is the short name of the vault (for instance MyVault), not its full URL.
- Click Authenticate. The Azure OAuth2 Settings dialog will open.
- Enter the Client ID and Tenant from your app registration, and the Client Secret if your app registration requires one. The authentication and token URLs are filled in automatically from the tenant.
- Click Test Connection.... Your browser will open so you can sign in to Azure and approve PKI Proxy's access to the vault. When sign-in completes, the access and refresh tokens are filled in. Click OK.
- The certificates in the vault are listed in the Certificates and Keys list. Select the one you want to share and click OK.
- Enter an alias for the shared certificate, configure access for your users, and click OK.
The alias used in PKI Proxy is independent of the name of the certificate in Azure Key Vault, and does not need to match it.
The Expert Mode button in the Azure OAuth2 Settings dialog allows you to view and change the scope, authentication URL, token URL, local web port and tokens. The default values work for most setups.
PKI Proxy connects to Azure Key Vault using OAuth 2.0 user sign-in only. Other Azure authentication methods, such as managed identities or client certificates, are not supported.
Keeping the Connection Authorized
PKI Proxy stores the OAuth tokens it receives with the shared certificate, and uses them each time it connects to the vault:
- If the access token has expired, PKI Proxy uses the refresh token to obtain a new access token automatically.
- When Azure issues new tokens, PKI Proxy saves them, so the service keeps working after restarts without anyone signing in again.
If the refresh token expires or is revoked (for instance, if the user's password changes, or the user's sessions are revoked in Azure), PKI Proxy can no longer connect to the vault, and operations with the shared certificate will fail. To fix this, open the shared certificate with Edit..., click Reauthenticate, and sign in again.
Since the stored tokens grant access to the vault, protect the PKI Proxy configuration in the same way as other credentials, and use a dedicated Azure account with access limited to the certificates you want to share.
Share the Certificate with a User
Only the users which have been allowed access to a shared certificate may perform operations with it. When adding the certificate, click the Add button in the Allowed Users section and select the user from the list, or select Create New User ... to create one. To change which users have access later, select the shared certificate on the Certificates tab and click Edit....

Finally, click the Start button to start the server and begin sharing the certificate.
To check that the certificate is available, you can list the shared objects with pkptool from the tools directory of the PKI Proxy installation. Adjust the -l, -u and -p parameters to match your PKI Proxy server and user:
pkptool list -l http://127.0.0.1:9266 -u user -p password
To keep the certificate available without the PKI Proxy application open, enable Run as a system service and Run at system startup at the bottom of the Settings tab. See Startup Settings for details.
Setting up the Client System
Client machines access the shared certificate through PKI Proxy, not Azure, so they only need network access to the PKI Proxy server. Requests can be made to PKI Proxy using the included PKCS#11 driver, by configuring the Windows Key Storage Provider (KSP), by utilizing the included command line tools, or by making requests directly via the Web API. This article uses the KSP, which lets Windows applications such as Microsoft SignTool use the certificate as if it were installed locally. For information about the PKCS#11 driver, see Getting Started with PKI Proxy.
Install PKI Proxy on the client machine to get the KSP module and the client tools.
Set up the KSP
The KSP module is installed during the setup process. After installation the PKIProxyKSP.dll library should be present in both C:\Windows\System32 and C:\Windows\SysWOW64.
Certificates shared by PKI Proxy are not exposed automatically by the KSP. To add the certificate to the Windows certificate store:
- Run PKIProxyCertMgr.exe from the installation directory of PKI Proxy, and click Add.
- In the Location field, enter the URL of the PKI Proxy server, including the port. If TLS is enabled, the URL should begin with "https://", for instance https://pkiproxy.example.com:9266.
- Select the Authentication mechanism and enter the credentials of the PKI Proxy user that the certificate was shared with. When using HTTP NTLM authentication the current user credentials are used automatically.
- If TLS is enabled, enter the fingerprint of PKI Proxy's TLS certificate in the TLS Fingerprints field. This value is shown on the Settings tab of the PKI Proxy application.
- Optionally, set an Access PIN. Any application using the certificate on the client machine will then need to provide this PIN.
- Click Test Connection to confirm that the client can communicate with PKI Proxy, then click OK.

The certificate shared by PKI Proxy should now be visible in the Current User's "Personal" certificate store in Windows. For more information about the options in this dialog, see Getting Started with PKI Proxy.
Signing a File
With the certificate added through the KSP, Microsoft SignTool can use it in the same way as any other certificate in the Windows certificate store. Specify the certificate by its SHA1 fingerprint using the /sha1 parameter:
signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /sha1 2170a80c36fcafe9b0a2f5ce150ccdd496c7203d program.exe
In the command above, replace the hex string with the SHA1 fingerprint of your certificate. The fingerprint is shown in the PKI Proxy Certificate Manager, and in the certificate's details in the Windows certificate store. The /tr and /td parameters add a timestamp, and are optional.
PKI Proxy forwards the signing request to Azure Key Vault, which performs the signing operation with the certificate's private key. SignTool should output the result of the signing operation:
Done Adding Additional Store
Successfully signed: program.exe
The signature can be verified by right-clicking the file in Windows Explorer, selecting Properties, and inspecting the Digital Signatures tab, or by running signtool verify /pa program.exe.
If you prefer not to use the KSP, PKI Proxy also includes pkpsigntool, a drop-in replacement for SignTool that uses the PKCS#11 driver. See SignTool (Authenticode) for details.
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.