MCPcopy Create free account
hub / github.com/bytebase/bytebase / configureClientCertificates

Function configureClientCertificates

backend/plugin/db/util/ssl.go:193–209  ·  view source on GitHub ↗

configureClientCertificates sets up client certificates for mutual TLS authentication

(ds *storepb.DataSource, cfg *tls.Config)

Source from the content-addressed store, hash-verified

191
192// configureClientCertificates sets up client certificates for mutual TLS authentication
193func configureClientCertificates(ds *storepb.DataSource, cfg *tls.Config) error {
194 // Validate that both cert and key are provided together
195 if (ds.GetSslCert() == "" && ds.GetSslKey() != "") || (ds.GetSslCert() != "" && ds.GetSslKey() == "") {
196 return errors.Errorf("ssl-cert and ssl-key must be both set or unset")
197 }
198
199 // Configure client certificate if both cert and key are provided
200 if ds.GetSslCert() != "" && ds.GetSslKey() != "" {
201 certs, err := tls.X509KeyPair([]byte(ds.GetSslCert()), []byte(ds.GetSslKey()))
202 if err != nil {
203 return err
204 }
205 cfg.Certificates = []tls.Certificate{certs}
206 }
207
208 return nil
209}
210
211// SSLMode is the PGSSLMode type.
212// https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE

Callers 1

GetTLSConfigFunction · 0.85

Calls 3

ErrorfMethod · 0.80
GetSslCertMethod · 0.45
GetSslKeyMethod · 0.45

Tested by

no test coverage detected