-
Notifications
You must be signed in to change notification settings - Fork 14
feat(jwt_issuer): add -priv-in flag to load existing private key from… #477
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?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ func main() { | |
| jwtFile := flag.String("jwt-out", "token.jwt", "output file for the signed JWT") | ||
| jwkFile := flag.String("jwk-out", "jwks.json", "output file for the JWKS (public keys)") | ||
| privFile := flag.String("priv-out", "", "output file for the private JWK (optional)") | ||
| privInFile := flag.String("priv-in", "", "input file for an existing private JWK (optional, generates new key if not set)") | ||
|
|
||
| flag.Parse() | ||
|
|
||
|
|
@@ -41,17 +42,31 @@ func main() { | |
| *email = *subject | ||
| } | ||
|
|
||
| // Generate ECDSA P-256 key pair | ||
| rawKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
| if err != nil { | ||
| fatal("generate key: %v", err) | ||
| } | ||
| var privJWK jwk.Key | ||
|
|
||
| // Build private JWK | ||
| privJWK, err := jwk.Import(rawKey) | ||
| if err != nil { | ||
| fatal("import private key: %v", err) | ||
| if *privInFile != "" { | ||
| // Load existing private key from file | ||
| privJSON, err := os.ReadFile(*privInFile) | ||
| if err != nil { | ||
| fatal("read private key file: %v", err) | ||
| } | ||
| privJWK, err = jwk.ParseKey(privJSON) | ||
| if err != nil { | ||
| fatal("parse private key: %v", err) | ||
| } | ||
| fmt.Printf("Private key loaded from %s\n", *privInFile) | ||
|
Comment on lines
+62
to
+74
Contributor
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 feedback makes sense!
Comment on lines
+62
to
+74
Contributor
Author
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. Fixed in 373ce75 — after parsing, we now export to |
||
| } else { | ||
| // Generate ECDSA P-256 key pair | ||
| rawKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
| if err != nil { | ||
| fatal("generate key: %v", err) | ||
| } | ||
| privJWK, err = jwk.Import(rawKey) | ||
| if err != nil { | ||
| fatal("import private key: %v", err) | ||
| } | ||
| } | ||
|
|
||
| if err := privJWK.Set(jwk.KeyIDKey, *kid); err != nil { | ||
| fatal("set kid: %v", err) | ||
| } | ||
|
|
||
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.
Fixed in 373ce75 — added a guard that checks all output paths against
-priv-inbefore proceeding.