| name | Cosmian KMS |
| description | Expert guidance for Cosmian Key Management System including key generation, certificate management, encryption operations, access policies, and KMS CLI operations. Use this when working with Cosmian KMS, cryptographic key management, or Cosmian-specific PKI operations. |
Cosmian KMS
Expert assistance with Cosmian Key Management System operations and workflows.
Overview
Cosmian KMS is an open-source Key Management System (KMS) that provides:
- Secure key generation and storage
- Certificate lifecycle management
- Encryption/decryption operations
- Access control policies
- Support for various cryptographic algorithms
- KMIP protocol support
- REST API and CLI interface
Installation & Setup
Install Cosmian KMS CLI
ckms config --server-url https://kms.example.com:9998
ckms config --server-url https://kms.example.com:9998 --access-token <token>
ckms version
Server Configuration
cosmian_kms_server --database-type sqlite --sqlite-path /path/to/kms.db
cosmian_kms_server --port 9998
cosmian_kms_server --https-p12-file cert.p12 --https-p12-password <password>
Key Management
Generate Keys
Symmetric Keys
ckms sym keys create --algorithm aes --key-size 256 --tag production
ckms sym keys create --algorithm aes --key-size 256 --id my-key-id
ckms sym keys create --algorithm chacha20
Asymmetric Keys
ckms rsa keys create --size 4096 --tag production
ckms ec keys create --curve nist-p256
ckms ec keys create --curve nist-p384
ckms rsa keys create --size 4096 --tag "env:prod" --tag "app:api"
Covercrypt Keys
ckms cc keys create-master-key-pair --policy policy.json
ckms cc keys create-user-key --master-private-key-id <id> --access-policy "dept::IT && level::confidential"
List Keys
ckms keys list
ckms keys list --tag production
ckms keys list --algorithm rsa
ckms keys list --detailed
Export Keys
ckms keys export --key-id <id> --output-file public.pem
ckms keys export --key-id <id> --output-file private.pem --unwrap
ckms keys export --key-id <id> --format pkcs8 --output-file key.p8
Import Keys
ckms keys import --key-file key.pem --tag imported
ckms keys import --key-file key.pem --key-id my-imported-key
ckms keys import --key-file wrapped-key.bin --wrapping-key-id <wrap-key-id>
Key Operations
ckms keys revoke --key-id <id> --revocation-reason "key-compromise"
ckms keys destroy --key-id <id>
ckms keys rekey --key-id <id>
ckms keys get --key-id <id>
Certificate Management
Generate Certificate
ckms certificates certify --key-id <key-id> \
--subject "CN=example.com,O=MyOrg,C=US" \
--days 365
ckms certificates certify --key-id <key-id> \
--subject "CN=example.com" \
--self-signed \
--days 365
ckms certificates certify --key-id <key-id> \
--subject "CN=example.com" \
--san "DNS:example.com" \
--san "DNS:www.example.com" \
--san "IP:192.168.1.1" \
--days 365
Certificate Signing Request (CSR)
ckms certificates request --key-id <key-id> \
--subject "CN=example.com,O=MyOrg,C=US" \
--output-file request.csr
ckms certificates import --certificate-file request.csr --tag csr
ckms certificates sign --csr-id <csr-id> \
--ca-key-id <ca-key-id> \
--days 365
Certificate Operations
ckms certificates list
ckms certificates export --certificate-id <id> --output-file cert.pem
ckms certificates import --certificate-file cert.pem --tag imported
ckms certificates validate --certificate-id <id>
ckms certificates revoke --certificate-id <id>
Encryption & Decryption
Symmetric Encryption
ckms sym encrypt --key-id <key-id> --input-file plaintext.txt --output-file encrypted.bin
ckms sym decrypt --key-id <key-id> --input-file encrypted.bin --output-file plaintext.txt
ckms sym encrypt --key-id <key-id> --input-file data.txt --output-file encrypted.bin --authenticated-data "metadata"
Asymmetric Encryption
ckms rsa encrypt --key-id <public-key-id> --input-file plaintext.txt --output-file encrypted.bin
ckms rsa decrypt --key-id <private-key-id> --input-file encrypted.bin --output-file plaintext.txt
Covercrypt (Policy-Based Encryption)
ckms cc encrypt --key-id <master-public-key-id> \
--encryption-policy "dept::IT && level::confidential" \
--input-file sensitive.txt \
--output-file encrypted.bin
ckms cc decrypt --key-id <user-key-id> \
--input-file encrypted.bin \
--output-file decrypted.txt
Access Control
Manage Permissions
ckms access grant --key-id <key-id> --user <username> --operations "encrypt,decrypt"
ckms access revoke --key-id <key-id> --user <username>
ckms access list --key-id <key-id>
ckms access grant --key-id <key-id> --user <username> --operations "*"
Tags & Organization
ckms keys tag --key-id <id> --tag "environment:production" --tag "team:backend"
ckms keys untag --key-id <id> --tag "environment:production"
ckms keys list --tag "environment:production"
Advanced Operations
Key Wrapping
ckms keys wrap --key-id <key-to-wrap> --wrapping-key-id <wrapping-key-id> --output-file wrapped.bin
ckms keys unwrap --wrapped-key-file wrapped.bin --wrapping-key-id <wrapping-key-id>
Batch Operations
for key in /path/to/keys/*.pem; do
ckms keys import --key-file "$key" --tag batch-import
done
ckms keys list --tag production | while read key_id; do
ckms keys export --key-id "$key_id" --output-file "backup/${key_id}.pem"
done
Audit & Logging
ckms keys history --key-id <id>
ckms audit export --start-date 2024-01-01 --end-date 2024-12-31
REST API Usage
API Authentication
export COSMIAN_KMS_TOKEN="your-api-token"
ckms config --access-token "your-api-token"
API Examples
curl -X POST https://kms.example.com:9998/kmip/2_1 \
-H "Authorization: Bearer $COSMIAN_KMS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tag": "CreateKeyPair",
"type": "Request",
"batch_count": 1,
"batch_item": [{
"operation": "CreateKeyPair",
"request_payload": {
"common_attributes": {
"cryptographic_algorithm": "RSA",
"cryptographic_length": 4096
}
}
}]
}'
curl -X POST https://kms.example.com:9998/kmip/2_1 \
-H "Authorization: Bearer $COSMIAN_KMS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tag": "Get",
"type": "Request",
"batch_item": [{
"operation": "Get",
"request_payload": {
"unique_identifier": "<key-id>"
}
}]
}'
Integration Examples
Python Integration
from cosmian_kms import KmsClient
kms = KmsClient("https://kms.example.com:9998", api_key="token")
key_id = kms.create_symmetric_key(algorithm="AES", key_size=256)
ciphertext = kms.encrypt(key_id, b"sensitive data")
plaintext = kms.decrypt(key_id, ciphertext)
Go Integration
import "github.com/cosmian/kms-go-client"
client := kms.NewClient("https://kms.example.com:9998", "token")
privateKeyID, publicKeyID, err := client.CreateRSAKeyPair(4096)
ciphertext, err := client.Encrypt(publicKeyID, plaintext)
plaintext, err := client.Decrypt(privateKeyID, ciphertext)
Best Practices
- Key Organization: Use meaningful tags and IDs for keys
- Access Control: Apply principle of least privilege
- Key Rotation: Regularly rotate encryption keys
- Backup: Securely backup master keys and CA certificates
- Audit: Enable and monitor audit logs
- HSM Integration: Use HSM for production CA keys
- Policy Management: Use Covercrypt policies for fine-grained access control
- Key Wrapping: Always wrap keys for export/backup
- Revocation: Revoke compromised keys immediately
- Testing: Test key operations in development before production
Common Workflows
Setup Production Environment
ckms rsa keys create --size 4096 --tag "ca" --tag "prod" --id prod-ca-key
ckms certificates certify --key-id prod-ca-key \
--subject "CN=MyOrg Root CA,O=MyOrg,C=US" \
--self-signed --days 3650
ckms rsa keys create --size 4096 --tag "server" --tag "prod"
ckms certificates certify --key-id <server-key-id> \
--subject "CN=api.example.com,O=MyOrg,C=US" \
--issuer-certificate-id <ca-cert-id> \
--san "DNS:api.example.com" \
--days 365
ckms certificates export --certificate-id <server-cert-id> --output-file server.crt
ckms keys export --key-id <server-key-id> --output-file server.key
Key Rotation
NEW_KEY=$(ckms sym keys create --algorithm aes --key-size 256 --tag "v2")
ckms keys revoke --key-id <old-key-id> --revocation-reason "superseded"
ckms keys destroy --key-id <old-key-id>
Troubleshooting
Connection Issues
curl -k https://kms.example.com:9998/version
ckms config --show
ckms version
Key Not Found
ckms keys list --detailed
ckms keys list --tag <tag-name>
ckms keys history --key-id <id>
Permission Denied
ckms access list --key-id <id>
ckms keys get --key-id <id>
Security Considerations
- Network Security: Always use HTTPS for KMS connections
- Token Management: Rotate API tokens regularly
- Key Lifecycle: Implement proper key lifecycle policies
- Separation of Duties: Different operators for key generation vs. usage
- Compliance: Ensure operations meet regulatory requirements (GDPR, HIPAA, etc.)
- Disaster Recovery: Have key backup and recovery procedures
- Monitoring: Set up alerts for suspicious key operations
Resources