@@ -6,17 +6,14 @@ import (
6
6
"fmt"
7
7
"log"
8
8
"net"
9
- "net/url"
10
9
"os"
11
10
"strconv"
12
11
"strings"
13
12
"sync"
14
13
15
14
"github.com/NHAS/wag/internal/acls"
16
15
"github.com/NHAS/wag/internal/routetypes"
17
- "github.com/NHAS/wag/internal/webserver/authenticators"
18
16
"github.com/NHAS/wag/pkg/control"
19
- "github.com/NHAS/webauthn/webauthn"
20
17
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
21
18
)
22
19
@@ -52,19 +49,19 @@ type Config struct {
52
49
path string
53
50
Socket string `json:",omitempty"`
54
51
GID * int `json:",omitempty"`
55
- CheckUpdates bool `json:",omitempty"`
52
+ CheckUpdates bool `json:",omitempty"` // Done
56
53
NumberProxies int
57
54
Proxied bool
58
55
ExposePorts []string `json:",omitempty"`
59
56
NAT * bool
60
57
61
58
MFATemplatesDirectory string `json:",omitempty"`
62
59
63
- HelpMail string
64
- Lockout int
65
- ExternalAddress string
66
- MaxSessionLifetimeMinutes int
67
- SessionInactivityTimeoutMinutes int
60
+ HelpMail string // Done
61
+ Lockout int // Done
62
+ ExternalAddress string // Done
63
+ MaxSessionLifetimeMinutes int // Done
64
+ SessionInactivityTimeoutMinutes int // Done
68
65
69
66
DownloadConfigFileName string `json:",omitempty"`
70
67
@@ -87,10 +84,10 @@ type Config struct {
87
84
}
88
85
89
86
Authenticators struct {
90
- DefaultMethod string `json:",omitempty"`
91
- Issuer string
87
+ DefaultMethod string `json:",omitempty"` // Done
88
+ Issuer string // Done
92
89
Methods []string `json:",omitempty"`
93
- DomainURL string
90
+ DomainURL string // Done
94
91
95
92
OIDC struct {
96
93
IssuerURL string
@@ -102,9 +99,6 @@ type Config struct {
102
99
PAM struct {
103
100
ServiceName string
104
101
} `json:",omitempty"`
105
-
106
- //Not externally configurable
107
- Webauthn * webauthn.WebAuthn `json:"-"`
108
102
}
109
103
Wireguard struct {
110
104
DevName string
@@ -365,112 +359,10 @@ func load(path string) (c Config, err error) {
365
359
}
366
360
}
367
361
368
- if len (c .Authenticators .Methods ) == 0 {
369
- for method := range authenticators .MFA {
370
- c .Authenticators .Methods = append (c .Authenticators .Methods , method )
371
- }
372
- }
373
-
374
- resultMFAMap := make (map [string ]authenticators.Authenticator )
375
- for _ , method := range c .Authenticators .Methods {
376
- _ , ok := authenticators .MFA [method ]
377
- if ! ok {
378
- return c , errors .New ("mfa method invalid: " + method )
379
- }
380
-
381
- resultMFAMap [method ] = authenticators .MFA [method ]
382
-
383
- settings := make (map [string ]string )
384
- switch method {
385
-
386
- case "oidc" :
387
- if c .Authenticators .DomainURL == "" {
388
- return c , errors .New ("Authenticators.DomainURL unset, needed for oidc" )
389
- }
390
-
391
- if c .Authenticators .OIDC .GroupsClaimName == "" {
392
- c .Authenticators .OIDC .GroupsClaimName = "groups"
393
- }
394
-
395
- if c .Authenticators .OIDC .IssuerURL == "" {
396
- return c , errors .New ("OIDC issuer url is not set, but oidc authentication method is enabled" )
397
- }
398
-
399
- tunnelURL , err := url .Parse (c .Authenticators .OIDC .IssuerURL )
400
- if err != nil {
401
- return c , errors .New ("unable to parse Authenticators.OIDC.IssuerURL: " + err .Error ())
402
- }
403
-
404
- if tunnelURL .Scheme != "https" && tunnelURL .Scheme != "http" {
405
- return c , errors .New ("Authenticators.OIDC.IssuerURL was not HTTP/HTTPS" )
406
- }
407
-
408
- if tunnelURL .Scheme == "http" {
409
- log .Println ("[WARNING] OIDC issuer url is http, this may be insecure" )
410
- }
411
-
412
- if c .Authenticators .OIDC .ClientSecret == "" {
413
- return c , errors .New ("Authenticators.OIDC.ClientSecret is empty, but oidc authentication method is enabled" )
414
- }
415
-
416
- if c .Authenticators .OIDC .ClientID == "" {
417
- return c , errors .New ("Authenticators.OIDC.ClientID is empty, but oidc authentication method is enabled" )
418
- }
419
-
420
- settings ["ClientID" ] = c .Authenticators .OIDC .ClientID
421
- settings ["ClientSecret" ] = c .Authenticators .OIDC .ClientSecret
422
- settings ["IssuerURL" ] = c .Authenticators .OIDC .IssuerURL
423
- settings ["DomainURL" ] = c .Authenticators .DomainURL
424
-
425
- case "webauthn" :
426
-
427
- if c .Authenticators .DomainURL == "" {
428
- return c , errors .New ("Authenticators.DomainURL unset, needed for webauthn" )
429
- }
430
-
431
- tunnelURL , err := url .Parse (c .Authenticators .DomainURL )
432
- if err != nil {
433
- return c , errors .New ("unable to parse Authenticators.DomainURL: " + err .Error ())
434
- }
435
-
436
- if ! c .Webserver .Tunnel .SupportsTLS () && c .NumberProxies == 0 {
437
- return c , errors .New ("tunnel does not support TLS (no cert/key given) required by webauthn" )
438
- }
439
-
440
- if tunnelURL .Scheme != "https" {
441
- return c , errors .New ("Authenticators.DomainURL was not HTTPS, yet webauthn was enabled (javascript wont be able to access window.PublicKeyCredential)" )
442
- }
443
-
444
- c .Authenticators .Webauthn , err = webauthn .New (& webauthn.Config {
445
- RPDisplayName : c .Authenticators .Issuer , // Display Name for your site
446
- RPID : strings .Split (tunnelURL .Host , ":" )[0 ], // Generally the domain name for your site
447
- RPOrigin : c .Authenticators .DomainURL , // The origin URL for WebAuthn requests
448
- })
449
-
450
- if err != nil {
451
- return c , errors .New ("could not configure webauthn domain: " + err .Error ())
452
- }
453
- }
454
-
455
- if err := resultMFAMap [method ].Init (settings ); err != nil {
456
- return c , err
457
- }
458
- }
459
-
460
- if c .Authenticators .DefaultMethod != "" {
461
- _ , ok := resultMFAMap [c .Authenticators .DefaultMethod ]
462
- if ! ok {
463
- return c , errors .New ("default mfa method invalid: " + c .Authenticators .DefaultMethod + " valid methods: " + strings .Join (c .Authenticators .Methods , "," ))
464
- }
465
- }
466
-
467
362
if len (c .Authenticators .Methods ) == 1 {
468
363
c .Authenticators .DefaultMethod = c .Authenticators .Methods [len (c .Authenticators .Methods )- 1 ]
469
364
}
470
365
471
- // Remove all uneeded MFA methods from the MFA map
472
- authenticators .MFA = resultMFAMap
473
-
474
366
return c , nil
475
367
}
476
368
0 commit comments