@@ -17,6 +17,8 @@ package service
1717import (
1818 "bytes"
1919 "context"
20+ "crypto"
21+ "crypto/rsa"
2022 "crypto/sha256"
2123 "crypto/tls"
2224 "crypto/x509"
@@ -109,6 +111,7 @@ func NewTLSConfigWithTLSCertificateCache(cfg config.TLS) (*tls.Config, *TLSCerti
109111 if err != nil {
110112 return nil , nil , errors .Wrap (err , "tls.LoadX509KeyPair(cert, key)" )
111113 }
114+ warnIfRSAPrivateKey (crt .PrivateKey )
112115
113116 crtHash , err := hash (cert )
114117 if err != nil {
@@ -131,6 +134,8 @@ func NewTLSConfigWithTLSCertificateCache(cfg config.TLS) (*tls.Config, *TLSCerti
131134 if err != nil {
132135 return nil , nil , errors .Wrap (err , "tls.LoadX509KeyPair(cert, key)" )
133136 }
137+ warnIfRSAPrivateKey (crt .PrivateKey )
138+
134139 t .Certificates = make ([]tls.Certificate , 1 )
135140 t .Certificates [0 ] = crt
136141 }
@@ -204,6 +209,8 @@ func (tcc *TLSCertificateCache) RefreshCertificate(ctx context.Context) error {
204209 tcc .serverCertMutex .Unlock ()
205210 continue
206211 }
212+ warnIfRSAPrivateKey (newCert .PrivateKey )
213+
207214 tcc .serverCert .Store (& newCert )
208215 tcc .serverCertHash = serverCertHash
209216 tcc .serverCertKeyHash = serverCertKeyHash
@@ -293,3 +300,10 @@ func defaultCipherSuitesMap() map[string]uint16 {
293300 }
294301 return ciphers
295302}
303+
304+ // warnIfRSAPrivateKey output warning log if the private key is RSA.
305+ func warnIfRSAPrivateKey (privateKey crypto.PrivateKey ) {
306+ if _ , ok := privateKey .(* rsa.PrivateKey ); ok {
307+ glg .Warn ("The private key used in the server certificate is RSA. Consider using an ECDSA key for better performance." )
308+ }
309+ }
0 commit comments