forked from quic-go/quic-go
http3: remove dependency on quic internal packages (#5256)
* Remove http3 dependency on quic internal packages Remove the dependency on internal/protocol from the http3 package. This makes it possible for a forked http3 to use the mainline quic-go package. * Address review comments * Fix syntax * Use broader pattern for http3 directory * Copy internal/testdata * Replace perspective with bool * clone the supported version slice --------- Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
56
http3/internal/testdata/cert.go
vendored
Normal file
56
http3/internal/testdata/cert.go
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var certPath string
|
||||
|
||||
func init() {
|
||||
_, filename, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
panic("Failed to get current frame")
|
||||
}
|
||||
|
||||
certPath = path.Dir(filename)
|
||||
}
|
||||
|
||||
// GetCertificatePaths returns the paths to certificate and key
|
||||
func GetCertificatePaths() (string, string) {
|
||||
return path.Join(certPath, "cert.pem"), path.Join(certPath, "priv.key")
|
||||
}
|
||||
|
||||
// GetTLSConfig returns a tls config for quic.clemente.io
|
||||
func GetTLSConfig() *tls.Config {
|
||||
cert, err := tls.LoadX509KeyPair(GetCertificatePaths())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &tls.Config{
|
||||
MinVersion: tls.VersionTLS13,
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
}
|
||||
|
||||
// AddRootCA adds the root CA certificate to a cert pool
|
||||
func AddRootCA(certPool *x509.CertPool) {
|
||||
caCertPath := path.Join(certPath, "ca.pem")
|
||||
caCertRaw, err := os.ReadFile(caCertPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if ok := certPool.AppendCertsFromPEM(caCertRaw); !ok {
|
||||
panic("Could not add root ceritificate to pool.")
|
||||
}
|
||||
}
|
||||
|
||||
// GetRootCA returns an x509.CertPool containing (only) the CA certificate
|
||||
func GetRootCA() *x509.CertPool {
|
||||
pool := x509.NewCertPool()
|
||||
AddRootCA(pool)
|
||||
return pool
|
||||
}
|
||||
Reference in New Issue
Block a user