예제 #1
0
func TestRegister(t *testing.T) {
	lol, err := GetDaemon()
	if err != nil {
		t.Fatal(err.Error())
	}
	listener, err := net.ListenTCP("tcp4", nil)
	if err != nil {
		t.Fatal(err.Error())
	}
	priv := natrium.EdDSAGenerateKey()
	fmt.Println("generated key ", priv)
	str, err := lol.StartForward(priv, 22345, listener.Addr().(*net.TCPAddr).Port)
	if err != nil {
		t.Fatal(err.Error())
	}
	fmt.Printf("find me at %v\n", str)
	haha = str
	go func() {
		defer listener.Close()
		for {
			clnt, err := listener.Accept()
			if err != nil {
				return
			}
			io.Copy(clnt, clnt)
		}
	}()
}
예제 #2
0
func runDir() {
	fh, err := os.Open("_SECRETS_/privkey-sanctum.bin")
	defer fh.Close()
	if err != nil {
		panic(err.Error())
	}
	masterPriv := natrium.EdDSAGenerateKey()
	_, err = io.ReadFull(fh, masterPriv)
	if err != nil {
		panic(err.Error())
	}
	haha := directory.NewServer(masterPriv)

	kilog.Info("starting SAGIRI directory on port 2378")
	server, err := net.Listen("tcp", "0.0.0.0:2378")
	if err != nil {
		panic(err.Error())
	}

	for {
		rawcl, err := server.Accept()
		if err != nil {
			return
		}
		go func() {
			defer rawcl.Close()
			haha.HandleClient(rawcl)
		}()
	}
}
예제 #3
0
func TestNeighInfo(t *testing.T) {
	lst := make([][]byte, 10)
	for i := 0; i < 10; i++ {
		lst[i] = natrium.EdDSAGenerateKey().PublicKey()
	}
	thing := NeighInfo{
		Signat: make([]byte, 32),
		Json: neighInfoNaked{
			Expires:   int(time.Now().Unix()),
			IssuedTo:  natrium.EdDSAGenerateKey().PublicKey(),
			NeighList: lst,
		},
	}
	xxx := thing.ToString()
	if xxx == "" {
		panic("sjdklfsdf")
	}
	fmt.Println(thing.ToString())
}
예제 #4
0
func BenchmarkKiss(b *testing.B) {
	lol := natrium.EdDSAGenerateKey()
	go func() {
		listener, _ := net.Listen("tcp", "127.0.0.1:12345")
		for {
			client, err := listener.Accept()
			if err != nil {
				continue
			}
			go func() {
				defer client.Close()
				actual_client, err := KiSSNamedHandshake(lol, nil, client)
				if err != nil {
					panic(err.Error())
				}
				defer actual_client.Close()
				for {
					actual_client.Write(make([]byte, 65536))
				}
			}()
		}
	}()
	listener, _ := net.Listen("tcp", "127.0.0.1:54321")
	for {
		client, err := listener.Accept()
		if err != nil {
			continue
		}
		func() {
			defer client.Close()
			remote, err := net.Dial("tcp", "127.0.0.1:12345")
			if err != nil {
				panic(err.Error())
			}
			defer remote.Close()
			actual_remote, err :=
				KiSSAnonHandshake(nil, remote)
			if err != nil {
				panic(err.Error())
			}
			go func() {
				defer actual_remote.Close()
				_, err := io.Copy(client, actual_remote)
				if err != nil {
					return
				}
			}()
			_, err = io.Copy(actual_remote, client)
			if err != nil {
				return
			}
		}()
		break
	}
}
예제 #5
0
func TestDirectoryEdge(t *testing.T) {
	return

	spinTestDir()
	defer stopTestDir()

	clnt := NewClient(natrium.EdDSAGenerateKey())
	prv := &dftProv{"127.0.0.1:12345"}

	neiz, err := prv.JoinEdge(clnt)
	if err != nil {
		panic(err.Error())
	}
	fmt.Println(neiz)
}
예제 #6
0
func initialize() {
	kilog.Info("SAGIRI version %v initializing...", VERSION)
	flag.Parse()
	lol, err := getPublicIP()
	kilog.Info("%v %v", lol, err)

	if isDirectory {
		runDir()
		os.Exit(0)
	}

	switch dirHelper {
	case "internal":
		dirProvider = directory.DefaultProvider("sanctum.sagiri.niwl.io:2378")
	}

	// obtain directory info
	id := directory.NewClient(natrium.EdDSAGenerateKey())
	kilog.Debug("master key: %v", id.GetPrivate().PublicKey())
	getNeighs(id)

	go func() {
		for {
			time.Sleep(time.Minute)
			getNeighs(id)
		}
	}()

	// set up core node
	if onionPort != 0 {
		ip, err := getPublicIP()
		if err != nil {
			panic(err.Error())
		}
		id.SetAddress(&net.TCPAddr{IP: ip, Port: onionPort, Zone: "tcp"})
		dirClient = id
		go runCore(id)
	} else {
		dirClient = id
		startSocks()
		startControl()
		go func() {
			log.Println(http.ListenAndServe("0.0.0.0:6060", nil))
		}()
	}
	kilog.Info("SAGIRI finished initializing.")
}
예제 #7
0
func spinTestDir() {
	var err error
	__test_srv, err = net.Listen("tcp", "127.0.0.1:12345")
	if err != nil {
		panic(err.Error())
	}
	go func() {
		fh, err := os.Open("privkey-sanctum.bin")
		defer fh.Close()
		if err != nil {
			panic(err.Error())
		}
		masterPriv := natrium.EdDSAGenerateKey()
		_, err = io.ReadFull(fh, masterPriv)
		if err != nil {
			panic(err.Error())
		}
		fmt.Println(masterPriv)

		haha := directory.NewServer(masterPriv)

		for {
			rawcl, err := __test_srv.Accept()
			if err != nil {
				return
			}
			go func() {
				defer rawcl.Close()
				/*obfscl, err := kiss.LLObfsServerHandshake(masterPriv.PublicKey(), rawcl)
				if err != nil {
					panic(err.Error())
				}*/
				haha.HandleClient(rawcl)
			}()
		}
	}()
}
예제 #8
0
func TestDirectoryCoreEdge(t *testing.T) {
	spinTestDir()
	defer stopTestDir()

	for i := 0; i < 10; i++ {
		//time.Sleep(time.Second)
		clnt := directory.NewClient(natrium.EdDSAGenerateKey())
		prv := directory.DefaultProvider("127.0.0.1:12345")

		addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
		__lol, err := net.ListenTCP("tcp", addr)
		if err != nil {
			panic(err.Error())
		}
		clnt.SetAddress(__lol.Addr().(*net.TCPAddr))
		addr = __lol.Addr().(*net.TCPAddr)
		__lol.Close()

		lol, err := kiricom.EasyListen(addr.String(), nil, clnt.GetSecret())
		if err != nil {
			panic(err.Error())
		}
		defer lol.Close()

		state := NewNodeState(prv, clnt)

		go func() {
			for {
				clnt, err := lol.Accept()
				if err != nil {
					return
				}
				go func() {
					defer clnt.Close()
					err := state.HandleClient(clnt)
					if err != nil {
						kilog.Debug(err.Error())
					}
				}()
			}
		}()

		err = prv.JoinCore(clnt)
		if err != nil {
			log.Fatal(err.Error())
		}
	}

	time.Sleep(time.Second * 2)
	clnt := directory.NewClient(natrium.EdDSAGenerateKey())
	prv := directory.DefaultProvider("127.0.0.1:12345")

	neiz, err := prv.JoinEdge(clnt)
	if err != nil {
		panic(err.Error())
	}
	fmt.Println(neiz)

	// route in a circle
	func() {
		spider, err := NewClient(neiz[0])
		if err != nil {
			panic(err.Error())
		}
		defer spider.Destroy()
		for i := 0; i < 11; i++ {
			fmt.Println(spider.curpk)
			lawl, err := spider.ListNeighs()
			if err != nil {
				panic(err.Error())
			}
			err = spider.ConnectNext(lawl[0])
			if err != nil {
				panic(err.Error())
			}
			//time.Sleep(time.Second)
		}
	}()

	fmt.Println("--- ROUTING DONE ---")

	// time to test ambassadors!
	func() {
		alpha, err := NewClient(neiz[0])
		if err != nil {
			panic(err.Error())
		}
		beta, err := NewClient(neiz[0])
		if err != nil {
			panic(err.Error())
		}
		defer alpha.Destroy()
		defer beta.Destroy()

		// alpha registers, beta connects
		id := natrium.EdDSAGenerateKey()
		srv, err := alpha.RegAmbassador(id.PublicKey())
		if err != nil {
			panic(err.Error())
		}
		clnt, err := beta.ConnAmbassador(id.PublicKey())
		if err != nil {
			panic(err.Error())
		}

		// throwaway echo server
		go func() {
			lol, err := srv.Accept()
			if err != nil {
				panic(err.Error())
			}
			defer lol.Close()
			io.Copy(lol, lol)
		}()

		// test with random stuff
		xaxa := make([]byte, 16)
		rand.Read(xaxa)

		sok, err := clnt.Dial()
		if err != nil {
			panic(err.Error())
		}
		sok.Write(xaxa)
		resp := make([]byte, 16)
		io.ReadFull(sok, resp)
		fmt.Printf("%x\n", xaxa)
		fmt.Printf("%x\n", resp)
		if subtle.ConstantTimeCompare(resp, xaxa) != 1 {
			t.Fatal("ambassador broken")
		}
	}()
	fmt.Println("--- AMBASSADOR DONE ---")
}