Skip to content

Commit 1198e73

Browse files
committed
Always support did:jwk, web, x509 and key when verifying VCs
1 parent fd2b4c5 commit 1198e73

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

auth/auth.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ import (
2323
"errors"
2424
"github.com/nuts-foundation/nuts-node/auth/client/iam"
2525
"github.com/nuts-foundation/nuts-node/vdr"
26+
"github.com/nuts-foundation/nuts-node/vdr/didjwk"
27+
"github.com/nuts-foundation/nuts-node/vdr/didkey"
28+
"github.com/nuts-foundation/nuts-node/vdr/didnuts"
2629
"github.com/nuts-foundation/nuts-node/vdr/didsubject"
30+
"github.com/nuts-foundation/nuts-node/vdr/didweb"
31+
"github.com/nuts-foundation/nuts-node/vdr/didx509"
2732
"github.com/nuts-foundation/nuts-node/vdr/resolver"
2833
"net/url"
2934
"path"
35+
"slices"
3036
"time"
3137

3238
"github.com/nuts-foundation/nuts-node/auth/services"
@@ -46,23 +52,25 @@ var _ AuthenticationServices = (*Auth)(nil)
4652

4753
// Auth is the main struct of the Auth service
4854
type Auth struct {
49-
config Config
50-
jsonldManager jsonld.JSONLD
51-
authzServer oauth.AuthorizationServer
52-
relyingParty oauth.RelyingParty
53-
contractNotary services.ContractNotary
54-
serviceResolver didman.CompoundServiceResolver
55-
keyStore crypto.KeyStore
56-
vcr vcr.VCR
57-
pkiProvider pki.Provider
58-
shutdownFunc func()
59-
vdrInstance vdr.VDR
60-
publicURL *url.URL
61-
strictMode bool
62-
httpClientTimeout time.Duration
63-
tlsConfig *tls.Config
64-
subjectManager didsubject.Manager
65-
supportedDIDMethods []string
55+
config Config
56+
jsonldManager jsonld.JSONLD
57+
authzServer oauth.AuthorizationServer
58+
relyingParty oauth.RelyingParty
59+
contractNotary services.ContractNotary
60+
serviceResolver didman.CompoundServiceResolver
61+
keyStore crypto.KeyStore
62+
vcr vcr.VCR
63+
pkiProvider pki.Provider
64+
shutdownFunc func()
65+
vdrInstance vdr.VDR
66+
publicURL *url.URL
67+
strictMode bool
68+
httpClientTimeout time.Duration
69+
tlsConfig *tls.Config
70+
subjectManager didsubject.Manager
71+
// configuredDIDMethods contains the DID methods that are configured in the Nuts node,
72+
// of which VDR will create DIDs.
73+
configuredDIDMethods []string
6674
}
6775

6876
// Name returns the name of the module.
@@ -137,7 +145,7 @@ func (auth *Auth) Configure(config core.ServerConfig) error {
137145
return err
138146
}
139147

140-
auth.supportedDIDMethods = config.DIDMethods
148+
auth.configuredDIDMethods = config.DIDMethods
141149

142150
auth.contractNotary = notary.NewNotary(notary.Config{
143151
PublicURL: auth.publicURL.String(),
@@ -179,7 +187,13 @@ func (auth *Auth) Configure(config core.ServerConfig) error {
179187
}
180188

181189
func (auth *Auth) SupportedDIDMethods() []string {
182-
return append(auth.supportedDIDMethods, "x509")
190+
// DID methods that don't require additional resources/configuration in the Nuts node are always supported.
191+
// Other DID methods (did:nuts), are only supported if explicitly enabled.
192+
result := []string{didweb.MethodName, didjwk.MethodName, didkey.MethodName, didx509.MethodName}
193+
if slices.Contains(auth.configuredDIDMethods, didnuts.MethodName) {
194+
result = append(result, didnuts.MethodName)
195+
}
196+
return result
183197
}
184198

185199
// Start starts the Auth engine (Noop)

auth/auth_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,22 @@ func TestAuth_IAMClient(t *testing.T) {
125125
})
126126

127127
}
128+
129+
func TestAuth_SupportedDIDMethods(t *testing.T) {
130+
t.Run("supports did:web", func(t *testing.T) {
131+
assert.Contains(t, (&Auth{}).SupportedDIDMethods(), "web")
132+
})
133+
t.Run("supports did:key", func(t *testing.T) {
134+
assert.Contains(t, (&Auth{}).SupportedDIDMethods(), "key")
135+
})
136+
t.Run("supports did:x509", func(t *testing.T) {
137+
assert.Contains(t, (&Auth{}).SupportedDIDMethods(), "x509")
138+
})
139+
t.Run("supports did:jwk", func(t *testing.T) {
140+
assert.Contains(t, (&Auth{}).SupportedDIDMethods(), "jwk")
141+
})
142+
t.Run("supports did:nuts if configured", func(t *testing.T) {
143+
assert.NotContains(t, (&Auth{}).SupportedDIDMethods(), "nuts")
144+
assert.Contains(t, (&Auth{configuredDIDMethods: []string{"nuts"}}).SupportedDIDMethods(), "nuts")
145+
})
146+
}

auth/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ type AuthenticationServices interface {
4242
PublicURL() *url.URL
4343
// AuthorizationEndpointEnabled returns whether the v2 API's OAuth2 Authorization Endpoint is enabled.
4444
AuthorizationEndpointEnabled() bool
45-
// SupportedDIDMethods list the DID methods configured for the nuts node in preferred order.
45+
// SupportedDIDMethods lists the DID methods the Nuts node can resolve.
4646
SupportedDIDMethods() []string
4747
}

0 commit comments

Comments
 (0)