Skip to content

Commit

Permalink
add client certificate verify (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
qq906907952 committed Sep 1, 2021
1 parent 46fa8f7 commit fb665ee
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
2 changes: 2 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,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 @@ -333,6 +334,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 @@ -211,20 +211,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;
}

0 comments on commit fb665ee

Please sign in to comment.