示例#1
0
func (srv *Server) HandleClient(raw io.ReadWriteCloser) {
	defer raw.Close()
	/*raw, err := kiss.LLObfsServerHandshake(srv.prv.PublicKey(), raw)
	if err != nil {
		kilog.Debug("directory: client failed LLObfs handshake: %v", err.Error())
		return
	}*/
	var theirKey natrium.EdDSAPublic
	// "verifier" that copies down their public key
	copier := func(haha natrium.EdDSAPublic) bool {
		theirKey = haha
		return true
	}
	sock, err := kiss.KiSSNamedHandshake(srv.prv, copier, raw)
	if err != nil {
		kilog.Debug("directory: client failed KiSS handshake: %v", err.Error())
		return
	}
	defer sock.Close()

	var request clntRequest
	err = struc.Unpack(sock, &request)
	if err != nil {
		kilog.Debug("directory: client sent malformed request: %v", err.Error())
		return
	}
	//fmt.Println(request)
	srv.rqDispatch(sock, request)
}
示例#2
0
func (sg *servGroup) Accept() (io.ReadWriteCloser, error) {
	select {
	case wire := <-sg.wirech:
		return kiss.KiSSNamedHandshake(sg.aidee, nil, wire)
	case <-sg.deadch:
		return nil, io.ErrClosedPipe
	}
}
示例#3
0
// HandleClient is to be called on every incoming connection. It handles KiSS
// but nothing underneath it.
func (ns *NodeState) HandleClient(rawsock io.ReadWriteCloser) error {
	defer rawsock.Close()
	// Do a named KiSS handshake without authentication of the other party
	sok, err := kiss.KiSSNamedHandshake(ns.client.GetPrivate(), nil, rawsock)
	if err != nil {
		return errors.New(fmt.Sprintf("core2core: incoming KiSS handshake failed: %v", err.Error()))
	}
	// Request dispatch loop
	for {
		var req textprot.TextReq
		err := req.ReadFrom(sok)
		if err != nil {
			return nil
		}
		err = ns.dispatchReq(sok, req)
		if err != nil {
			return err
		}
	}
}
示例#4
0
func (dpv dftProv) getSock(clnt Client) io.ReadWriteCloser {
	sock, err := net.Dial("tcp", dpv.url)
	if err != nil {
		kilog.Warning("directory: default provider failed: %v", err.Error())
		return nil
	}
	/*obsok, err := kiss.LLObfsClientHandshake(dpv.PublicKey(), sock)
	if err != nil {
		kilog.Warning("directory: default provider failed: %v", err.Error())
		sock.Close()
		return nil
	}*/
	secsok, err := kiss.KiSSNamedHandshake(clnt.private, kiss.NewDirectVerifier(dpv.PublicKey()), sock)
	if err != nil {
		kilog.Warning("directory: default provider failed: %v", err.Error())
		sock.Close()
		return nil
	}
	return secsok
}
示例#5
0
// EasyListen listens for incoming kiricom connections.
//
// If privkey is nil, then no KiSS would be done, just obfuscation.
func EasyListen(addr string, privkey natrium.EdDSAPrivate, secret []byte) (toret *EasyListener, err error) {
	tcpadd, err := net.ResolveTCPAddr("tcp", addr)
	if err != nil {
		return
	}

	toret = new(EasyListener)

	toret.Addr = tcpadd
	toret.Secret = secret
	toret.core, err = net.ListenTCP("tcp", tcpadd)
	if err != nil {
		return
	}
	toret.deadch = make(chan bool)
	toret.sockch = make(chan io.ReadWriteCloser)

	go func() {
		for {
			lol, err := toret.core.Accept()
			if err != nil {
				return
			}
			lol.(*net.TCPConn).SetNoDelay(true)
			go func() {
				obfs, err := kiss.LLObfsServerHandshake(secret, lol)
				if err != nil {
					kilog.FineDebug("kiricom: EasyListen failed HLObfs: %v", err)
					lol.Close()
					return
				}
				if privkey != nil {
					kss, err := kiss.KiSSNamedHandshake(privkey, nil, obfs)
					if err != nil {
						kilog.FineDebug("kiricom: EasyListen failed KiSS: %v", kss)
						obfs.Close()
						return
					}
					obfs = kss
				}

				state := NewServerCtx(32768, obfs)
				go func() {
					<-toret.deadch
					state.Close()
				}()
				defer state.Close()

				for {
					sok, err := state.Accept()
					if err != nil {
						kilog.Debug("kiricom: EasyListen internal accept error %v", err.Error())
						return
					}
					select {
					case toret.sockch <- sok:
					case <-toret.deadch:
						return
					}
				}
			}()
		}
	}()

	return toret, nil
}