fix: tolerate literal \n in GHL_WEBHOOK_PUBLIC_KEY env var
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
pem.Decode requires actual newlines. When a PEM key is pasted into a .env file it is commonly stored as a single line with \n literals. Normalise these before decoding so both formats work. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
83de6cb089
commit
2e07374681
@ -14,6 +14,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -230,7 +231,10 @@ func (h *WebhookHandler) HandleUninstall(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseRSAPublicKey decodes a PEM-encoded PKIX RSA public key.
|
// parseRSAPublicKey decodes a PEM-encoded PKIX RSA public key.
|
||||||
|
// Tolerates literal \n sequences in the input (common when the key is stored
|
||||||
|
// as a single line in a .env file).
|
||||||
func parseRSAPublicKey(pemStr string) (*rsa.PublicKey, error) {
|
func parseRSAPublicKey(pemStr string) (*rsa.PublicKey, error) {
|
||||||
|
pemStr = strings.ReplaceAll(pemStr, `\n`, "\n")
|
||||||
block, _ := pem.Decode([]byte(pemStr))
|
block, _ := pem.Decode([]byte(pemStr))
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil, fmt.Errorf("failed to decode PEM block")
|
return nil, fmt.Errorf("failed to decode PEM block")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user