Securely Exporting Certificates with jksExportKey: Permissions and Encryption
Overview
jksExportKey exports certificates/keys from Java KeyStores (JKS). When exporting, protect private keys, enforce proper file permissions, and use encryption in transit and at rest.
Steps (prescriptive)
- Identify items to export: Export only necessary certificates or key entries (alias names).
- Use the tool with minimal privileges: Run jksExportKey under a dedicated service account with just-read access to the keystore.
- Export to encrypted format: Export private keys into a PKCS#12 (.p12/.pfx) container protected with a strong passphrase rather than raw PEM. Example approach:
- Export keystore entry to PKCS#12 using jksExportKey (or keytool): provide a unique, strong passphrase.
- Use secure transport: When moving exported files, use secure channels (SFTP/SSH, scp with key auth, or HTTPS with TLS 1.2+).
- Set strict file permissions immediately: On UNIX, set ownership to the service/admin account and permissions to 600 (rw——-). On Windows, restrict ACLs to specific user accounts.
- Rotate and limit passphrase exposure: Generate one-time passphrases per export, transmit them separately (e.g., via a different secure channel), and rotate keys/certificates per your rotation policy.
- Audit and logging: Log export actions (who, when, alias) to an immutable, access-controlled log; avoid logging passphrases or private key material.
- Secure deletion: After use, securely wipe exported files (shred or use platform-specific secure-delete tools) and remove passphrase copies from memory/storage.
- Validate exported artifact: Verify the exported certificate and private key match (e.g., compare public key fingerprint) and check the PKCS#12 integrity before use.
Permissions checklist
- Keystore file readable only by a dedicated account.
- jksExportKey executable accessible only to authorized roles.
- Export destination writable only by destination account.
- Audit logs write-protected and accessible to auditors.
Encryption checklist
- Use PKCS#12 with AES-256 encryption for private key protection.
- Use strong passphrases (minimum 16 characters, mix of entropy) or derive keys via PBKDF2 with high iteration counts.
- Encrypt transport with TLS 1.2+ or secure shell protocols.
- At rest, store exported archives in encrypted storage (LUKS, BitLocker, or encrypted object storage).
Quick commands (examples)
- Export to PKCS#12 (keytool alternative):
bash
keytool -importkeystore -srckeystore my.jks -destkeystore export.p12 -srcalias myalias -deststoretype PKCS12 -deststorepass “” -srcstorepass “”
- Set permissions:
bash
chown admin:admin export.p12chmod 600 export.p12
Post-export actions
- Transfer via secure channel, import into target keystore, verify, then securely delete the exported file and passphrase copies.
- Document the export event in change control and rotate the secret if the passphrase or exported file was exposed.
If you want, I can generate a secure script that automates these steps for Linux (export, set permissions, transfer, and secure-delete).
Leave a Reply