MCPcopy Create free account
hub / github.com/XTLS/Go / unsupportedCertificateError

Function unsupportedCertificateError

auth.go:253–289  ·  view source on GitHub ↗

unsupportedCertificateError returns a helpful error for certificates with an unsupported private key.

(cert *Certificate)

Source from the content-addressed store, hash-verified

251// unsupportedCertificateError returns a helpful error for certificates with
252// an unsupported private key.
253func unsupportedCertificateError(cert *Certificate) error {
254 switch cert.PrivateKey.(type) {
255 case rsa.PrivateKey, ecdsa.PrivateKey:
256 return fmt.Errorf("tls: unsupported certificate: private key is %T, expected *%T",
257 cert.PrivateKey, cert.PrivateKey)
258 case *ed25519.PrivateKey:
259 return fmt.Errorf("tls: unsupported certificate: private key is *ed25519.PrivateKey, expected ed25519.PrivateKey")
260 }
261
262 signer, ok := cert.PrivateKey.(crypto.Signer)
263 if !ok {
264 return fmt.Errorf("tls: certificate private key (%T) does not implement crypto.Signer",
265 cert.PrivateKey)
266 }
267
268 switch pub := signer.Public().(type) {
269 case *ecdsa.PublicKey:
270 switch pub.Curve {
271 case elliptic.P256():
272 case elliptic.P384():
273 case elliptic.P521():
274 default:
275 return fmt.Errorf("tls: unsupported certificate curve (%s)", pub.Curve.Params().Name)
276 }
277 case *rsa.PublicKey:
278 return fmt.Errorf("tls: certificate RSA key size too small for supported signature algorithms")
279 case ed25519.PublicKey:
280 default:
281 return fmt.Errorf("tls: unsupported certificate key (%T)", pub)
282 }
283
284 if cert.SupportedSignatureAlgorithms != nil {
285 return fmt.Errorf("tls: peer doesn't support the certificate custom signature algorithms")
286 }
287
288 return fmt.Errorf("tls: internal error: unsupported key (%T)", cert.PrivateKey)
289}

Callers 2

SupportsCertificateMethod · 0.85
selectSignatureSchemeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…