This document provides comprehensive API documentation for the LockLess biometric authentication system.
- Core API
- Biometric API
- Security API
- UI API
- REST API
- Python SDK
- Configuration API
- Error Handling
- Examples
Manages system configuration and settings.
from src.core.config import ConfigManager
# Initialize with default config
config = ConfigManager()
# Initialize with custom config
config = ConfigManager("path/to/config.yaml")
# Get configuration value
value = config.get('camera.device_id', default=0)
# Set configuration value
config.set('camera.device_id', 1)
# Save configuration
config.save()Initialize configuration manager.
Parameters:
config_path(str, optional): Path to configuration file
Get configuration value by key.
Parameters:
key(str): Configuration key (supports dot notation)default(Any): Default value if key not found
Returns:
- Configuration value or default
Set configuration value.
Parameters:
key(str): Configuration keyvalue(Any): Value to set
Structured logging with security event tracking.
from src.core.logging import get_logger, get_security_logger, SecurityEventType
# Get standard logger
logger = get_logger(__name__)
# Get security logger
security_logger = get_security_logger()
# Log security event
security_logger.log_security_event(
SecurityEventType.TEMPLATE_ACCESS,
user_id="john_doe",
additional_data={"action": "read"},
success=True
)TEMPLATE_ACCESS: Template access eventsAUTHENTICATION_ATTEMPT: Authentication attemptsENROLLMENT_ATTEMPT: Enrollment attemptsSECURITY_VIOLATION: Security violationsSYSTEM_ERROR: System errors
Handles user enrollment process.
from src.biometric.enrollment import BiometricEnrollment, EnrollmentConfig
# Create enrollment configuration
config = EnrollmentConfig(
camera_id=0,
required_samples=5,
quality_threshold=0.7
)
# Initialize enrollment
enrollment = BiometricEnrollment(config)
# Enroll user
result = enrollment.enroll_user("john_doe", "password123")Configuration for enrollment process.
@dataclass
class EnrollmentConfig:
camera_id: int = 0
required_samples: int = 5
quality_threshold: float = 0.7
max_enrollment_time: int = 30
sample_interval: float = 1.0Enroll a new user with biometric data.
Parameters:
user_id(str): Unique user identifierpassword(str): Master password for encryption
Returns:
EnrollmentResult: Enrollment result with success status and metadata
Handles user authentication.
from src.biometric.authentication import AuthenticationEngine, AuthenticationConfig
# Create authentication configuration
config = AuthenticationConfig(
camera_id=0,
similarity_threshold=0.7,
quality_threshold=0.6,
max_authentication_time=10
)
# Initialize authentication engine
auth_engine = AuthenticationEngine(config)
# Authenticate user
result = auth_engine.authenticate_user("john_doe", "password123")Configuration for authentication process.
@dataclass
class AuthenticationConfig:
camera_id: int = 0
similarity_threshold: float = 0.7
quality_threshold: float = 0.6
max_authentication_time: int = 10
max_attempts: int = 3
lockout_duration: int = 300Authenticate a user with biometric data.
Parameters:
user_id(str): User identifierpassword(str): Master password
Returns:
AuthenticationResult: Authentication result with success status and confidence
Face detection and feature extraction.
from src.biometric.face_detection import FaceDetector
# Initialize face detector
detector = FaceDetector()
# Detect faces in image
faces = detector.detect_faces(image)
# Extract face features
features = detector.extract_features(face_image)Detect faces in an image.
Parameters:
image(np.ndarray): Input image
Returns:
- List of detected faces
Extract face features for recognition.
Parameters:
face_image(np.ndarray): Cropped face image
Returns:
- Feature vector (512-dimensional)
Anti-spoofing and liveness detection.
from src.biometric.liveness import LivenessDetector
# Initialize liveness detector
liveness = LivenessDetector()
# Check if face is live
is_live = liveness.check_liveness(face_image, depth_map)Check if detected face is live.
Parameters:
face_image(np.ndarray): Face imagedepth_map(np.ndarray, optional): Depth information
Returns:
- True if face is live, False otherwise
Encrypted storage for biometric templates.
from src.security.encryption import SecureTemplateStorage
# Initialize storage
storage = SecureTemplateStorage()
# Store template
storage.store_template("john_doe", encrypted_template, password)
# Retrieve template
template = storage.load_template("john_doe", password)
# Delete template
storage.delete_template("john_doe")
# List users
users = storage.list_users()Store encrypted biometric template.
Parameters:
user_id(str): User identifiertemplate(bytes): Encrypted template datapassword(str): Encryption password
Returns:
- True if successful, False otherwise
Load encrypted biometric template.
Parameters:
user_id(str): User identifierpassword(str): Decryption password
Returns:
- Decrypted template or None if not found
Secure key derivation and management.
from src.security.key_management import KeyManager
# Initialize key manager
key_manager = KeyManager()
# Derive key from password
key = key_manager.derive_key(password, salt)
# Generate random salt
salt = key_manager.generate_salt()
# Encrypt data
encrypted_data = key_manager.encrypt(data, key)
# Decrypt data
decrypted_data = key_manager.decrypt(encrypted_data, key)Main application window.
from src.ui.main_window import MainWindow
# Create main window
window = MainWindow()
# Show window
window.show()
# Start event loop
window.run()User enrollment interface.
from src.ui.enrollment_dialog import EnrollmentDialog
# Create enrollment dialog
dialog = EnrollmentDialog(parent_window)
# Start enrollment
result = dialog.start_enrollment("john_doe")User authentication interface.
from src.ui.authentication_dialog import AuthenticationDialog
# Create authentication dialog
dialog = AuthenticationDialog(parent_window)
# Start authentication
result = dialog.start_authentication("john_doe")Enroll a new user.
Request:
{
"user_id": "john_doe",
"password": "secret123"
}Response:
{
"success": true,
"user_id": "john_doe",
"samples_collected": 5,
"average_quality": 0.85,
"processing_time": 12.3
}Authenticate a user.
Request:
{
"user_id": "john_doe",
"password": "secret123"
}Response:
{
"success": true,
"user_id": "john_doe",
"confidence": 0.92,
"quality_score": 0.88,
"processing_time": 0.35
}List enrolled users.
Response:
{
"users": ["john_doe", "jane_smith"],
"count": 2
}Delete a user.
Response:
{
"success": true,
"message": "User deleted successfully"
}Get system status.
Response:
{
"status": "healthy",
"version": "1.0.0",
"uptime": 3600,
"camera_available": true,
"users_count": 2
}Get system diagnostics.
Response:
{
"camera": {
"available": true,
"resolution": "640x480",
"fps": 30
},
"performance": {
"memory_usage": "256MB",
"cpu_usage": "5%",
"disk_usage": "50MB"
},
"security": {
"encryption_enabled": true,
"tpm_available": false
}
}Main client for interacting with LockLess.
from lockless import LockLessClient
# Initialize client
client = LockLessClient()
# Enroll user
result = client.enroll_user("john_doe", "password123")
print(f"Enrollment: {result.success}")
# Authenticate user
result = client.authenticate_user("john_doe", "password123")
print(f"Authentication: {result.success}")
# List users
users = client.list_users()
print(f"Users: {users}")
# Delete user
success = client.delete_user("john_doe")
print(f"Deletion: {success}")Enroll a new user.
Authenticate a user.
List enrolled users.
Delete a user.
Get system status.
camera.device_id: Camera device ID (default: 0)camera.resolution.width: Image width (default: 640)camera.resolution.height: Image height (default: 480)camera.fps: Frames per second (default: 30)
authentication.similarity_threshold: Similarity threshold (default: 0.7)authentication.quality_threshold: Quality threshold (default: 0.6)authentication.max_attempts: Maximum attempts (default: 3)authentication.lockout_duration: Lockout duration in seconds (default: 300)
enrollment.required_samples: Required samples (default: 5)enrollment.quality_threshold: Quality threshold (default: 0.4)enrollment.max_enrollment_time: Max enrollment time (default: 30)
security.encryption_enabled: Enable encryption (default: true)security.tpm_enabled: Enable TPM (default: false)security.key_derivation_iterations: Key derivation iterations (default: 100000)
# Base exception
class LockLessError(Exception):
"""Base exception for LockLess errors."""
# Configuration errors
class ConfigurationError(LockLessError):
"""Configuration-related errors."""
# Biometric errors
class BiometricError(LockLessError):
"""Biometric processing errors."""
class EnrollmentError(BiometricError):
"""Enrollment-specific errors."""
class AuthenticationError(BiometricError):
"""Authentication-specific errors."""
# Security errors
class SecurityError(LockLessError):
"""Security-related errors."""
class EncryptionError(SecurityError):
"""Encryption/decryption errors."""
# Camera errors
class CameraError(LockLessError):
"""Camera-related errors."""
# Validation errors
class ValidationError(LockLessError):
"""Input validation errors."""E001: Configuration file not foundE002: Invalid configuration valueE003: Camera not availableE004: Face not detectedE005: Liveness check failedE006: Template not foundE007: Authentication failedE008: Encryption errorE009: Invalid user IDE010: Password too weak
from src.core.config import ConfigManager
from src.biometric.enrollment import BiometricEnrollment, EnrollmentConfig
from src.core.logging import get_logger
logger = get_logger(__name__)
def enroll_user_example():
"""Complete example of user enrollment."""
try:
# Load configuration
config_manager = ConfigManager()
# Create enrollment configuration
enrollment_config = EnrollmentConfig(
camera_id=config_manager.get('camera.device_id', 0),
required_samples=config_manager.get('enrollment.required_samples', 5),
quality_threshold=config_manager.get('enrollment.quality_threshold', 0.7)
)
# Initialize enrollment
enrollment = BiometricEnrollment(enrollment_config)
# Enroll user
result = enrollment.enroll_user("john_doe", "password123")
if result.success:
logger.info(f"User {result.user_id} enrolled successfully")
logger.info(f"Samples collected: {result.samples_collected}")
logger.info(f"Average quality: {result.average_quality}")
else:
logger.error(f"Enrollment failed: {result.error_message}")
except Exception as e:
logger.error(f"Enrollment error: {e}")from src.core.config import ConfigManager
from src.biometric.authentication import AuthenticationEngine, AuthenticationConfig
from src.core.logging import get_logger
logger = get_logger(__name__)
def authenticate_user_example():
"""Complete example of user authentication."""
try:
# Load configuration
config_manager = ConfigManager()
# Create authentication configuration
auth_config = AuthenticationConfig(
camera_id=config_manager.get('camera.device_id', 0),
similarity_threshold=config_manager.get('authentication.similarity_threshold', 0.7),
quality_threshold=config_manager.get('authentication.quality_threshold', 0.6)
)
# Initialize authentication engine
auth_engine = AuthenticationEngine(auth_config)
# Authenticate user
result = auth_engine.authenticate_user("john_doe", "password123")
if result.success:
logger.info(f"Authentication successful for {result.user_id}")
logger.info(f"Confidence: {result.confidence}")
logger.info(f"Quality score: {result.quality_score}")
else:
logger.error(f"Authentication failed: {result.error_message}")
except Exception as e:
logger.error(f"Authentication error: {e}")import requests
import json
class LockLessAPIClient:
"""Client for LockLess REST API."""
def __init__(self, base_url="http://localhost:8080"):
self.base_url = base_url
self.session = requests.Session()
def enroll_user(self, user_id: str, password: str):
"""Enroll a new user."""
response = self.session.post(
f"{self.base_url}/api/v1/enroll",
json={"user_id": user_id, "password": password}
)
return response.json()
def authenticate_user(self, user_id: str, password: str):
"""Authenticate a user."""
response = self.session.post(
f"{self.base_url}/api/v1/authenticate",
json={"user_id": user_id, "password": password}
)
return response.json()
def list_users(self):
"""List enrolled users."""
response = self.session.get(f"{self.base_url}/api/v1/users")
return response.json()
def delete_user(self, user_id: str):
"""Delete a user."""
response = self.session.delete(f"{self.base_url}/api/v1/users/{user_id}")
return response.json()
# Usage example
client = LockLessAPIClient()
# Enroll user
result = client.enroll_user("john_doe", "password123")
print(f"Enrollment: {result}")
# Authenticate user
result = client.authenticate_user("john_doe", "password123")
print(f"Authentication: {result}")This API reference provides comprehensive documentation for all LockLess APIs. For more specific examples and advanced usage, refer to the individual module documentation and the test suite.