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)
| 808 | // generated certificate, and byte arrays containing the certificate and |
| 809 | // key associated with the certificate. |
| 810 | func 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…