Fix key decoding

#3 Fix key decoding
This commit is contained in:
Anbraten 2022-12-27 11:15:06 +01:00 committed by GitHub
commit 13f6281a00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

17
main.go
View File

@ -2,9 +2,10 @@ package main
import ( import (
"crypto/ed25519" "crypto/ed25519"
"crypto/x509"
_ "embed" _ "embed"
"encoding/hex"
"encoding/json" "encoding/json"
"encoding/pem"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
@ -38,7 +39,7 @@ func main() {
log.Fatalf("Error loading .env file: %v", err) log.Fatalf("Error loading .env file: %v", err)
} }
pubKeyPath := os.Getenv("CONFIG_SERVICE_PUBLIC_KEY_FILE") pubKeyPath := os.Getenv("CONFIG_SERVICE_PUBLIC_KEY_FILE") // Key in format of the one fetched from http(s)://your-woodpecker-server/api/signature/public-key
host := os.Getenv("CONFIG_SERVICE_HOST") host := os.Getenv("CONFIG_SERVICE_HOST")
filterRegex := os.Getenv("CONFIG_SERVICE_OVERRIDE_FILTER") filterRegex := os.Getenv("CONFIG_SERVICE_OVERRIDE_FILTER")
@ -50,11 +51,17 @@ func main() {
if err != nil { if err != nil {
log.Fatal("Failed to read public key file") log.Fatal("Failed to read public key file")
} }
pubKeyStr, err := hex.DecodeString(string(pubKeyRaw))
pemblock, _ := pem.Decode(pubKeyRaw)
b, err := x509.ParsePKIXPublicKey(pemblock.Bytes)
if err != nil { if err != nil {
log.Fatal("Failed to decode public key") log.Fatal("Failed to parse public key file ", err)
}
pubKey, ok := b.(ed25519.PublicKey)
if !ok {
log.Fatal("Failed to parse public key file")
} }
pubKey := ed25519.PublicKey(pubKeyStr)
filter := regexp.MustCompile(filterRegex) filter := regexp.MustCompile(filterRegex)