Skip to content

Commit

Permalink
Add multi-certificate authentication to client
Browse files Browse the repository at this point in the history
Add the command line arguments "-user-cert" and "-user-key" to oc-client
and the options "UserCertificate" and "UserKey" to the client config to
support multi-certificate authentication.

Signed-off-by: hwipl <[email protected]>
  • Loading branch information
hwipl committed Mar 13, 2024
1 parent ae9f423 commit f418ddc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
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
13 changes: 13 additions & 0 deletions internal/client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ 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")
userKey := flags.String("user-key", "", "set user key `file` or PKCS11 URI")
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 +163,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

0 comments on commit f418ddc

Please sign in to comment.