GlobalPlatform Amendment B (SCP81) UICC Test Platform with mobile phone integration.
- Overview
- Prerequisites
- Installation
- Project Structure
- Quick Start
- CLI Commands
- Configuration
- Usage Examples
- Troubleshooting
- Advanced Features
GP OTA Tester is a comprehensive testing platform for GlobalPlatform SCP81 Over-The-Air (OTA) administration of UICC (Universal Integrated Circuit Card) smart cards. It provides:
- PSK-TLS Admin Server: Secure server for SCP81 OTA communication
- Phone Controller: Android device management via ADB for UICC testing
- Modem Controller: IoT cellular modem management for M2M testing
- UICC Provisioner: PC/SC smart card provisioning with SCP02/SCP03 secure channels
- Database Layer: SQLAlchemy-based storage for test results and PSK keys
- Web Dashboard: Real-time monitoring of APDU traffic and test sessions
- Python: 3.9 or higher
- Operating System: Linux, macOS, or Windows
- Android Phone: For phone-based UICC testing (with USB debugging enabled)
- Smart Card Reader: PC/SC compatible reader for UICC provisioning
- IoT Modem: Serial-connected cellular modem for M2M testing
For Android device control:
# Install Android Debug Bridge (ADB)
# Ubuntu/Debian
sudo apt install android-tools-adb
# Arch Linux
sudo pacman -S android-tools
# macOS
brew install android-platform-tools
# Windows: Download from Android SDK Platform ToolsFor smart card provisioning (PC/SC):
# Ubuntu/Debian
sudo apt install pcscd pcsc-tools libpcsclite-dev
# Arch Linux
sudo pacman -S pcsclite ccid
# Start PC/SC daemon
sudo systemctl start pcscd
sudo systemctl enable pcscd-
Clone the repository:
git clone git@github.com:veenone/cardlink.git cd cardlink -
Create virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS # or .\venv\Scripts\activate # Windows
-
Install the package:
Basic installation (core features):
pip install -e .With PSK-TLS server support:
pip install -e ".[server]"With all features:
pip install -e ".[all]"
The package provides optional dependency groups:
| Group | Description | Command |
|---|---|---|
psk |
PSK-TLS support (sslpsk3) | pip install -e ".[psk]" |
server |
Full server support with validation | pip install -e ".[server]" |
database |
SQLAlchemy ORM and Alembic migrations | pip install -e ".[database]" |
mysql |
MySQL database driver | pip install -e ".[mysql]" |
postgresql |
PostgreSQL database driver | pip install -e ".[postgresql]" |
pcsc |
PC/SC smart card support (pyscard) | pip install -e ".[pcsc]" |
phone |
Android ADB libraries | pip install -e ".[phone]" |
modem |
Serial modem support (pyserial) | pip install -e ".[modem]" |
dev |
Development tools (pytest, mypy, etc.) | pip install -e ".[dev]" |
docs |
Documentation generation (mkdocs) | pip install -e ".[docs]" |
all |
All optional dependencies | pip install -e ".[all]" |
# Check installed CLI commands
gp-server --help
gp-simulator --help
gp-phone --help
gp-modem --help
gp-db --help
gp-dashboard --helpcardlink/
├── src/cardlink/
│ ├── __init__.py # Package version
│ ├── cli/ # CLI commands
│ │ ├── server.py # gp-server / gp-ota-server
│ │ ├── simulator.py # gp-simulator
│ │ ├── phone.py # gp-phone
│ │ ├── modem.py # gp-modem
│ │ ├── db.py # gp-db
│ │ └── dashboard.py # gp-dashboard
│ ├── server/ # PSK-TLS Admin Server
│ │ ├── admin_server.py # Main server class
│ │ ├── tls_handler.py # TLS connection handler
│ │ ├── key_store.py # PSK key storage backends
│ │ └── config.py # Server configuration
│ ├── phone/ # Android Phone Controller
│ │ ├── controller.py # PhoneController class
│ │ ├── device.py # Device abstraction
│ │ └── adb_client.py # ADB communication
│ ├── modem/ # IoT Modem Controller
│ │ ├── controller.py # ModemController class
│ │ └── serial_client.py # Serial AT commands
│ ├── provisioner/ # UICC Provisioner (PC/SC)
│ │ ├── pcsc_client.py # PC/SC reader interface
│ │ ├── apdu_interface.py # APDU command helpers
│ │ ├── secure_domain.py # GlobalPlatform Security Domain
│ │ ├── scp02.py # SCP02 secure channel
│ │ ├── scp03.py # SCP03 secure channel
│ │ └── tlv_parser.py # BER-TLV parsing
│ ├── database/ # Database Layer
│ │ ├── manager.py # DatabaseManager
│ │ └── models.py # SQLAlchemy models
│ ├── dashboard/ # Web Dashboard
│ │ └── server.py # Dashboard HTTP server
│ └── simulator/ # UICC Card Simulator
│ ├── virtual_uicc.py # Virtual card implementation
│ └── http_client.py # GP Admin HTTP client
├── examples/
│ └── configs/ # Example configuration files
│ ├── server_config.yaml
│ └── psk_keys.yaml
├── tests/ # Test suite
├── docs/ # Documentation
└── pyproject.toml # Project configuration
# Create keys.yaml with a test key
cat > keys.yaml << 'EOF'
# PSK keys: identity -> hex key (16 or 32 bytes)
test_card: "0102030405060708090A0B0C0D0E0F10"
EOF# Start server with dashboard (foreground mode)
gp-server start --port 8443 --keys keys.yaml --foreground --dashboard --dashboard-port 8080
# For testing, enable NULL ciphers (no encryption)
gp-server start --port 8443 --keys keys.yaml --enable-null-ciphers --foreground --dashboard --dashboard-port 8080Open a new terminal and run the simulator:
# Run single card simulation
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10
# With NULL ciphers (must match server)
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --enable-null-ciphersOpen your browser and navigate to http://127.0.0.1:8080 to see:
- Active sessions
- Real-time APDU traffic
- Connection status
# Ensure ADB is running
adb start-server
# List devices
gp-phone list# Using default SQLite
gp-db init
# Using PostgreSQL
gp-db --database postgresql://user:pass@localhost/cardlink initPSK-TLS Admin Server for SCP81 OTA administration.
# Start server with defaults (foreground mode)
gp-server start --port 8443 --keys keys.yaml --foreground
# Start with web dashboard for real-time monitoring
gp-server start --port 8443 --keys keys.yaml --foreground --dashboard --dashboard-port 8080
# Start on specific host/port with NULL ciphers (testing only)
gp-server start --host 0.0.0.0 --port 8443 --keys keys.yaml --enable-null-ciphers --foreground
# Enable verbose debug logging
gp-server start --port 8443 --keys keys.yaml --foreground --verbose
# Enable both verbose and debug logging
gp-server start --port 8443 --keys keys.yaml --foreground --verbose --debug
# Run in background (daemon mode, Unix only)
gp-server start --port 8443 --keys keys.yamlServer Options:
| Option | Description |
|---|---|
--host |
Bind address (default: 127.0.0.1) |
--port |
Listen port (default: 8443) |
--keys |
Path to PSK keys YAML file |
--foreground |
Run in foreground (required on Windows) |
--dashboard |
Enable web dashboard |
--dashboard-port |
Dashboard HTTP port (default: 8080) |
--tls-version |
TLS version: 1.1, 1.2, 1.3 (default: 1.2, recommended per GP SCP81) |
--min-tls-version |
Minimum TLS version to accept |
--max-tls-version |
Maximum TLS version to accept |
--enable-null-ciphers |
Allow NULL ciphers for testing (INSECURE) |
--verbose |
Enable verbose logging |
--debug |
Enable debug-level logging |
Session Management:
# List active sessions (requires running server in another process)
gp-server sessions
# Close a specific session by ID (supports partial ID matching)
gp-server close-session abc123
# Close all active sessions
gp-server close-session --all
# Force close without confirmation prompt
gp-server close-session abc123 --force
gp-server close-session --all --forceClose-Session Options:
| Option | Description |
|---|---|
SESSION_ID |
Session ID to close (optional, supports partial matching with min 4 chars) |
--all |
Close all active sessions |
--force |
Skip confirmation prompt |
UICC card simulator for testing the PSK-TLS Admin Server.
# Run single simulation connecting to server
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10
# Run with NULL ciphers (must match server)
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --enable-null-ciphers
# Run multiple simulated cards in sequence
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --count 5
# Run multiple simulated cards in parallel
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --count 3 --parallel
# Run in continuous loop with interval
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --loop --interval 5
# Enable verbose output
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --verboseSimulator Options:
| Option | Description |
|---|---|
--server |
Server address as host:port |
--psk-identity |
PSK identity (must exist in server's keys file) |
--psk-key |
PSK key in hexadecimal |
--tls-version |
TLS version: 1.1, 1.2, 1.3 (default: 1.2, must match server) |
--apdu-format |
APDU payload format per ETSI 102.226: compact, expanded_definite, expanded_indefinite |
--enable-null-ciphers |
Use NULL ciphers (must match server) |
--count |
Number of simulations to run (default: 1) |
--parallel |
Run simulations concurrently |
--loop |
Run continuously until interrupted |
--interval |
Delay between loop iterations in seconds |
--verbose |
Enable verbose logging |
Android phone control and monitoring via ADB.
# List connected devices
gp-phone list
# Show device info
gp-phone info <serial>
# Show all info (device, SIM, network)
gp-phone info <serial> --all
# Send AT command
gp-phone at <serial> "AT+CPIN?"
# Monitor device events
gp-phone monitor <serial>
# Save device profile
gp-phone profile save <serial> my_phone
# Load device profile
gp-phone profile load my_phone
# Output as JSON
gp-phone list --json
gp-phone info <serial> --jsonIoT cellular modem control and monitoring.
# List connected modems
gp-modem list
# Show modem info
gp-modem info /dev/ttyUSB2
# Send AT command
gp-modem at /dev/ttyUSB2 "ATI"
# Monitor modem
gp-modem monitor /dev/ttyUSB2Database management commands.
# Initialize database (create tables)
gp-db init
# Force recreate (drops existing tables)
gp-db init --force
# Check database status
gp-db status
# Export data to YAML
gp-db export --format yaml --output backup.yaml
# Export to JSON
gp-db export --format json --output backup.json
# Import data
gp-db import backup.yaml
# Use custom database URL
gp-db --database postgresql://user:pass@localhost/db statusWeb-based monitoring dashboard.
# Start dashboard on default port (8080)
gp-dashboard start
# Custom host and port
gp-dashboard start --host 0.0.0.0 --port 3000
# Open browser automatically
gp-dashboard start --open# Network settings
host: "127.0.0.1" # Bind address
port: 8443 # Listen port
backlog: 5 # Connection backlog
# Connection handling
max_connections: 10 # Max concurrent connections
read_timeout: 30.0 # HTTP read timeout (seconds)
handshake_timeout: 30.0 # TLS handshake timeout
# Session management
session_timeout: 300.0 # Idle session timeout
# PSK key store
keys_file: "psk_keys.yaml"
# Cipher suites
cipher_config:
enable_production: true # AES-CBC-SHA256/SHA384
enable_legacy: false # AES-CBC-SHA (older clients)
enable_null_ciphers: false # DANGER: No encryption
# Logging
logging:
level: "INFO" # DEBUG, INFO, WARNING, ERROR
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
# Security monitoring
security:
mismatch_window: 60.0 # PSK mismatch tracking window
mismatch_threshold: 3 # Trigger warning after N mismatches
error_rate_window: 300.0 # Error rate monitoring window
error_rate_threshold: 10 # High error rate alert threshold
# Event emission
events:
enabled: true
queue_size: 1000# Format: identity: hex_encoded_key
# Test cards (16-byte / 128-bit keys)
test_card_001: "0102030405060708090A0B0C0D0E0F10"
test_card_002: "1112131415161718191A1B1C1D1E1F20"
# 32-byte / 256-bit key
test_card_003: "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF"
# Production cards (use secure random keys)
# card_ICCID_12345678901234567890: "YOUR_SECURE_KEY_HEX"# Server configuration
export GP_OTA_SERVER_HOST="0.0.0.0"
export GP_OTA_SERVER_PORT="8443"
export GP_OTA_SERVER_CONFIG="/etc/gp-ota/config.yaml"
# Database URL
export DATABASE_URL="postgresql://user:pass@localhost/cardlink"# Terminal 1: Start the server with dashboard
gp-server start --port 8443 --keys keys.yaml --enable-null-ciphers --foreground --dashboard --dashboard-port 8080
# Terminal 2: Run a single simulation
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --enable-null-ciphers
# Terminal 2: Run 5 simulations in parallel
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --enable-null-ciphers --count 5 --parallel
# Terminal 2: Run continuous loop (press Ctrl+C to stop)
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --enable-null-ciphers --loop --interval 2# Create PSK keys file with secure random keys
python -c "import secrets; print(f'card_001: \"{secrets.token_hex(16)}\"')" > keys.yaml
python -c "import secrets; print(f'card_002: \"{secrets.token_hex(16)}\"')" >> keys.yaml
# Start server (production - no NULL ciphers)
gp-server start --host 0.0.0.0 --port 8443 --keys keys.yaml --foreground --dashboard --dashboard-port 8080# 1. Discover connected devices
gp-phone list
# 2. Get device details
gp-phone info ABC123456789 --all
# 3. Check SIM status
gp-phone at ABC123456789 "AT+CPIN?"
# 4. Monitor for OTA events
gp-phone monitor ABC123456789import asyncio
from cardlink.phone import PhoneController
async def main():
# Create controller
controller = PhoneController()
# Discover devices
devices = await controller.discover_devices()
print(f"Found {len(devices)} devices")
# Get specific device
if devices:
phone = await controller.get_device(devices[0].serial)
profile = await phone.info.get_full_profile()
print(f"Model: {profile.device.model}")
print(f"ICCID: {profile.sim.iccid}")
asyncio.run(main())from cardlink.provisioner import (
PCSCClient, APDUInterface, SecureDomainManager,
SCP02, SCPKeys
)
# Connect to card
client = PCSCClient()
readers = client.list_readers()
client.connect(readers[0])
# Create APDU interface
apdu = APDUInterface(client.transmit)
# Create secure domain manager
sd = SecureDomainManager(client.transmit)
# Select ISD
response = sd.select_isd()
print(f"ISD selected: SW={response.sw:04X}")
# Establish SCP02 secure channel
keys = SCPKeys(
enc=bytes.fromhex("404142434445464748494A4B4C4D4E4F"),
mac=bytes.fromhex("404142434445464748494A4B4C4D4E4F"),
dek=bytes.fromhex("404142434445464748494A4B4C4D4E4F"),
)
scp02 = SCP02(client.transmit)
scp02.initialize(keys)
# Now all commands are secured with C-MAC
apps = sd.get_status_apps()
for app in apps:
print(f"AID: {app.aid.hex().upper()}")
client.disconnect()from cardlink.database import DatabaseManager, DatabaseConfig
# Configure database
config = DatabaseConfig(url="sqlite:///data/cardlink.db")
db = DatabaseManager(config)
db.initialize()
db.create_tables()
# Use database...
db.close()Server fails to start with "Address already in use":
# Check what's using the port
lsof -i :8443
# or
netstat -tlnp | grep 8443
# Use a different port
gp-server start --port 9443SSL handshake fails:
- Ensure client and server use matching PSK identity and key
- Check cipher suite compatibility
- Verify TLS version (requires TLS 1.2)
No devices shown by gp-phone list:
# Check ADB server
adb devices
# Restart ADB
adb kill-server
adb start-server
# Check USB connection
lsusb | grep -i androidDevice shows as "unauthorized":
- Enable USB debugging on phone
- Accept the RSA fingerprint prompt on phone
- Run
adb devicesagain
No readers found:
# Check pcscd service
sudo systemctl status pcscd
# Start pcscd
sudo systemctl start pcscd
# List readers
pcsc_scanCard not responding:
- Ensure card is properly inserted
- Try a different reader
- Check card ATR with
pcsc_scan
SQLite "database is locked":
- Close other connections to the database
- Use WAL mode for concurrent access
PostgreSQL connection refused:
# Check PostgreSQL is running
sudo systemctl status postgresql
# Verify connection settings
psql -h localhost -U user -d cardlinkEnable verbose logging:
gp-server start --verbose
gp-phone --verbose listCheck Python dependencies:
pip list | grep -E "sslpsk|pyscard|pyserial|adb"Reinstall with all dependencies:
pip install -e ".[all]" --force-reinstallThe PSK-TLS server and simulator support configurable TLS versions per GlobalPlatform GPC_SPE_011:
- TLS 1.2 (default, recommended): Mandatory per GP SCP81 specification
- TLS 1.1: Legacy support for older implementations
- TLS 1.3: Optional advanced security (requires updated OpenSSL)
Server Example:
# Use TLS 1.2 (default, recommended)
gp-server start --port 8443 --keys keys.yaml --foreground
# Use specific TLS version
gp-server start --port 8443 --keys keys.yaml --tls-version 1.2 --foreground
# Accept range of TLS versions
gp-server start --port 8443 --keys keys.yaml --min-tls-version 1.1 --max-tls-version 1.3 --foregroundSimulator Example:
# Use TLS 1.2 (must match server)
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key 0102030405060708090A0B0C0D0E0F10 --tls-version 1.2The simulator supports three APDU payload encoding formats per ETSI TS 102.226:
| Format | Description |
|---|---|
compact |
T=0 TPDU format (default, Section 5.1.1) |
expanded_definite |
BER-TLV with definite length encoding (Section 5.1.2) |
expanded_indefinite |
BER-TLV with indefinite length encoding (Section 5.1.2) |
Usage:
# Use compact format (default)
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key KEY --apdu-format compact
# Use expanded definite format
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key KEY --apdu-format expanded_definite
# Use expanded indefinite format
gp-simulator run --server 127.0.0.1:8443 --psk-identity test_card --psk-key KEY --apdu-format expanded_indefiniteYAML Configuration:
# In simulator.yaml
tls:
version: "1.2"
apdu_payload_format: "compact" # or expanded_definite, expanded_indefinite- PSK-TLS Server Guide - Detailed PSK-TLS server setup and configuration
- Simulator Guide - UICC card simulator for testing
- Dashboard Guide - Web dashboard for monitoring sessions and APDU traffic
This project is licensed under the MIT License.