Example #1
0
// 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.d5sAddrStr, GENERAL_SO_TIMEOUT)
	if err != nil {
		return nil, err
	}

	buf := new(bytes.Buffer)
	obf := makeDbcHead(TYPE_DAT, t.nego.rsaKey.SharedKey())
	buf.Write(obf)
	token := t.getToken()
	buf.Write(token)

	setWTimeout(conn)
	_, err = conn.Write(buf.Bytes())
	ThrowErr(err)

	cipher := t.tp.cipherFactory.InitCipher(token)
	c = NewConn(conn.(*net.TCPConn), cipher)
	c.identifier = t.nego.RemoteName()
	return c, nil
}
Example #2
0
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.Cipher, skey)
	hConn.cipher = cf.NewCipher(nil)
	session = NewSession(hConn.Conn, cf, nego)
	setSoTimeout(hConn)
	nego.respondTestWithToken(hConn, session)
	return
}
Example #3
0
// public for external
func Parse_d5s_file(path string) (d5s *D5ServConf, err error) {
	d5s = new(D5ServConf)
	defer func() {
		if e, y := exception.ErrorOf(recover()); y {
			err = e
		}
	}()
	var kParse = func(buf []byte) {
		d5s.rsaKey = parseRSAPrivateKey(buf)
	}
	desc := getImportableDesc(d5s)
	parseConfigFile(path, desc, kParse)
	err = d5s.validate()
	return
}
Example #4
0
// public for external
func Parse_d5c_file(path string) (d5c *D5ClientConf, err error) {
	d5c = new(D5ClientConf)
	defer func() {
		if e, y := exception.ErrorOf(recover()); y {
			err = e
		}
	}()
	var kParse = func(buf []byte) {
		d5c.d5p = parse_d5p(buf)
	}
	desc := getImportableDesc(d5c)
	parseConfigFile(path, desc, kParse)
	err = d5c.validate()
	return
}
Example #5
0
// new connection
func (n *dbcSerNego) handshakeSession(hConn *hashedConn) (session *Session, err error) {
	defer func() {
		// free ibHash
		n.ibHash = nil
		if e, y := exception.ErrorOf(recover()); y {
			log.Warningln("handshake error", e)
			err = e
		}
	}()
	var skey = n.verifyThenDHExchange(hConn)
	var cf = NewCipherFactory(n.Cipher, skey)

	hConn.cipher = cf.InitCipher(n.ibHash)
	session = NewSession(hConn.Conn, cf, n)
	n.isNewSession = true
	n.respondTestWithToken(hConn, session)
	return
}
Example #6
0
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
}
Example #7
0
// 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
}
Example #8
0
func (n *dbcCltNego) negotiate(p *tunParams) (conn *Conn, err error) {
	var rawConn net.Conn
	defer func() {
		// free ibHash
		n.ibHash = nil
		if e, y := exception.ErrorOf(recover()); y {
			SafeClose(rawConn)
			err = e
		}
	}()
	rawConn, err = net.DialTimeout("tcp", n.d5sAddrStr, GENERAL_SO_TIMEOUT)
	ThrowIf(err != nil, D5SER_UNREACHABLE)

	var hConn *hashedConn
	hConn, conn = newHashedConn(rawConn)
	n.requestAuthAndDHExchange(hConn)

	p.cipherFactory = n.finishDHExThenSetupCipher(hConn)
	hConn.cipher = p.cipherFactory.InitCipher(n.ibHash)

	n.validateAndGetTokens(hConn, p)
	return
}