We start the SASL authentication by asking the memcached server for the mechanisms it supports. This is achieved by sending the following packet:
Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| 80 | 20 | 00 | 00 | +---------------+---------------+---------------+---------------+ 4| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 8| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 12| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 16| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 20| 00 | 00 | 00 | 00 |
Header breakdown Field (offset) (value) Magic (0): 0x80 (PROTOCOL_BINARY_REQ) Opcode (1): 0x20 (sasl list mechs) Key length (2-3): 0x0000 (0) Extra length (4): 0x00 Data type (5): 0x00 vBucket (6-7): 0x0000 (0) Total body (8-11): 0x00000000 (0) Opaque (12-15): 0x00000000 (0) CAS (16-23): 0x0000000000000000 (0)
If the server supports SASL authentication the following packet is returned:
Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| 81 | 20 | 00 | 00 | +---------------+---------------+---------------+---------------+ 4| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 8| 00 | 00 | 00 | 05 | +---------------+---------------+---------------+---------------+ 12| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 16| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 20| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 24| 50 ('P') | 4c ('L') | 41 ('A') | 49 ('I') | +---------------+---------------+---------------+---------------+
28| 4e ('N') |
Header breakdown Field (offset) (value) Magic (0): 0x81 (PROTOCOL_BINARY_RES) Opcode (1): 0x20 (sasl list mechs) Key length (2-3): 0x0000 (0) Extra length (4): 0x00 Data type (5): 0x00 Status (6-7): 0x0000 (SUCCESS) Total body (8-11): 0x00000005 (5) Opaque (12-15): 0x00000000 (0) CAS (16-23): 0x0000000000000000 (0) Mechanisms (24-28): PLAIN
Please note that the server may support a different set of mechanisms. The list of mechanisms is a space-separated list of SASL mechanism names (e.g. "PLAIN CRAM-MD5 GSSAPI").