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 client certificate verify #1169

Merged
merged 1 commit into from
Sep 1, 2021
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 infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ type TLSConfig struct {
EnableSessionResumption bool `json:"enableSessionResumption"`
DisableSystemRoot bool `json:"disableSystemRoot"`
PinnedPeerCertificateChainSha256 *[]string `json:"pinnedPeerCertificateChainSha256"`
ClientVerify bool `json:"clientVerify"`
}

// Build implements Buildable.
Expand All @@ -337,6 +338,7 @@ func (c *TLSConfig) Build() (proto.Message, error) {
}
serverName := c.ServerName
config.AllowInsecure = c.Insecure
config.ClientVerify = c.ClientVerify
if len(c.ServerName) > 0 {
config.ServerName = serverName
}
Expand Down
6 changes: 4 additions & 2 deletions transport/internet/tls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,22 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
SessionTicketsDisabled: true,
}
}

config := &tls.Config{
ClientSessionCache: globalSessionCache,
RootCAs: root,
InsecureSkipVerify: c.AllowInsecure,
NextProtos: c.NextProtocol,
SessionTicketsDisabled: !c.EnableSessionResumption,
VerifyPeerCertificate: c.verifyPeerCert,
ClientCAs: root,
}

for _, opt := range opts {
opt(config)
}

if c.ClientVerify {
config.ClientAuth = tls.RequireAndVerifyClientCert
}
config.Certificates = c.BuildCertificates()
config.BuildNameToCertificate()

Expand Down
33 changes: 22 additions & 11 deletions transport/internet/tls/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions transport/internet/tls/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ message Config {
@Critical
*/
repeated bytes pinned_peer_certificate_chain_sha256 = 7;

// Whether or not server verify client cert
bool client_verify = 8;
}