Path: blob/main/crypto/krb5/src/kdc/t_bigreply.py
105585 views
from k5test import *1import struct23# Set the maximum UDP reply size very low, so that all replies go4# through the RESPONSE_TOO_BIG path.5kdc_conf = {'kdcdefaults': {'kdc_max_dgram_reply_size': '10'}}6realm = K5Realm(kdc_conf=kdc_conf, get_creds=False)78msgs = ('Sending initial UDP request',9'Received answer',10'Request or response is too big for UDP; retrying with TCP',11' to KRBTEST.COM (tcp only)',12'Initiating TCP connection',13'Sending TCP request',14'Terminating TCP connection')15realm.kinit(realm.user_princ, password('user'), expected_trace=msgs)16realm.run([kvno, realm.host_princ], expected_trace=msgs)1718# Pretend to send an absurdly long request over TCP, and verify that19# we get back a reply of plausible length to be an encoded20# KRB_ERR_RESPONSE_TOO_BIG error.21s = socket.create_connection((hostname, realm.portbase))22s.sendall(b'\xFF\xFF\xFF\xFF')23lenbytes = s.recv(4)24assert(len(lenbytes) == 4)25resplen, = struct.unpack('>L', lenbytes)26if resplen < 10:27fail('KDC response too short (KRB_ERR_RESPONSE_TOO_BIG error expected)')28resp = s.recv(resplen)29assert(len(resp) == resplen)3031success('Large KDC replies')323334