Ejemplo n.º 1
0
// Example demonstrating the use of neptulon/ca with a tls.Listener.
func Example() {
	// create CA and server certificates along with ready-to-use tls.Conf object that uses generated certs
	certChain, certErr := ca.GenCertChain("FooBar", "127.0.0.1", "127.0.0.1", time.Hour, 512)
	if certErr != nil {
		log.Fatal(certErr)
	}

	/*listener*/ _, tlsErr := tls.Listen("tcp", "127.0.0.1:4444", certChain.ServerTLSConf)
	if tlsErr != nil {
		log.Fatal(tlsErr)
	}

	// todo: uncomment /*listener*/ and use listener.Accept() to start accepting connections
}
Ejemplo n.º 2
0
// UseTLS enables Transport Layer Security for the connections.
func (sh *ServerHelper) UseTLS() *ServerHelper {
	// generate TLS certs
	certChain, err := ca.GenCertChain("FooBar", host, host, time.Hour, 512)
	if err != nil {
		sh.testing.Fatal("Failed to create TLS certificate chain:", err)
	}

	sh.RootCACert = certChain.RootCACert
	sh.RootCAKey = certChain.RootCAKey
	sh.IntCACert = certChain.IntCACert
	sh.IntCAKey = certChain.IntCAKey
	sh.ServerCert = certChain.ServerCert
	sh.ServerKey = certChain.ServerKey

	sh.Server.UseTLS(sh.ServerCert, sh.ServerKey, sh.IntCACert)

	return sh
}