1# -*- mode: perl; -*-
2# Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the Apache License 2.0 (the "License").  You may not use
5# this file except in compliance with the License.  You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
9
10## Test packet fragmentation
11
12use strict;
13use warnings;
14
15package ssltests;
16
17our $fips_3_4;
18
19our @tests = (
20    # Default fragment size is 512.
21    {
22        name => "one-fragment-minus-app-data",
23        server => { },
24        client => { },
25        test => {
26            ApplicationData => 511,
27        }
28    },
29    {
30        name => "one-fragment-app-data",
31        server => { },
32        client => { },
33        test => {
34            ApplicationData => 512,
35        }
36    },
37    {
38        name => "one-fragment-plus-app-data",
39        server => { },
40        client => { },
41        test => {
42            ApplicationData => 513,
43        }
44    },
45    {
46        name => "small-app-data",
47        server => { },
48        client => { },
49        test => {
50            ApplicationData => 4 * 1024 + 1,
51        }
52    },
53    {
54        name => "small-app-data-large-fragment-size",
55        server => { },
56        client => { },
57        test => {
58            ApplicationData => 4 * 1024 + 1,
59            MaxFragmentSize => 16384,
60        }
61    },
62    {
63        name => "medium-app-data",
64        server => { },
65        client => { },
66        test => {
67            ApplicationData => 32 * 1024 + 7,
68        }
69    },
70    # Exceeds the 64kB write buffer size.
71    {
72        name => "medium-plus-app-data",
73        server => { },
74        client => { },
75        test => {
76            ApplicationData => 128 * 1024 - 3,
77        }
78    },
79    {
80        name => "large-app-data",
81        server => { },
82        client => { },
83        test => {
84            ApplicationData => 1024 * 1024,
85        }
86    },
87    {
88        name => "large-app-data-large-fragment-size",
89        server => { },
90        client => { },
91        test => {
92            ApplicationData => 1024 * 1024,
93            MaxFragmentSize => 16384,
94        }
95    },
96    {
97        name => "large-app-data-odd-fragment-size",
98        server => { },
99        client => { },
100        test => {
101            ApplicationData => 1024 * 1024,
102            MaxFragmentSize => 5 * 1024 - 5,
103        }
104    },
105    ############################################
106    # Default (Max) Fragment Size is 512.
107    # Default Application data size is 256.
108    {
109        name => "Maximum Fragment Len extension set to 1024 w. FragmentSize disabled",
110        server => { },
111        client => {
112            extra => {
113                MaxFragmentLenExt => 1024,
114            },
115        },
116        test => {
117            ApplicationData => 3072,
118            MaxFragmentSize => 16384,
119        }
120    },
121    {
122        name => "Maximum Fragment Len extension equal FragmentSize to 2048",
123        server => { },
124        client => {
125            extra => {
126                MaxFragmentLenExt => 2048,
127            },
128        },
129        test => {
130            ApplicationData => 3072,
131            MaxFragmentSize => 2048,
132        }
133    },
134    {
135        name => "Maximum Fragment Len extension 512 lower than FragmentSize 1024",
136        server => { },
137        client => {
138            extra => {
139                MaxFragmentLenExt => 512,
140            },
141        },
142        test => {
143            ApplicationData => 3072,
144            MaxFragmentSize => 1024,
145        }
146    },
147    {
148        name => "Maximum Fragment Len extension 1024 lower than FragmentSize 1024",
149        server => { },
150        client => {
151            extra => {
152                MaxFragmentLenExt => 2048,
153            },
154        },
155        test => {
156            ApplicationData => 3072,
157            MaxFragmentSize => 1024,
158        }
159    },
160    {
161        name => "Maximum Fragment Len extension 4096 greater than FragmentSize 2048",
162        server => { },
163        client => {
164            extra => {
165                MaxFragmentLenExt => 4096,
166            },
167        },
168        test => {
169            ApplicationData => 8196,
170            MaxFragmentSize => 2048,
171        }
172    },
173    {
174        name => "Maximum Fragment Len extension 2048 greater than FragmentSize 1024",
175        server => { },
176        client => {
177            extra => {
178                MaxFragmentLenExt => 2048,
179            },
180        },
181        test => {
182            ApplicationData => 3072,
183            MaxFragmentSize => 1024,
184        }
185    },
186);
187
188# Tests using RSA key exchange
189my @tests_rsa = (
190    # When the buffer / fragment size ratio is sufficiently large,
191    # multi-buffer code kicks in on some platforms for AES-SHA.  The
192    # exact minimum ratio depends on the platform, and is usually
193    # around 4. Since the test buffer is 64kB, a 4kB fragment is
194    # easily sufficient.
195    #
196    # (We run this test on all platforms though it's only true multibuffer
197    #  on some of them.)
198    {
199        name => "large-app-data-aes-sha1-multibuffer",
200        server => { },
201        client => {
202            CipherString => "AES128-SHA",
203            MaxProtocol => "TLSv1.2"
204        },
205        test => {
206            ApplicationData => 1024 * 1024,
207            MaxFragmentSize => 4 * 1024,
208        }
209    },
210    {
211        name => "large-app-data-aes-sha2-multibuffer",
212        server => { },
213        client => {
214            CipherString => "AES128-SHA256",
215            MaxProtocol => "TLSv1.2"
216        },
217        test => {
218            ApplicationData => 1024 * 1024,
219            MaxFragmentSize => 4 * 1024,
220        }
221    },
222        {
223        name => "large-app-data-aes-sha1-multibuffer-odd-fragment",
224        server => { },
225        client => {
226            CipherString => "AES128-SHA",
227            MaxProtocol => "TLSv1.2"
228        },
229        test => {
230            ApplicationData => 1024 * 1024 + 3,
231            MaxFragmentSize => 5 * 1024 - 5,
232        }
233    },
234    {
235        name => "large-app-data-aes-sha2-multibuffer-odd-fragment",
236        server => { },
237        client => {
238            CipherString => "AES128-SHA256",
239            MaxProtocol => "TLSv1.2"
240        },
241        test => {
242            ApplicationData => 1024 * 1024 - 3,
243            MaxFragmentSize => 5 * 1024 + 5,
244        }
245    },
246    # Test that multibuffer-capable code also handles small data correctly.
247    # Here fragment size == app data size < buffer size,
248    # so no multibuffering should happen.
249    {
250        name => "small-app-data-aes-sha1-multibuffer",
251        server => { },
252        client => {
253            CipherString => "AES128-SHA",
254            MaxProtocol => "TLSv1.2"
255        },
256        test => {
257            ApplicationData => 4 * 1024,
258            MaxFragmentSize => 4 * 1024,
259        }
260    },
261    {
262        name => "small-app-data-aes-sha2-multibuffer",
263        server => { },
264        client => {
265            CipherString => "AES128-SHA256",
266            MaxProtocol => "TLSv1.2"
267        },
268        test => {
269            ApplicationData => 4 * 1024,
270            MaxFragmentSize => 4 * 1024,
271        }
272    }
273);
274
275push @tests, @tests_rsa
276    unless $fips_3_4;
277