> ## Documentation Index
> Fetch the complete documentation index at: https://docs.futurex.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Renew or replace the certificate

> Renew or replace the certificate on an existing CryptoHub key pair with a certificate signing request (CSR) from that key, without changing JSign.

Use this procedure to put a CA-signed certificate on the key pair you generated in [Generate a code signing key pair](https://docs.futurex.com/Integrations/CryptoHub/Code_signing/JSign/Generate_a_code_signing_key_pair.md), or to renew that certificate before it expires. You generate a certificate signing request (CSR) from the existing private key, have your certificate authority (CA) sign it, and import the signed certificate back to the same alias. The private key never leaves the CryptoHub, and the alias does not change, so JSign needs no configuration change.

> [!NOTE]
>
> Renewing the certificate on the same key pair is supported. Generate a new key pair instead when your key-rotation policy requires it or when your CA no longer accepts the key size. For example, CAs that issue publicly trusted code signing certificates require RSA 3072 or larger.

## Before you begin

* The key pair exists on the CryptoHub, and `keytool -list` shows it as a `PrivateKeyEntry`.
* `FXPKCS11_CFG` points to your `fxpkcs11.cfg` in the shell where you run **keytool**, as described in [Install and configure Futurex PKCS #11](https://docs.futurex.com/Integrations/CryptoHub/Code_signing/JSign/Install_and_configure_Futurex_PKCS_11.md).
* You have the signed certificate chain from your CA, or you can obtain it: the signed certificate plus every intermediate and root CA certificate.

## Back up the current certificate

**Step 1**

List the entries on the token and copy the exact alias of the key pair:

```shell expandable lines wrap title="Shell" theme={null}
keytool -list -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg /usr/local/etc/pkcs11.cfg -providerName SunPKCS11-Futurex
```

> [!TIP]
>
> The entry shows as `PrivateKeyEntry`, with an alias in the form `<alias>-<id>:<alias>` (for example, `jsign-demo-1785267399:jsign-demo`).

**Step 2**

Export the current certificate. Keep it, together with the CA chain it was issued with, so you can restore it if you need to:

```shell expandable lines wrap title="Shell" theme={null}
keytool -exportcert -rfc -alias "jsign-demo-1785267399:jsign-demo" -file current-cert.pem -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg /usr/local/etc/pkcs11.cfg -providerName SunPKCS11-Futurex
```

> [!TIP]
>
> `current-cert.pem` contains one PEM certificate.

> [!NOTE]
>
> When **keytool** prompts for the key store password, enter the CryptoHub identity password (PKCS #11 PIN) from the `<CRYPTO-OPR-PASS>` tag in `fxpkcs11.cfg`.

## Generate a CSR from the existing key

Run the following command with the exact alias you copied. The CryptoHub signs the CSR with the existing private key; no new key is created:

```shell expandable lines wrap title="Shell" theme={null}
keytool -certreq -alias "jsign-demo-1785267399:jsign-demo" -sigalg SHA256withRSA -file renew.csr -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg /usr/local/etc/pkcs11.cfg -providerName SunPKCS11-Futurex
```

> [!TIP]
>
> `openssl req -in renew.csr -noout -verify -subject` reports `Certificate request self-signature verify OK` and shows the subject of the current certificate.

Submit `renew.csr` to your CA. Request the signed certificate together with its full chain, as a PKCS #7 file (`.p7b`) or as one PEM file that holds the signed certificate followed by each intermediate and root CA certificate.

## Import the signed certificate

> [!WARNING]
>
> Import the full chain. If the file contains only the signed certificate, **keytool** cannot build the chain and stops with `Failed to establish chain from reply`. The certificate on the CryptoHub does not change when this happens.

**Step 1**

Import the CA response to the same alias:

```shell expandable lines wrap title="Shell" theme={null}
keytool -importcert -alias "jsign-demo-1785267399:jsign-demo" -file signed-chain.pem -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg /usr/local/etc/pkcs11.cfg -providerName SunPKCS11-Futurex
```

> [!TIP]
>
> **keytool** prints `Certificate reply was installed in keystore`. If **keytool** asks whether to install a reply from a CA it does not trust, confirm that the root certificate in the file belongs to your CA, and then enter `yes`.

**Step 2**

Confirm the result:

```shell expandable lines wrap title="Shell" theme={null}
keytool -list -v -alias "jsign-demo-1785267399:jsign-demo" -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg /usr/local/etc/pkcs11.cfg -providerName SunPKCS11-Futurex
```

> [!TIP]
>
> The entry keeps the same alias and is still a `PrivateKeyEntry`. The first certificate in the chain shows the new serial number, validity dates, and your CA as the issuer. The token holds one certificate for the alias: the import replaces the previous certificate rather than adding a second one.

## Restart JSign

Start every new JSign run after the import. A signing job or build agent that loaded the PKCS #11 key store before the import keeps the old certificate until it restarts, so restart any long-running build agent that hosts JSign.

## Verify it works

Sign a test artifact as shown in [JSign command examples](https://docs.futurex.com/Integrations/CryptoHub/Code_signing/JSign/JSign_command_examples.md), then confirm that the embedded signer certificate shows the new serial number and expiration date.

## Troubleshooting

| Symptom | Cause and solution |
| - | - |
| `keytool error: java.lang.Exception: Failed to establish chain from reply` | The file holds only the signed certificate. Build a file that contains the signed certificate followed by each intermediate and root CA certificate, or use the CA's PKCS #7 file, and run the import again. |
| `keytool -list -v` shows the new certificate, but JSign still presents the old one | The process loaded the key store before the import. Restart it. |
| `Alias <name> does not exist` | The command uses the short `-alias` value from key generation. Copy the full `<alias>-<id>:<alias>` value from `keytool -list`. |

To roll back, import the previous certificate and its full CA chain to the same alias with the same `keytool -importcert` command, and then restart JSign.

> [!NOTE]
>
> The CSR command uses `SHA256withRSA` for the RSA key pairs this guide generates. Futurex validated this procedure on CryptoHub 7.0.3.x with Futurex PKCS #11 (FXPKCS11) 6.0 rev dc27 and 6.5, OpenJDK 21, and an RSA 3072 key pair.
