コード例 #1
0
ファイル: register.go プロジェクト: jsimonetti/tlstun
func post(pass string) (string, error) {
	mynil := ""
	certf, keyf, err := shared.ReadMyCert("client.crt", "client.key")
	if err != nil {
		return mynil, err
	}
	tlsConfig, err := shared.GetTLSConfig(certf, keyf)
	if err != nil {
		return mynil, err
	}

	//loadServerCert()
	uri := fmt.Sprintf("https://%s:%d/register", serverIp, serverPort)

	tr := &http.Transport{
		TLSClientConfig: tlsConfig,
		Proxy:           http.ProxyFromEnvironment,
	}
	hc := http.Client{Transport: tr}

	form := url.Values{}
	form.Add("password", pass)

	resp, err := hc.PostForm(uri, form)
	if err != nil {
		return mynil, err
	}
	defer resp.Body.Close()
	s, err := ioutil.ReadAll(resp.Body)
	val := fmt.Sprintf("%s", s)
	if err != nil {
		return mynil, err
	}
	return val, err
}
コード例 #2
0
ファイル: daemon.go プロジェクト: jsimonetti/tlstun
func (d *Daemon) Init() error {

	/* Setup the TLS authentication */
	certf, keyf, err := shared.ReadMyCert("client.crt", "client.key")
	if err != nil {
		return err
	}
	d.certf = certf
	d.keyf = keyf
	d.tlsConfig, err = shared.GetTLSConfig(d.certf, d.keyf)
	if err != nil {
		return err
	}
	srvlog := log.New(log.Ctx{"module": "client"})
	d.log = srvlog

	handler := log.StdoutHandler

	if quiet {
		d.log.SetHandler(log.DiscardHandler())
	} else if verbose {
		d.log.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
	} else if debug {
		d.log.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
	} else {
		d.log.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
	}

	d.Run()
	return nil
}
コード例 #3
0
ファイル: daemon.go プロジェクト: jsimonetti/tlstun
func (d *Daemon) Init() error {

	/* Setup the TLS authentication */
	certf, keyf, err := shared.ReadMyCert("server.crt", "server.key")
	if err != nil {
		return err
	}
	d.certf = certf
	d.keyf = keyf
	d.tlsConfig, err = shared.GetTLSConfig(d.certf, d.keyf)
	if err != nil {
		return err
	}

	srvlog := log.New(log.Ctx{"module": "server"})
	d.log = srvlog

	handler := log.StdoutHandler

	if quiet {
		d.log.SetHandler(log.DiscardHandler())
	} else if verbose {
		d.log.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
	} else if debug {
		d.log.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
	} else {
		d.log.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
	}

	err = initializeDbObject(d, "server.db")
	if err != nil {
		return err
	}
	readSavedClientCAList(d)

	return d.Run()
}