// STARTTLS creates a reply to a STARTTLS command
965481
func (proto *Protocol) STARTTLS(args string) (reply *Reply) {
	if proto.TLSUpgraded {
		return ReplyUnrecognisedCommand()
	}

	if proto.TLSHandler == nil {
		proto.logf("tls handler not found")
		return ReplyUnrecognisedCommand()
	}

	if len(args) > 0 {
		return ReplySyntaxError("no parameters allowed")
	}

	r, callback, ok := proto.TLSHandler(func(ok bool) {
		proto.TLSUpgraded = ok
		proto.TLSPending = ok
		if ok {
			proto.resetState()
			proto.State = ESTABLISH
		}
	})
	if !ok {
		return r
	}

	proto.TLSPending = true
	return ReplyReadyToStartTLS(callback)
}
109110
func (app *App) ListenTLS(addr, certFile, keyFile string) error {
	app.Server.Addr = addr
	app.Server.ErrorLog = app.logger
	app.Server.Handler = app
	return app.Server.ListenAndServeTLS(certFile, keyFile)
}
980939
func WithTLS(cfg *tls.Config) Option {
	return func(opts *options) {
		opts.useTLS = true
		opts.tlsConfig = cfg
	}
}
453315
func (c *Client) InitTLS(certFile string) error {
	serverCert, err := ioutil.ReadFile(certFile)
	if err != nil {
		return err
	}
	CA_Pool := x509.NewCertPool()
	CA_Pool.AppendCertsFromPEM(serverCert)
	c.tlsConfig = &tls.Config{RootCAs: CA_Pool}
	return nil
}
1353435
func DialTLS(network, addr string, config *tls.Config) (Conn, error) {
	conn, err := tls.Dial(network, addr, config)
	if err != nil {
		return nil, err
	}

	return NewConn(conn), nil
}
465694
func (t *Tree) startParse(funcs []map[string]interface{}, lex *lexer) {
	t.Root = nil
	t.lex = lex
	t.vars = []string{"$"}
	t.funcs = funcs
}
186272
func StartHTTP(address string) error {
	var err error
	if httpListener != nil {
		httpListener.Close()
	}

	if address != "" {
		httpAddress = address
	}
	if httpAddress == "" {
		return fmt.Errorf("HTTP address not defined")
	}

	httpListener, err = net.Listen("tcp", httpAddress)
	if err != nil {
		return err
	}

	httpServer = &http.Server{
		Handler:           &handler{},
		ReadHeaderTimeout: 5 * time.Second,
		IdleTimeout:       120 * time.Second,
		TLSConfig:         tlsConfig,
	}

	go httpServer.Serve(httpListener)

	return nil
}
674755
func (ref *Config) SetTLS(tlsConfig *tls.Config) (err error) {
	ref.Net.TLS.Enable = true
	ref.Net.TLS.Config = tlsConfig

	return nil
}
129125
func startCommand(sysCommand string) *exec.Cmd {
	cmdTokens := strings.Split(sysCommand, " ")
	cmd := cmdTokens[0]
	if len(cmdTokens) == 1 {
		return exec.Command(cmd)
	}
	return exec.Command(cmd, strings.Join(cmdTokens[1:], " "))
}
1199143
func (s *Service) StartCommands() ([]string, error) {
	name := s.Name()
	cmdList := []string{
		cmds.start(name),
	}
	return cmdList, nil
}
454084
func startCommand(command string) (cmd *exec.Cmd, stdout io.ReadCloser, stderr io.ReadCloser, err error) {
	args := strings.Split(command, " ")
	cmd = exec.Command(args[0], args[1:]...)
	
	if *flag_run_dir != "" {
		cmd.Dir = *flag_run_dir
	}

	if stdout, err = cmd.StdoutPipe(); err != nil {
		err = fmt.Errorf("can't get stdout pipe for command: %s", err)
		return
	}

	if stderr, err = cmd.StderrPipe(); err != nil {
		err = fmt.Errorf("can't get stderr pipe for command: %s", err)
		return
	}

	if err = cmd.Start(); err != nil {
		err = fmt.Errorf("can't start command: %s", err)
		return
	}

	return
}
307782
func WithTLS(t *tls.Config) source.Option {
	return func(o *source.Options) {
		if o.Context == nil {
			o.Context = context.Background()
		}
		o.Context = context.WithValue(o.Context, tls.Config{}, t)
	}
}
339403
func (pc *ProtoClient) ConnectToTLS(addr string, skipVerify bool) error {
	err := pc.Client.ConnectToTLS(addr, skipVerify)
	if err != nil {
		return err
	}

	if !pc.ready {
		err = pc.LoadServerInfo(addr)
		if err != nil {
			return err
		}
	}

	if pc.ready {
		go pc.waitForData()
	}
	return nil
}
404872
func (c *Client) ConnectToTLS(addr string, skipVerify bool) error {
	conn, err := tls.Dial("tcp", addr, &tls.Config{
		InsecureSkipVerify: skipVerify,
	})
	if err != nil {
		return err
	}
	c.conn = conn
	c.IncomingMsgChan = make(chan *message.Message, 10)

	if err = c.handleHandshake(); err != nil {
		return err
	}

	c.closeChan = make(chan struct{})
	return nil
}
744333
func DialUseTLS(useTLS bool) DialOption {
	return DialOption{func(do *dialOptions) {
		do.useTLS = useTLS
	}}
}
161077
func startWS(ctx *cli.Context) (err error) {
	server, cleanup, err := newServer(ctx)
	if err != nil {
		return err
	}
	defer cleanup()

	listener, err := net.Listen("tcp", ctx.String("addr"))
	if err != nil {
		return err
	}
	origins := ctx.StringSlice("origins")
	log.Info("websocket", "address", listener.Addr().String(), "origins", origins)

	return http.Serve(listener, server.WebsocketHandler(origins))
}
150585
func (d *Dialer) connectTLS(ctx context.Context, conn net.Conn) (tlsConn *tls.Conn, err error) {
	tlsConn = tls.Client(conn, d.TLS)
	errch := make(chan error)

	go func() {
		defer close(errch)
		errch <- tlsConn.Handshake()
	}()

	select {
	case <-ctx.Done():
		conn.Close()
		tlsConn.Close()
		<-errch // ignore possible error from Handshake
		err = ctx.Err()

	case err = <-errch:
	}

	return
}