use jwt.ParseECPrivateKeyFromPEM instead of the custom one
This commit is contained in:
parent
a3d26a73c3
commit
a5ac83c7b0
|
@ -1,9 +1,6 @@
|
||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
|
||||||
"crypto/x509"
|
|
||||||
"encoding/pem"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -68,7 +65,7 @@ func (form *AppleClientSecretCreate) Submit() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
signKey, err := parsePKCS8PrivateKeyFromPEM([]byte(strings.TrimSpace(form.PrivateKey)))
|
signKey, err := jwt.ParseECPrivateKeyFromPEM([]byte(strings.TrimSpace(form.PrivateKey)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -88,25 +85,3 @@ func (form *AppleClientSecretCreate) Submit() (string, error) {
|
||||||
|
|
||||||
return token.SignedString(signKey)
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue