Authentication and Entitlement WebAuthn and Smart Contract
# Server Configuration
export PORT=8443
export TLS_CERT_PATH=/path/to/fullchain.pem
export TLS_KEY_PATH=/path/to/privkey.pem
# Cryptographic Keys
export SIGN_KEY_PATH=/path/to/signkey.pem
export ENCODING_KEY_PATH=/path/to/encodekey.pem
export DECODING_KEY_PATH=/path/to/decodekey.pem
# DynamoDB Configuration
export DYNAMODB_CREDENTIALS_TABLE=prod-credentials
export DYNAMODB_HANDLES_TABLE=prod-handles
export AWS_REGION=your-region
aws dynamodb create-table \
--table-name credentials \
--attribute-definitions \
AttributeName=user_id,AttributeType=S \
AttributeName=username,AttributeType=S \
--key-schema AttributeName=user_id,KeyType=HASH \
--global-secondary-indexes \
"[{
\"IndexName\": \"username-index\",
\"KeySchema\": [{\"AttributeName\":\"username\",\"KeyType\":\"HASH\"}],
\"Projection\":{\"ProjectionType\":\"ALL\"}
}]" \
--billing-mode PAY_PER_REQUEST
Run the unit test suite:
cargo test
- Set up local DynamoDB:
docker run -p 8000:8000 amazon/dynamodb-local
- Run integration tests:
export DYNAMODB_ENDPOINT=http://localhost:8000
cargo test --test '*' --features integration
- Register a new user:
curl http://localhost:8080/register/testuser
curl -X POST http://localhost:8080/register/testuser \
-H "Content-Type: application/json" \
-d '{"challenge": "..."}'
- Authenticate:
curl http://localhost:8080/authenticate/testuser
curl -X POST http://localhost:8080/authenticate/testuser \
-H "Content-Type: application/json" \
-d '{"challenge": "..."}'
- Create signing key (SIGN_KEY_PATH):
openssl ecparam -genkey -name prime256v1 -noout -out signkey.pem
- Create encoding key (ENCODING_KEY_PATH):
openssl ecparam -genkey -noout -name prime256v1 \
| openssl pkcs8 -topk8 -nocrypt -out encodekey.pem
- Create decoding key (DECODING_KEY_PATH):
openssl ec -in encodekey.pem -pubout -out decodekey.pem
- Verify keys:
openssl ec -in signkey.pem -text -noout
openssl ec -in encodekey.pem -text -noout
openssl ec -in decodekey.pem -text -noout
- Create Credentials Table:
aws dynamodb create-table \
--endpoint-url http://localhost:8000 \
--table-name credentials \
--attribute-definitions \
AttributeName=user_id,AttributeType=S \
AttributeName=username,AttributeType=S \
--key-schema AttributeName=user_id,KeyType=HASH \
--global-secondary-indexes \
"[{
\"IndexName\": \"username-index\",
\"KeySchema\": [{\"AttributeName\":\"username\",\"KeyType\":\"HASH\"}],
\"Projection\":{\"ProjectionType\":\"ALL\"},
\"ProvisionedThroughput\":{\"ReadCapacityUnits\":5,\"WriteCapacityUnits\":5}
}]" \
--billing-mode PAY_PER_REQUEST
- Create Handles Table:
aws dynamodb create-table \
--endpoint-url http://localhost:8000 \
--table-name handles \
--attribute-definitions \
AttributeName=handle,AttributeType=S \
--key-schema AttributeName=handle,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
Configure AWS credentials using one of:
- Environment variables:
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
- AWS credentials file (~/.aws/credentials)
- IAM role when running on AWS services
- AWS SSO configuration
Format code using:
cargo fmt
Run clippy lints:
cargo clippy
- Always use HTTPS in production
- Keep AWS credentials secure and rotate regularly
- Monitor DynamoDB table usage and costs
- Consider enabling DynamoDB encryption at rest
- Use VPC endpoints for DynamoDB in production
- Implement proper request rate limiting
- Monitor and log authentication attempts
- Regularly update dependencies
- Implement key rotation
- Add an endpoint to retrieve public keys
- Implement signature verification on the client-side
- Enhance error handling and logging for key operations
- Consider using a key management service for production environments
- Implement secure key deletion
- Add support for additional cryptographic algorithms as needed
- Implement a mechanism to revoke or update signed tokens if necessary
- Add table backups and point-in-time recovery for DynamoDB tables
- Implement DynamoDB auto-scaling policies
- Add monitoring and alerting for DynamoDB operations
- Configure DynamoDB DAX for caching if needed
- Add retries and circuit breakers for DynamoDB operations