#!/usr/bin/python3 import socket # Test excess number of exchanges during security negotiation. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(('192.168.122.30', 3260)) send = ( b'\x43' # 00: -> Immediate marker + Login request b'\x00' # 01: -> Continue security negotiation b'\x00' # 02: VersionMax b'\x00' # 03: VersionMin b'\x00' # 04: TotalAHSLength b'\x00\x00\x8c' # 05: DataSegmentLength b'\x0c\xfd\x37\x00\x00\x01' # 08: ISID -> OUI, SUSE, Qualifier=1 b'\x00\x00' # 14: TSIH b'\x00\x00\x00\x00' # 16: InitiatorTaskTag b'\x00\x00' # 20: CID b'\x00\x00' # 22: Reserved b'\x00\x00\x00\x00' # 24: CmdSN b'\x00\x00\x00\x00' # 28: ExpStatSN b'\x00\x00\x00\x00' # 32: Reserved b'\x00\x00\x00\x00' # 36: Reserved b'\x00\x00\x00\x00' # 40: Reserved b'\x00\x00\x00\x00' # 44: Reserved # 48: Login parameters b'InitiatorName=iqn.1996-04.de.suse:01:6fd07434abf9\x00' b'SessionType=Normal\x00' b'TargetName=iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8726b6baa6b9\x00' # 188: Padding to 4 bytes b'' # 188: ) for i in range(1, 8): print(f"Send #{i}: {send}") s.sendall(send) data = s.recv(1024) print(f"Response: {data}") assert data[0] == 0x23 # Opcode assert data[36] == (0 if i < 7 else 3) # Status-Class assert data[37] == 0 # Status-Detail print() # Test excess number of exchanges during operation parameter negotiation. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(('192.168.122.30', 3260)) send = ( b'\x43' # 00: -> Immediate marker + Login request b'\x81' # 01: -> Transfer to operational parameter negotiation b'\x00' # 02: VersionMax b'\x00' # 03: VersionMin b'\x00' # 04: TotalAHSLength b'\x00\x00\x9c' # 05: DataSegmentLength b'\x0c\xfd\x37\x00\x00\x01' # 08: ISID -> OUI, SUSE, Qualifier=1 b'\x00\x00' # 14: TSIH b'\x00\x00\x00\x00' # 16: InitiatorTaskTag b'\x00\x00' # 20: CID b'\x00\x00' # 22: Reserved b'\x00\x00\x00\x00' # 24: CmdSN b'\x00\x00\x00\x00' # 28: ExpStatSN b'\x00\x00\x00\x00' # 32: Reserved b'\x00\x00\x00\x00' # 36: Reserved b'\x00\x00\x00\x00' # 40: Reserved b'\x00\x00\x00\x00' # 44: Reserved # 48: Login parameters b'InitiatorName=iqn.1996-04.de.suse:01:6fd07434abf9\x00' b'SessionType=Normal\x00' b'TargetName=iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8726b6baa6b9\x00' b'AuthMethod=None\x00' # 204: Padding to 4 bytes b'' # 204: ) print(f"Send #1: {send}") s.sendall(send) data = s.recv(1024) print(f"Response: {data}") assert data[0] == 0x23 # Opcode assert data[1] == 0x81 # -> Transfer to operational parameter negotiation assert data[36] == 0 # Status-Class assert data[37] == 0 # Status-Detail send = ( b'\x43' # 00: -> Immediate marker + Login request b'\x04' # 01: -> Continue operational parameter negotiation b'\x00' # 02: VersionMax b'\x00' # 03: VersionMin b'\x00' # 04: TotalAHSLength b'\x00\x00\x12' # 05: DataSegmentLength b'\x0c\xfd\x37\x00\x00\x01' # 08: ISID -> OUI, SUSE, Qualifier=1 b'\x00\x00' # 14: TSIH b'\x00\x00\x00\x00' # 16: InitiatorTaskTag b'\x00\x00' # 20: CID b'\x00\x00' # 22: Reserved b'\x00\x00\x00\x00' # 24: CmdSN b'\x00\x00\x00\x00' # 28: ExpStatSN b'\x00\x00\x00\x00' # 32: Reserved b'\x00\x00\x00\x00' # 36: Reserved b'\x00\x00\x00\x00' # 40: Reserved b'\x00\x00\x00\x00' # 44: Reserved # 48: Login parameters b'HeaderDigest=None\x00' # 66: Padding to 4 bytes b'\x00\x00' # 68: ) for i in range(2, 9): print(f"Send #{i}: {send}") s.sendall(send) data = s.recv(1024) print(f"Response: {data}") assert data[0] == 0x23 assert data[36] == (0 if i < 8 else 3) # Status-Class assert data[37] == 0 # Status-Detail