The Shamir Secret Sharing API provides both cryptographic functions and distributed storage capabilities through RESTful endpoints and gRPC services.
All endpoints except /
and /register
require JWT authentication.
Register a new user account.
{
"username": "string",
"password": "string"
}
{
"msg": "User registered successfully"
}
Authenticate and receive JWT token.
{
"username": "string",
"password": "string"
}
{
"access_token": "string",
"token_type": "bearer"
}
Test authenticated route.
Authorization: Bearer {token}
{
"msg": "Hello, {username}. This is a protected route."
}
Store a secret key-value pair using Shamir's algorithm.
Authorization: Bearer {token}
Content-Type: application/json
{
key: string; // Unique identifier for the secret
value: string; // The secret value to store
}
HTTP 201 Created on success
Retrieve a previously stored secret.
Authorization: Bearer {token}
Content-Type: application/json
{
key: string; // The identifier of the secret to retrieve
}
{
"secret": "string" // The reconstructed secret value
}
Central coordination service for managing slave nodes and secret distribution.
class MasterServer(cf_grpc.MasterServicer):
def Connect(self, request, context):
peer = context.peer() # Get client IP
# Register slave in database
slave_manager.add(peer.split(':')[1])
return cf.ConnectionResponse(approve=True)
Service for storing and retrieving secret parts on slave nodes.
def start_slave(master_host, port):
# Connect to master first
if connect_to_master(master_host):
# Start gRPC server
server = grpc.server(futures.ThreadPoolExecutor())
cf_grpc.add_SlaveServicer_to_server(SlaveServer(), server)
server.add_insecure_port(f"0.0.0.0:{port}")
server.start()
Compile .proto files using the provided script:
./compile_proto.sh
# Generates:
# - resources/generated/*_pb2.py
# - resources/generated/*_pb2_grpc.py
# - resources/generated/*_pb2.pyi (mypy types)
Code | Description |
---|---|
400 | Bad request (invalid parameters) |
401 | Unauthorized (invalid/missing token) |
404 | Secret not found |
500 | Internal server error |