Created
August 18, 2018 21:28
-
-
Save lthibault/2174b017abc05ffb677b13c75aabfe9c to your computer and use it in GitHub Desktop.
H2QUIC TLS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func GenerateTLSConfig() *tls.Config { | |
key, err := rsa.GenerateKey(rand.Reader, 1024) | |
if err != nil { | |
panic(err) | |
} | |
// generate a random serial number (a real cert authority would have some logic behind this) | |
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) | |
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) | |
if err != nil { | |
panic("failed to generate serial number: " + err.Error()) | |
} | |
template := x509.Certificate{ | |
SerialNumber: serialNumber, | |
// SignatureAlgorithm: x509.ECDSAWithSHA512, | |
NotBefore: time.Now(), | |
NotAfter: time.Now().Add(time.Hour * 87600), // in 10 years | |
BasicConstraintsValid: true, | |
} | |
certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key) | |
if err != nil { | |
panic(err) | |
} | |
keyPEM := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)}) | |
certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certDER}) | |
tlsCert, err := tls.X509KeyPair(certPEM, keyPEM) | |
if err != nil { | |
panic(err) | |
} | |
return &tls.Config{Certificates: []tls.Certificate{tlsCert}, InsecureSkipVerify: true} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var c = &http.Client{ | |
Transport: &h2quic.RoundTripper{ | |
TLSClientConfig: cert, | |
}, | |
} | |
var server = h2quic.Server{ | |
Server: &http.Server{ | |
Addr: ":9001", | |
TLSConfig: cert, | |
// Handler: http.HandlerFunc(handle), | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment