Esempio n. 1
0
func main() {
	flag.Parse()
	if *egdPath != "" {
		govpn.EGDInit(*egdPath)
	}
	key, err := govpn.KeyRead(*keyPath)
	if err != nil {
		log.Fatalln("Unable to read the key", err)
	}
	if *verifier == "" {
		id := new([govpn.IDSize]byte)
		if _, err := govpn.Rand.Read(id[:]); err != nil {
			log.Fatalln(err)
		}
		pid := govpn.PeerId(*id)
		v := govpn.VerifierNew(*mOpt, *tOpt, *pOpt, &pid)
		v.PasswordApply(key)
		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(key)
	fmt.Println(bytes.Equal(v.Pub[:], pub[:]))
}
Esempio n. 2
0
func main() {
	flag.Parse()
	timeout = *timeoutP
	var err error
	log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)

	if *mtu > govpn.MTUMax {
		log.Fatalln("Maximum allowable MTU is", govpn.MTUMax)
	}
	if *egdPath != "" {
		log.Println("Using", *egdPath, "EGD")
		govpn.EGDInit(*egdPath)
	}

	if *verifierRaw == "" {
		log.Fatalln("No verifier specified")
	}
	verifier, err := govpn.VerifierFromString(*verifierRaw)
	if err != nil {
		log.Fatalln(err)
	}
	key, err := govpn.KeyRead(*keyPath)
	if err != nil {
		log.Fatalln("Unable to read the key", err)
	}
	priv := verifier.PasswordApply(key)
	if *encless {
		if *proto != "tcp" {
			log.Fatalln("Currently encryptionless mode works only with TCP")
		}
		*noisy = true
	}
	conf = &govpn.PeerConf{
		Id:       verifier.Id,
		Iface:    *ifaceName,
		MTU:      *mtu,
		Timeout:  time.Second * time.Duration(timeout),
		TimeSync: *timeSync,
		Noise:    *noisy,
		CPR:      *cpr,
		Encless:  *encless,
		Verifier: verifier,
		DSAPriv:  priv,
	}
	idsCache = govpn.NewCipherCache()
	confs := map[govpn.PeerId]*govpn.PeerConf{*verifier.Id: conf}
	idsCache.Update(&confs)
	log.Println(govpn.VersionGet())

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

	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)
}