-
Notifications
You must be signed in to change notification settings - Fork 504
Wire ACME extension configuration refactor #1671
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
Merged
hslatman
merged 7 commits into
herman/remove-rusty-cli
from
herman/wire-configuration-refactor
Jan 12, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6ef64b6
Refactor the `Wire` option configuration
hslatman 1f5f756
Make Wire options more robust
hslatman 1bf807a
Use base64 encoded signing key format
hslatman 7eacb68
Merge branch 'herman/remove-rusty-cli' into herman/wire-configuration…
hslatman 79739e5
Change signature algorithm property name
hslatman 2479572
Perform initialization of DPoP and OIDC options once
hslatman c8160ca
Fix test; reworded error message
hslatman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,44 +2,61 @@ package wire | |
|
||
import ( | ||
"bytes" | ||
"crypto" | ||
"errors" | ||
"fmt" | ||
"text/template" | ||
|
||
"go.step.sm/crypto/pemutil" | ||
) | ||
|
||
type DPOPOptions struct { | ||
// Backend signing key for DPoP access token | ||
SigningKey string `json:"key"` | ||
// Public part of the signing key for DPoP access token | ||
SigningKey []byte `json:"key"` | ||
// URI template acme client must call to fetch the DPoP challenge proof (an access token from wire-server) | ||
DpopTarget string `json:"dpop-target"` | ||
Target string `json:"target"` | ||
} | ||
|
||
func (o *DPOPOptions) GetSigningKey() string { | ||
func (o *DPOPOptions) GetSigningKey() crypto.PublicKey { | ||
if o == nil { | ||
return "" | ||
return nil | ||
} | ||
return o.SigningKey | ||
k, err := pemutil.Parse(o.SigningKey) // TODO(hs): do this once? | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return k | ||
} | ||
|
||
func (o *DPOPOptions) GetDPOPTarget() string { | ||
func (o *DPOPOptions) GetTarget() string { | ||
if o == nil { | ||
return "" | ||
} | ||
return o.DpopTarget | ||
return o.Target | ||
} | ||
|
||
func (o *DPOPOptions) GetTarget(deviceID string) (string, error) { | ||
func (o *DPOPOptions) EvaluateTarget(deviceID string) (string, error) { | ||
if o == nil { | ||
return "", errors.New("misconfigured target template configuration") | ||
} | ||
targetTemplate := o.GetDPOPTarget() | ||
tmpl, err := template.New("DeviceId").Parse(targetTemplate) | ||
tmpl, err := template.New("DeviceID").Parse(o.GetTarget()) | ||
if err != nil { | ||
return "", fmt.Errorf("failed parsing dpop template: %w", err) | ||
} | ||
buf := new(bytes.Buffer) | ||
if err = tmpl.Execute(buf, struct{ DeviceId string }{DeviceId: deviceID}); err != nil { //nolint:revive,stylecheck // TODO(hs): this requires changes in configuration | ||
if err = tmpl.Execute(buf, struct{ DeviceID string }{DeviceID: deviceID}); err != nil { | ||
return "", fmt.Errorf("failed executing dpop template: %w", err) | ||
} | ||
return buf.String(), nil | ||
} | ||
|
||
func (o *DPOPOptions) validate() error { | ||
if _, err := pemutil.Parse(o.SigningKey); err != nil { | ||
return fmt.Errorf("failed parsing key: %w", err) | ||
} | ||
if _, err := template.New("DeviceID").Parse(o.GetTarget()); err != nil { | ||
return fmt.Errorf("failed parsing template: %w", err) | ||
} | ||
return nil | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you clarify the name of these variables? Looking at the code below, I think they can be something like
tokenKey
anddpopKey
.It's also quite weird to see two types here. I assume these keys come from some configuration, and you should be able to create the verifyParams with two
crypto.PublicKey