MCPcopy Create free account
hub / github.com/google/pprof / selfSignedCert

Function selfSignedCert

internal/driver/fetch_test.go:810–840  ·  view source on GitHub ↗

selfSignedCert generates a self-signed certificate, and returns the generated certificate, and byte arrays containing the certificate and key associated with the certificate.

(t *testing.T, host string)

Source from the content-addressed store, hash-verified

808// generated certificate, and byte arrays containing the certificate and
809// key associated with the certificate.
810func selfSignedCert(t *testing.T, host string) (tls.Certificate, []byte, []byte) {
811 privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
812 if err != nil {
813 t.Fatalf("failed to generate private key: %v", err)
814 }
815 b, err := x509.MarshalECPrivateKey(privKey)
816 if err != nil {
817 t.Fatalf("failed to marshal private key: %v", err)
818 }
819 bk := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: b})
820
821 tmpl := x509.Certificate{
822 SerialNumber: big.NewInt(1),
823 NotBefore: time.Now(),
824 NotAfter: time.Now().Add(10 * time.Minute),
825 IsCA: true,
826 DNSNames: []string{host},
827 }
828
829 b, err = x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, privKey.Public(), privKey)
830 if err != nil {
831 t.Fatalf("failed to create cert: %v", err)
832 }
833 bc := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: b})
834
835 cert, err := tls.X509KeyPair(bc, bk)
836 if err != nil {
837 t.Fatalf("failed to create TLS key pair: %v", err)
838 }
839 return cert, bc, bk
840}

Callers 2

TestHTTPSInsecureFunction · 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…