| 1 |
package openvpn |
| 2 |
|
| 3 |
import ( |
| 4 |
"bufio" |
| 5 |
"bytes" |
| 6 |
"context" |
| 7 |
"log/slog" |
| 8 |
"net" |
| 9 |
"sync" |
| 10 |
"sync/atomic" |
| 11 |
"time" |
| 12 |
|
| 13 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config" |
| 14 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/idtoken" |
| 15 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/types" |
| 16 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/openvpn/connection" |
| 17 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/state" |
| 18 |
) |
| 19 |
|
| 20 |
const ( |
| 21 |
SchemeTCP = "tcp" |
| 22 |
SchemeUnix = "unix" |
| 23 |
) |
| 24 |
|
| 25 |
type Client struct { |
| 26 |
oauth2 oauth2Client |
| 27 |
conn net.Conn |
| 28 |
commandResponseCh chan string |
| 29 |
commandLock chan struct{} |
| 30 |
commandTimer *time.Timer |
| 31 |
commandsCh chan string |
| 32 |
logger *slog.Logger |
| 33 |
scanner *bufio.Scanner |
| 34 |
ctxCancel context.CancelFunc |
| 35 |
clientsCh chan connection.Client |
| 36 |
passThroughCh chan string |
| 37 |
shutdownCh chan struct{} |
| 38 |
conf *config.Config |
| 39 |
commandsBuffer bytes.Buffer |
| 40 |
acceptMu sync.Mutex |
| 41 |
connMu sync.Mutex |
| 42 |
closed atomic.Uint32 |
| 43 |
passThroughConnected atomic.Uint32 |
| 44 |
} |
| 45 |
|
| 46 |
type oauth2Client interface { |
| 47 |
RefreshClientAuth(ctx context.Context, logger *slog.Logger, client connection.Client) (types.UserInfo, *idtoken.IDToken, []string, bool, error) |
| 48 |
ResolveClientConfigNames( |
| 49 |
authMode types.AuthMode, |
| 50 |
session state.State, |
| 51 |
tokens *idtoken.IDToken, |
| 52 |
user types.UserInfo, |
| 53 |
) ([]string, error) |
| 54 |
ClientDisconnect(ctx context.Context, logger *slog.Logger, client connection.Client) |
| 55 |
EncryptState(oidcState state.State) (state.EncryptedState, error) |
| 56 |
} |