fix: use webpush-go's GenerateVAPIDKeys

Old implementation just copied random bytes as the public key (not real EC math).
New cmd/keygen calls the library's proper P-256 key generation.
Removed broken local GenerateVAPIDKeys from push/handlers.go.
This commit is contained in:
2026-07-02 14:24:24 -04:00
parent 85f9c21f4c
commit 8336ca5d87
3 changed files with 18 additions and 18 deletions
+17
View File
@@ -0,0 +1,17 @@
package main
import (
"fmt"
"log"
webpush "github.com/SherClockHolmes/webpush-go"
)
func main() {
priv, pub, err := webpush.GenerateVAPIDKeys()
if err != nil {
log.Fatal(err)
}
fmt.Println("VAPID_PRIVATE_KEY=" + priv)
fmt.Println("VAPID_PUBLIC_KEY=" + pub)
}
+1 -18
View File
@@ -2,9 +2,7 @@ package push
import ( import (
"context" "context"
"crypto/rand"
"database/sql" "database/sql"
"encoding/base64"
"encoding/json" "encoding/json"
"log/slog" "log/slog"
"net/http" "net/http"
@@ -256,19 +254,4 @@ func (h *Handler) SendChannelNotification(ctx context.Context, channelID, author
} }
} }
// GenerateVAPIDKeys generates a new VAPID key pair. // GenerateVAPIDKeys is in cmd/keygen. Use github.com/SherClockHolmes/webpush-go directly.
func GenerateVAPIDKeys() (publicKey, privateKey string, err error) {
privateKeyBytes := make([]byte, 32)
_, err = rand.Read(privateKeyBytes)
if err != nil {
return "", "", err
}
pubBytes := make([]byte, 65)
copy(pubBytes, privateKeyBytes)
publicKey = base64.RawURLEncoding.EncodeToString(pubBytes)
privateKey = base64.RawURLEncoding.EncodeToString(privateKeyBytes)
return publicKey, privateKey, nil
}
Executable
BIN
View File
Binary file not shown.