KRATool Examples - dogtagpki/pki GitHub Wiki

KRATool Cross-Scheme Migration Guide

Table of Contents

1. Overview

This guide demonstrates how to use KRATool to migrate archived keys between PKI Key Recovery Authority (KRA) instances, including cross-scheme cryptographic migration scenarios.

1.1. What is Cross-Scheme Migration?

Cross-scheme migration allows you to change cryptographic algorithms during key migration:

  • RSA wrapping algorithms: Migrate from RSA PKCS#1 v1.5 to RSA-OAEP (or vice versa)

  • Payload wrapping algorithms: Migrate from AES/CBC to AES KeyWrap (or vice versa)

  • Key sizes: Change session key sizes (e.g., 128-bit to 256-bit AES)

  • Session key regeneration: Optionally regenerate session keys during migration

1.2. Use Cases

  • Security upgrades: Migrate to stronger algorithms (RSA-OAEP, AES-256)

  • HSM compatibility: Adapt to different HSM capabilities on source and target

  • Compliance requirements: Meet new cryptographic standards

  • Hardware migration: Move keys between different HSM vendors with different algorithm support

2. Prerequisites

2.1. Software Requirements

  • PKI KRA 10.13+ or 11.6+ with cross-scheme support

  • KRATool standalone package installed

  • Source KRA with archived keys

  • Target KRA instance configured

2.2. Knowledge Requirements

  • Basic understanding of PKI KRA operations

  • Familiarity with NSS databases and certificate management

  • Understanding of wrapped key cryptography concepts

3. Migration Scenarios

This guide covers four common migration scenarios:

  1. Software Token Migration (NSS DB to NSS DB): Testing and development

  2. HSM-to-HSM Migration: Production key migration between hardware security modules

  3. Algorithm Migration: Changing cryptographic algorithms during migration

  4. TPS/TMS Key Migration and External Registration Recovery: Migrating TPS-generated smart card keys and testing recovery

4. Scenario 1: Software Token Migration (NSS DB to NSS DB)

This scenario demonstrates migration using NSS databases on a single system, ideal for testing and understanding the migration process.

4.1. Environment Setup

Source KRA:

  • NSS database: ~/migration/source

  • Storage certificate nickname: test KRA Storage Certificate

  • Token: Internal Key Storage Token

Target KRA:

  • Storage certificate: ~/migration/target/kra_storage.pem

  • NSS database for testing: ~/migration/target

4.2. Step 1: Export Source KRA Keys to LDIF

First, stop the source KRA instance to ensure data consistency:

sudo systemctl stop [email protected]

Export the KRA data from the Directory Server:

# Create output directory
mkdir -p ~/migration/source

# Export using Directory Server native tools (recommended for production)

# RHEL 9+ (389 DS 2.x):
sudo dsconf localhost backend export kra \
    /var/lib/dirsrv/slapd-localhost/ldif/kra-keys-export.ldif

# RHEL 8 (389 DS 1.4):
sudo db2ldif.pl -Z localhost -n kra \
    -a /var/lib/dirsrv/slapd-localhost/ldif/kra-keys-export.ldif

# Copy to working directory
sudo cp /var/lib/dirsrv/slapd-localhost/ldif/kra-keys-export.ldif ~/migration/source/
sudo chown $(whoami):$(whoami) ~/migration/source/kra-keys-export.ldif
Tip
For testing or exporting specific keys only, you can use ldapsearch:
ldapsearch -LLL -x -H ldap://localhost:3389 \
    -D "cn=Directory Manager" -w "password" \
    -b "ou=keyRepository,ou=kra,dc=kra,dc=pki-tomcat,dc=example,dc=com" \
    -o ldif_wrap=no \
    > ~/migration/source/kra-keys-export.ldif
Tip
For production systems exporting the entire KRA backend, use db2ldif.pl or dsconf:
# RHEL 8 (389 DS 1.4)
sudo db2ldif.pl -Z instance_name -n kra-db \
    -a /var/lib/dirsrv/slapd-instance_name/ldif/kra-export.ldif

# RHEL 9+ (389 DS 2.x)
sudo dsconf localhost backend export kra-db \
    /var/lib/dirsrv/slapd-localhost/ldif/kra-export.ldif

4.3. Step 2: Create KRATool Configuration File

The KRATool configuration file specifies which LDIF fields to process during migration. Copy the standard configuration file from the PKI installation:

cp /usr/share/pki/tools/KRATool.cfg ~/migration/kratool.cfg

Alternatively, create ~/migration/kratool.cfg with the content shown in KRATool Configuration File Reference.

Note
The privateKeyData fields in caKeyRecord and tpsKeyRecord sections are essential for rewrapping archived keys.

4.4. Step 3: Extract Target Storage Certificate

The target storage certificate’s public key is used to wrap session keys for the target KRA:

# If target is also NSS DB (for testing)
certutil -L -d ~/migration/target \
    -n "test KRA Storage Certificate" -a > ~/migration/target/kra_storage.pem

# If target is production KRA
# Extract from target KRA's certificate file
cp /var/lib/pki/pki-tomcat/kra/alias/kra_storage.cert \
    ~/migration/target/kra_storage.pem

4.5. Step 4: Run KRATool - Basic Same-Algorithm Migration

This example demonstrates migration without changing algorithms:

KRATool \
    -use_cross_scheme \
    -kratool_config_file ~/migration/kratool.cfg \
    -source_ldif_file ~/migration/source/kra-archived-keys.ldif \
    -target_ldif_file ~/migration/target/kra-archived-keys-target.ldif \
    -log_file ~/migration/KRATool.log \
    -source_pki_security_database_path ~/migration/source \
    -source_storage_token_name "Internal Key Storage Token" \
    -source_storage_certificate_nickname "test KRA Storage Certificate" \
    -target_storage_certificate_file ~/migration/target/kra_storage.pem \
    -source_pki_security_database_pwdfile ~/migration/source/passwd \
    -source_kra_naming_context "pki-tomcat-KRA" \
    -target_kra_naming_context "pki-tomcat-target-KRA" \
    -verbose
Important
Naming Context Parameters:

The -source_kra_naming_context and -target_kra_naming_context parameters specify the LDAP organizational context for the source and target KRA instances.

  • Find your KRA naming context with: ldapsearch -LLL -x -H ldap://localhost:3389 -D "cn=Directory Manager" -w "password" -b "" -s base namingContexts

  • Common format: o=<instance-name>-<subsystem> (e.g., o=pki-tomcat-KRA, o=topology-02-KRA-KRA)

  • Optional but strongly recommended: If not specified, KRATool copies the source naming context to the target LDIF, which will cause DN mismatches if the source and target KRAs have different naming contexts

  • Required when: Migrating between KRA instances with different naming contexts in the same or different LDAP directories

Expected output:

BEGIN "KRATool -use_cross_scheme ..."

PROCESSING KRATOOL CONFIG FILE: ................................... FINISHED.

SUCCESSFULLY processed kratool config file!

Initializing source PKI security databases in '~/migration/source'.

Retrieving source storage token called 'Internal Key Storage Token'.

Retrieving source storage cert with nickname of 'Internal Key Storage Token:test KRA Storage Certificate'.

BEGIN: Obtaining the private key from the source storage token . . .

FINISHED: Obtaining the private key from the source storage token.

BEGIN: Obtaining the public key from the target storage certificate . . .

FINISHED: Obtaining the public key from the target storage certificate.

PROCESSING: ........................... FINISHED.

SUCCESSFULLY converted source LDIF file --> target LDIF file!

Summary: 60 key record(s) processed successfully, 0 failed.

Target LDIF file: ~/migration/target/kra-archived-keys-target.ldif
Debug log file:   ~/migration/KRATool.log
Note
If RSA or payload wrap algorithms are not explicitly specified via command-line parameters, KRATool will use default values. Run KRATool --help to find defaults or run with -verbose to see which algorithms are being used.

4.6. Step 5: Run KRATool - Algorithm Migration with Session Key Regeneration

This example demonstrates changing algorithms and session key size:

KRATool \
    -use_cross_scheme \
    -kratool_config_file ~/migration/kratool.cfg \
    -source_ldif_file ~/migration/source/kra-archived-keys.ldif \
    -target_ldif_file ~/migration/target/kra-keys-upgraded.ldif \
    -log_file ~/migration/KRATool-upgrade.log \
    -source_pki_security_database_path ~/migration/source \
    -source_storage_token_name "Internal Key Storage Token" \
    -source_storage_certificate_nickname "test KRA Storage Certificate" \
    -target_storage_certificate_file ~/migration/target/kra_storage.pem \
    -source_pki_security_database_pwdfile ~/migration/source/passwd \
    -source_rsa_wrap_algorithm RSA \
    -target_rsa_wrap_algorithm RSA-OAEP \
    -source_payload_wrap_algorithm "AES/CBC/PKCS5Padding" \
    -target_payload_wrap_algorithm "AES KeyWrap/Wrapped" \
    -source_payload_wrap_keysize 128 \
    -target_payload_wrap_keysize 256 \
    -regenerate_session_key \
    -source_kra_naming_context "pki-tomcat-KRA" \
    -target_kra_naming_context "pki-tomcat-target-KRA" \
    -verbose
Important
Algorithm Migration Notes:
  • RSA to RSA-OAEP: More secure padding scheme

  • AES/CBC to AES KeyWrap: NIST-recommended key wrapping

  • 128-bit to 256-bit: Larger session keys for enhanced security

  • -regenerate_session_key: Forces regeneration without prompting

4.7. Step 6: Verify Migration Results

Review the log file to ensure all keys were processed successfully:

# Check summary
tail -20 ~/migration/KRATool.log

# Count successful vs failed records
grep "Successfully" ~/migration/KRATool.log

Expected log entries:

[2026-03-19 14:30:15]:  Successfully converted source LDIF file --> target LDIF file!
[2026-03-19 14:30:15]:
[2026-03-19 14:30:15]:  Summary: 60 key record(s) processed successfully, 0 failed.
[2026-03-19 14:30:15]:
[2026-03-19 14:30:15]:  Target LDIF file: ~/migration/target/kra-keys-upgraded.ldif
[2026-03-19 14:30:15]:  Debug log file:   ~/migration/KRATool.log

4.8. Step 7: Import Target LDIF to Target KRA

Prepare the LDIF for import by removing the repository organizational entry:

# Remove organizational entry (first 7 lines) from KRATool output
tail -n +8 ~/migration/target/kra-keys-upgraded.ldif > ~/migration/target/kra-keys-only.ldif

Import the migrated keys into the target KRA using ldapmodify:

# Import keys to target KRA (KRA must be running)
ldapmodify -x -H ldap://localhost:3389 \
    -D "cn=Directory Manager" -w "password" \
    -a -f ~/migration/target/kra-keys-only.ldif

Verify the import:

# Check that all keys imported successfully
ldapsearch -LLL -x -H ldap://localhost:3389 \
    -D "cn=Directory Manager" -w "password" \
    -b "ou=keyRepository,ou=kra,o=<target-kra-naming-context>" \
    "(cn=*)" dn | grep "^dn:" | wc -l
Tip
For complete backend replacement (not recommended for key migration), use ldif2db.pl or dsconf backend import instead. The ldapmodify approach shown above adds keys to an existing KRA instance without disrupting other data.

Alternative: Full backend import (use with caution):

# Stop target KRA
sudo systemctl stop [email protected]

# RHEL 8 (389 DS 1.4)
sudo ldif2db.pl -Z instance_name -n kra-db \
    -i ~/migration/target/kra-keys-upgraded.ldif

# RHEL 9+ (389 DS 2.x)
sudo dsconf localhost backend import kra-db \
    ~/migration/target/kra-keys-upgraded.ldif

# Start target KRA
sudo systemctl start [email protected]

4.9. Step 8: Test Key Recovery

Verify that keys can be recovered from the target KRA:

# List archived keys
pki -n caadmin kra-key-find

# Test recovery of a specific key
pki -n kra-agent kra-key-retrieve --keyID 0x1
Tip
For automated testing, use the KRA REST API to recover multiple keys and verify the decrypted data matches the original.

5. Scenario 2: HSM-to-HSM Migration

This scenario demonstrates migrating keys between hardware security modules.

5.1. Environment Setup

Source System:

  • KRA: rhcs10-kra-source

  • HSM: SourceHSM

  • Storage cert: storageCert cert-rhcs10-kra-source KRA

Target System:

  • KRA: rhcs11-kra-target

  • HSM: TargetHSM

  • Storage cert: Exported to ~/tmp/target-storage.pem

5.2. Step 1: Prepare HSM Credentials

Create password files for HSM access:

# Create tmp directory
mkdir -p ~/tmp

# Source HSM password
echo "SourceHSMPassword123" > ~/tmp/source-hsm-passwd
chmod 600 ~/tmp/source-hsm-passwd

# Target system will need its own HSM password file

5.3. Step 2: Export Source KRA LDIF

On the source system:

sudo systemctl stop [email protected]

# Export KRA database
sudo dsconf localhost backend export kra-db \
    /var/lib/dirsrv/slapd-localhost/ldif/kra-export.ldif

# Copy to migration directory
mkdir -p ~/migration
cp /var/lib/dirsrv/slapd-localhost/ldif/kra-export.ldif \
    ~/migration/source-kra.ldif

5.4. Step 3: Extract Target Storage Certificate

On the target system:

# Create tmp directory
mkdir -p ~/tmp

# Export target KRA storage certificate using pki-server
pki-server cert-export -i <target-kra-instance-name> kra_storage \
    --cert-file ~/tmp/target-storage.pem

# Alternative: Export using certutil
certutil -L -d /var/lib/pki/pki-tomcat/alias \
    -n "storageCert cert-rhcs11-kra-target KRA" -a \
    > ~/tmp/target-storage.pem

# Copy to source system for migration
scp ~/tmp/target-storage.pem root@source-system:~/migration/
Warning
Critical - Use TARGET KRA’s Storage Certificate

Ensure you export the storage certificate from the TARGET KRA, not the source KRA. Using the wrong storage certificate will cause the target KRA to fail unwrapping session keys, even though KRATool appears to complete successfully.

Symptom of wrong certificate: "Failed to unwrap session key" errors in target KRA when attempting key recovery.

5.5. Step 4: Run KRATool on Source System

KRATool \
    -use_cross_scheme \
    -kratool_config_file ~/migration/kratool.cfg \
    -source_ldif_file ~/migration/source-kra.ldif \
    -target_ldif_file ~/migration/target-kra.ldif \
    -log_file ~/migration/KRATool.log \
    -source_pki_security_database_path /var/lib/pki/pki-tomcat/alias \
    -source_storage_token_name "SourceHSM" \
    -source_storage_certificate_nickname "storageCert cert-rhcs10-kra-source KRA" \
    -target_storage_certificate_file ~/migration/target-storage.pem \
    -source_pki_security_database_pwdfile ~/tmp/source-hsm-passwd \
    -source_hsm_token_pwdfile ~/tmp/source-hsm-passwd \
    -source_rsa_wrap_algorithm RSA-OAEP \
    -target_rsa_wrap_algorithm RSA-OAEP \
    -source_payload_wrap_algorithm "AES KeyWrap/Wrapped" \
    -target_payload_wrap_algorithm "AES KeyWrap/Wrapped" \
    -source_kra_naming_context "rhcs10-kra-source-KRA" \
    -target_kra_naming_context "rhcs11-kra-target-KRA" \
    -split_target_ldif_per_records 1000 \
    -verbose
Note
HSM-Specific Options:
  • -source_hsm_token_pwdfile: Password for HSM token (may differ from NSS DB password)

  • -split_target_ldif_per_records: Split output into multiple files for large migrations

5.6. Step 5: Transfer and Import to Target

Copy the migrated LDIF to the target system:

# On source system
scp ~/migration/target-kra.ldif* root@target-system:~/migration/

# On target system
sudo systemctl stop [email protected]

# If split into multiple files, combine them
cat ~/migration/target-kra.ldif.* > ~/migration/target-kra-combined.ldif

# Import
sudo dsconf localhost backend import kra-db \
    ~/migration/target-kra-combined.ldif

sudo systemctl start [email protected]

6. Scenario 3: Algorithm Migration with Software Token Fallback

Some HSMs don’t support certain payload wrapping algorithms. This scenario shows how to use NSS DB for payload operations.

6.1. When to Use Software Token Fallback

Use -use_nss_for_payload_processing when:

  • Source HSM doesn’t support the target payload wrap algorithm

  • Target HSM doesn’t support unwrap operations needed for migration

  • Performance testing on software before HSM deployment

6.2. Example: AES/CBC to AES KeyWrap Migration

KRATool \
    -use_cross_scheme \
    -kratool_config_file ~/migration/kratool.cfg \
    -source_ldif_file ~/migration/source-kra.ldif \
    -target_ldif_file ~/migration/target-kra.ldif \
    -log_file ~/migration/KRATool.log \
    -source_pki_security_database_path /var/lib/pki/pki-tomcat/alias \
    -source_storage_token_name "SourceHSM" \
    -source_storage_certificate_nickname "storageCert cert-source-kra KRA" \
    -target_storage_certificate_file ~/migration/target-storage.pem \
    -source_pki_security_database_pwdfile ~/tmp/passwd \
    -source_hsm_token_pwdfile ~/tmp/hsm-passwd \
    -source_rsa_wrap_algorithm RSA \
    -target_rsa_wrap_algorithm RSA-OAEP \
    -source_payload_wrap_algorithm "AES/CBC/PKCS5Padding" \
    -target_payload_wrap_algorithm "AES KeyWrap/Wrapped" \
    -source_payload_wrap_keysize 128 \
    -target_payload_wrap_keysize 256 \
    -use_nss_for_payload_processing \
    -source_kra_naming_context "source-kra-KRA" \
    -target_kra_naming_context "target-kra-KRA" \
    -verbose
Important
How Software Token Fallback Works:
  1. Session key unwrapped from source HSM using source storage private key

  2. Session key imported to NSS DB (software token) for payload operations

  3. Private key unwrapped in NSS DB using session key

  4. New session key generated (if key size changed)

  5. Private key rewrapped with new session key in NSS DB

  6. Session key wrapped with target storage public key

This allows the HSM to handle RSA operations while NSS handles AES operations that the HSM may not support.

7. TPS/TMS Key Migration and External Registration Recovery

This section provides a complete workflow for migrating TPS-generated smart card keys from an HSM-backed source KRA to a target KRA, and then testing recovery via TPS external registration.

Note
This example uses a specific test topology for illustration. Your environment will have different hostnames, ports, instance names, and HSM configurations. Adapt the commands and configuration to match your actual deployment.

7.1. Example Test Topology

This guide uses the following example topology:

  • Host: pki1.example.com

  • CA: topology-02-CA (port 20443)

  • Source KRA: topology-02-KRA (port 21443, HSM-backed, keys to be migrated out)

  • Target KRA: topology-02-KRA-1 (port 26443, receives migrated keys)

  • TKS: topology-02-TKS (shared)

  • TPS: topology-02-TPS-1 (port 25443, configured for external registration)

  • LDAP: port 3389

  • HSM: SourceHSM (token: SOURCE-HSM)

Your topology may differ - substitute your actual values throughout this guide.

7.2. Overview

This complete workflow demonstrates:

  1. KRA Migration: Exporting TPS smart card keys from an HSM-backed source KRA and migrating them to a target KRA using KRATool

  2. TPS Configuration: Configuring TPS for external registration recovery

  3. Testing: Verifying that migrated keys can be successfully recovered to smart cards

TPS external registration allows you to recover a previously issued certificate and its associated archived private key onto a smart card or hardware token. This is essential for:

  • Re-issuing lost or damaged smart cards

  • Migrating users to new tokens after KRA migration

  • Verifying end-to-end key recovery workflow after cross-scheme migration

7.3. Use Case

  • Migrating TPS/TMS (Token Management System) smart card enrollments

  • Source KRA uses HSM for storage key protection

  • Target KRA may use HSM or software token

  • Must preserve ability to recover keys to replacement smart cards via TPS external registration

7.4. Prerequisites

  • PKI KRA instances (source and target) configured

  • Source KRA contains TPS-archived keys from smart card enrollments

  • HSM access credentials (if using HSM)

  • TPS instance configured and connected to target KRA

  • User LDAP directory with user entries

  • Smart card or hardware token for testing

  • ESC (Enterprise Security Client) or compatible enrollment tool

7.5. Environment Setup

Source KRA (topology-02-KRA):

  • HSM token: SOURCE-HSM (SourceHSM)

  • Storage certificate nickname: storageCert cert-topology-02-KRA KRA

  • RSA wrapping: RSA-OAEP

  • Session key regeneration: enabled

  • Contains TPS-archived keys from smart card enrollments

Target KRA (topology-02-KRA-1):

  • Storage certificate: exported to target_kra_storage.pem

  • RSA wrapping: RSA-OAEP (matching source)

  • Will receive migrated TPS keys

7.6. Step 1: Export Keys from Source KRA LDAP

# Export keyRepository from source KRA
ldapsearch -LLL -x -H ldap://pki1.example.com:3389 \
  -D "cn=Directory Manager" \
  -w "$(cat /secure/ds-password.txt)" \
  -b "ou=keyRepository,ou=kra,o=topology-02-KRA-KRA" \
  > kra-export.ldif

# Remove organizational entry (first 7 lines)
tail -n +8 kra-export.ldif > kra-keys-only.ldif

7.7. Step 2: Extract Target Storage Certificate

Get the target KRA’s storage certificate from the CA (only the certificate is needed, not the private key).

Using CA End-Entity Interface:

  1. Navigate to https://pki1.example.com:20443/ca/ee/ca/

  2. Click "Retrieval" tab

  3. Enter the serial number of the target KRA storage certificate (or search by subject DN)

  4. Click "Submit"

  5. Copy the certificate in Base64 encoded format

  6. Save to ~/migration/target_kra_storage.pem:

    cat > ~/migration/target_kra_storage.pem << 'EOF'
    -----BEGIN CERTIFICATE-----
    <paste Base64 certificate here>
    -----END CERTIFICATE-----
    EOF
    
    # Verify the certificate
    openssl x509 -in ~/migration/target_kra_storage.pem -noout -subject -serial

7.8. Step 3: Create KRATool Configuration

The KRATool configuration file specifies which LDIF fields to process during migration. Copy the standard configuration file from the PKI installation:

cp /usr/share/pki/tools/KRATool.cfg ~/migration/kratool.cfg

Alternatively, create ~/migration/kratool.cfg with the content shown in KRATool Configuration File Reference.

Note
The privateKeyData fields in caKeyRecord and tpsKeyRecord sections are essential for rewrapping archived keys during cross-scheme migration.

7.9. Step 4: Run KRATool with HSM

KRATool \
  -use_cross_scheme \
  -kratool_config_file ./kratool.cfg \
  -source_ldif_file kra-keys-only.ldif \
  -target_ldif_file ./kra-import.ldif \
  -log_file ./kratool.log \
  -source_pki_security_database_path /var/lib/pki/topology-02-KRA/alias \
  -source_storage_token_name "SOURCE-HSM" \
  -source_storage_certificate_nickname 'storageCert cert-topology-02-KRA KRA' \
  -target_storage_certificate_file ~/migration/target_kra_storage.pem \
  -source_pki_security_database_pwdfile ~/secure/nss-token-password.txt \
  -source_hsm_token_pwdfile ~/secure/hsm-password.txt \
  -source_rsa_wrap_algorithm RSA-OAEP \
  -target_rsa_wrap_algorithm RSA-OAEP \
  -source_kra_naming_context "topology-02-KRA-KRA" \
  -target_kra_naming_context "topology-02-KRA-1-KRA" \
  -regenerate_session_key \
  -use_nss_for_payload_processing
Important
Key parameters for TPS/TMS migration:
  • -source_storage_token_name "SOURCE-HSM" - Specifies HSM token containing storage private key

  • -source_hsm_token_pwdfile - Separate password file for HSM (if different from NSS DB password)

  • -source_storage_certificate_nickname - Full nickname with token prefix

  • -regenerate_session_key - Forces regeneration of session keys (needed when changing key sizes or payload algorithms)

  • -use_nss_for_payload_processing - Performs payload unwrap/rewrap in NSS DB instead of HSM (use when HSM doesn’t support the payload algorithm)

  • Naming contexts must match source and target KRA LDAP suffixes

7.10. Step 5: Verify Migration Output

Check KRATool output:

Source RSA wrap algorithm: RSA-OAEP
Target RSA wrap algorithm: RSA-OAEP
BEGIN "KRATool -kratool_config_file ./kratool.cfg ..."

SUCCESSFULLY processed kratool config file!

Initializing source PKI security databases in '/var/lib/pki/topology-02-KRA/alias'.
Retrieving source storage token called 'SOURCE-HSM'.
Retrieving source storage cert with nickname of 'SOURCE-HSM:storageCert cert-topology-02-KRA KRA'.

BEGIN: Obtaining the private key from the source storage token . . .
FINISHED: Obtaining the private key from the source storage token.

BEGIN: Obtaining the public key from the target storage certificate . . .
FINISHED: Obtaining the public key from the target storage certificate.

PROCESSING: ........................... FINISHED.

SUCCESSFULLY converted source LDIF file --> target LDIF file!

Summary: 13 key record(s) processed successfully, 0 failed.

Target LDIF file: ./kra-import.ldif

The "13 key record(s) processed successfully" indicates all TPS smart card keys were migrated.

7.11. Step 6: Import to Target KRA

# Remove organizational entry from import file
tail -n +8 kra-import.ldif > kra-import-keys-only.ldif

# Import to target KRA LDAP
ldapmodify -x -H ldap://pki1.example.com:3389 \
  -D "cn=Directory Manager" \
  -w "$(cat /secure/ds-password.txt)" \
  -a -f kra-import-keys-only.ldif

# Verify keys imported
ldapsearch -LLL -x -H ldap://pki1.example.com:3389 \
  -D "cn=Directory Manager" \
  -w "$(cat /secure/ds-password.txt)" \
  -b "ou=keyRepository,ou=kra,o=topology-02-KRA-1-KRA" \
  "(cn=*)" cn | grep "^cn:" | wc -l
# Should show: 13 (matching KRATool output)

7.12. Configure TPS for External Registration

Now that the TPS keys have been migrated to the target KRA, configure TPS to recover these keys to smart cards via external registration.

Add the following configuration to TPS CS.cfg:

# Enable external registration profile
op.enroll.externalRegAddToToken.enable=true

# Configure applet version for SCP03 protocol
op.format.externalRegAddToToken.applet.requiredVersion=1.5.65cbf5a6
op.enroll.externalRegAddToToken.applet.requiredVersion=1.5.65cbf5a6

# Configure AES KWP for key unwrapping on token
op.enroll.externalRegAddToToken.keyGen.aesKeyWrapAlg=KWP
op.enroll.externalRegAddToToken.tks.keySet=defKeySet

# Enable RSA-OAEP wrapping (if target KRA uses OAEP)
keyWrap.useOAEP=1

# External registration LDAP auth
auths.instance.ldap1.externalReg.enable=true
auths.instance.ldap1.externalReg.certs.recoverAttributeName=certsToAdd

Restart TPS after configuration changes:

sudo systemctl restart [email protected]

7.13. Configure User LDAP Entry

7.13.1. Finding Certificate and Key Serial Numbers

At this point, we need to select a certificate and its corresponding private key that we want to recover to the smart card. These are based on the KRA key records that have been migrated to the new KRA (topology-02-KRA-1). The TPS external registration process requires the serial numbers of both the certificate (from the CA) and the archived key (from the KRA) to recover them to the token.

Before configuring the certsToAdd attribute, you need to identify the certificate and key serial numbers for the user.

Method 1: Using Web Interfaces

  1. Find the certificate serial number via CA EE interface:

  2. Find the associated key serial number via KRA Agent interface:

Method 2: Using LDAP Queries

# Find certificate serial in CA LDAP
ldapsearch -x -H ldap://pki1.example.com:3389 \
  -D "cn=Directory Manager" \
  -w "$(cat /secure/ldap-password.txt)" \
  -b "ou=certificateRepository,ou=ca,o=topology-02-CA" \
  "(subjectname=*user4*)" serialno

# Find key serial in KRA LDAP (search by owner)
ldapsearch -x -H ldap://pki1.example.com:3389 \
  -D "cn=Directory Manager" \
  -w "$(cat /secure/ldap-password.txt)" \
  -b "ou=keyRepository,ou=kra,o=topology-02-KRA-1-KRA" \
  "(ownerName=*user4*)" cn

7.13.2. Converting Hex to Decimal

TPS external registration requires serial numbers in decimal format, but PKI displays them in hexadecimal.

Convert using:

# Using printf and bash
echo $((0x35))     # Output: 53
echo $((0x213))    # Output: 531

# Using Python
python3 -c "print(int('0x35', 16))"   # Output: 53
python3 -c "print(int('0x213', 16))"  # Output: 531

# Using bc
echo "ibase=16; 35" | bc    # Output: 53
echo "ibase=16; 213" | bc   # Output: 531

7.13.3. Complete Example Workflow

This example demonstrates external registration recovery after migrating keys from an HSM-backed source KRA to a target KRA.

Scenario: User smart card certificate was originally generated on topology-02-KRA with storage keys on HSM. Keys were migrated to topology-02-KRA-1 using KRATool cross-scheme migration with RSA-OAEP wrapping.

Step 1: Find certificate serial from CA

Using CA EE interface (https://pki1.example.com:20443/ca/ee/ca/): * Search for user4’s certificate * Certificate serial shown: 0x35 (hex)

Step 2: Convert certificate serial to decimal

echo $((0x35))
# Output: 53

Step 3: Find key serial from KRA

Using KRA Agent interface (https://pki1.example.com:26443/kra/agent/kra/): * Click "Retrieve Key" → "Search by Certificate" * Paste certificate PEM content or search by client ID * Key serial shown: 0x213 (hex)

Step 4: Convert key serial to decimal

echo $((0x213))
# Output: 531

Step 5: Identify CA and KRA connectors

From CA CS.cfg: ca.connector.KRA.enable=true → connector name is KRA

From TPS CS.cfg connector configuration → KRA connector name is kra1

Step 6: Build certsToAdd value

For user user4:

  • Certificate serial (decimal): 53

  • CA connector: KRA

  • Key serial (decimal): 531

  • KRA connector: kra1

Final certsToAdd value: 53,KRA,531,kra1

7.13.4. Add certsToAdd Attribute to User

Add the certsToAdd attribute to the user’s LDAP entry to specify which certificate and key to recover:

# Format: cert_serial_decimal,ca_connector,key_serial_decimal,kra_connector
# IMPORTANT: Use DECIMAL format for both cert and key serials, not hex!

ldapmodify -x -H ldap://pki1.example.com:3389 \
  -D "cn=Directory Manager" \
  -w "$(cat /secure/ldap-password.txt)" << EOF
dn: uid=user4,ou=people,dc=example,dc=org
changetype: modify
add: certsToAdd
certsToAdd: 53,KRA,531,kra1
EOF

This example adds external registration recovery information for user user4: * Certificate serial: 0x35 (hex) = 53 (decimal) * Key serial: 0x213 (hex) = 531 (decimal) * Originally archived on HSM-backed KRA, migrated with KRATool cross-scheme

To verify the attribute was added:

ldapsearch -x -H ldap://pki1.example.com:3389 \
  -D "cn=Directory Manager" \
  -w "$(cat /secure/ldap-password.txt)" \
  -b "uid=user4,ou=people,dc=example,dc=org" \
  certsToAdd

7.14. Perform External Registration Enrollment

Use ESC (Enterprise Security Client) or compatible smart card tool to:

  1. Format the token

  2. Enroll using the externalRegAddToToken profile

  3. Verify the recovered certificate and key are loaded onto the token

7.15. Verify Success

Check TPS debug log (/var/lib/pki/pki-tomcat/logs/tps/debug.<date>) for successful key recovery:

ExternalRegAttrs: getCertsToAdd: certsToAdd: 53,KRA,531,kra1
ExternalRegRecoverOp: recoverCertificates: found cert serial: 53
ExternalRegRecoverOp: recoverKeys: found key serial: 531
KRARecoveryClient: recoverKey: recovering key ID 0x213 from KRA
KRARecoveryClient: recoverKey: using RSA-OAEP for session key unwrap
TPSEnrollProcessor.importPrivateKeyPKCS8: unwrap the priv key with AES KWP
TPSEnrollProcessor.importPrivateKeyPKCS8: kek wrapped key outgoing: size: 16
TPSEnrollProcessor.importPrivateKeyPKCS8: importing RSA-2048 key
...
APDUResponse.checkResult: sw1: 0x90 sw2: 0x0
TPSEnrollProcessor.importPrivateKeyPKCS8 successful, leaving...
ExternalRegRecoverOp: certificate and key successfully recovered to token

Key indicators of success: * sw1: 0x90 sw2: 0x0 - Smart card accepted the key import * using RSA-OAEP for session key unwrap - Shows cross-scheme migration worked * unwrap the priv key with AES KWP - Confirms modern wrapping algorithm * ExternalRegRecoverOp: certificate and key successfully recovered to token - Final success

7.16. Verification Steps

The successful enrollment shown in the TPS debug log (sw1: 0x90 sw2: 0x0 and certificate and key successfully recovered to token) confirms that:

  • The HSM-migrated key was successfully recovered from the KRA

  • The private key was unwrapped and imported to the smart card

  • Cross-scheme migration (including any algorithm changes) is working correctly

View certificate on smart card:

Use ESC (Enterprise Security Client) to view the enrolled certificate:

  1. Launch ESC

  2. Select the smart card

  3. View enrolled certificates - should show the recovered certificate with user’s subject DN

Alternatively, use Firefox to view the certificate:

  1. Insert smart card

  2. Open Firefox → Settings → Privacy & Security → Security Devices

  3. Load the smart card module if not already loaded

  4. Go to Settings → Privacy & Security → Certificates → View Certificates

  5. Select "Your Certificates" tab

  6. The recovered certificate should appear with the smart card token name

If the certificate appears in ESC or Firefox, the HSM-migrated key is fully functional on the token.

8. Command-Line Options Reference

8.1. Mandatory Options

-use_cross_scheme

Enables cross-scheme migration mode with enhanced algorithm support.

-kratool_config_file <file>

Path to KRATool configuration file specifying which LDIF fields to process.

-source_ldif_file <file>

Input LDIF file exported from source KRA.

-target_ldif_file <file>

Output LDIF file for import to target KRA. Must not exist.

-log_file <file>

Debug log file. Must not exist.

-source_pki_security_database_path <path>

Path to source NSS database containing storage certificate and private key.

-source_storage_token_name <name>

Token name containing source storage certificate (e.g., "Internal Key Storage Token" or "MyHSM").

-source_storage_certificate_nickname <nickname>

Nickname of source KRA storage certificate in NSS database.

-target_storage_certificate_file <file>

Path to target KRA storage certificate in PEM format.

-source_pki_security_database_pwdfile <file>

Password file for source NSS database.

-source_kra_naming_context <context>

LDAP organizational context for the source KRA instance. Optional, but strongly recommended when source and target KRAs have different naming contexts.

Format: "<instance-name>-<subsystem>" (e.g., "pki-tomcat-KRA", "topology-02-KRA-KRA")

Find with: ldapsearch -LLL -x -H ldap://localhost:3389 -D "cn=Directory Manager" -w "password" -b "" -s base namingContexts

If not specified, KRATool will copy the source naming context from the LDIF, which may not match the target KRA’s organizational structure.

-target_kra_naming_context <context>

LDAP organizational context for the target KRA instance. Optional, but strongly recommended when source and target KRAs have different naming contexts.

Format: Same as source (e.g., "pki-tomcat-target-KRA", "topology-02-KRA-1-KRA")

If not specified, target LDIF entries will retain the source naming context in their DNs.

8.2. Cross-Scheme Options

-source_rsa_wrap_algorithm <algorithm>

RSA algorithm used by source KRA. Values: RSA or RSA-OAEP. Default: RSA.

-target_rsa_wrap_algorithm <algorithm>

RSA algorithm for target KRA. Values: RSA or RSA-OAEP. Default: RSA-OAEP.

-source_payload_wrap_algorithm <algorithm>

Payload wrapping algorithm used by source KRA.

Supported values:

  • "AES/CBC/PKCS5Padding"

  • "AES KeyWrap/Wrapped" (KWP - recommended)

  • "AES/KWP/NoPadding" (AES-KWP)

  • "AES KeyWrap/Padding"

-target_payload_wrap_algorithm <algorithm>

Payload wrapping algorithm for target KRA. Same values as source.

-source_payload_wrap_keysize <bits>

Source session key size in bits. Values: 128, 192, or 256.

-target_payload_wrap_keysize <bits>

Target session key size in bits. Values: 128, 192, or 256.

-regenerate_session_key

Force session key regeneration without prompting. Use when changing key sizes or algorithms.

-use_nss_for_payload_processing

Perform payload unwrap/rewrap operations in NSS DB instead of HSM. Use when HSM doesn’t support target payload algorithm.

-source_hsm_token_pwdfile <file>

Password file for HSM token (if different from NSS DB password).

-split_target_ldif_per_records <count>

Split output into multiple files with specified number of records each. Useful for large migrations.

-verbose

Enable detailed per-record logging. Recommended for troubleshooting.

9. Troubleshooting

9.1. Common Issues

9.1.1. "publicKeyData is null or empty"

Cause: Using baseline rewrap mode instead of cross-scheme mode, or LDIF missing public key data.

Solution: Ensure -use_cross_scheme flag is present and source LDIF contains publicKeyData attributes.

9.1.2. "Unsupported payload wrap algorithm"

Cause: HSM doesn’t support the specified algorithm.

Solution: Add -use_nss_for_payload_processing to use NSS DB for payload operations.

9.1.3. "Failed to unwrap session key"

Cause: Incorrect storage certificate, wrong algorithm specified, or HSM authentication issue.

Solution:

  • Verify source storage certificate nickname

  • Check HSM password file

  • Confirm source RSA wrap algorithm matches what was used to wrap the keys

9.1.4. "Target LDIF file ALREADY exists"

Cause: Previous run left output file.

Solution: Remove the file: rm ~/migration/target.ldif or use a different filename.

9.1.5. Missing Naming Context Parameters

Cause: -source_kra_naming_context or -target_kra_naming_context parameters not specified.

Symptom: KRATool may complete but target KRA cannot identify which keys belong to it in a multi-KRA environment.

Solution: Always include naming context parameters in cross-scheme migration:

-source_kra_naming_context "pki-tomcat-KRA" \
-target_kra_naming_context "pki-tomcat-target-KRA"

9.1.6. Wrong Target Storage Certificate

Cause: Used source KRA’s storage certificate instead of target KRA’s certificate.

Symptom: KRATool completes successfully, but target KRA fails with "Failed to unwrap session key" during recovery.

Solution: Export storage certificate from the TARGET KRA:

pki-server cert-export -i <target-kra-instance> kra_storage --cert-file ~/migration/target_storage.pem

9.1.7. LDAP Organizational Entry Not Removed

Cause: Repository organizational entry (first 7 lines) not removed before import.

Symptom: ldapmodify fails or creates duplicate organizational entries.

Solution: Remove organizational entry before import:

tail -n +8 kra-import.ldif > kra-keys-only.ldif

9.1.8. External Registration Serial Number Format Error

Cause: Using hexadecimal format for certificate or key serials in certsToAdd attribute.

Symptom: CA or KRA cannot find certificate or key during external registration.

Solution: TPS uses DECIMAL format for serial numbers:

  • Certificate serial 0x35 (hex) = 53 (decimal)

  • Key serial 0x213 (hex) = 531 (decimal)

  • Correct format: certsToAdd: 53,ca1,531,kra1

9.2. Debugging Tips

Enable verbose mode

Add -verbose flag to see detailed per-record processing information.

Check log file

Review the debug log for specific error messages:

tail -100 ~/migration/KRATool.log | less
Test with small dataset

Extract a small subset of keys for initial testing:

head -500 source-kra.ldif > test-keys.ldif
Verify algorithms

KRATool will log the detected algorithms at startup. Verify they match your source KRA configuration.

10. Performance Considerations

10.1. Large Migrations

For migrations with thousands of keys:

Split output files

Use -split_target_ldif_per_records 1000 to create manageable file sizes.

Disable verbose logging

Remove -verbose flag for production runs to reduce I/O overhead.

HSM session caching

KRATool caches HSM sessions and keys to minimize expensive cryptographic operations.

10.2. Expected Performance

  • Software token: 50-100 keys/second

  • HSM with cloneKey support: 20-50 keys/second

  • HSM without cloneKey (RSA keypair method): 5-15 keys/second

11. Security Considerations

11.1. Password Files

Protect password files with restrictive permissions:

chmod 600 ~/tmp/passwd

11.2. LDIF Files

LDIF files contain sensitive wrapped key data:

  • Store in encrypted filesystem

  • Delete after successful import

  • Restrict access: chmod 600 ldif-file

11.3. Migration Environment

Run KRATool in a secure, isolated environment:

  • Dedicated migration server

  • No network access during migration

  • Audit all operations

  • Secure deletion of intermediate files

11.4. Session Key Regeneration

When changing key sizes or algorithms, session keys MUST be regenerated:

  • Different key sizes: Automatic regeneration

  • Same size: Use -regenerate_session_key to force regeneration

12. Appendix

12.1. KRATool Configuration File Reference

The standard KRATool.cfg configuration file specifies which LDIF fields to process during migration. The privateKeyData fields in caKeyRecord and tpsKeyRecord sections are essential for rewrapping archived keys.

kratool.ldif.caEnrollmentRequest._000=########################################
kratool.ldif.caEnrollmentRequest._001=##     KRA CA Enrollment Request      ##
kratool.ldif.caEnrollmentRequest._002=########################################
kratool.ldif.caEnrollmentRequest._003=##                                    ##
kratool.ldif.caEnrollmentRequest._004=##  NEVER allow 'KRATOOL' the ability ##
kratool.ldif.caEnrollmentRequest._005=##  to change the CA 'naming context' ##
kratool.ldif.caEnrollmentRequest._006=##  data in the following fields:     ##
kratool.ldif.caEnrollmentRequest._007=##                                    ##
kratool.ldif.caEnrollmentRequest._008=##    extdata-auth--005ftoken;uid     ##
kratool.ldif.caEnrollmentRequest._009=##    extdata-auth--005ftoken;userid  ##
kratool.ldif.caEnrollmentRequest._010=##    extdata-updatedby               ##
kratool.ldif.caEnrollmentRequest._011=##                                    ##
kratool.ldif.caEnrollmentRequest._012=##  NEVER allow 'KRATOOL' the ability ##
kratool.ldif.caEnrollmentRequest._013=##  to change CA 'numeric' data in    ##
kratool.ldif.caEnrollmentRequest._014=##  the following fields:             ##
kratool.ldif.caEnrollmentRequest._015=##                                    ##
kratool.ldif.caEnrollmentRequest._016=##    extdata-requestId               ##
kratool.ldif.caEnrollmentRequest._017=##                                    ##
kratool.ldif.caEnrollmentRequest._018=########################################
kratool.ldif.caEnrollmentRequest.cn=true
kratool.ldif.caEnrollmentRequest.dateOfModify=true
kratool.ldif.caEnrollmentRequest.dn=true
kratool.ldif.caEnrollmentRequest.extdata.keyRecord=true
kratool.ldif.caEnrollmentRequest.extdata.requestNotes=true
kratool.ldif.caEnrollmentRequest.requestId=true
kratool.ldif.caKeyRecord._000=#########################################
kratool.ldif.caKeyRecord._001=##          KRA CA Key Record          ##
kratool.ldif.caKeyRecord._002=#########################################
kratool.ldif.caKeyRecord._003=##                                     ##
kratool.ldif.caKeyRecord._004=##  NEVER allow 'KRATOOL' the ability  ##
kratool.ldif.caKeyRecord._005=##  to change the CA 'naming context'  ##
kratool.ldif.caKeyRecord._006=##  data in the following fields:      ##
kratool.ldif.caKeyRecord._007=##                                     ##
kratool.ldif.caKeyRecord._008=##    archivedBy                       ##
kratool.ldif.caKeyRecord._009=##                                     ##
kratool.ldif.caKeyRecord._010=#########################################
kratool.ldif.caKeyRecord.cn=true
kratool.ldif.caKeyRecord.dateOfModify=true
kratool.ldif.caKeyRecord.dn=true
kratool.ldif.caKeyRecord.privateKeyData=true
kratool.ldif.caKeyRecord.serialno=true
kratool.ldif.namingContext._000=############################################
kratool.ldif.namingContext._001=##       KRA Naming Context Fields        ##
kratool.ldif.namingContext._002=############################################
kratool.ldif.namingContext._003=##                                        ##
kratool.ldif.namingContext._004=##  NEVER allow 'KRATOOL' the ability to  ##
kratool.ldif.namingContext._005=##  change the CA 'naming context' data   ##
kratool.ldif.namingContext._006=##  in the following 'non-KeyRecord /     ##
kratool.ldif.namingContext._007=##  non-Request' fields (as these records ##
kratool.ldif.namingContext._008=##  should be removed via the option to   ##
kratool.ldif.namingContext._009=##  process requests and key records only ##
kratool.ldif.namingContext._010=##  if this is a KRA migration):          ##
kratool.ldif.namingContext._011=##                                        ##
kratool.ldif.namingContext._012=##    cn                                  ##
kratool.ldif.namingContext._013=##    sn                                  ##
kratool.ldif.namingContext._014=##    uid                                 ##
kratool.ldif.namingContext._015=##    uniqueMember                        ##
kratool.ldif.namingContext._016=##                                        ##
kratool.ldif.namingContext._017=##  NEVER allow 'KRATOOL' the ability to  ##
kratool.ldif.namingContext._018=##  change the KRA 'naming context' data  ##
kratool.ldif.namingContext._019=##  in the following 'non-KeyRecord /     ##
kratool.ldif.namingContext._020=##  non-Request' fields (as these records ##
kratool.ldif.namingContext._021=##  should be removed via the option to   ##
kratool.ldif.namingContext._022=##  process requests and key records only ##
kratool.ldif.namingContext._023=##  if this is a KRA migration):          ##
kratool.ldif.namingContext._024=##                                        ##
kratool.ldif.namingContext._025=##      dc                                ##
kratool.ldif.namingContext._026=##      dn                                ##
kratool.ldif.namingContext._027=##      uniqueMember                      ##
kratool.ldif.namingContext._028=##                                        ##
kratool.ldif.namingContext._029=##  NEVER allow 'KRATOOL' the ability to  ##
kratool.ldif.namingContext._030=##  change the TPS 'naming context' data  ##
kratool.ldif.namingContext._031=##  in the following 'non-KeyRecord /     ##
kratool.ldif.namingContext._032=##  non-Request' fields (as these records ##
kratool.ldif.namingContext._033=##  should be removed via the option to   ##
kratool.ldif.namingContext._034=##  process requests and key records only ##
kratool.ldif.namingContext._035=##  if this is a KRA migration):          ##
kratool.ldif.namingContext._036=##                                        ##
kratool.ldif.namingContext._037=##    uid                                 ##
kratool.ldif.namingContext._038=##    uniqueMember                        ##
kratool.ldif.namingContext._039=##                                        ##
kratool.ldif.namingContext._040=##  If '-source_naming_context            ##
kratool.ldif.namingContext._041=##  <original source KRA naming context>' ##
kratool.ldif.namingContext._042=##  and '-target_naming_context           ##
kratool.ldif.namingContext._043=##  <renamed target KRA naming context>'  ##
kratool.ldif.namingContext._044=##  options are specified, ALWAYS         ##
kratool.ldif.namingContext._045=##  require 'KRATOOL' to change the       ##
kratool.ldif.namingContext._046=##  KRA 'naming context' data in ALL of   ##
kratool.ldif.namingContext._047=##  the following fields in EACH of the   ##
kratool.ldif.namingContext._048=##  following types of records:           ##
kratool.ldif.namingContext._049=##                                        ##
kratool.ldif.namingContext._050=##    caEnrollmentRequest:                ##
kratool.ldif.namingContext._051=##                                        ##
kratool.ldif.namingContext._052=##      dn                                ##
kratool.ldif.namingContext._053=##      extdata-auth--005ftoken;user      ##
kratool.ldif.namingContext._054=##      extdata-auth--005ftoken;userdn    ##
kratool.ldif.namingContext._055=##                                        ##
kratool.ldif.namingContext._056=##    caKeyRecord:                        ##
kratool.ldif.namingContext._057=##                                        ##
kratool.ldif.namingContext._058=##      dn                                ##
kratool.ldif.namingContext._059=##                                        ##
kratool.ldif.namingContext._060=##    recoveryRequest:                    ##
kratool.ldif.namingContext._061=##                                        ##
kratool.ldif.namingContext._062=##      dn                                ##
kratool.ldif.namingContext._063=##                                        ##
kratool.ldif.namingContext._064=##    tpsKeyRecord:                       ##
kratool.ldif.namingContext._065=##                                        ##
kratool.ldif.namingContext._066=##      dn                                ##
kratool.ldif.namingContext._067=##                                        ##
kratool.ldif.namingContext._068=##    tpsNetkeyKeygenRequest:             ##
kratool.ldif.namingContext._069=##                                        ##
kratool.ldif.namingContext._070=##      dn                                ##
kratool.ldif.namingContext._071=##                                        ##
kratool.ldif.namingContext._072=##    tpsNetkeyKeyRecoveryRequest:        ##
kratool.ldif.namingContext._073=##                                        ##
kratool.ldif.namingContext._074=##      dn                                ##
kratool.ldif.namingContext._075=##                                        ##
kratool.ldif.namingContext._076=############################################
kratool.ldif.recoveryRequest._000=#####################################
kratool.ldif.recoveryRequest._001=##  KRA CA / TPS Recovery Request  ##
kratool.ldif.recoveryRequest._002=#####################################
kratool.ldif.recoveryRequest.cn=true
kratool.ldif.recoveryRequest.dateOfModify=true
kratool.ldif.recoveryRequest.dn=true
kratool.ldif.recoveryRequest.extdata.requestId=true
kratool.ldif.recoveryRequest.extdata.requestNotes=true
kratool.ldif.recoveryRequest.extdata.serialnumber=true
kratool.ldif.recoveryRequest.requestId=true
kratool.ldif.tpsKeyRecord._000=#########################################
kratool.ldif.tpsKeyRecord._001=##         KRA TPS Key Record          ##
kratool.ldif.tpsKeyRecord._002=#########################################
kratool.ldif.tpsKeyRecord._003=##                                     ##
kratool.ldif.tpsKeyRecord._004=##  NEVER allow 'KRATOOL' the ability  ##
kratool.ldif.tpsKeyRecord._005=##  to change the TPS 'naming context' ##
kratool.ldif.tpsKeyRecord._006=##  data in the following fields:      ##
kratool.ldif.tpsKeyRecord._007=##                                     ##
kratool.ldif.tpsKeyRecord._008=##    archivedBy                       ##
kratool.ldif.tpsKeyRecord._009=##                                     ##
kratool.ldif.tpsKeyRecord._010=#########################################
kratool.ldif.tpsKeyRecord.cn=true
kratool.ldif.tpsKeyRecord.dateOfModify=true
kratool.ldif.tpsKeyRecord.dn=true
kratool.ldif.tpsKeyRecord.privateKeyData=true
kratool.ldif.tpsKeyRecord.serialno=true
kratool.ldif.tpsNetkeyKeygenRequest._000=#####################################
kratool.ldif.tpsNetkeyKeygenRequest._001=##  KRA TPS Netkey Keygen Request  ##
kratool.ldif.tpsNetkeyKeygenRequest._002=#####################################
kratool.ldif.tpsNetkeyKeygenRequest._003=##                                 ##
kratool.ldif.tpsNetkeyKeygenRequest._004=##  NEVER allow 'KRATOOL' the      ##
kratool.ldif.tpsNetkeyKeygenRequest._005=##  ability to change the          ##
kratool.ldif.tpsNetkeyKeygenRequest._006=##  TPS 'naming context' data in   ##
kratool.ldif.tpsNetkeyKeygenRequest._007=##  the following fields:          ##
kratool.ldif.tpsNetkeyKeygenRequest._008=##                                 ##
kratool.ldif.tpsNetkeyKeygenRequest._009=##    extdata-updatedby            ##
kratool.ldif.tpsNetkeyKeygenRequest._010=##                                 ##
kratool.ldif.tpsNetkeyKeygenRequest._011=#####################################
kratool.ldif.tpsNetkeyKeygenRequest.cn=true
kratool.ldif.tpsNetkeyKeygenRequest.dateOfModify=true
kratool.ldif.tpsNetkeyKeygenRequest.dn=true
kratool.ldif.tpsNetkeyKeygenRequest.extdata.keyRecord=true
kratool.ldif.tpsNetkeyKeygenRequest.extdata.requestId=true
kratool.ldif.tpsNetkeyKeygenRequest.extdata.requestNotes=true
kratool.ldif.tpsNetkeyKeygenRequest.requestId=true
kratool.ldif.tpsNetkeyKeyRecoveryRequest._000=########################################
kratool.ldif.tpsNetkeyKeyRecoveryRequest._001=## KRA TPS Netkey Keyrecovery Request ##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._002=########################################
kratool.ldif.tpsNetkeyKeyRecoveryRequest._003=##                                    ##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._004=##  NEVER allow 'KRATOOL' the ability ##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._005=##  to change the TPS 'naming context'##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._006=##  data in the following fields:     ##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._007=##                                    ##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._008=##        extdata-updatedby           ##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._009=##                                    ##
kratool.ldif.tpsNetkeyKeyRecoveryRequest._010=########################################
kratool.ldif.tpsNetkeyKeyRecoveryRequest.cn=true
kratool.ldif.tpsNetkeyKeyRecoveryRequest.requestId=true
kratool.ldif.tpsNetkeyKeyRecoveryRequest.dn=true
kratool.ldif.tpsNetkeyKeyRecoveryRequest.dateOfModify=true
kratool.ldif.tpsNetkeyKeyRecoveryRequest.extdata.requestId=true
kratool.ldif.tpsNetkeyKeyRecoveryRequest.extdata.requestNotes=true

12.2. Sample LDIF Record Structure

A typical archived key record in LDIF format:

dn: cn=1,ou=keyRepository,ou=kra,dc=example,dc=com
objectClass: top
objectClass: keyRecord
cn: 1
serialno: 1
algorithm: RSA
privateKeyData:: MIICdQIBADANBgkqhkiG9w0BAQE...
publicKeyData:: MIGfMA0GCSqGSIb3DQEBAQUAA4GN...
dateOfCreate: 20260101120000Z
dateOfModify: 20260101120000Z
keyState: active
ownerName: uid=testuser
privateKeyFormat: PKCS8
publicKeyFormat: X.509
Note
Repository Serial Number

The repository organizational entry in LDIF exports contains a serialno field. This field is NOT used by the KRA to determine the last serial number. Instead, the KRA queries actual key records to find the highest serial number in use. The repository organizational entry can be safely removed before importing keys, which is why we use tail -n +8 to strip it from LDIF files.

12.3. Algorithm Compatibility Matrix

Source Algorithm Target Algorithm Session Key Action Notes

RSA

RSA

Keep or regenerate

No algorithm change

RSA

RSA-OAEP

Keep or regenerate

Upgrade to more secure padding

RSA-OAEP

RSA

Keep or regenerate

Downgrade (not recommended)

RSA-OAEP

RSA-OAEP

Keep or regenerate

No algorithm change

AES/CBC

AES/CBC

Keep or regenerate

No algorithm change

AES/CBC

AES KeyWrap

Must regenerate

Different wrapping method

AES KeyWrap

AES/CBC

Must regenerate

Different wrapping method

AES KeyWrap

AES KeyWrap

Keep or regenerate

No algorithm change

128-bit

256-bit

Automatic regeneration

Key size change detected

⚠️ **GitHub.com Fallback** ⚠️