cert.go 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package testdata
  2. import (
  3. "crypto/tls"
  4. "path"
  5. "runtime"
  6. )
  7. var certPath string
  8. func init() {
  9. _, filename, _, ok := runtime.Caller(0)
  10. if !ok {
  11. panic("Failed to get current frame")
  12. }
  13. certPath = path.Join(path.Dir(path.Dir(path.Dir(filename))), "example")
  14. }
  15. // GetCertificatePaths returns the paths to 'fullchain.pem' and 'privkey.pem' for the
  16. // quic.clemente.io cert.
  17. func GetCertificatePaths() (string, string) {
  18. return path.Join(certPath, "fullchain.pem"), path.Join(certPath, "privkey.pem")
  19. }
  20. // GetTLSConfig returns a tls config for quic.clemente.io
  21. func GetTLSConfig() *tls.Config {
  22. cert, err := tls.LoadX509KeyPair(GetCertificatePaths())
  23. if err != nil {
  24. panic(err)
  25. }
  26. return &tls.Config{
  27. Certificates: []tls.Certificate{cert},
  28. }
  29. }
  30. // GetCertificate returns a certificate for quic.clemente.io
  31. func GetCertificate() tls.Certificate {
  32. cert, err := tls.LoadX509KeyPair(GetCertificatePaths())
  33. if err != nil {
  34. panic(err)
  35. }
  36. return cert
  37. }