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

Loading ECC PKCS8 keys generated by go #245

Closed
wbl opened this issue Apr 17, 2019 · 5 comments
Closed

Loading ECC PKCS8 keys generated by go #245

wbl opened this issue Apr 17, 2019 · 5 comments

Comments

@wbl
Copy link

wbl commented Apr 17, 2019

We have been having lots of problems and have been unable to get ECC to work. First off the PEM lines are subtly different: go includes EC PRIVATE KEY, but rustls expects only PRIVATE KEY. I don't think it pays to be pedantic about that. But after changing that by hand we get errors about the private key being invalid due to ASN.1 issues. I'm not sure which part actually has the bug between go and this project but I am not an ASN.1 expert enough to figure that out.

@briansmith
Copy link
Contributor

Please generate a dummy PKCS#8 key from Go that fails to parse in Rustls and post the PEM here.

@briansmith
Copy link
Contributor

Also, read the documentation here at https://briansmith.org/rustdoc/ring/signature/struct.EcdsaKeyPair.html#method.from_pkcs8 and see if that narrows down the issue. For example, does the PKCS#8 document contain the public key? Is it using named curve AlgorithmIdentifiers or the other kind?

@wbl
Copy link
Author

wbl commented Apr 17, 2019

-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIMY4Javm8p/EUEj8Vqp970VhlqcXTbQR4xS+Pg+wMZlEoAoGCCqGSM49
AwEHoUQDQgAE2OiErbskHuuNPRJWorVRXuVG4lsoZIUNxgke5ahna6d/+iWB9V6k
NYDCfkRFQ2rpBoSSefGNafhumEOmkuVnrQ==
-----END EC PRIVATE KEY-----

@ctz
Copy link
Member

ctz commented Apr 18, 2019

First off the PEM lines are subtly different: go includes EC PRIVATE KEY, but rustls expects only PRIVATE KEY

"EC PRIVATE KEY" introduces a SEC1-style private key (its the encoding ECPrivateKey in SEC1v2 section C.4 -- http://www.secg.org/sec1-v2.pdf )

You can convert these to PKCS#8 with openssl pkcs8 -topk8 -nocrypt -in sec1.pem -out pkcs8.pem

@wbl
Copy link
Author

wbl commented Apr 19, 2019

Ah, thank you!

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

3 participants