Beispiel #1
0
func confRead() map[govpn.PeerId]*govpn.PeerConf {
	data, err := ioutil.ReadFile(*confPath)
	if err != nil {
		log.Fatalln("Unable to read configuration:", err)
	}
	confsRaw := new(map[string]govpn.PeerConf)
	err = json.Unmarshal(data, confsRaw)
	if err != nil {
		log.Fatalln("Unable to parse configuration:", err)
	}

	confs := make(map[govpn.PeerId]*govpn.PeerConf, len(*confsRaw))
	for name, pc := range *confsRaw {
		verifier, err := govpn.VerifierFromString(pc.VerifierRaw)
		if err != nil {
			log.Fatalln("Unable to decode the key:", err.Error(), pc.VerifierRaw)
		}
		conf := govpn.PeerConf{
			Verifier: verifier,
			Id:       verifier.Id,
			Name:     name,
			Up:       pc.Up,
			Down:     pc.Down,
			Noise:    pc.Noise,
			CPR:      pc.CPR,
		}
		if pc.TimeoutInt <= 0 {
			pc.TimeoutInt = govpn.TimeoutDefault
		}
		conf.Timeout = time.Second * time.Duration(pc.TimeoutInt)
		confs[*verifier.Id] = &conf
	}
	return confs
}
Beispiel #2
0
func main() {
	flag.Parse()
	if *verifier == "" {
		id := new([govpn.IDSize]byte)
		if _, err := rand.Read(id[:]); err != nil {
			log.Fatalln(err)
		}
		pid := govpn.PeerId(*id)
		v := govpn.VerifierNew(*mOpt, *tOpt, *pOpt, &pid)
		v.PasswordApply(govpn.StringFromFile(*keyPath))
		fmt.Println(v.LongForm())
		fmt.Println(v.ShortForm())
		return
	}
	v, err := govpn.VerifierFromString(*verifier)
	if err != nil {
		log.Fatalln("Can not decode verifier", err)
	}
	if v.Pub == nil {
		log.Fatalln("Verifier does not contain public key")
	}
	pub := *v.Pub
	v.PasswordApply(govpn.StringFromFile(*keyPath))
	fmt.Println(subtle.ConstantTimeCompare(v.Pub[:], pub[:]) == 1)
}
Beispiel #3
0
func main() {
	flag.Parse()
	timeout = *timeoutP
	var err error
	log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)

	govpn.MTU = *mtu

	if *egdPath != "" {
		log.Println("Using", *egdPath, "EGD")
		govpn.EGDInit(*egdPath)
	}

	verifier, err := govpn.VerifierFromString(*verifierRaw)
	if err != nil {
		log.Fatalln(err)
	}
	priv := verifier.PasswordApply(govpn.StringFromFile(*keyPath))
	conf = &govpn.PeerConf{
		Id:       verifier.Id,
		Timeout:  time.Second * time.Duration(timeout),
		Noise:    *noisy,
		CPR:      *cpr,
		Verifier: verifier,
		DSAPriv:  priv,
	}
	idsCache = govpn.NewCipherCache([]govpn.PeerId{*verifier.Id})
	log.Println(govpn.VersionGet())

	tap, err = govpn.TAPListen(*ifaceName)
	if err != nil {
		log.Fatalln("Can not listen on TAP interface:", err)
	}

	log.Println("Max MTU on TAP interface:", govpn.TAPMaxMTU())
	if *stats != "" {
		log.Println("Stats are going to listen on", *stats)
		statsPort, err := net.Listen("tcp", *stats)
		if err != nil {
			log.Fatalln("Can not listen on stats port:", err)
		}
		go govpn.StatsProcessor(statsPort, &knownPeers)
	}

	termSignal := make(chan os.Signal, 1)
	signal.Notify(termSignal, os.Interrupt, os.Kill)

MainCycle:
	for {
		timeouted := make(chan struct{})
		rehandshaking := make(chan struct{})
		termination := make(chan struct{})
		if *proxyAddr != "" {
			*proto = "tcp"
		}
		switch *proto {
		case "udp":
			go startUDP(timeouted, rehandshaking, termination)
		case "tcp":
			if *proxyAddr != "" {
				go proxyTCP(timeouted, rehandshaking, termination)
			} else {
				go startTCP(timeouted, rehandshaking, termination)
			}
		default:
			log.Fatalln("Unknown protocol specified")
		}
		select {
		case <-termSignal:
			log.Fatalln("Finishing")
			termination <- struct{}{}
			break MainCycle
		case <-timeouted:
			break MainCycle
		case <-rehandshaking:
		}
		close(timeouted)
		close(rehandshaking)
		close(termination)
	}
	govpn.ScriptCall(*downPath, *ifaceName)
}