Example #1
0
func main() {
	flag.Parse()

	listener, err := net.Listen("tcp", *addr)
	if err != nil {
		logger.Fatalf("error listening: %s", err)
	}

	logger.Printf("starting listener addr=%q", listener.Addr())

	context := gossl.NewContext(gossl.SSLv23ServerMethod())
	context.UseCertificateFile(*cert, gossl.FILETYPE_PEM)
	context.UsePrivateKeyFile(*key, gossl.FILETYPE_PEM)
	context.SetCipherList("ALL:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP")

	sslListener, err := gossl.NewListener(listener, context)
	if err != nil {
		logger.Fatalf("error starting ssl listener: ", err)
	}

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		http.Error(w, "giddy up", 409)
	})

	if err := http.Serve(sslListener, nil); err != nil {
		logger.Fatal("error serving http: %s", err)
	}
}
Example #2
0
func main() {

	flag.Parse()

	fmt.Println("Starting")
	timeout := 100 * time.Second

	// set up the smtp server
	s := smtp.NewServer("banner", nil)
	s.IdleTimeout = 100 * time.Second
	s.ShutdownTimeout = timeout

	l, err := net.Listen("tcp", *addr)
	if err != nil {
		log.Fatal("Unable to start tcp listener", err)
	}

	context := gossl.NewContext(gossl.SSLv23ServerMethod())
	context.UseCertificateFile(*cert, gossl.FILETYPE_PEM)
	context.UsePrivateKeyFile(*key, gossl.FILETYPE_PEM)

	sslListener, err := gossl.NewListener(l, context)
	if err != nil {
		log.Fatal(err)
	}

	go s.Serve(sslListener)
	wg := new(sync.WaitGroup)
	wg.Add(1)
	fmt.Println("waiting..")
	wg.Wait()

	// never should get here
	fmt.Println("stopping")
	s.Stop()
}