func pemToX509Cert(data []byte) (*x509.Certificate, error) {
	certDERBlock, _ := pem.Decode(data)
	if certDERBlock == nil {
		return nil, errors.New("Failed to decode PEM")
	}
	if certDERBlock.Type != "CERTIFICATE" {
		return nil, errors.New("Decoded DER block was not a certificate")
	}
	cert, err := x509.ParseCertificate(certDERBlock.Bytes)
	if err != nil {
		return nil, err
	}
	return cert, nil
}
Convert PEM-encoded certificate into DER and parse it into x509.Certificate
package network
import (
	"bytes"
	"crypto/x509"
	"crypto/x509/pkix"
	"encoding/pem"
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"os"
	"path"
	"testing"
	"time"
)
const (
	TestCertPrefix          = "../tests/ssl"
	TestCACertFilename      = "ca/ca.crt"
	TestCertFilename        = "acra-writer/acra-writer.crt"
	TestRevokedCertFilename = "acra-writer-revoked/acra-writer-revoked.crt"
	TestCRLFilename         = "ca/crl.pem"
	TestOCSPCertFilename    = "ocsp-responder/ocsp-responder.crt"
	TestOCSPKeyFilename     = "ocsp-responder/ocsp-responder.key"
	TestCertPrefix3          = "../tests/ssl"
	TestCACertFilename3      = "ca/ca.crt"
	TestICACertFilename3     = "intermediate-ca/intermediate-ca.crt"
	TestCertFilename3        = "intermediate-acra-writer/intermediate-acra-writer.crt"
	TestRevokedCertFilename3 = "intermediate-acra-writer-revoked/intermediate-acra-writer-revoked.crt"
	TestCRLFilename3         = "intermediate-ca/crl.pem"
	TestOCSPCertFilename3    = "intermediate-ocsp-responder/intermediate-ocsp-responder.crt"
	TestOCSPKeyFilename3     = "intermediate-ocsp-responder/intermediate-ocsp-responder.key"
	TestCRLFilenameRootSelfRevoked = "ca/crl_with_root.pem"
)
type TestCertGroup struct {
	prefix string
	ca             string
	intermediateCA string  
	validCert   string
	revokedCert string
	crl        string
	validCRL   string  
	revokedCRL string  
	ocspCert string
	ocspKey  string
	validRawCerts       [][]byte
	validVerifiedChains [][]*x509.Certificate
	invalidRawCerts       [][]byte
	invalidVerifiedChains [][]*x509.Certificate
}
func getTestCertGroup(t *testing.T) TestCertGroup {
	validRawCerts, validVerifiedChains := getValidTestChain(t)
	invalidRawCerts, invalidVerifiedChains := getInvalidTestChain(t)
	return TestCertGroup{
		prefix:                TestCertPrefix,
		ca:                    TestCACertFilename,
		intermediateCA:        "",
		validCert:             TestCertFilename,
		revokedCert:           TestRevokedCertFilename,
		crl:                   TestCRLFilename,
		ocspCert:              TestOCSPCertFilename,
		ocspKey:               TestOCSPKeyFilename,
		validRawCerts:         validRawCerts,
		validVerifiedChains:   validVerifiedChains,
		invalidRawCerts:       invalidRawCerts,
		invalidVerifiedChains: invalidVerifiedChains,
	}
}
func getTestCertGroup3(t *testing.T) TestCertGroup {
	validRawCerts, validVerifiedChains := getValidTestChain3(t)
	invalidRawCerts, invalidVerifiedChains := getInvalidTestChain3(t)
	return TestCertGroup{
		prefix:                TestCertPrefix3,
		ca:                    TestCACertFilename3,
		intermediateCA:        TestICACertFilename3,
		validCert:             TestCertFilename3,
		revokedCert:           TestRevokedCertFilename3,
		crl:                   TestCRLFilename3,
		ocspCert:              TestOCSPCertFilename3,
		ocspKey:               TestOCSPKeyFilename3,
		validRawCerts:         validRawCerts,
		validVerifiedChains:   validVerifiedChains,
		invalidRawCerts:       invalidRawCerts,
		invalidVerifiedChains: invalidVerifiedChains,
	}
}
func getTestCertGroupOnlyRoot(t *testing.T) TestCertGroup {
	validRawCerts, validVerifiedChains := getTestChain(t, TestCertPrefix, TestCACertFilename)
	invalidRawCerts, invalidVerifiedChains := getTestChain(t, TestCertPrefix, TestCACertFilename)
	return TestCertGroup{
		prefix:                TestCertPrefix,
		ca:                    TestCACertFilename,
		intermediateCA:        "",
		validCert:             TestCACertFilename,
		revokedCert:           TestCACertFilename,
		validCRL:              TestCRLFilename,                 
		revokedCRL:            TestCRLFilenameRootSelfRevoked,  
		ocspCert:              TestOCSPCertFilename,
		ocspKey:               TestOCSPKeyFilename,
		validRawCerts:         validRawCerts,
		validVerifiedChains:   validVerifiedChains,
		invalidRawCerts:       invalidRawCerts,
		invalidVerifiedChains: invalidVerifiedChains,
	}
}
func getTestCert(t *testing.T, filename string) ([]byte, *x509.Certificate) {
	rawCert, err := ioutil.ReadFile(filename)
	if err != nil {
		t.Fatalf("Cannot read certificate: %v\n", err)
	}
	cert, err := pemToX509Cert(rawCert)
	if err != nil {
		t.Fatalf("Failed to parse certificate: %v\n", err)
	}
	return rawCert, cert
}
func getTestCRL(t *testing.T, filename string) ([]byte, *pkix.CertificateList) {
	rawCRL, err := ioutil.ReadFile(filename)
	if err != nil {
		t.Fatalf("Cannot read CRL: %v\n", err)
	}
	crl, err := x509.ParseCRL(rawCRL)
	if err != nil {
		t.Fatalf("Failed to parse CRL: %v\n", err)
	}
	return rawCRL, crl
}