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

support TLS client certificates #29

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Changes from 2 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
16 changes: 16 additions & 0 deletions ircdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Sending Escapes:
Options:
--tls Connect using TLS.
--tls-noverify Don't verify the provided TLS certificates.
--tls-cert=<file> A file containing a TLS client cert & key, to use for TLS connections.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more thing, could you name this --client-cert? We are also considering a server cert argument in #9.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--client-cert is long enough that it throws out the alignment of flag name vs description, btw

--listen=<address> Listen on an address like ":7778", pass through traffic.
--hide=<messages> Comma-separated list of commands/numerics to not print.
--origin=<url> URL to send as the Origin header for a WebSocket connection
Expand Down Expand Up @@ -157,6 +158,21 @@ func parseConnectionConfig(arguments map[string]any) (config lib.ConnectionConfi
InsecureSkipVerify: true,
}
}

if tlsCert := arguments["--tls-cert"]; tlsCert != nil {
if config.TLSConfig == nil {
config.TLSConfig = new(tls.Config)
}

tlsCert, tErr := tls.LoadX509KeyPair(tlsCert.(string), tlsCert.(string))

if tErr != nil {
err = fmt.Errorf("Cannot load TLS cert/key: %w", tErr)
return
}
config.TLSConfig.Certificates = []tls.Certificate{tlsCert}
}

return
}

Expand Down