Skip to content

Commit f4d06ca

Browse files
committed
keygen webpage
1 parent 9822106 commit f4d06ca

8 files changed

Lines changed: 2572 additions & 0 deletions

File tree

keygen_function/.gcloudignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# The .gcloudignore file for a Google Cloud Function deployment
2+
# This file specifies files to ignore when deploying
3+
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool
15+
*.out
16+
17+
# Dependency directories
18+
vendor/
19+
20+
# Go workspace files
21+
go.work
22+
go.work.sum
23+
24+
# IDE files
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS generated files
32+
.DS_Store
33+
.DS_Store?
34+
._*
35+
.Spotlight-V100
36+
.Trashes
37+
ehthumbs.db
38+
Thumbs.db
39+
40+
# Logs
41+
*.log
42+
43+
# Local development files
44+
.env
45+
.env.local
46+
.env.development.local
47+
.env.test.local
48+
.env.production.local
49+
50+
# Temporary files
51+
tmp/
52+
temp/
53+
54+
# Documentation
55+
README.md
56+
*.md

keygen_function/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

keygen_function/deploy.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Deploy PASETO v4 Key Generator to Google Cloud Functions
4+
5+
set -e
6+
7+
# Configuration
8+
FUNCTION_NAME="keygen-function"
9+
REGION="europe-west1" # Belgium region
10+
PROJECT_ID="notifusev3"
11+
RUNTIME="go123"
12+
ENTRY_POINT="KeygenFunction"
13+
14+
echo "🚀 Deploying PASETO v4 Key Generator to Google Cloud Functions..."
15+
16+
# Set the project
17+
echo "📋 Setting project to $PROJECT_ID..."
18+
gcloud config set project $PROJECT_ID
19+
20+
# Deploy the function (2nd gen for Go 1.23 support)
21+
gcloud functions deploy $FUNCTION_NAME \
22+
--gen2 \
23+
--runtime $RUNTIME \
24+
--trigger-http \
25+
--entry-point $ENTRY_POINT \
26+
--allow-unauthenticated \
27+
--source . \
28+
--region $REGION \
29+
--project $PROJECT_ID \
30+
--memory 128Mi \
31+
--timeout 60s
32+
33+
echo "✅ Deployment complete!"
34+
echo ""
35+
echo "🌐 Function URL:"
36+
gcloud functions describe $FUNCTION_NAME --region $REGION --gen2 --format="value(serviceConfig.uri)"
37+
echo ""
38+
echo "📝 To test the function:"
39+
echo " curl \$(gcloud functions describe $FUNCTION_NAME --region $REGION --gen2 --format=\"value(serviceConfig.uri)\")"

0 commit comments

Comments
 (0)