/* Implementation of Accept() in net.Listener iface
 * Additionally creates AR with obtained nonce and returns it
 */
Implementation of Accept() in net.Listener iface
Additionally creates AR with obtained nonce and returns it
/ * Implementation of Accept () in net . Listener iface * Additionally creates AR with obtained nonce and returns it * /
func (ln Listener) Accept() (net.Conn, error) {
	var err error
	var conn net.Conn
	var data []byte
	var resp *ci.AttestationResponse
	conn, err = ln.Ln.Accept()
	if err != nil {
		return nil, err
	}
	_ = conn.SetReadDeadline(time.Now().Add(timeout))
	log.Trace("TLS established. Providing attestation report....")
	data, err = Read(conn)
	if err != nil {
		log.Error(err)
		conn.Close()
		return nil, errors.New("[Listener] Did not receive (right sized) nonce")
	}
	log.Trace("[Listener] Received: ",  hex.EncodeToString(data))
	req := &ci.AttestationRequest{}
	err = proto.Unmarshal(data, req)
	if err != nil {
		log.Error(err)
		conn.Close()
		return nil, errors.New("[Dialer] Failed to parse attestation request.")
	}
	if len(req.Nonce) != noncelen {
		conn.Close()
		return nil, errors.New("[Dialer] Nonce does not have expected size")
	}
	log.Info("[Listener] Contacting backend for AR verification")
	resp, err = obtainAR(req)
	if err != nil {
		log.Error(err)
		conn.Close()
		return nil, errors.New("[Listener] Could not obtain response")
	}
	data, err = proto.Marshal(resp)
	if err != nil {
		log.Error(err)
		conn.Close()
		return nil, errors.New("[Dialer] Failed to marshal response.")
	}
	log.Info("[Listener] Sending AR to client")
	err = Write(data,conn)
	if err != nil {
		log.Error(err)
		conn.Close()
		return nil, errors.New("[Listener] Failed to write AR")
	}
	log.Info("[Listener] Sent AR")
	log.Info("[Listener] Server-side connection complete")
	return conn, nil
}
func ( ln Listener ) Accept ( ) ( net . Conn , error ) { var err error var conn net . Conn var data [ ] byte var resp * ci . AttestationResponse conn , err = ln . Ln . Accept ( ) if err != nil { return nil , err } _ = conn . SetReadDeadline ( time . Now ( ) . Add ( timeout ) ) log . Trace ( " " ) data , err = Read ( conn ) if err != nil { log . Error ( err ) conn . Close ( ) return nil , errors . New ( " " ) } log . Trace ( " " , hex . EncodeToString ( data ) ) req := & ci . AttestationRequest { } err = proto . Unmarshal ( data , req ) if err != nil { log . Error ( err ) conn . Close ( ) return nil , errors . New ( " " ) } if len ( req . Nonce ) != noncelen { conn . Close ( ) return nil , errors . New ( " " ) } log . Info ( " " ) resp , err = obtainAR ( req ) if err != nil { log . Error ( err ) conn . Close ( ) return nil , errors . New ( " " ) } data , err = proto . Marshal ( resp ) if err != nil { log . Error ( err ) conn . Close ( ) return nil , errors . New ( " " ) } log . Info ( " " ) err = Write ( data , conn ) if err != nil { log . Error ( err ) conn . Close ( ) return nil , errors . New ( " " ) } log . Info ( " " ) log . Info ( " " ) return conn , nil }
Implementation of Accept() in net.Listener iface
Additionally creates AR with obtained nonce and returns it
Implementation of Accept () in net . Listener iface Additionally creates AR with obtained nonce and returns it
// Accept TLS connection // Obtain request msg // Parse request msg // Check nonce length // Obtain response // Send response // FUTURE: Receive some sort of Ack (or send if mTLS) // FUTURE: check for mTLS here: if enabled, create and send nonce to connector, receive and verify its AR // finished