-
Notifications
You must be signed in to change notification settings - Fork 23
fix: EC fallback to PEM #2758
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
base: main
Are you sure you want to change the base?
fix: EC fallback to PEM #2758
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -351,7 +351,12 @@ | |||||
|
||||||
priv, err := x509.ParsePKCS8PrivateKey(block.Bytes) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("ec x509.ParsePKCS8PrivateKey failed: %w", err) | ||||||
// If PKCS8 fails, try EC private key format | ||||||
ecKey, ecErr := x509.ParseECPrivateKey(block.Bytes) | ||||||
if ecErr != nil { | ||||||
return nil, fmt.Errorf("failed to parse private key as PKCS8 or EC format: PKCS8 error: %w, EC error: %v", err, ecErr) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current error message wraps the PKCS8 error ( Since the project appears to use Go 1.20+ (indicated by the
Suggested change
|
||||||
} | ||||||
return ConvertToECDHPrivateKey(ecKey) | ||||||
} | ||||||
Comment on lines
353
to
360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change introduces new logic for parsing EC keys, but there are no corresponding unit tests as indicated by the unchecked item in the PR checklist. It's crucial to add unit tests to cover the new fallback behavior. Please add tests for at least the following scenarios:
Without tests, it's difficult to be confident in the correctness of this new logic and protect against future regressions. |
||||||
|
||||||
switch privateKey := priv.(type) { | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm somewhat surprised there's no logger in this file, but maybe that was a performance choice?
In any case, I was thinking a warning message might be useful just above the comment on line 354.
Printing to STDOUT here just as an example... I'll defer to others about the logger usage.