Пример #1
0
func LoadX509KeyPair(certpath, keypath string) (cert tls.Certificate, err error) {
	key_buf, err := ioutil.ReadFile(keypath)
	if err != nil {
		return
	}
	cert_buf, err := ioutil.ReadFile(certpath)
	if err != nil {
		return
	}
	pkey, err := evp.LoadPrivateKeyPEM(key_buf)
	if err != nil {
		return
	}
	key_buf, err = pkey.DumpPEM()
	return tls.X509KeyPair(cert_buf, key_buf)
}
Пример #2
0
func TestContext(t *testing.T) {
	c := NewContext(SSLv3Method())
	pkey, err := evp.LoadPrivateKeyPEM(key_pem)
	cert, err := ParseCertificatePEM(cert_pem)
	if err != nil {
		t.Fatal(err)
	}
	c.UsePrivateKey(pkey)
	c.UseCertificate(cert)
	err = c.CheckPrivateKey()
	if err != nil {
		t.Fatal(err)
	}
	c.SetVerify(VERIFY_NONE)
	c.SetVerify(9)
	c.GetCertStore()
}
Пример #3
0
func main() {
	keypath := flag.String("key", "", "The path to a PEM key")
	flag.Parse()
	if len(*keypath) == 0 {
		flag.PrintDefaults()
		return
	}
	buf, err := ioutil.ReadFile(*keypath)
	if err != nil {
		panic(err)
	}
	key, err := evp.LoadPrivateKeyPEM(buf)
	if err != nil {
		panic(err)
	}
	buf, err = key.DumpPEM()
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s", buf)
}