|
| 1 | +# PASETO v4 Key Generator - Google Cloud Function |
| 2 | + |
| 3 | +This Google Cloud Function serves a web page that generates PASETO v4 asymmetric key pairs. It provides both a user-friendly web interface and a REST API for key generation. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Web Interface**: Beautiful, responsive HTML page for generating keys |
| 8 | +- **REST API**: POST endpoint for programmatic key generation |
| 9 | +- **Secure**: Uses the same PASETO v4 library as the main application |
| 10 | +- **Copy to Clipboard**: Easy copying of generated keys |
| 11 | +- **Security Warnings**: Clear warnings about private key handling |
| 12 | + |
| 13 | +## Local Development |
| 14 | + |
| 15 | +1. Install dependencies: |
| 16 | + |
| 17 | + ```bash |
| 18 | + go mod tidy |
| 19 | + ``` |
| 20 | + |
| 21 | +2. Run locally using the Functions Framework: |
| 22 | + |
| 23 | + ```bash |
| 24 | + go run function.go |
| 25 | + ``` |
| 26 | + |
| 27 | + Or install the Functions Framework CLI: |
| 28 | + |
| 29 | + ```bash |
| 30 | + go install github.com/GoogleCloudPlatform/functions-framework-go/funcframework/cmd/function@latest |
| 31 | + function --target KeygenFunction --source . |
| 32 | + ``` |
| 33 | + |
| 34 | +3. Open http://localhost:8080 in your browser |
| 35 | + |
| 36 | +## Deployment |
| 37 | + |
| 38 | +Deploy to Google Cloud Functions: |
| 39 | + |
| 40 | +```bash |
| 41 | +gcloud functions deploy keygen-function \ |
| 42 | + --runtime go121 \ |
| 43 | + --trigger-http \ |
| 44 | + --entry-point KeygenFunction \ |
| 45 | + --allow-unauthenticated \ |
| 46 | + --source . |
| 47 | +``` |
| 48 | + |
| 49 | +## API Usage |
| 50 | + |
| 51 | +### GET / |
| 52 | + |
| 53 | +Returns the HTML interface for key generation. |
| 54 | + |
| 55 | +### POST / |
| 56 | + |
| 57 | +Generates a new PASETO v4 key pair. |
| 58 | + |
| 59 | +**Response:** |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "privateKey": "base64-encoded-private-key", |
| 64 | + "publicKey": "base64-encoded-public-key" |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +**Example:** |
| 69 | + |
| 70 | +```bash |
| 71 | +curl -X POST https://your-function-url/ |
| 72 | +``` |
| 73 | + |
| 74 | +## Security Considerations |
| 75 | + |
| 76 | +- **Private Key Security**: The private key should be kept secret and stored securely |
| 77 | +- **HTTPS Only**: Always use HTTPS in production |
| 78 | +- **Access Control**: Consider adding authentication for production use |
| 79 | +- **Key Storage**: Never store private keys in client-side code or public repositories |
| 80 | + |
| 81 | +## Dependencies |
| 82 | + |
| 83 | +- `aidanwoods.dev/go-paseto` - PASETO implementation |
| 84 | +- `github.com/GoogleCloudPlatform/functions-framework-go` - Google Cloud Functions framework |
0 commit comments