Commit 49f84e6
authored
[PM-2460/24639] Allow empty arrays, and fix string plaintext length hiding (#379)
## 🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-24640
https://bitwarden.atlassian.net/browse/PM-24639
## 📔 Objective
`""` is a valid value to encrypt, and the current vault code in clients
*sometimes* does encrypt `""` (and sometimes just returns null). This
was not anticipated when writing the padding initially. This changes the
padding to allow padding empty byte arrays.
Further, it seems the block padding for strings was done incorrectly and
only hides the first block's plaintext length, but afterwards has a 1:1
correlation to plaintext length:
Before:
```
String Length -> EncString Length
================================
0 -> 194
1 -> 194
2 -> 194
3 -> 194
4 -> 194
5 -> 194
6 -> 194
7 -> 194
8 -> 194
9 -> 194
10 -> 194
11 -> 194
12 -> 194
13 -> 194
14 -> 194
15 -> 194
16 -> 194
17 -> 194
18 -> 194
19 -> 194
20 -> 194
21 -> 194
22 -> 194
23 -> 194
24 -> 194
25 -> 194
26 -> 194
27 -> 194
28 -> 194
29 -> 194
30 -> 194
31 -> 194
32 -> 198
33 -> 198
34 -> 198
35 -> 202
36 -> 202
37 -> 202
38 -> 206
39 -> 206
40 -> 206
41 -> 210
42 -> 210
43 -> 210
44 -> 214
45 -> 214
46 -> 214
47 -> 218
48 -> 218
49 -> 218
50 -> 222
51 -> 222
52 -> 222
53 -> 226
54 -> 226
55 -> 226
56 -> 230
57 -> 230
58 -> 230
59 -> 234
60 -> 234
61 -> 234
62 -> 238
63 -> 238
64 -> 238
65 -> 242
66 -> 242
67 -> 242
68 -> 246
69 -> 246
70 -> 246
71 -> 250
72 -> 250
73 -> 250
74 -> 254
75 -> 254
76 -> 254
77 -> 258
78 -> 258
79 -> 258
80 -> 262
```
After:
```
String Length -> EncString Length
================================
0 -> 194
1 -> 194
2 -> 194
3 -> 194
4 -> 194
5 -> 194
6 -> 194
7 -> 194
8 -> 194
9 -> 194
10 -> 194
11 -> 194
12 -> 194
13 -> 194
14 -> 194
15 -> 194
16 -> 194
17 -> 194
18 -> 194
19 -> 194
20 -> 194
21 -> 194
22 -> 194
23 -> 194
24 -> 194
25 -> 194
26 -> 194
27 -> 194
28 -> 194
29 -> 194
30 -> 194
31 -> 194
32 -> 238
33 -> 238
34 -> 238
35 -> 238
36 -> 238
37 -> 238
38 -> 238
39 -> 238
40 -> 238
41 -> 238
42 -> 238
43 -> 238
44 -> 238
45 -> 238
46 -> 238
47 -> 238
48 -> 238
49 -> 238
50 -> 238
51 -> 238
52 -> 238
53 -> 238
54 -> 238
55 -> 238
56 -> 238
57 -> 238
58 -> 238
59 -> 238
60 -> 238
61 -> 238
62 -> 238
63 -> 238
64 -> 282
65 -> 282
66 -> 282
67 -> 282
68 -> 282
69 -> 282
70 -> 282
71 -> 282
72 -> 282
73 -> 282
74 -> 282
75 -> 282
76 -> 282
77 -> 282
78 -> 282
79 -> 282
80 -> 282
```
Both of these changes don't break compatibility. However, even if they
did, the code is not rolled out yet so it would be OK.
## ⏰ Reminders before review
- Contributor guidelines followed
- All formatters and local linters executed and passed
- Written new unit and / or integration tests where applicable
- Protected functional changes with optionality (feature flags)
- Used internationalization (i18n) for all UI strings
- CI builds passed
- Communicated to DevOps any deployment requirements
- Updated any necessary documentation (Confluence, contributing docs) or
informed the documentation
team
## 🦮 Reviewer guidelines
<!-- Suggested interactions but feel free to use (or not) as you desire!
-->
- 👍 (`:+1:`) or similar for great changes
- 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info
- ❓ (`:question:`) for questions
- 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry
that's not quite a confirmed
issue and could potentially benefit from discussion
- 🎨 (`:art:`) for suggestions / improvements
- ❌ (`:x:`) or 1 parent ae9b9f1 commit 49f84e6
File tree
4 files changed
+189
-9
lines changed- crates/bitwarden-crypto/src
- enc_string
- keys
4 files changed
+189
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
367 | 405 | | |
368 | 406 | | |
369 | 407 | | |
| |||
390 | 428 | | |
391 | 429 | | |
392 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
393 | 457 | | |
394 | 458 | | |
395 | 459 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
382 | | - | |
383 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
25 | 31 | | |
26 | 32 | | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
34 | | - | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
71 | 86 | | |
72 | 87 | | |
73 | 88 | | |
74 | 89 | | |
75 | 90 | | |
76 | 91 | | |
77 | 92 | | |
78 | | - | |
| 93 | + | |
79 | 94 | | |
80 | 95 | | |
81 | 96 | | |
82 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
83 | 196 | | |
0 commit comments