PyKMIP
The Cosmian KMS strives to be compatible with the PyKMIP client library, which is widely used for KMIP protocol interactions. This document provides a comprehensive guide to testing and validating PyKMIP compatibility with the Cosmian KMS server.
- Purpose of PyKMIP compatibility tests
- Prerequisites
- Quick Start
- Supported Operations
- Understanding Test Results
- Troubleshooting
- File Structure
- Configuration
- Contributing
- Available Operations (Detailed Examples)
- Using the Test Runner (Recommended)
- Manual Client Usage (Advanced)
- 1. Query Server Capabilities
- 2. Create Symmetric Key
- 3. Create RSA Key Pair
- 4. Test Encryption/Decryption
- 5. Activate Objects
- Operation Categories
- ✅ Fully Supported Operations
- ⚠️ Partially Supported Operations
- ❌ Known Problematic Operations
- 🧪 Experimental Operations
- Integration with CI/CD
- Known Limitations and Compatibility
- Related Documentation
Purpose of PyKMIP compatibility tests¶
The PyKMIP compatibility tests serve to:
- Verify that our KMS server correctly implements the KMIP protocol standard
- Ensure interoperability with existing KMIP client implementations
- Catch any regression issues that might break compatibility with PyKMIP clients
- Validate that common KMIP operations work as expected across different client implementations
- Test edge cases and error handling for unsupported operations
Prerequisites¶
- Python 3.x installed on your system
- PyKMIP library (will be installed by setup script)
- Cosmian KMS server running and accessible with KMIP socket server enabled
- All scripts must be executed from the project root directory (not from within the
scripts/
directory) - Virtual environment (.venv) set up and activated for Python dependencies
Quick Start¶
The fastest way to test PyKMIP compatibility is to use the automated test runner:
# 1. Set up the environment (from project root)
./scripts/setup_pykmip.sh
# 2. Start the KMS server (in another terminal)\
pkill -f cosmian_kms # Stop any existing instance
COSMIAN_KMS_CONF=./scripts/kms.toml cargo run --bin cosmian_kms --features non-fips
# 3. Run all compatibility tests
./scripts/test_pykmip.sh all
# 4. Or run specific operations
./scripts/test_pykmip.sh query -v
./scripts/test_pykmip.sh create
./scripts/test_pykmip.sh check
The test runner automatically:
- Activates the Python virtual environment
- Validates prerequisites and connectivity
- Executes the requested operations with proper error handling
- Provides detailed output and status reporting
- Runs with timeout protection to prevent hanging tests
Supported Operations¶
The current test suite supports the following KMIP operations:
Core Operations¶
- query - Discover server capabilities and protocol versions
- create - Create symmetric keys
- create_keypair - Create RSA key pairs
- get - Retrieve an object
- get_attributes - Retrieve object attributes
- destroy - Delete objects from the server
- locate - Find objects by search criteria
Cryptographic Operations¶
- encrypt - Encrypt data using managed keys
- decrypt - Decrypt data using managed keys
- mac - Generate Message Authentication Codes
- activate - Activate objects for use
Management Operations¶
- revoke - Revoke objects and certificates
- discover_versions - Discover supported KMIP protocol versions
Special Commands¶
- all - Execute all supported operations in sequence
- check - Validate prerequisites and connectivity
- rust-test - Run Rust-based PyKMIP integration tests
Experimental/Unsupported Operations¶
- certify - Certificate signing (implemented via separate module
pykmip_certify.py
, uses operations not yet supported by Cosmian KMS)
Note: Some operations may fail due to server limitations or KMIP 1.x compatibility constraints. The test runner handles these gracefully and provides detailed error reporting.
Understanding Test Results¶
The test script provides comprehensive output for each operation with clear status indicators:
Success Case¶
Operations that complete successfully will show:
{
"operation": "Create",
"status": "success",
"unique_identifier": "abc123-def456-789",
"additional_info": {
...
}
}
Failure Case¶
Operations that fail will show:
{
"operation": "MAC",
"status": "error",
"error": "Invalid parameter provided",
"details": "Cryptographic algorithm not supported"
}
Test Summary¶
After running all operations, you’ll see a summary like:
======================================
FINAL TEST RESULTS SUMMARY
======================================
✅ SUCCESSFUL operations (12/13):
✅ query
✅ create
✅ get_attributes
✅ get
✅ destroy
✅ encrypt
✅ decrypt
✅ locate
✅ discover_versions
✅ mac
✅ activate
✅ revoke
✅ create_keypair
🔍 certify (not supported in PyKMIP - workaround under study)
Operation Status Types¶
- ✅ SUCCESS: Operation completed and returned successful status
- ❌ FAILED: Operation returned error status or threw exception
- ⚠️ TIMEOUT: Operation timed out after 30 seconds
- 🔍 UNSUPPORTED: Operation not supported by server or KMIP version
Troubleshooting¶
Common Issues¶
-
Script execution fails: Ensure you’re running from the project root, not from
scripts/
-
PyKMIP import errors: Run
setup_pykmip.sh
to install dependencies -
Connection refused: Verify the KMS server is running with KMIP socket server enabled
-
Virtual environment not found: The test runner requires a .venv directory
-
TLS/Certificate errors: Verify certificate paths and validity
-
Operation timeouts: Some operations may timeout due to server processing time
Advanced Troubleshooting¶
Enable verbose output to see detailed operation information:
Check server logs while running tests:
Test connectivity manually:
Run individual operations to isolate issues:
File Structure¶
The PyKMIP test suite consists of the following files:
scripts/
├── README_PYKMIP.md # Additional documentation
├── setup_pykmip.sh # Environment setup script
├── verify_pykmip.sh # Configuration verification script
├── test_pykmip.sh # Main compatibility test runner
├── pykmip_client.py # PyKMIP client implementation (12 operations)
├── pykmip_certify.py # Separate certify operation module
├── pykmip.conf # PyKMIP configuration file
├── kms.toml # KMS server configuration for testing
├── activate_venv.sh # Virtual environment activation helper
└── certify_implementation_summary.py # Certify operation analysis script
Key Files¶
test_pykmip.sh
: Main test runner with colored output, timeout protection, and comprehensive error handlingpykmip_client.py
: Core client implementing 12 KMIP operations with JSON output formattingpykmip_certify.py
: Modular implementation of certificate-related operations (experimental)pykmip.conf
: Configuration file with TLS settings, authentication, and server connection detailskms.toml
: KMS server configuration optimized for PyKMIP compatibility testing
Configuration¶
The pykmip.conf
file contains the connection settings for the PyKMIP client. Key configuration sections:
Server Connection¶
TLS Configuration¶
[tls]
client_cert_file=test_data/client_server/owner/owner.client.acme.com.crt
client_key_file=test_data/client_server/owner/owner.client.acme.com.key
ca_cert_file=test_data/client_server/ca/ca.crt
Protocol Settings¶
Ensure these parameters match your KMS server setup:
- Server hostname/IP and port (default: 127.0.0.1:5696)
- TLS certificate paths (must exist and be valid)
- KMIP protocol version compatibility
KMS Server Configuration¶
Your KMS server must be configured to accept KMIP connections. Key settings in scripts/kms.toml
:
[server]
# Enable KMIP socket server
socket_server_start = true
socket_server_port = 5696
socket_server_hostname = "0.0.0.0"
[tls]
# Server certificate and key
tls_p12_file = "test_data/client_server/server/kmserver.acme.com.p12"
tls_p12_password = "password"
clients_ca_cert_file = "test_data/client_server/ca/ca.crt"
Contributing¶
When adding new PyKMIP compatibility tests:
-
Add new operations to the
operations
array intest_pykmip.sh
: -
Implement operation functions in
pykmip_client.py
: -
Add to argument parser choices in
pykmip_client.py
: -
Update help text in
test_pykmip.sh
to include the new operation -
Handle modular operations like certify by creating separate files:
- Create
pykmip_operation.py
for complex operations - Import and call from main client:
from pykmip_operation import perform_operation
- Create
-
Test both success and failure scenarios to ensure proper error handling
-
Update this README if new setup steps or dependencies are required
Testing Best Practices¶
- Always test with both verbose (
-v
) and normal output modes - Verify operations work individually and in the “all” test suite
- Check for JSON serialization issues with complex data types
- Ensure timeout handling works correctly for long-running operations
- Document any server limitations or KMIP version constraints
Available Operations (Detailed Examples)¶
Using the Test Runner (Recommended)¶
The test runner (test_pykmip.sh
) automatically handles environment setup and provides consistent output formatting:
# Run all operations with summary report
./scripts/test_pykmip.sh all
# Run specific operation with verbose output
./scripts/test_pykmip.sh query -v
# Check prerequisites and connectivity
./scripts/test_pykmip.sh check
# Run individual operations
./scripts/test_pykmip.sh create
./scripts/test_pykmip.sh encrypt
./scripts/test_pykmip.sh mac
Manual Client Usage (Advanced)¶
For direct client access with custom parameters:
1. Query Server Capabilities¶
source .venv/bin/activate
python scripts/pykmip_client.py \
--configuration scripts/pykmip.conf \
--operation query \
--verbose
2. Create Symmetric Key¶
source .venv/bin/activate
python scripts/pykmip_client.py \
--configuration scripts/pykmip.conf \
--operation create
3. Create RSA Key Pair¶
source .venv/bin/activate
python scripts/pykmip_client.py \
--configuration scripts/pykmip.conf \
--operation create_keypair
4. Test Encryption/Decryption¶
source .venv/bin/activate
python scripts/pykmip_client.py \
--configuration scripts/pykmip.conf \
--operation encrypt
python scripts/pykmip_client.py \
--configuration scripts/pykmip.conf \
--operation decrypt
5. Activate Objects¶
source .venv/bin/activate
python scripts/pykmip_client.py \
--configuration scripts/pykmip.conf \
--operation activate