golang-jwt / jwt

Community maintained clone of https://github.com/dgrijalva/jwt-go

Home Page:https://golang-jwt.github.io/jwt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support pkcs8 from Apple APNs

conotto opened this issue · comments

commented

Hi,
After spending a few hours on trying to import Apple Mapkit p8 file, which is pkcs8, i have stumbled on someones post here:
dgrijalva/jwt-go#179

It includes a working function to import the private key, i've tested it and it works.
While i am not the author of the post in the link, i feel it would be beneficial to many people to have this function be included in your repo.
Would you be interested in a pull request with the above mentioned change ?
I will make sure to include the original author.

Isn't this solved by this function here?

jwt/ecdsa_utils.go

Lines 15 to 40 in b88a60f

// ParseECPrivateKeyFromPEM parses a PEM encoded Elliptic Curve Private Key Structure
func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
var err error
// Parse PEM block
var block *pem.Block
if block, _ = pem.Decode(key); block == nil {
return nil, ErrKeyMustBePEMEncoded
}
// Parse the key
var parsedKey interface{}
if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil {
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
return nil, err
}
}
var pkey *ecdsa.PrivateKey
var ok bool
if pkey, ok = parsedKey.(*ecdsa.PrivateKey); !ok {
return nil, ErrNotECPrivateKey
}
return pkey, nil
}