@@ -707,6 +707,25 @@ export const Channel = GObject.registerClass({
707707 return this . _authenticate ( connection ) ;
708708 }
709709
710+ async _exchangeIdentities ( ) {
711+ await this . sendPacket ( this . backend . identity ) ;
712+ const identity = await this . readPacket ( ) ;
713+
714+ if ( this . identity . body . protocolVersion !== identity . body . protocolVersion ) {
715+ this . identity = null ;
716+ throw new Error ( `Unexpected protocol version ${ identity . protocolVersion } ; ` +
717+ `handshake started with protocol version ${ this . identity . protocolVersion } ` ) ;
718+ }
719+
720+ if ( this . identity . body . deviceId !== identity . body . deviceId ) {
721+ this . identity = null ;
722+ throw new Error ( `Unexpected device ID "${ identity . body . deviceId } "; ` +
723+ `handshake started with device ID "${ this . identity . body . deviceId } "` ) ;
724+ }
725+
726+ this . identity = identity ;
727+ }
728+
710729 /**
711730 * Negotiate an incoming connection
712731 *
@@ -755,8 +774,7 @@ export const Channel = GObject.registerClass({
755774 // Starting with protocol version 8, the devices are expected to
756775 // exchange identity packets again after TLS negotiation
757776 if ( this . identity . body . protocolVersion >= 8 ) {
758- await this . sendPacket ( this . backend . identity ) ;
759- this . identity = await this . readPacket ( ) ;
777+ await this . _exchangeIdentities ( ) ;
760778 }
761779 } catch ( e ) {
762780 this . close ( ) ;
@@ -786,8 +804,7 @@ export const Channel = GObject.registerClass({
786804 // Starting with protocol version 8, the devices are expected to
787805 // exchange identity packets again after TLS negotiation
788806 if ( this . identity . body . protocolVersion >= 8 ) {
789- await this . sendPacket ( this . backend . identity ) ;
790- this . identity = await this . readPacket ( ) ;
807+ await this . _exchangeIdentities ( ) ;
791808 }
792809 } catch ( e ) {
793810 this . close ( ) ;
0 commit comments