4
0
Эх сурвалжийг харах

Put Wire options in lower level `wire` struct

Herman Slatman 2 жил өмнө
parent
commit
acad227b25

+ 2 - 2
acme/api/order.go

@@ -286,9 +286,9 @@ func newAuthorization(ctx context.Context, az *acme.Authorization) error {
 			var targetProvider interface{ GetTarget(string) (string, error) }
 			switch typ {
 			case acme.WIREOIDC01:
-				targetProvider = prov.GetOptions().GetOIDCOptions()
+				targetProvider = prov.GetOptions().GetWireOptions().GetOIDCOptions()
 			case acme.WIREDPOP01:
-				targetProvider = prov.GetOptions().GetDPOPOptions()
+				targetProvider = prov.GetOptions().GetWireOptions().GetDPOPOptions()
 			default:
 				return acme.NewError(acme.ErrorMalformedType, "unsupported type %q", typ)
 			}

+ 23 - 20
acme/api/order_test.go

@@ -24,6 +24,7 @@ import (
 	"github.com/smallstep/certificates/acme"
 	"github.com/smallstep/certificates/authority/policy"
 	"github.com/smallstep/certificates/authority/provisioner"
+	"github.com/smallstep/certificates/authority/provisioner/wire"
 )
 
 func TestNewOrderRequest_Validate(t *testing.T) {
@@ -1716,26 +1717,28 @@ func TestHandler_NewOrder(t *testing.T) {
 		},
 		"ok/default-naf-nbf-wireapp": func(t *testing.T) test {
 			acmeWireProv := newWireProvisionerWithOptions(t, &provisioner.Options{
-				OIDC: &provisioner.OIDCOptions{
-					Provider: provisioner.ProviderJSON{
-						IssuerURL:   "",
-						AuthURL:     "",
-						TokenURL:    "",
-						JWKSURL:     "",
-						UserInfoURL: "",
-						Algorithms:  []string{},
-					},
-					Config: provisioner.ConfigJSON{
-						ClientID:                   "integration test",
-						SupportedSigningAlgs:       []string{},
-						SkipClientIDCheck:          true,
-						SkipExpiryCheck:            true,
-						SkipIssuerCheck:            true,
-						InsecureSkipSignatureCheck: true,
-						Now:                        time.Now,
-					},
-				},
-				DPOP: &provisioner.DPOPOptions{},
+				Wire: &wire.Options{
+					OIDC: &wire.OIDCOptions{
+						Provider: wire.ProviderJSON{
+							IssuerURL:   "",
+							AuthURL:     "",
+							TokenURL:    "",
+							JWKSURL:     "",
+							UserInfoURL: "",
+							Algorithms:  []string{},
+						},
+						Config: wire.ConfigJSON{
+							ClientID:                   "integration test",
+							SupportedSigningAlgs:       []string{},
+							SkipClientIDCheck:          true,
+							SkipExpiryCheck:            true,
+							SkipIssuerCheck:            true,
+							InsecureSkipSignatureCheck: true,
+							Now:                        time.Now,
+						},
+					},
+					DPOP: &wire.DPOPOptions{},
+				},
 			})
 			acc := &acme.Account{ID: "accID"}
 			nor := &NewOrderRequest{

+ 21 - 18
acme/api/wire_integration_test.go

@@ -26,6 +26,7 @@ import (
 	"github.com/smallstep/certificates/acme/db/nosql"
 	"github.com/smallstep/certificates/authority"
 	"github.com/smallstep/certificates/authority/provisioner"
+	"github.com/smallstep/certificates/authority/provisioner/wire"
 	nosqlDB "github.com/smallstep/nosql"
 	"github.com/stretchr/testify/require"
 	"go.step.sm/crypto/jose"
@@ -51,26 +52,28 @@ func newWireProvisionerWithOptions(t *testing.T, options *provisioner.Options) *
 
 func TestWireIntegration(t *testing.T) {
 	prov := newWireProvisionerWithOptions(t, &provisioner.Options{
-		OIDC: &provisioner.OIDCOptions{
-			Provider: provisioner.ProviderJSON{
-				IssuerURL:   "",
-				AuthURL:     "",
-				TokenURL:    "",
-				JWKSURL:     "",
-				UserInfoURL: "",
-				Algorithms:  []string{},
-			},
-			Config: provisioner.ConfigJSON{
-				ClientID:                   "integration test",
-				SupportedSigningAlgs:       []string{},
-				SkipClientIDCheck:          true,
-				SkipExpiryCheck:            true,
-				SkipIssuerCheck:            true,
-				InsecureSkipSignatureCheck: true,
-				Now:                        time.Now,
+		Wire: &wire.Options{
+			OIDC: &wire.OIDCOptions{
+				Provider: wire.ProviderJSON{
+					IssuerURL:   "",
+					AuthURL:     "",
+					TokenURL:    "",
+					JWKSURL:     "",
+					UserInfoURL: "",
+					Algorithms:  []string{},
+				},
+				Config: wire.ConfigJSON{
+					ClientID:                   "integration test",
+					SupportedSigningAlgs:       []string{},
+					SkipClientIDCheck:          true,
+					SkipExpiryCheck:            true,
+					SkipIssuerCheck:            true,
+					InsecureSkipSignatureCheck: true,
+					Now:                        time.Now,
+				},
 			},
+			DPOP: &wire.DPOPOptions{},
 		},
-		DPOP: &provisioner.DPOPOptions{},
 	})
 
 	// mock provisioner and linker

+ 2 - 2
acme/challenge.go

@@ -370,7 +370,7 @@ func wireOIDC01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSO
 			"error unmarshalling Wire challenge payload"))
 	}
 
-	oidcOptions := prov.GetOptions().GetOIDCOptions()
+	oidcOptions := prov.GetOptions().GetWireOptions().GetOIDCOptions()
 	idToken, err := oidcOptions.GetProvider(ctx).Verifier(oidcOptions.GetConfig()).Verify(ctx, oidcPayload.IDToken)
 	if err != nil {
 		return storeError(ctx, db, ch, false, WrapError(ErrorRejectedIdentifierType, err,
@@ -474,7 +474,7 @@ func wireDPOP01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSO
 		return WrapErrorISE(err, "error parsing device id")
 	}
 
-	dpopOptions := prov.GetOptions().GetDPOPOptions()
+	dpopOptions := prov.GetOptions().GetWireOptions().GetDPOPOptions()
 
 	issuer, err := dpopOptions.GetTarget(clientID.DeviceID)
 	if err != nil {

+ 6 - 14
authority/provisioner/options.go

@@ -11,6 +11,7 @@ import (
 	"go.step.sm/crypto/x509util"
 
 	"github.com/smallstep/certificates/authority/policy"
+	"github.com/smallstep/certificates/authority/provisioner/wire"
 )
 
 // CertificateOptions is an interface that returns a list of options passed when
@@ -30,11 +31,10 @@ func (fn certificateOptionsFunc) Options(so SignOptions) []x509util.Option {
 type Options struct {
 	X509 *X509Options `json:"x509,omitempty"`
 	SSH  *SSHOptions  `json:"ssh,omitempty"`
-	OIDC *OIDCOptions `json:"oidc,omitempty"`
-	DPOP *DPOPOptions `json:"dpop,omitempty"`
-
 	// Webhooks is a list of webhooks that can augment template data
 	Webhooks []*Webhook `json:"webhooks,omitempty"`
+	// Wire holds the options used for the ACME Wire integration
+	Wire *wire.Options `json:"wire,omitempty"`
 }
 
 // GetX509Options returns the X.509 options.
@@ -53,20 +53,12 @@ func (o *Options) GetSSHOptions() *SSHOptions {
 	return o.SSH
 }
 
-// GetOIDCOptions returns the OIDC options.
-func (o *Options) GetOIDCOptions() *OIDCOptions {
-	if o == nil {
-		return nil
-	}
-	return o.OIDC
-}
-
-// GetDPOPOptions returns the OIDC options.
-func (o *Options) GetDPOPOptions() *DPOPOptions {
+// GetWireOptions returns the SSH options.
+func (o *Options) GetWireOptions() *wire.Options {
 	if o == nil {
 		return nil
 	}
-	return o.DPOP
+	return o.Wire
 }
 
 // GetWebhooks returns the webhooks options.

+ 1 - 1
authority/provisioner/dpop_options.go → authority/provisioner/wire/dpop_options.go

@@ -1,4 +1,4 @@
-package provisioner
+package wire
 
 import (
 	"bytes"

+ 1 - 1
authority/provisioner/oidc_options.go → authority/provisioner/wire/oidc_options.go

@@ -1,4 +1,4 @@
-package provisioner
+package wire
 
 import (
 	"bytes"

+ 23 - 0
authority/provisioner/wire/wire_options.go

@@ -0,0 +1,23 @@
+package wire
+
+// Options holds the Wire ACME extension options
+type Options struct {
+	OIDC *OIDCOptions `json:"oidc,omitempty"`
+	DPOP *DPOPOptions `json:"dpop,omitempty"`
+}
+
+// GetOIDCOptions returns the OIDC options.
+func (o *Options) GetOIDCOptions() *OIDCOptions {
+	if o == nil {
+		return nil
+	}
+	return o.OIDC
+}
+
+// GetDPOPOptions returns the OIDC options.
+func (o *Options) GetDPOPOptions() *DPOPOptions {
+	if o == nil {
+		return nil
+	}
+	return o.DPOP
+}