You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-09-16 17:46:19 +02:00
use jwt.ParseECPrivateKeyFromPEM instead of the custom one
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package forms
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -68,7 +65,7 @@ func (form *AppleClientSecretCreate) Submit() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
signKey, err := parsePKCS8PrivateKeyFromPEM([]byte(strings.TrimSpace(form.PrivateKey)))
|
||||
signKey, err := jwt.ParseECPrivateKeyFromPEM([]byte(strings.TrimSpace(form.PrivateKey)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -88,25 +85,3 @@ func (form *AppleClientSecretCreate) Submit() (string, error) {
|
||||
|
||||
return token.SignedString(signKey)
|
||||
}
|
||||
|
||||
// parsePKCS8PrivateKeyFromPEM parses PEM encoded Elliptic Curve Private Key Structure.
|
||||
//
|
||||
// https://github.com/dgrijalva/jwt-go/issues/179
|
||||
func parsePKCS8PrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
|
||||
block, _ := pem.Decode(key)
|
||||
if block == nil {
|
||||
return nil, jwt.ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
parsedKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pkey, ok := parsedKey.(*ecdsa.PrivateKey)
|
||||
if !ok {
|
||||
return nil, jwt.ErrNotECPrivateKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user