-
Notifications
You must be signed in to change notification settings - Fork 55
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
Fix eddsa private key parsing bug #123
Conversation
The eddsa private key is encoded as PEM(PKCS#8) format. While decoding the private key a bug was introduced to generate a new key from the encoded bytes. Fixed the issue by decoding the private key with same format.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #123 +/- ##
==========================================
+ Coverage 62.46% 62.53% +0.07%
==========================================
Files 79 79
Lines 7576 7584 +8
==========================================
+ Hits 4732 4743 +11
Misses 2541 2541
+ Partials 303 300 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes
crypto/keygen/keygen.go
Outdated
@@ -233,7 +233,17 @@ func ParsePrivateKey(buf []byte) (key hotstuff.PrivateKey, err error) { | |||
case ecdsacrypto.PrivateKeyFileType: | |||
key, err = x509.ParseECPrivateKey(b.Bytes) | |||
case eddsa.PrivateKeyFileType: | |||
key = ed25519.NewKeyFromSeed(b.Bytes[:32]) | |||
//key = ed25519.NewKeyFromSeed(b.Bytes[:32]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete
crypto/keygen/keygen.go
Outdated
//key = ed25519.NewKeyFromSeed(b.Bytes[:32]) | ||
var genericKey any | ||
var ok bool | ||
genericKey, err = x509.ParsePKCS8PrivateKey(b.Bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do:
genericKey, err :=
To avoid the var genericKey any
line above.
crypto/keygen/keygen.go
Outdated
key = ed25519.NewKeyFromSeed(b.Bytes[:32]) | ||
//key = ed25519.NewKeyFromSeed(b.Bytes[:32]) | ||
var genericKey any | ||
var ok bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move ok
closer to its usage point.
The eddsa private key is encoded as PEM(PKCS#8) format. While decoding the private key a bug was introduced to generate a new key from the encoded bytes.
Fixed the issue by decoding the private key with same format.