//Wrap an existing listener + crypto config and return a new TLS enabled listener.
Wrap an existing listener + crypto config and return a new TLS enabled listener.
// Wrap an existing listener + crypto config and return a new TLS enabled listener .
func NewListener(inner net.Listener, config *tls.Config) (net.Listener, error) {
	l := new(gossl.Listener)
	l.Listener = inner
	l.Context = gossl.NewContext(gossl.SSLv23Method())
	if l.Context == nil {
		msg := sslerr.SSLErrorMessage().String()
		return nil, errors.New("problem creating ssl context:\n" + msg)
	}
	Kr := config.Certificates[0].PrivateKey
	private_key_der, err := extractDERKey(Kr)
	private_key, err := evp.LoadPrivateKeyDER(private_key_der)
	if err != nil {
		return nil, err
	}
	err = l.Context.UsePrivateKey(private_key)
	if err != nil {
		return nil, errors.New("problem loading key " + sslerr.SSLErrorMessage().String())
	}
	cert, err := x509.ParseCertificate(config.Certificates[0].Certificate[0])
	if err != nil {
		return nil, err
	}
	err = l.Context.UseCertificate(cert)
	if err != nil {
		return nil, errors.New("problem loading key " + sslerr.SSLErrorMessage().String())
	}
	return l, nil
}
func NewListener ( inner net . Listener , config * tls . Config ) ( net . Listener , error ) { l := new ( gossl . Listener ) l . Listener = inner l . Context = gossl . NewContext ( gossl . SSLv23Method ( ) ) if l . Context == nil { msg := sslerr . SSLErrorMessage ( ) . String ( ) return nil , errors . New ( " \n " + msg ) } Kr := config . Certificates [ 0 ] . PrivateKey private_key_der , err := extractDERKey ( Kr ) private_key , err := evp . LoadPrivateKeyDER ( private_key_der ) if err != nil { return nil , err } err = l . Context . UsePrivateKey ( private_key ) if err != nil { return nil , errors . New ( " " + sslerr . SSLErrorMessage ( ) . String ( ) ) } cert , err := x509 . ParseCertificate ( config . Certificates [ 0 ] . Certificate [ 0 ] ) if err != nil { return nil , err } err = l . Context . UseCertificate ( cert ) if err != nil { return nil , errors . New ( " " + sslerr . SSLErrorMessage ( ) . String ( ) ) } return l , nil }
Wrap an existing listener + crypto config and return a new TLS enabled listener.
Wrap an existing listener + crypto config and return a new TLS enabled listener .
//FIXME hardcoded in method //set certificates //grab the private key //set the private key into the context