Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-certificate authentication to client #60

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions configs/oc-client.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"ClientCertificate": "/path/to/file or PKCS11 URI",
"ClientKey": "/path/to/file or PKCS11 URI",
"UserCertificate": "Empty or /path/to/file or PKCS11 URI",
"UserKey": "Empty or /path/to/file or PKCS11 URI",
"CACertificate": "Empty or additional CA Certificate file(s)",
"XMLProfile": "/var/lib/oc-daemon/profile.xml",
"VPNServer": "My VPN Server Name",
Expand Down
14 changes: 14 additions & 0 deletions internal/client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func setConfig(args []string) error {
cert := flags.String("cert", "", "set client certificate `file` or "+
"PKCS11 URI")
key := flags.String("key", "", "set client key `file` or PKCS11 URI")
userCert := flags.String("user-cert", "", "set user certificate `file` or PKCS11 URI.\n"+
"Note: requires OpenConnect v9.00 or higher")
userKey := flags.String("user-key", "", "set user key `file` or PKCS11 URI.\n"+
"Note: requires OpenConnect v9.00 or higher")
ca := flags.String("ca", "", "set additional CA certificate `file`")
profile := flags.String("profile", "", "set XML profile `file`")
srv := flags.String("server", "", "set server `address`")
Expand Down Expand Up @@ -160,6 +164,16 @@ func setConfig(args []string) error {
config.ClientKey = *key
}

// set user certificate
if *userCert != "" {
config.UserCertificate = *userCert
}

// set user key
if *userKey != "" {
config.UserKey = *userKey
}

// set ca certificate
if *ca != "" {
config.CACertificate = *ca
Expand Down
6 changes: 6 additions & 0 deletions internal/client/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func TestRun(t *testing.T) {
if err := run([]string{"test",
"-cert", "cert-file",
"-key", "key-file",
"-user-cert", "user-cert-file",
"-user-key", "user-key-file",
"-ca", "ca-file",
"-profile", "profile-file",
"-server", "test-server",
Expand All @@ -99,6 +101,8 @@ func TestRun(t *testing.T) {
if err := run([]string{"test",
"-cert", "cert-file",
"-key", "key-file",
"-user-cert", "user-cert-file",
"-user-key", "user-key-file",
"-ca", "ca-file",
"-profile", "profile-file",
"-server", "test-server",
Expand Down Expand Up @@ -126,6 +130,8 @@ func TestRun(t *testing.T) {
if err := run([]string{"test",
"-cert", "cert-file",
"-key", "key-file",
"-user-cert", "user-cert-file",
"-user-key", "user-key-file",
"-ca", "ca-file",
"-profile", "profile-file",
"-server", "test-server",
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ var authenticate = func(d *DBusClient) error {
userAgent := fmt.Sprintf("--useragent=%s", config.UserAgent)
certificate := fmt.Sprintf("--certificate=%s", config.ClientCertificate)
sslKey := fmt.Sprintf("--sslkey=%s", config.ClientKey)
mcaCertificate := fmt.Sprintf("--mca-certificate=%s", config.UserCertificate)
mcaKey := fmt.Sprintf("--mca-key=%s", config.UserKey)
caFile := fmt.Sprintf("--cafile=%s", config.CACertificate)
xmlConfig := fmt.Sprintf("--xmlconfig=%s", config.XMLProfile)
user := fmt.Sprintf("--user=%s", config.User)
Expand All @@ -424,6 +426,12 @@ var authenticate = func(d *DBusClient) error {
xmlConfig,
"--authenticate",
}
if config.UserCertificate != "" {
parameters = append(parameters, mcaCertificate)
}
if config.UserKey != "" {
parameters = append(parameters, mcaKey)
}
if config.Quiet {
parameters = append(parameters, "--quiet")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ func TestDBusClientAuthenticate(t *testing.T) {

// create test client
conf := NewConfig()
conf.UserCertificate = "/test/user-cert"
conf.UserKey = "/test/user-key"
conf.CACertificate = "/test/ca"
conf.User = "test-user"
conf.Password = "test-passwd"
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var (
type Config struct {
ClientCertificate string
ClientKey string
UserCertificate string
UserKey string
CACertificate string
XMLProfile string
VPNServer string
Expand Down
Loading