Example #1
0
func (mm *MemberMaker) SessionSetup(proposedVersion uint32) (
	cnx *xt.TcpConnection, decidedVersion uint32, err error) {
	var (
		ciphertext1 []byte
		ciphertext2 []byte
	)
	// Set up connection to server. ---------------------------------
	ctor := mm.RegPeer.GetConnector(0)
	// DEBUG
	fmt.Printf("        SessionSetup: ctor is %s\n", ctor.String())
	// END
	var conn xt.ConnectionI
	//conn, err = ctor.Connect(xt.ANY_TCP_END_POINT) // 2016-11-14
	conn, err = ctor.Connect(nil)
	if err == nil {
		cnx = conn.(*xt.TcpConnection)
		// DEBUG
		fmt.Printf("        SessionSetup: cnx is %s\n", cnx.String())
		// END
		var cnxHandler *CnxHandler
		if err == nil {
			cnxHandler, err = NewCnxHandler(cnx, nil, nil)
			if err == nil {
				cnxHandler.State = MEMBER_START
				mm.CnxHandler = *cnxHandler
			}
		}
	}
	if err == nil {
		var cOneShot, cSession *xa.AesSession
		// Send HELLO -----------------------------------------------
		mm.Cnx = cnx
		ck := mm.RegPeer.GetCommsPublicKey()
		rng := xr.MakeSystemRNG()
		cOneShot, ciphertext1, err = xa.ClientEncryptHello(
			proposedVersion, ck, rng)
		if err == nil {
			err = mm.WriteData(ciphertext1)
			// Process HELLO REPLY ----------------------------------
			if err == nil {
				ciphertext2, err = mm.ReadData()

				if len(ciphertext2) == 0 {
					if err == nil {
						err = io.EOF
					}
				}
				if err == nil {
					cSession, decidedVersion,
						err = xa.ClientDecryptHelloReply(cOneShot, ciphertext2)
					if err == nil {
						mm.AesSession = *cSession
					}
				}
			}
		}
	}
	return
}
Example #2
0
func (upc *UpaxClient) SessionSetup(proposedVersion uint32) (
	upcx *xt.TcpConnection, decidedVersion uint32, err error) {
	var (
		ciphertext1, ciphertext2 []byte
		cOneShot, cSession       *xa.AesSession
	)
	rng := xr.MakeSystemRNG()
	// Set up connection to server. -----------------------------
	ctor, err := xt.NewTcpConnector(upc.serverEnd)
	if err == nil {
		var conn xt.ConnectionI
		conn, err = ctor.Connect(nil)
		if err == nil {
			upcx = conn.(*xt.TcpConnection)
		}
	}
	// Send HELLO -----------------------------------------------
	if err == nil {
		upc.Cnx = upcx
		cOneShot, ciphertext1, err = xa.ClientEncryptHello(
			proposedVersion, upc.serverCK, rng)
	}
	if err == nil {
		err = upc.WriteData(ciphertext1)
	}
	// Process HELLO REPLY --------------------------------------
	if err == nil {
		ciphertext2, err = upc.ReadData()
	}
	if err == nil {
		cSession, decidedVersion, err = xa.ClientDecryptHelloReply(
			cOneShot, ciphertext2)
	}
	// Set up AES engines ---------------------------------------
	if err == nil {
		upc.AesSession = *cSession
		upc.Version = xu.DecimalVersion(decidedVersion)
	}
	return
}