예제 #1
0
파일: d5.go 프로젝트: hangim/deblocus
func (nego *d5SNegotiation) handshakeSession(hConn *hashedConn, buf []byte) (session *Session, err error) {
	defer func() {
		if e, y := exception.ErrorOf(recover()); y {
			err = e
		}
	}()
	setSoTimeout(hConn)
	var skey = nego.verifyThenDHExchange(hConn, buf[256:])
	var cf = NewCipherFactory(nego.Algo, skey)
	hConn.cipher = cf.NewCipher(nil)
	session = NewSession(hConn.Conn, cf, nego)
	setSoTimeout(hConn)
	nego.respondTestWithToken(hConn, session)
	return
}
예제 #2
0
파일: d5.go 프로젝트: hangim/deblocus
func (nego *d5CNegotiation) negotiate(p *tunParams) (conn *Conn, err error) {
	var con *net.TCPConn
	defer func() {
		if e, y := exception.ErrorOf(recover()); y {
			SafeClose(con)
			err = e
		}
	}()
	con, err = net.DialTCP("tcp", nil, nego.d5sAddr)
	ThrowIf(err != nil, D5SER_UNREACHABLE)
	setSoTimeout(con)
	var hConn = NewConnWithHash(con)
	conn = hConn.Conn
	nego.requestAuthAndDHExchange(hConn)
	setSoTimeout(con)
	p.cipherFactory = nego.finishDHExThenSetupCipher(hConn)
	hConn.cipher = p.cipherFactory.NewCipher(nil)
	setSoTimeout(con)
	nego.validateAndGetTokens(hConn, p)
	return
}
예제 #3
0
파일: client.go 프로젝트: hangim/deblocus
// must catch exceptions and return
func (t *Client) createDataTun() (c *Conn, err error) {
	defer func() {
		if e, y := ex.ErrorOf(recover()); y {
			err = e
		}
	}()
	conn, err := net.DialTimeout("tcp", t.nego.d5sAddr.String(), GENERAL_SO_TIMEOUT)
	if err != nil {
		return nil, err
	}
	buf := make([]byte, DMLEN2)
	token := t.getToken()
	copy(buf, token)
	buf[TKSZ] = d5Sub(token[TKSZ-2])
	buf[TKSZ+1] = d5Sub(token[TKSZ-1])

	cipher := t.tp.cipherFactory.NewCipher(token)
	_, err = conn.Write(buf)
	ThrowErr(err)
	c = NewConn(conn.(*net.TCPConn), cipher)
	c.identifier = t.nego.RemoteName()
	return c, nil
}