Commit 39b87ee
authored
Fix S3 PartialContentInputStream to be compliant to InputStream specification (#2217)
* Make S3 PartialContentInputStream spec-compliant
The PartialContentInputStream was a minimal implementation that worked
well when used directly with the spring byte-range support.
However, using the InputStream variant in any other place (like wrapping it for decryption),
the minimal implementation breaks down, requiring workarounds when
handling the encryption.
Using an implementation that is fully compliant with the InputStream
specifications makes implementation of a wrapping InputStream easier,
as no special provisions need to be made for a read method that
immediately reads the byte-range (instead of empty space before the
start)
* Simplify encryption for byte-range requests
Because an actual compliant InputStream is now returned from
the backing store, encryption can be handled simpler by just running the
cipher for the whole range.
Since encryption is not authenticated, and CTR mode is byte-addressable,
this just works. The zero-bytes before/after the actual data are
decrypted as garbage, but they will be cut out when streaming the
response back to the user.
* Make range-request not aligned to an AES block boundary
Although the testcase works when aligned on a block boundary, the test is more comprehensive when it is not aligned
* Add back block skipping for offsets
Skipping decrypting blocks that do not have data and will be skipped anyways is wasted work.
Reintroduce the technique to calculate IV for a certain block offset to save decryption work for larger offsets
* Use long for file offsets
Using an int limits the offset to about 2GB, which might not be sufficient for very large files.
Using a long results in an offset of 9EB, which should be sufficient.1 parent a6c42d2 commit 39b87ee
File tree
9 files changed
+551
-204
lines changed- spring-content-encryption/src
- main/java
- internal/org/springframework/content/fragments
- org/springframework/content/encryption
- test/java/org/springframework/content/encryption
- s3
- spring-content-s3/src
- main/java/internal/org/springframework/content/s3/io
- test/java/internal/org/springframework/content/s3
- io
- it
9 files changed
+551
-204
lines changedLines changed: 8 additions & 62 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
267 | 266 | | |
268 | 267 | | |
269 | 268 | | |
270 | | - | |
| 269 | + | |
271 | 270 | | |
272 | 271 | | |
273 | 272 | | |
| |||
282 | 281 | | |
283 | 282 | | |
284 | 283 | | |
285 | | - | |
| 284 | + | |
286 | 285 | | |
287 | 286 | | |
288 | 287 | | |
| |||
309 | 308 | | |
310 | 309 | | |
311 | 310 | | |
312 | | - | |
| 311 | + | |
313 | 312 | | |
314 | 313 | | |
315 | 314 | | |
| |||
330 | 329 | | |
331 | 330 | | |
332 | 331 | | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
| 332 | + | |
352 | 333 | | |
353 | 334 | | |
354 | 335 | | |
355 | 336 | | |
356 | 337 | | |
357 | 338 | | |
358 | 339 | | |
359 | | - | |
| 340 | + | |
360 | 341 | | |
361 | 342 | | |
362 | | - | |
363 | | - | |
| 343 | + | |
| 344 | + | |
364 | 345 | | |
365 | 346 | | |
366 | 347 | | |
367 | 348 | | |
368 | 349 | | |
369 | 350 | | |
370 | | - | |
| 351 | + | |
371 | 352 | | |
372 | 353 | | |
373 | 354 | | |
| |||
440 | 421 | | |
441 | 422 | | |
442 | 423 | | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | 424 | | |
479 | 425 | | |
480 | 426 | | |
| |||
Lines changed: 65 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
91 | 90 | | |
92 | 91 | | |
93 | 92 | | |
94 | 93 | | |
95 | | - | |
| 94 | + | |
96 | 95 | | |
97 | 96 | | |
98 | 97 | | |
| |||
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
111 | 112 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 113 | + | |
118 | 114 | | |
119 | | - | |
| 115 | + | |
120 | 116 | | |
| 117 | + | |
121 | 118 | | |
122 | 119 | | |
123 | 120 | | |
| |||
127 | 124 | | |
128 | 125 | | |
129 | 126 | | |
130 | | - | |
| 127 | + | |
131 | 128 | | |
132 | 129 | | |
133 | 130 | | |
| |||
148 | 145 | | |
149 | 146 | | |
150 | 147 | | |
151 | | - | |
152 | | - | |
| 148 | + | |
| 149 | + | |
153 | 150 | | |
154 | 151 | | |
155 | 152 | | |
156 | | - | |
| 153 | + | |
157 | 154 | | |
158 | 155 | | |
159 | 156 | | |
| |||
182 | 179 | | |
183 | 180 | | |
184 | 181 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
198 | 194 | | |
199 | 195 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
205 | 213 | | |
206 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
207 | 221 | | |
208 | 222 | | |
| 223 | + | |
| 224 | + | |
209 | 225 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
218 | 230 | | |
| 231 | + | |
| 232 | + | |
219 | 233 | | |
220 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
221 | 240 | | |
222 | 241 | | |
223 | 242 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
165 | 178 | | |
166 | 179 | | |
167 | 180 | | |
| |||
0 commit comments