|
|
@@ -33,11 +33,13 @@ import (
|
|
|
"github.com/fxamacker/cbor/v2"
|
|
|
"github.com/smallstep/certificates/authority/config"
|
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
|
|
+ wireprovisioner "github.com/smallstep/certificates/authority/provisioner/wire"
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
"github.com/stretchr/testify/require"
|
|
|
"go.step.sm/crypto/jose"
|
|
|
"go.step.sm/crypto/keyutil"
|
|
|
"go.step.sm/crypto/minica"
|
|
|
+ "go.step.sm/crypto/pemutil"
|
|
|
"go.step.sm/crypto/x509util"
|
|
|
)
|
|
|
|
|
|
@@ -196,6 +198,25 @@ func mustAttestYubikey(t *testing.T, _, keyAuthorization string, serial int) ([]
|
|
|
return payload, leaf, ca.Root
|
|
|
}
|
|
|
|
|
|
+func newWireProvisionerWithOptions(t *testing.T, options *provisioner.Options) *provisioner.ACME {
|
|
|
+ t.Helper()
|
|
|
+ prov := &provisioner.ACME{
|
|
|
+ Type: "ACME",
|
|
|
+ Name: "wire",
|
|
|
+ Options: options,
|
|
|
+ Challenges: []provisioner.ACMEChallenge{
|
|
|
+ provisioner.WIREOIDC_01,
|
|
|
+ provisioner.WIREDPOP_01,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ if err := prov.Init(provisioner.Config{
|
|
|
+ Claims: config.GlobalProvisionerClaims,
|
|
|
+ }); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ return prov
|
|
|
+}
|
|
|
+
|
|
|
func Test_storeError(t *testing.T) {
|
|
|
type test struct {
|
|
|
ch *Challenge
|
|
|
@@ -396,6 +417,9 @@ func TestKeyAuthorization(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestChallenge_Validate(t *testing.T) {
|
|
|
+ fakeKey := `-----BEGIN PUBLIC KEY-----
|
|
|
+MCowBQYDK2VwAyEA5c+4NKZSNQcR1T8qN6SjwgdPZQ0Ge12Ylx/YeGAJ35k=
|
|
|
+-----END PUBLIC KEY-----`
|
|
|
type test struct {
|
|
|
ch *Challenge
|
|
|
vc Client
|
|
|
@@ -430,7 +454,7 @@ func TestChallenge_Validate(t *testing.T) {
|
|
|
}
|
|
|
return test{
|
|
|
ch: ch,
|
|
|
- err: NewErrorISE("unexpected challenge type 'foo'"),
|
|
|
+ err: NewErrorISE(`unexpected challenge type "foo"`),
|
|
|
}
|
|
|
},
|
|
|
"fail/http-01": func(t *testing.T) test {
|
|
|
@@ -646,7 +670,7 @@ func TestChallenge_Validate(t *testing.T) {
|
|
|
assert.Equal(t, "zap.internal", updch.Value)
|
|
|
assert.Equal(t, StatusPending, updch.Status)
|
|
|
|
|
|
- err := NewError(ErrorConnectionType, "error doing TLS dial for %v:443: force", ch.Value)
|
|
|
+ err := NewError(ErrorConnectionType, "error doing TLS dial for %v: force", ch.Value)
|
|
|
|
|
|
assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
@@ -853,6 +877,496 @@ func TestChallenge_Validate(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
},
|
|
|
+ "ok/wire-oidc-01": func(t *testing.T) test {
|
|
|
+ jwk, keyAuth := mustAccountAndKeyAuthorization(t, "token")
|
|
|
+ signerJWK, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
+ require.NoError(t, err)
|
|
|
+ signer, err := jose.NewSigner(jose.SigningKey{
|
|
|
+ Algorithm: jose.SignatureAlgorithm(signerJWK.Algorithm),
|
|
|
+ Key: signerJWK,
|
|
|
+ }, new(jose.SignerOptions))
|
|
|
+ require.NoError(t, err)
|
|
|
+ srv := mustJWKServer(t, signerJWK.Public())
|
|
|
+ tokenBytes, err := json.Marshal(struct {
|
|
|
+ jose.Claims
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ PreferredUsername string `json:"preferred_username,omitempty"`
|
|
|
+ KeyAuth string `json:"keyauth"`
|
|
|
+ ACMEAudience string `json:"acme_aud"`
|
|
|
+ }{
|
|
|
+ Claims: jose.Claims{
|
|
|
+ Issuer: srv.URL,
|
|
|
+ Audience: []string{"test"},
|
|
|
+ Expiry: jose.NewNumericDate(time.Now().Add(1 * time.Minute)),
|
|
|
+ },
|
|
|
+ Name: "Alice Smith",
|
|
|
+ PreferredUsername: "wireapp://%40alice_wire@wire.com",
|
|
|
+ KeyAuth: keyAuth,
|
|
|
+ ACMEAudience: "https://ca.example.com/acme/wire/challenge/azID/chID",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ signed, err := signer.Sign(tokenBytes)
|
|
|
+ require.NoError(t, err)
|
|
|
+ idToken, err := signed.CompactSerialize()
|
|
|
+ require.NoError(t, err)
|
|
|
+ payload, err := json.Marshal(struct {
|
|
|
+ IDToken string `json:"id_token"`
|
|
|
+ }{
|
|
|
+ IDToken: idToken,
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ valueBytes, err := json.Marshal(struct {
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ Domain string `json:"domain,omitempty"`
|
|
|
+ ClientID string `json:"client-id,omitempty"`
|
|
|
+ Handle string `json:"handle,omitempty"`
|
|
|
+ }{
|
|
|
+ Name: "Alice Smith",
|
|
|
+ Domain: "wire.com",
|
|
|
+ ClientID: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ Handle: "wireapp://%40alice_wire@wire.com",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ ctx := NewProvisionerContext(context.Background(), newWireProvisionerWithOptions(t, &provisioner.Options{
|
|
|
+ Wire: &wireprovisioner.Options{
|
|
|
+ OIDC: &wireprovisioner.OIDCOptions{
|
|
|
+ Provider: &wireprovisioner.Provider{
|
|
|
+ IssuerURL: srv.URL,
|
|
|
+ JWKSURL: srv.URL + "/keys",
|
|
|
+ Algorithms: []string{"ES256"},
|
|
|
+ },
|
|
|
+ Config: &wireprovisioner.Config{
|
|
|
+ ClientID: "test",
|
|
|
+ SignatureAlgorithms: []string{"ES256"},
|
|
|
+ Now: time.Now,
|
|
|
+ },
|
|
|
+ TransformTemplate: "",
|
|
|
+ },
|
|
|
+ DPOP: &wireprovisioner.DPOPOptions{
|
|
|
+ SigningKey: []byte(fakeKey),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }))
|
|
|
+ ctx = NewLinkerContext(ctx, NewLinker("ca.example.com", "acme"))
|
|
|
+ return test{
|
|
|
+ ch: &Challenge{
|
|
|
+ ID: "chID",
|
|
|
+ AuthorizationID: "azID",
|
|
|
+ AccountID: "accID",
|
|
|
+ Token: "token",
|
|
|
+ Type: "wire-oidc-01",
|
|
|
+ Status: StatusPending,
|
|
|
+ Value: string(valueBytes),
|
|
|
+ },
|
|
|
+ srv: srv,
|
|
|
+ payload: payload,
|
|
|
+ ctx: ctx,
|
|
|
+ jwk: jwk,
|
|
|
+ db: &MockWireDB{
|
|
|
+ MockDB: MockDB{
|
|
|
+ MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
|
|
|
+ assert.Equal(t, "chID", updch.ID)
|
|
|
+ assert.Equal(t, "token", updch.Token)
|
|
|
+ assert.Equal(t, StatusValid, updch.Status)
|
|
|
+ assert.Equal(t, ChallengeType("wire-oidc-01"), updch.Type)
|
|
|
+ assert.Equal(t, string(valueBytes), updch.Value)
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ },
|
|
|
+ MockGetAllOrdersByAccountID: func(ctx context.Context, accountID string) ([]string, error) {
|
|
|
+ assert.Equal(t, "accID", accountID)
|
|
|
+ return []string{"orderID"}, nil
|
|
|
+ },
|
|
|
+ MockCreateOidcToken: func(ctx context.Context, orderID string, idToken map[string]interface{}) error {
|
|
|
+ assert.Equal(t, "orderID", orderID)
|
|
|
+ assert.Equal(t, "Alice Smith", idToken["name"].(string))
|
|
|
+ assert.Equal(t, "wireapp://%40alice_wire@wire.com", idToken["preferred_username"].(string))
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "fail/wire-oidc-01-no-wire-db": func(t *testing.T) test {
|
|
|
+ jwk, keyAuth := mustAccountAndKeyAuthorization(t, "token")
|
|
|
+ signerJWK, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
+ require.NoError(t, err)
|
|
|
+ signer, err := jose.NewSigner(jose.SigningKey{
|
|
|
+ Algorithm: jose.SignatureAlgorithm(signerJWK.Algorithm),
|
|
|
+ Key: signerJWK,
|
|
|
+ }, new(jose.SignerOptions))
|
|
|
+ require.NoError(t, err)
|
|
|
+ srv := mustJWKServer(t, signerJWK.Public())
|
|
|
+ tokenBytes, err := json.Marshal(struct {
|
|
|
+ jose.Claims
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ PreferredUsername string `json:"preferred_username,omitempty"`
|
|
|
+ KeyAuth string `json:"keyauth"`
|
|
|
+ ACMEAudience string `json:"acme_aud"`
|
|
|
+ }{
|
|
|
+ Claims: jose.Claims{
|
|
|
+ Issuer: srv.URL,
|
|
|
+ Audience: []string{"test"},
|
|
|
+ Expiry: jose.NewNumericDate(time.Now().Add(1 * time.Minute)),
|
|
|
+ },
|
|
|
+ Name: "Alice Smith",
|
|
|
+ PreferredUsername: "wireapp://%40alice_wire@wire.com",
|
|
|
+ KeyAuth: keyAuth,
|
|
|
+ ACMEAudience: "https://ca.example.com/acme/wire/challenge/azID/chID",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ signed, err := signer.Sign(tokenBytes)
|
|
|
+ require.NoError(t, err)
|
|
|
+ idToken, err := signed.CompactSerialize()
|
|
|
+ require.NoError(t, err)
|
|
|
+ payload, err := json.Marshal(struct {
|
|
|
+ IDToken string `json:"id_token"`
|
|
|
+ }{
|
|
|
+ IDToken: idToken,
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ valueBytes, err := json.Marshal(struct {
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ Domain string `json:"domain,omitempty"`
|
|
|
+ ClientID string `json:"client-id,omitempty"`
|
|
|
+ Handle string `json:"handle,omitempty"`
|
|
|
+ }{
|
|
|
+ Name: "Alice Smith",
|
|
|
+ Domain: "wire.com",
|
|
|
+ ClientID: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ Handle: "wireapp://%40alice_wire@wire.com",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ ctx := NewProvisionerContext(context.Background(), newWireProvisionerWithOptions(t, &provisioner.Options{
|
|
|
+ Wire: &wireprovisioner.Options{
|
|
|
+ OIDC: &wireprovisioner.OIDCOptions{
|
|
|
+ Provider: &wireprovisioner.Provider{
|
|
|
+ IssuerURL: srv.URL,
|
|
|
+ JWKSURL: srv.URL + "/keys",
|
|
|
+ Algorithms: []string{"ES256"},
|
|
|
+ },
|
|
|
+ Config: &wireprovisioner.Config{
|
|
|
+ ClientID: "test",
|
|
|
+ SignatureAlgorithms: []string{"ES256"},
|
|
|
+ Now: time.Now,
|
|
|
+ },
|
|
|
+ TransformTemplate: "",
|
|
|
+ },
|
|
|
+ DPOP: &wireprovisioner.DPOPOptions{
|
|
|
+ SigningKey: []byte(fakeKey),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }))
|
|
|
+ ctx = NewLinkerContext(ctx, NewLinker("ca.example.com", "acme"))
|
|
|
+ return test{
|
|
|
+ ch: &Challenge{
|
|
|
+ ID: "chID",
|
|
|
+ AuthorizationID: "azID",
|
|
|
+ AccountID: "accID",
|
|
|
+ Token: "token",
|
|
|
+ Type: "wire-oidc-01",
|
|
|
+ Status: StatusPending,
|
|
|
+ Value: string(valueBytes),
|
|
|
+ },
|
|
|
+ srv: srv,
|
|
|
+ payload: payload,
|
|
|
+ ctx: ctx,
|
|
|
+ jwk: jwk,
|
|
|
+ db: &MockDB{},
|
|
|
+ err: &Error{
|
|
|
+ Type: "urn:ietf:params:acme:error:serverInternal",
|
|
|
+ Detail: "The server experienced an internal error",
|
|
|
+ Status: 500,
|
|
|
+ Err: errors.New("db *acme.MockDB is not a WireDB"),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "ok/wire-dpop-01": func(t *testing.T) test {
|
|
|
+ jwk, keyAuth := mustAccountAndKeyAuthorization(t, "token")
|
|
|
+ _ = keyAuth // TODO(hs): keyAuth (not) required for DPoP? Or needs to be added to validation?
|
|
|
+ dpopSigner, err := jose.NewSigner(jose.SigningKey{
|
|
|
+ Algorithm: jose.SignatureAlgorithm(jwk.Algorithm),
|
|
|
+ Key: jwk,
|
|
|
+ }, new(jose.SignerOptions))
|
|
|
+ require.NoError(t, err)
|
|
|
+ signerJWK, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
+ require.NoError(t, err)
|
|
|
+ signer, err := jose.NewSigner(jose.SigningKey{
|
|
|
+ Algorithm: jose.SignatureAlgorithm(signerJWK.Algorithm),
|
|
|
+ Key: signerJWK,
|
|
|
+ }, new(jose.SignerOptions))
|
|
|
+ require.NoError(t, err)
|
|
|
+ signerPEMBlock, err := pemutil.Serialize(signerJWK.Public().Key)
|
|
|
+ require.NoError(t, err)
|
|
|
+ signerPEMBytes := pem.EncodeToMemory(signerPEMBlock)
|
|
|
+ dpopBytes, err := json.Marshal(struct {
|
|
|
+ jose.Claims
|
|
|
+ Challenge string `json:"chal,omitempty"`
|
|
|
+ Handle string `json:"handle,omitempty"`
|
|
|
+ Nonce string `json:"nonce,omitempty"`
|
|
|
+ HTU string `json:"htu,omitempty"`
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ }{
|
|
|
+ Claims: jose.Claims{
|
|
|
+ Subject: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ Audience: jose.Audience{"https://ca.example.com/acme/wire/challenge/azID/chID"},
|
|
|
+ },
|
|
|
+ Challenge: "token",
|
|
|
+ Handle: "wireapp://%40alice_wire@wire.com",
|
|
|
+ Nonce: "nonce",
|
|
|
+ HTU: "http://issuer.example.com",
|
|
|
+ Name: "Alice Smith",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ dpop, err := dpopSigner.Sign(dpopBytes)
|
|
|
+ require.NoError(t, err)
|
|
|
+ proof, err := dpop.CompactSerialize()
|
|
|
+ require.NoError(t, err)
|
|
|
+ tokenBytes, err := json.Marshal(struct {
|
|
|
+ jose.Claims
|
|
|
+ Challenge string `json:"chal,omitempty"`
|
|
|
+ Nonce string `json:"nonce,omitempty"`
|
|
|
+ Cnf struct {
|
|
|
+ Kid string `json:"kid,omitempty"`
|
|
|
+ } `json:"cnf"`
|
|
|
+ Proof string `json:"proof,omitempty"`
|
|
|
+ ClientID string `json:"client_id"`
|
|
|
+ APIVersion int `json:"api_version"`
|
|
|
+ Scope string `json:"scope"`
|
|
|
+ }{
|
|
|
+ Claims: jose.Claims{
|
|
|
+ Issuer: "http://issuer.example.com",
|
|
|
+ Audience: jose.Audience{"https://ca.example.com/acme/wire/challenge/azID/chID"},
|
|
|
+ Expiry: jose.NewNumericDate(time.Now().Add(1 * time.Minute)),
|
|
|
+ },
|
|
|
+ Challenge: "token",
|
|
|
+ Nonce: "nonce",
|
|
|
+ Cnf: struct {
|
|
|
+ Kid string `json:"kid,omitempty"`
|
|
|
+ }{
|
|
|
+ Kid: jwk.KeyID,
|
|
|
+ },
|
|
|
+ Proof: proof,
|
|
|
+ ClientID: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ APIVersion: 5,
|
|
|
+ Scope: "wire_client_id",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ signed, err := signer.Sign(tokenBytes)
|
|
|
+ require.NoError(t, err)
|
|
|
+ accessToken, err := signed.CompactSerialize()
|
|
|
+ require.NoError(t, err)
|
|
|
+ payload, err := json.Marshal(struct {
|
|
|
+ AccessToken string `json:"access_token"`
|
|
|
+ }{
|
|
|
+ AccessToken: accessToken,
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ valueBytes, err := json.Marshal(struct {
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ Domain string `json:"domain,omitempty"`
|
|
|
+ ClientID string `json:"client-id,omitempty"`
|
|
|
+ Handle string `json:"handle,omitempty"`
|
|
|
+ }{
|
|
|
+ Name: "Alice Smith",
|
|
|
+ Domain: "wire.com",
|
|
|
+ ClientID: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ Handle: "wireapp://%40alice_wire@wire.com",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ ctx := NewProvisionerContext(context.Background(), newWireProvisionerWithOptions(t, &provisioner.Options{
|
|
|
+ Wire: &wireprovisioner.Options{
|
|
|
+ OIDC: &wireprovisioner.OIDCOptions{
|
|
|
+ Provider: &wireprovisioner.Provider{
|
|
|
+ IssuerURL: "http://issuerexample.com",
|
|
|
+ Algorithms: []string{"ES256"},
|
|
|
+ },
|
|
|
+ Config: &wireprovisioner.Config{
|
|
|
+ ClientID: "test",
|
|
|
+ SignatureAlgorithms: []string{"ES256"},
|
|
|
+ Now: time.Now,
|
|
|
+ },
|
|
|
+ TransformTemplate: "",
|
|
|
+ },
|
|
|
+ DPOP: &wireprovisioner.DPOPOptions{
|
|
|
+ Target: "http://issuer.example.com",
|
|
|
+ SigningKey: signerPEMBytes,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }))
|
|
|
+ ctx = NewLinkerContext(ctx, NewLinker("ca.example.com", "acme"))
|
|
|
+ return test{
|
|
|
+ ch: &Challenge{
|
|
|
+ ID: "chID",
|
|
|
+ AuthorizationID: "azID",
|
|
|
+ AccountID: "accID",
|
|
|
+ Token: "token",
|
|
|
+ Type: "wire-dpop-01",
|
|
|
+ Status: StatusPending,
|
|
|
+ Value: string(valueBytes),
|
|
|
+ },
|
|
|
+ payload: payload,
|
|
|
+ ctx: ctx,
|
|
|
+ jwk: jwk,
|
|
|
+ db: &MockWireDB{
|
|
|
+ MockDB: MockDB{
|
|
|
+ MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
|
|
|
+ assert.Equal(t, "chID", updch.ID)
|
|
|
+ assert.Equal(t, "token", updch.Token)
|
|
|
+ assert.Equal(t, StatusValid, updch.Status)
|
|
|
+ assert.Equal(t, ChallengeType("wire-dpop-01"), updch.Type)
|
|
|
+ assert.Equal(t, string(valueBytes), updch.Value)
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ },
|
|
|
+ MockGetAllOrdersByAccountID: func(ctx context.Context, accountID string) ([]string, error) {
|
|
|
+ assert.Equal(t, "accID", accountID)
|
|
|
+ return []string{"orderID"}, nil
|
|
|
+ },
|
|
|
+ MockCreateDpopToken: func(ctx context.Context, orderID string, dpop map[string]interface{}) error {
|
|
|
+ assert.Equal(t, "orderID", orderID)
|
|
|
+ assert.Equal(t, "token", dpop["chal"].(string))
|
|
|
+ assert.Equal(t, "wireapp://%40alice_wire@wire.com", dpop["handle"].(string))
|
|
|
+ assert.Equal(t, "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com", dpop["sub"].(string))
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "fail/wire-dpop-01-no-wire-db": func(t *testing.T) test {
|
|
|
+ jwk, _ := mustAccountAndKeyAuthorization(t, "token")
|
|
|
+ dpopSigner, err := jose.NewSigner(jose.SigningKey{
|
|
|
+ Algorithm: jose.SignatureAlgorithm(jwk.Algorithm),
|
|
|
+ Key: jwk,
|
|
|
+ }, new(jose.SignerOptions))
|
|
|
+ require.NoError(t, err)
|
|
|
+ signerJWK, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
+ require.NoError(t, err)
|
|
|
+ signer, err := jose.NewSigner(jose.SigningKey{
|
|
|
+ Algorithm: jose.SignatureAlgorithm(signerJWK.Algorithm),
|
|
|
+ Key: signerJWK,
|
|
|
+ }, new(jose.SignerOptions))
|
|
|
+ require.NoError(t, err)
|
|
|
+ signerPEMBlock, err := pemutil.Serialize(signerJWK.Public().Key)
|
|
|
+ require.NoError(t, err)
|
|
|
+ signerPEMBytes := pem.EncodeToMemory(signerPEMBlock)
|
|
|
+ dpopBytes, err := json.Marshal(struct {
|
|
|
+ jose.Claims
|
|
|
+ Challenge string `json:"chal,omitempty"`
|
|
|
+ Handle string `json:"handle,omitempty"`
|
|
|
+ Nonce string `json:"nonce,omitempty"`
|
|
|
+ HTU string `json:"htu,omitempty"`
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ }{
|
|
|
+ Claims: jose.Claims{
|
|
|
+ Subject: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ Audience: jose.Audience{"https://ca.example.com/acme/wire/challenge/azID/chID"},
|
|
|
+ },
|
|
|
+ Challenge: "token",
|
|
|
+ Handle: "wireapp://%40alice_wire@wire.com",
|
|
|
+ Nonce: "nonce",
|
|
|
+ HTU: "http://issuer.example.com",
|
|
|
+ Name: "Alice Smith",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ dpop, err := dpopSigner.Sign(dpopBytes)
|
|
|
+ require.NoError(t, err)
|
|
|
+ proof, err := dpop.CompactSerialize()
|
|
|
+ require.NoError(t, err)
|
|
|
+ tokenBytes, err := json.Marshal(struct {
|
|
|
+ jose.Claims
|
|
|
+ Challenge string `json:"chal,omitempty"`
|
|
|
+ Nonce string `json:"nonce,omitempty"`
|
|
|
+ Cnf struct {
|
|
|
+ Kid string `json:"kid,omitempty"`
|
|
|
+ } `json:"cnf"`
|
|
|
+ Proof string `json:"proof,omitempty"`
|
|
|
+ ClientID string `json:"client_id"`
|
|
|
+ APIVersion int `json:"api_version"`
|
|
|
+ Scope string `json:"scope"`
|
|
|
+ }{
|
|
|
+ Claims: jose.Claims{
|
|
|
+ Issuer: "http://issuer.example.com",
|
|
|
+ Audience: jose.Audience{"https://ca.example.com/acme/wire/challenge/azID/chID"},
|
|
|
+ Expiry: jose.NewNumericDate(time.Now().Add(1 * time.Minute)),
|
|
|
+ },
|
|
|
+ Challenge: "token",
|
|
|
+ Nonce: "nonce",
|
|
|
+ Cnf: struct {
|
|
|
+ Kid string `json:"kid,omitempty"`
|
|
|
+ }{
|
|
|
+ Kid: jwk.KeyID,
|
|
|
+ },
|
|
|
+ Proof: proof,
|
|
|
+ ClientID: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ APIVersion: 5,
|
|
|
+ Scope: "wire_client_id",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ signed, err := signer.Sign(tokenBytes)
|
|
|
+ require.NoError(t, err)
|
|
|
+ accessToken, err := signed.CompactSerialize()
|
|
|
+ require.NoError(t, err)
|
|
|
+ payload, err := json.Marshal(struct {
|
|
|
+ AccessToken string `json:"access_token"`
|
|
|
+ }{
|
|
|
+ AccessToken: accessToken,
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ valueBytes, err := json.Marshal(struct {
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ Domain string `json:"domain,omitempty"`
|
|
|
+ ClientID string `json:"client-id,omitempty"`
|
|
|
+ Handle string `json:"handle,omitempty"`
|
|
|
+ }{
|
|
|
+ Name: "Alice Smith",
|
|
|
+ Domain: "wire.com",
|
|
|
+ ClientID: "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com",
|
|
|
+ Handle: "wireapp://%40alice_wire@wire.com",
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ ctx := NewProvisionerContext(context.Background(), newWireProvisionerWithOptions(t, &provisioner.Options{
|
|
|
+ Wire: &wireprovisioner.Options{
|
|
|
+ OIDC: &wireprovisioner.OIDCOptions{
|
|
|
+ Provider: &wireprovisioner.Provider{
|
|
|
+ IssuerURL: "http://issuerexample.com",
|
|
|
+ Algorithms: []string{"ES256"},
|
|
|
+ },
|
|
|
+ Config: &wireprovisioner.Config{
|
|
|
+ ClientID: "test",
|
|
|
+ SignatureAlgorithms: []string{"ES256"},
|
|
|
+ Now: time.Now,
|
|
|
+ },
|
|
|
+ TransformTemplate: "",
|
|
|
+ },
|
|
|
+ DPOP: &wireprovisioner.DPOPOptions{
|
|
|
+ Target: "http://issuer.example.com",
|
|
|
+ SigningKey: signerPEMBytes,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }))
|
|
|
+ ctx = NewLinkerContext(ctx, NewLinker("ca.example.com", "acme"))
|
|
|
+ return test{
|
|
|
+ ch: &Challenge{
|
|
|
+ ID: "chID",
|
|
|
+ AuthorizationID: "azID",
|
|
|
+ AccountID: "accID",
|
|
|
+ Token: "token",
|
|
|
+ Type: "wire-dpop-01",
|
|
|
+ Status: StatusPending,
|
|
|
+ Value: string(valueBytes),
|
|
|
+ },
|
|
|
+ payload: payload,
|
|
|
+ ctx: ctx,
|
|
|
+ jwk: jwk,
|
|
|
+ db: &MockDB{},
|
|
|
+ err: &Error{
|
|
|
+ Type: "urn:ietf:params:acme:error:serverInternal",
|
|
|
+ Detail: "The server experienced an internal error",
|
|
|
+ Status: 500,
|
|
|
+ Err: errors.New("db *acme.MockDB is not a WireDB"),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
}
|
|
|
for name, run := range tests {
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
@@ -867,25 +1381,63 @@ func TestChallenge_Validate(t *testing.T) {
|
|
|
ctx = context.Background()
|
|
|
}
|
|
|
ctx = NewClientContext(ctx, tc.vc)
|
|
|
- if err := tc.ch.Validate(ctx, tc.db, tc.jwk, tc.payload); err != nil {
|
|
|
- if assert.Error(t, tc.err) {
|
|
|
- var k *Error
|
|
|
- if errors.As(err, &k) {
|
|
|
- assert.Equal(t, tc.err.Type, k.Type)
|
|
|
- assert.Equal(t, tc.err.Detail, k.Detail)
|
|
|
- assert.Equal(t, tc.err.Status, k.Status)
|
|
|
- assert.Equal(t, tc.err.Err.Error(), k.Err.Error())
|
|
|
- } else {
|
|
|
- assert.Fail(t, "unexpected error type")
|
|
|
- }
|
|
|
+ err := tc.ch.Validate(ctx, tc.db, tc.jwk, tc.payload)
|
|
|
+ if tc.err != nil {
|
|
|
+ var k *Error
|
|
|
+ if errors.As(err, &k) {
|
|
|
+ assert.Equal(t, tc.err.Type, k.Type)
|
|
|
+ assert.Equal(t, tc.err.Detail, k.Detail)
|
|
|
+ assert.Equal(t, tc.err.Status, k.Status)
|
|
|
+ assert.Equal(t, tc.err.Err.Error(), k.Err.Error())
|
|
|
+ } else {
|
|
|
+ assert.Fail(t, "unexpected error type")
|
|
|
}
|
|
|
- } else {
|
|
|
- assert.Nil(t, tc.err)
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ assert.NoError(t, err)
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func mustJWKServer(t *testing.T, pub jose.JSONWebKey) *httptest.Server {
|
|
|
+ t.Helper()
|
|
|
+ mux := http.NewServeMux()
|
|
|
+ server := httptest.NewServer(mux)
|
|
|
+ b, err := json.Marshal(struct {
|
|
|
+ Keys []jose.JSONWebKey `json:"keys,omitempty"`
|
|
|
+ }{
|
|
|
+ Keys: []jose.JSONWebKey{pub},
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ jwks := string(b)
|
|
|
+
|
|
|
+ wellKnown := fmt.Sprintf(`{
|
|
|
+ "issuer": "%[1]s",
|
|
|
+ "authorization_endpoint": "%[1]s/auth",
|
|
|
+ "token_endpoint": "%[1]s/token",
|
|
|
+ "jwks_uri": "%[1]s/keys",
|
|
|
+ "userinfo_endpoint": "%[1]s/userinfo",
|
|
|
+ "id_token_signing_alg_values_supported": ["ES256"]
|
|
|
+ }`, server.URL)
|
|
|
+
|
|
|
+ mux.HandleFunc("/.well-known/openid-configuration", func(w http.ResponseWriter, req *http.Request) {
|
|
|
+ _, err := io.WriteString(w, wellKnown)
|
|
|
+ if err != nil {
|
|
|
+ w.WriteHeader(500)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ mux.HandleFunc("/keys", func(w http.ResponseWriter, req *http.Request) {
|
|
|
+ _, err := io.WriteString(w, jwks)
|
|
|
+ if err != nil {
|
|
|
+ w.WriteHeader(500)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Cleanup(server.Close)
|
|
|
+ return server
|
|
|
+}
|
|
|
+
|
|
|
type errReader int
|
|
|
|
|
|
func (errReader) Read([]byte) (int, error) {
|
|
|
@@ -1723,7 +2275,7 @@ func TestTLSALPN01Validate(t *testing.T) {
|
|
|
assert.Equal(t, ChallengeType("tls-alpn-01"), updch.Type)
|
|
|
assert.Equal(t, "zap.internal", updch.Value)
|
|
|
|
|
|
- err := NewError(ErrorConnectionType, "error doing TLS dial for %v:443: force", ch.Value)
|
|
|
+ err := NewError(ErrorConnectionType, "error doing TLS dial for %v: force", ch.Value)
|
|
|
|
|
|
assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
@@ -1754,7 +2306,7 @@ func TestTLSALPN01Validate(t *testing.T) {
|
|
|
assert.Equal(t, ChallengeType("tls-alpn-01"), updch.Type)
|
|
|
assert.Equal(t, "zap.internal", updch.Value)
|
|
|
|
|
|
- err := NewError(ErrorConnectionType, "error doing TLS dial for %v:443: force", ch.Value)
|
|
|
+ err := NewError(ErrorConnectionType, "error doing TLS dial for %v: force", ch.Value)
|
|
|
|
|
|
assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
@@ -1786,7 +2338,7 @@ func TestTLSALPN01Validate(t *testing.T) {
|
|
|
assert.Equal(t, ChallengeType("tls-alpn-01"), updch.Type)
|
|
|
assert.Equal(t, "zap.internal", updch.Value)
|
|
|
|
|
|
- err := NewError(ErrorConnectionType, "error doing TLS dial for %v:443: context deadline exceeded", ch.Value)
|
|
|
+ err := NewError(ErrorConnectionType, "error doing TLS dial for %v: context deadline exceeded", ch.Value)
|
|
|
|
|
|
assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
@@ -2767,14 +3319,34 @@ func Test_serverName(t *testing.T) {
|
|
|
|
|
|
func Test_http01ChallengeHost(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
- name string
|
|
|
- value string
|
|
|
- want string
|
|
|
+ name string
|
|
|
+ strictFQDN bool
|
|
|
+ value string
|
|
|
+ want string
|
|
|
}{
|
|
|
{
|
|
|
- name: "dns",
|
|
|
- value: "www.example.com",
|
|
|
- want: "www.example.com",
|
|
|
+ name: "dns",
|
|
|
+ strictFQDN: false,
|
|
|
+ value: "www.example.com",
|
|
|
+ want: "www.example.com",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "dns strict",
|
|
|
+ strictFQDN: true,
|
|
|
+ value: "www.example.com",
|
|
|
+ want: "www.example.com.",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "rooted dns",
|
|
|
+ strictFQDN: false,
|
|
|
+ value: "www.example.com.",
|
|
|
+ want: "www.example.com.",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "rooted dns strict",
|
|
|
+ strictFQDN: true,
|
|
|
+ value: "www.example.com.",
|
|
|
+ want: "www.example.com.",
|
|
|
},
|
|
|
{
|
|
|
name: "ipv4",
|
|
|
@@ -2789,6 +3361,11 @@ func Test_http01ChallengeHost(t *testing.T) {
|
|
|
}
|
|
|
for _, tt := range tests {
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
+ tmp := StrictFQDN
|
|
|
+ t.Cleanup(func() {
|
|
|
+ StrictFQDN = tmp
|
|
|
+ })
|
|
|
+ StrictFQDN = tt.strictFQDN
|
|
|
if got := http01ChallengeHost(tt.value); got != tt.want {
|
|
|
t.Errorf("http01ChallengeHost() = %v, want %v", got, tt.want)
|
|
|
}
|
|
|
@@ -3263,10 +3840,50 @@ func Test_deviceAttest01Validate(t *testing.T) {
|
|
|
AttObj: "?!",
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
- errorCBORPayload, err := json.Marshal(struct {
|
|
|
+ emptyPayload, err := json.Marshal(struct {
|
|
|
AttObj string `json:"attObj"`
|
|
|
}{
|
|
|
- AttObj: "AAAA",
|
|
|
+ AttObj: base64.RawURLEncoding.EncodeToString([]byte("")),
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ emptyObjectPayload, err := json.Marshal(struct {
|
|
|
+ AttObj string `json:"attObj"`
|
|
|
+ }{
|
|
|
+ AttObj: base64.RawURLEncoding.EncodeToString([]byte("{}")),
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ attObj, err := cbor.Marshal(struct {
|
|
|
+ Format string `json:"fmt"`
|
|
|
+ AttStatement map[string]interface{} `json:"attStmt,omitempty"`
|
|
|
+ }{
|
|
|
+ Format: "step",
|
|
|
+ AttStatement: map[string]interface{}{
|
|
|
+ "alg": -7,
|
|
|
+ "sig": "",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ errorNonWellformedCBORPayload, err := json.Marshal(struct {
|
|
|
+ AttObj string `json:"attObj"`
|
|
|
+ }{
|
|
|
+ AttObj: base64.RawURLEncoding.EncodeToString(attObj[:len(attObj)-1]), // cut the CBOR encoded data off
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ unsupportedFormatAttObj, err := cbor.Marshal(struct {
|
|
|
+ Format string `json:"fmt"`
|
|
|
+ AttStatement map[string]interface{} `json:"attStmt,omitempty"`
|
|
|
+ }{
|
|
|
+ Format: "unsupported-format",
|
|
|
+ AttStatement: map[string]interface{}{
|
|
|
+ "alg": -7,
|
|
|
+ "sig": "",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ require.NoError(t, err)
|
|
|
+ errorUnsupportedFormat, err := json.Marshal(struct {
|
|
|
+ AttObj string `json:"attObj"`
|
|
|
+ }{
|
|
|
+ AttObj: base64.RawURLEncoding.EncodeToString(unsupportedFormatAttObj),
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
type args struct {
|
|
|
@@ -3403,7 +4020,7 @@ func Test_deviceAttest01Validate(t *testing.T) {
|
|
|
wantErr: nil,
|
|
|
}
|
|
|
},
|
|
|
- "fail/base64-decode": func(t *testing.T) test {
|
|
|
+ "ok/base64-decode": func(t *testing.T) test {
|
|
|
return test{
|
|
|
args: args{
|
|
|
ch: &Challenge{
|
|
|
@@ -3419,13 +4036,29 @@ func Test_deviceAttest01Validate(t *testing.T) {
|
|
|
assert.Equal(t, "azID", id)
|
|
|
return &Authorization{ID: "azID"}, nil
|
|
|
},
|
|
|
+ MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
|
|
|
+ assert.Equal(t, "chID", updch.ID)
|
|
|
+ assert.Equal(t, "token", updch.Token)
|
|
|
+ assert.Equal(t, StatusInvalid, updch.Status)
|
|
|
+ assert.Equal(t, ChallengeType("device-attest-01"), updch.Type)
|
|
|
+ assert.Equal(t, "12345678", updch.Value)
|
|
|
+
|
|
|
+ err := NewDetailedError(ErrorBadAttestationStatementType, "failed base64 decoding attObj %q", "?!")
|
|
|
+
|
|
|
+ assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
+ assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
+ assert.Equal(t, err.Detail, updch.Error.Detail)
|
|
|
+ assert.Equal(t, err.Status, updch.Error.Status)
|
|
|
+ assert.Equal(t, err.Subproblems, updch.Error.Subproblems)
|
|
|
+
|
|
|
+ return nil
|
|
|
+ },
|
|
|
},
|
|
|
payload: errorBase64Payload,
|
|
|
},
|
|
|
- wantErr: NewErrorISE("error base64 decoding attObj: illegal base64 data at input byte 0"),
|
|
|
}
|
|
|
},
|
|
|
- "fail/cbor.Unmarshal": func(t *testing.T) test {
|
|
|
+ "ok/empty-attobj": func(t *testing.T) test {
|
|
|
return test{
|
|
|
args: args{
|
|
|
ch: &Challenge{
|
|
|
@@ -3441,10 +4074,142 @@ func Test_deviceAttest01Validate(t *testing.T) {
|
|
|
assert.Equal(t, "azID", id)
|
|
|
return &Authorization{ID: "azID"}, nil
|
|
|
},
|
|
|
+ MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
|
|
|
+ assert.Equal(t, "chID", updch.ID)
|
|
|
+ assert.Equal(t, "token", updch.Token)
|
|
|
+ assert.Equal(t, StatusInvalid, updch.Status)
|
|
|
+ assert.Equal(t, ChallengeType("device-attest-01"), updch.Type)
|
|
|
+ assert.Equal(t, "12345678", updch.Value)
|
|
|
+
|
|
|
+ err := NewDetailedError(ErrorBadAttestationStatementType, "attObj must not be empty")
|
|
|
+
|
|
|
+ assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
+ assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
+ assert.Equal(t, err.Detail, updch.Error.Detail)
|
|
|
+ assert.Equal(t, err.Status, updch.Error.Status)
|
|
|
+ assert.Equal(t, err.Subproblems, updch.Error.Subproblems)
|
|
|
+
|
|
|
+ return nil
|
|
|
+ },
|
|
|
},
|
|
|
- payload: errorCBORPayload,
|
|
|
+ payload: emptyPayload,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "ok/empty-json-attobj": func(t *testing.T) test {
|
|
|
+ return test{
|
|
|
+ args: args{
|
|
|
+ ch: &Challenge{
|
|
|
+ ID: "chID",
|
|
|
+ AuthorizationID: "azID",
|
|
|
+ Token: "token",
|
|
|
+ Type: "device-attest-01",
|
|
|
+ Status: StatusPending,
|
|
|
+ Value: "12345678",
|
|
|
+ },
|
|
|
+ db: &MockDB{
|
|
|
+ MockGetAuthorization: func(ctx context.Context, id string) (*Authorization, error) {
|
|
|
+ assert.Equal(t, "azID", id)
|
|
|
+ return &Authorization{ID: "azID"}, nil
|
|
|
+ },
|
|
|
+ MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
|
|
|
+ assert.Equal(t, "chID", updch.ID)
|
|
|
+ assert.Equal(t, "token", updch.Token)
|
|
|
+ assert.Equal(t, StatusInvalid, updch.Status)
|
|
|
+ assert.Equal(t, ChallengeType("device-attest-01"), updch.Type)
|
|
|
+ assert.Equal(t, "12345678", updch.Value)
|
|
|
+
|
|
|
+ err := NewDetailedError(ErrorBadAttestationStatementType, "attObj must not be empty")
|
|
|
+
|
|
|
+ assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
+ assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
+ assert.Equal(t, err.Detail, updch.Error.Detail)
|
|
|
+ assert.Equal(t, err.Status, updch.Error.Status)
|
|
|
+ assert.Equal(t, err.Subproblems, updch.Error.Subproblems)
|
|
|
+
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ },
|
|
|
+ payload: emptyObjectPayload,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "ok/cborDecoder.Wellformed": func(t *testing.T) test {
|
|
|
+ return test{
|
|
|
+ args: args{
|
|
|
+ ch: &Challenge{
|
|
|
+ ID: "chID",
|
|
|
+ AuthorizationID: "azID",
|
|
|
+ Token: "token",
|
|
|
+ Type: "device-attest-01",
|
|
|
+ Status: StatusPending,
|
|
|
+ Value: "12345678",
|
|
|
+ },
|
|
|
+ db: &MockDB{
|
|
|
+ MockGetAuthorization: func(ctx context.Context, id string) (*Authorization, error) {
|
|
|
+ assert.Equal(t, "azID", id)
|
|
|
+ return &Authorization{ID: "azID"}, nil
|
|
|
+ },
|
|
|
+ MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
|
|
|
+ assert.Equal(t, "chID", updch.ID)
|
|
|
+ assert.Equal(t, "token", updch.Token)
|
|
|
+ assert.Equal(t, StatusInvalid, updch.Status)
|
|
|
+ assert.Equal(t, ChallengeType("device-attest-01"), updch.Type)
|
|
|
+ assert.Equal(t, "12345678", updch.Value)
|
|
|
+
|
|
|
+ err := NewDetailedError(ErrorBadAttestationStatementType, "attObj is not well formed CBOR: unexpected EOF")
|
|
|
+
|
|
|
+ assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
+ assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
+ assert.Equal(t, err.Detail, updch.Error.Detail)
|
|
|
+ assert.Equal(t, err.Status, updch.Error.Status)
|
|
|
+ assert.Equal(t, err.Subproblems, updch.Error.Subproblems)
|
|
|
+
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ },
|
|
|
+ payload: errorNonWellformedCBORPayload,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "ok/unsupported-attestation-format": func(t *testing.T) test {
|
|
|
+ ctx := NewProvisionerContext(context.Background(), mustNonAttestationProvisioner(t))
|
|
|
+ return test{
|
|
|
+ args: args{
|
|
|
+ ctx: ctx,
|
|
|
+ ch: &Challenge{
|
|
|
+ ID: "chID",
|
|
|
+ AuthorizationID: "azID",
|
|
|
+ Token: "token",
|
|
|
+ Type: "device-attest-01",
|
|
|
+ Status: StatusPending,
|
|
|
+ Value: "12345678",
|
|
|
+ },
|
|
|
+ db: &MockDB{
|
|
|
+ MockGetAuthorization: func(ctx context.Context, id string) (*Authorization, error) {
|
|
|
+ assert.Equal(t, "azID", id)
|
|
|
+ return &Authorization{ID: "azID"}, nil
|
|
|
+ },
|
|
|
+ MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
|
|
|
+ assert.Equal(t, "chID", updch.ID)
|
|
|
+ assert.Equal(t, "token", updch.Token)
|
|
|
+ assert.Equal(t, StatusInvalid, updch.Status)
|
|
|
+ assert.Equal(t, ChallengeType("device-attest-01"), updch.Type)
|
|
|
+ assert.Equal(t, "12345678", updch.Value)
|
|
|
+
|
|
|
+ err := NewDetailedError(ErrorBadAttestationStatementType, "unsupported attestation object format %q", "unsupported-format")
|
|
|
+
|
|
|
+ assert.EqualError(t, updch.Error.Err, err.Err.Error())
|
|
|
+ assert.Equal(t, err.Type, updch.Error.Type)
|
|
|
+ assert.Equal(t, err.Detail, updch.Error.Detail)
|
|
|
+ assert.Equal(t, err.Status, updch.Error.Status)
|
|
|
+ assert.Equal(t, err.Subproblems, updch.Error.Subproblems)
|
|
|
+
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ },
|
|
|
+ payload: errorUnsupportedFormat,
|
|
|
},
|
|
|
- wantErr: NewErrorISE("error unmarshalling CBOR: cbor:"),
|
|
|
}
|
|
|
},
|
|
|
"ok/prov.IsAttestationFormatEnabled": func(t *testing.T) test {
|
|
|
@@ -4301,3 +5066,59 @@ func createSubjectAltNameExtension(dnsNames, emailAddresses x509util.MultiString
|
|
|
Value: rawBytes,
|
|
|
}, nil
|
|
|
}
|
|
|
+
|
|
|
+func Test_tlsAlpn01ChallengeHost(t *testing.T) {
|
|
|
+ type args struct {
|
|
|
+ name string
|
|
|
+ }
|
|
|
+ tests := []struct {
|
|
|
+ name string
|
|
|
+ strictFQDN bool
|
|
|
+ args args
|
|
|
+ want string
|
|
|
+ }{
|
|
|
+ {"dns", false, args{"smallstep.com"}, "smallstep.com"},
|
|
|
+ {"dns strict", true, args{"smallstep.com"}, "smallstep.com."},
|
|
|
+ {"rooted dns", false, args{"smallstep.com."}, "smallstep.com."},
|
|
|
+ {"rooted dns strict", true, args{"smallstep.com."}, "smallstep.com."},
|
|
|
+ {"ipv4", true, args{"1.2.3.4"}, "1.2.3.4"},
|
|
|
+ {"ipv6", true, args{"2607:f8b0:4023:1009::71"}, "2607:f8b0:4023:1009::71"},
|
|
|
+ }
|
|
|
+ for _, tt := range tests {
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
+ tmp := StrictFQDN
|
|
|
+ t.Cleanup(func() {
|
|
|
+ StrictFQDN = tmp
|
|
|
+ })
|
|
|
+ StrictFQDN = tt.strictFQDN
|
|
|
+ assert.Equal(t, tt.want, tlsAlpn01ChallengeHost(tt.args.name))
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func Test_dns01ChallengeHost(t *testing.T) {
|
|
|
+ type args struct {
|
|
|
+ domain string
|
|
|
+ }
|
|
|
+ tests := []struct {
|
|
|
+ name string
|
|
|
+ strictFQDN bool
|
|
|
+ args args
|
|
|
+ want string
|
|
|
+ }{
|
|
|
+ {"dns", false, args{"smallstep.com"}, "_acme-challenge.smallstep.com"},
|
|
|
+ {"dns strict", true, args{"smallstep.com"}, "_acme-challenge.smallstep.com."},
|
|
|
+ {"rooted dns", false, args{"smallstep.com."}, "_acme-challenge.smallstep.com."},
|
|
|
+ {"rooted dns strict", true, args{"smallstep.com."}, "_acme-challenge.smallstep.com."},
|
|
|
+ }
|
|
|
+ for _, tt := range tests {
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
+ tmp := StrictFQDN
|
|
|
+ t.Cleanup(func() {
|
|
|
+ StrictFQDN = tmp
|
|
|
+ })
|
|
|
+ StrictFQDN = tt.strictFQDN
|
|
|
+ assert.Equal(t, tt.want, dns01ChallengeHost(tt.args.domain))
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|