Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pkcs8 from Apple APNs #263

Open
conotto opened this issue Dec 16, 2022 · 1 comment
Open

Support pkcs8 from Apple APNs #263

conotto opened this issue Dec 16, 2022 · 1 comment

Comments

@conotto
Copy link

conotto commented Dec 16, 2022

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.

@oxisto
Copy link
Collaborator

oxisto commented Apr 5, 2023

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants